This project allows you to use LED’s as a way to display temperature information.
Functional Parts in the Project:
- Arduino Uno – https://store.arduino.cc/usa/arduino-uno-rev3
- HC-SR204 Ultrasonic Sensor – https://amzn.to/31AGgYC
- Breadboard Kit – https://amzn.to/2Xih5ei
- Analog Temperature Sensor – https://amzn.to/2Rkkl3k
- 220 Ohm Resistors – https://amzn.to/2RiiMD9
- LED’s – https://amzn.to/2Rjhs2N
#define sensorPin A0
#define greenLED 8
#define yellowLED 9
#define redLED 10
void setup()
{
pinMode(greenLED, OUTPUT);
pinMode(yellowLED, OUTPUT);
pinMode(redLED, OUTPUT);
Serial.begin(9600);
}
void loop()
{
int reading = analogRead(sensorPin);
float voltage = reading * 5.0;
voltage /= 1024.0;
float temperatureC = (voltage - 0.5) * 100 ;
float temperatureF = (temperatureC * 9.0 / 5.0) + 32.0;
Serial.print(voltage); Serial.print(" volts - ");
Serial.print(temperatureC); Serial.print(" degrees C - ");
Serial.print(temperatureF); Serial.println(" degrees F");
if (temperatureF >= 75) {
digitalWrite(greenLED, LOW);
digitalWrite(yellowLED, LOW);
digitalWrite(redLED, HIGH);
}
else if (temperatureF >= 70 && temperatureF < 75) {
digitalWrite(greenLED, LOW);
digitalWrite(yellowLED, HIGH);
digitalWrite(redLED, LOW);
}
else {
digitalWrite(greenLED, HIGH);
digitalWrite(yellowLED, LOW);
digitalWrite(redLED, LOW);
}
delay(3000);
}
Be the first to comment