Arduino Challenge Week 6
For my challenge I decided to work with a motor and a thermometer. This way I could build a fan that can turn on whenever it hits a certain temperature.
1. thermometer read and spits out temperature on the screen
2. motor read temperature and either turns on or off
3. found great amount of trouble but the "If, and Else If" statements saved the date!
const int temperaturePin = 0;
const int motorPin = 9;
void setup()
{
Serial.begin(9600);
pinMode(motorPin, OUTPUT);
}
void loop()
{
float voltage, degreesC, degreesF;
voltage = getVoltage(temperaturePin);
degreesC = (voltage - 0.5) * 100.0;
degreesF = degreesC * (9.0/5.0) + 32.0;
//printout
Serial.print("voltage: ");
Serial.print(voltage);
Serial.print(" deg C: ");
Serial.print(degreesC);
Serial.print(" deg F: ");
Serial.println(degreesF);
if (degreesF > 77){
digitalWrite(motorPin, HIGH);
}
else if (degreesF <77)
{
digitalWrite(motorPin, LOW);
}
delay (3000);
}
float getVoltage(int pin)
{
return (analogRead(pin) * 0.004882814);
}
part 1
Part 2
part 3
The coding part was at the end the easiest part to work with. What I had an issue was getting constant readings due to the flow of electricity to the motor the thermometer gave me crazy readings.
THE SOLUTION was! Drum roll!
Space out the readings change the delay to really spaced out times. Began with 1000 but settled with 3000, but for better results 10000 would be better. I figured this would let the temperature settle and and readings more constant and accurate.
If anyone knows how to fix that reading of temperature let me know! thank you!

Comments
Post a Comment