Definition : We use temperature sensor to construct a circuit to determine temperature value by leds. If our sensor reads a value that is smaller than 23 degree, our light will be green, if it is equal to 22, we have yellow and if it is greater than 22, we have red light.
Circuit Diagram
Components:
- 1 x Temperature Sensor
- 3 x LED ( Green, Yellow, Red)
- 3 x 330 Ω Resistor
- Uno board
- Wires
Code :
const int temperaturePin = 0;
int green = 9;
int yellow = 10;
int red = 11;
void setup()
{
pinMode(green,OUTPUT);
pinMode(yellow,OUTPUT);
pinMode(red,OUTPUT);
Serial.begin(9600);
}
void loop()
{
float voltage,
degreesC, degreesF;
voltage =
getVoltage(temperaturePin);
degreesC = (voltage
- 0.5) * 100.0;
degreesF = degreesC
* (9.0/5.0) + 32.0;
if(degreesC<22) {
digitalWrite(green,HIGH);
digitalWrite(yellow,LOW);
}
else if
(degreesC<23) {
digitalWrite(green,LOW);
digitalWrite(yellow,HIGH);
digitalWrite(red,LOW);
}
if(degreesC>23) {
digitalWrite(green,LOW);
digitalWrite(yellow,LOW);
digitalWrite(red,HIGH);
}
Serial.print("voltage: ");
Serial.print(voltage);
Serial.print(" deg C:
");
Serial.print(degreesC);
Serial.print(" deg F:
");
Serial.println(degreesF);
delay(1000); //
repeat once per second (change as you wish!)
}
float getVoltage(int pin)
{
return
(analogRead(pin) * 0.004882814);
}
Video
Hiç yorum yok:
Yorum Gönder