For my minor project I made a temperature reading device that returns the temperature every hour of the room it is placed in.
Photo:
Code:
const int temperaturePin = 0;
#include <EEPROM.h>
int addr = 0;
int time = 16; //Manually input the hour from what time (in 24 hours) the program will begin running (in this case starting reading at 4pm)
void setup()
{
Serial.begin(9600);
}
void loop()
{
float voltage, degreesC, degreesF;
int val = analogRead(0) / 4; //EEPROM so results so can be recovered if Arduino turns off
voltage = getVoltage(temperaturePin);
degreesC = (voltage - 0.5) * 100.0; //reads arduons voltage, and calculates that into celcius
EEPROM.write(addr, val);
if (time < 24) //If time is below 24 (or 0000/midnight) time arduino reads the temperature and displays
//what the hour is, and the current temperature
{
Serial.print("The hour is: ");
Serial.print(time);
Serial.print('\n');
time += 1; //Increases time display by an hour for next reading
Serial.print("The degrees in Celcius is: ");
Serial.print(degreesC);
Serial.print('\n');
Serial.print('\n');
}
else if (time -= 24) //If time reaches midnight, the program resets the display back to 0/midnight
{
time == 0; //sets time to midnight
Serial.print("The hour is: ");
Serial.print(time);
Serial.print('\n');
Serial.print("The degrees in Celcius is: ");
Serial.print(degreesC);
Serial.print('\n');
Serial.print('\n');
}
addr = addr + 1;
if (addr == 512)
addr = 0;
delay(3600000); //wait 1 hour
}
float getVoltage(int pin)
{
return (analogRead(pin) * 0.004882814);
}
Displayed Result:
Problems:
I came across two main problems while making this project.
1) I could not figure out how to get the EEPROM fully running, so if the Arduino loses power, the information recorded could still be retrieved.
2) I could not find a way to read the actual time from your computer, so I had to make the time be manually input by the user.


No comments:
Post a Comment