LUOBIN_HOMEWORK

 

This device is using Arduino, a photocell, an accelerometer, and a LCD. The goal is to help people to take more stable shots of photo/video by notification. In a darker environment, the helper will tell user to hold steady until it’s stable enough to take a clear photo. The helper will automatically turns off when there’s enough light.

The photocell senses the lightness of the environment. A line code is checking the value, if the value is low enough, it will check the realtime reading from accelerometer and give out suggestions.

Test without enclosure…………………………………

breadboard…………………………………..

wire_bbschematic…………………………………………….

 

 

code………………………………………………….

/******************************************************************************
*
* peterobbin
*
* Courtesy To:
* SFE_MMA8452Q Library Basic Example Sketch
* Jim Lindblom @ SparkFun Electronics
* Original Creation Date: June 3, 2014
* https://github.com/sparkfun/MMA8452_Accelerometer
*
* This sketch uses the SFE_MMA8452Q library to initialize the
* accelerometer, and stream values from it.
******************************************************************************/
#include <Wire.h> // Must include Wire library for I2C
#include <SFE_MMA8452Q.h> // Includes the SFE_MMA8452Q library

// Begin using the library by creating an instance of the MMA8452Q
MMA8452Q accel;

float lastasValue;
float asValue;
float asThreshold = 0.015;
float lightThreshold = 220;
int photocellPin = A0;
int pcValue;
// include the library code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

// The setup function simply starts serial and initializes the
// accelerometer.
void setup()
{
Serial.begin(9600);
Serial.println(“MMA8452Q Test Code!”);

accel.init();

// set up the LCD’s number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
//lcd.print(“HOLD STEADY”);
}
void loop()
{

pcValue = analogRead(photocellPin);
Serial.println(pcValue);

// Use the accel.available() function to wait for new data
// from the accelerometer.
if (accel.available())
{
// First, use accel.read() to read the new variables:
accel.read();

// accel.read() will update two sets of variables.
// * int’s x, y, and z will store the signed 12-bit values
// read out of the accelerometer.
// * floats cx, cy, and cz will store the calculated
// acceleration from those 12-bit values. These variables
// are in units of g’s.
if (pcValue < lightThreshold){
printCalculatedAccels();
lcd.setCursor(13, 1);
lcd.print(” ON”);
}
else{
lcd.setCursor(0, 0);
lcd.print(“STABILIZE HELPER”);
lcd.setCursor(13, 1);
lcd.print(“OFF”);
}

printOrientation();
Serial.println();
}
}

void printCalculatedAccels()
{
lastasValue = asValue;
asValue = accel.cz;
float a = asValue – lastasValue;
float compareValue = abs(a);
Serial.print(compareValue, 3);
Serial.print(“\t”);
Serial.print(accel.cx, 3);
Serial.print(“\t”);
Serial.print(accel.cy, 3);
Serial.print(“\t”);
Serial.print(accel.cz, 3);
Serial.print(“\t”);
if(compareValue > asThreshold){
lcd.setCursor(0, 0);
lcd.print(“HOLD STEADY “);
}
else{
lcd.setCursor(0, 0);
lcd.print(“OKAY TO SHOOT “);
}

lcd.setCursor(0, 1);
lcd.print(compareValue);
}

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *