Disclaimer-- There is an issue with my DC Motor because it does not respond to analogWrite correctly. It only starts to function after I've gotten to the 500 threshold out of 1200. This is something that I did not expect with this project, so I would like to request a new DC Motor when I get to class.
Description
I wanted this assignment to be a fan that turns off when you go to sleep. When the lights go out, the fan starts spinning. At first,I wanted it to be variable speed. However, that wasn't possible because there are issues with my hardware. Instead, I hard coded the 500 value for analogWrite to enable the DC Motor Fan. When the photoresister detects a value under 500, it turns the fan on. This is a source of soothing white noise and air circulation that the user sorely needs. I experimented with an actual spinning blade toy, but it kept flying off when it got faster. Instead, I used tape to symbolize the spinning blade. I then figured out a way to keep the flying wing on the device.
I also used a sound test to see if my Arduino was to blame for the malfunctioning motor. It showed that the motor only turns on when it gets to a threshold (and doesn't spin faster or slower). I would like to figure out why this is the case when I come in this week. I also tried using another Arduino, and the power didn't transfer correctly. Could it be the breadboard I am using?
Materials Used
1x Fan Blade Toy Topper
1x 10k Ohm Resistor
1x Photoresistor
1x Piezo Speaker
1x Arduino Uno
Code
/*
* one pot fades one motor
* modified version of AnalogInput
* by DojoDave <http://www.0j0.org>
* http://www.arduino.cc/en/Tutorial/AnalogInput
* Modified again by dave
*/
int sensorPin = 5; // select the input pin for the potentiometer
int motorPin = 8; // select the pin for the Motor
int speakerPin = 9;
int val = 0; // variable to store the value coming from the sensor
int val2 = 0; // variable to store the value coming from the sensor
void setup() {
Serial.begin(9600);
pinMode(speakerPin, OUTPUT);
pinMode(8, OUTPUT);
pinMode(A5, INPUT);
}
void loop() {
val = analogRead(sensorPin); // read the value from the sensor, between 0 - 1024
// SOUND TEST TO TROUBLESHOOT DC MOTOR
// digitalWrite(speakerPin, LOW);
// val2 = val*2; // process the value a little
// for( int i=0; i<50; i++ ) { // play it for 50 cycles
// digitalWrite(speakerPin, HIGH);
// delayMicroseconds(val2);
// digitalWrite(speakerPin, LOW);
// delayMicroseconds(val2);
// }
// Serial.println(val2);
Serial.println(val);
if (val <= 500) {
analogWrite(motorPin, 250); // analogWrite can be between 0-255
} else {
analogWrite(motorPin, 0);
}
}
- Login to post comments