Assignment: DC Motor: Actuation Assignment 1
Collaborators:
Description
I got out of bed late this morning. The alarm went off, but I slept through it. Well, no more. For this project, I created a light sensitive, vibrating, beeping alarm, and in consideration of my neighbors, it is only active when my empty coffee cup is on the bed side table.
Materials
- photocell
- motor
- FSR
- resistors
- battery pack
- cork
- arduino
Programs
Arduino
/*
* Ben C.
* Coffee Cup Present? Alarm is photo sensitive!
*/
int photoPin = 0; // the photocell
int fsrPin = 1; // The fsrpin
int motorPin = 9; // the motor
int speakerPin = 7; // the speaker
int val = 0; // variable to store the value coming from the photocell
int fsrVal = 0;
boolean cupPresent = false;
boolean dark = false;
void setup() {
pinMode(speakerPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
fsrVal = analogRead(fsrPin);
cupPresent = iscuppresent(fsrVal);
if(cupPresent)
{
val = analogRead(photoPin); // read the value from the sensor, between 0 - 1024
dark = isitdark(val);
if (!dark)
{
Serial.println(val);
analogWrite(motorPin, val/4); // analogWrite can be between 0-255
for( int i=0; i<50; i++ ) { // play it for 5 cycles
digitalWrite(speakerPin, HIGH);
delayMicroseconds(val);
digitalWrite(speakerPin, LOW);
delayMicroseconds(val);
}
}
else
{
analogWrite(motorPin, 0);
}
}
else
{
digitalWrite(speakerPin, LOW);
analogWrite(motorPin, 0);
}
}
boolean iscuppresent(int val)
{
int threshhold = 100;
if (val > threshhold)
{
return true;
}
return false;
}
boolean isitdark(int val)
{
int threshhold = 100;
if (val < threshhold)
{
return true;
}
return false;
}