I'll get straight to the point, I'm trying to create a relay to turn on and off a light bulb - controlled by a TMP36 temperature sensor. I am a complete beginner. My sensor is outputting negative values, and are incredibly in accurate.
My code is as follows, I've also attached my schematic below.
int sensorPin = A0;
int relay = 6;
- pinMode(relay, OUTPUT);*
*void loop() *
- int reading = analogRead(sensorPin); *
_ float voltage = reading * 5.0;_
- voltage /= 1024.0;*
- Serial.print(voltage); Serial.println(" volts");*
_ float temperatureC = (voltage - 0.5) * 100 ;_
- Serial.print(temperatureC); Serial.println(" degrees C");*
- if (temperatureC <= 25)*
- digitalWrite(relay, HIGH);*
- digitalWrite(relay, LOW);*
The temperature sensor does not seem to be working well with the relay, and I'm not sure whether I have the code correct for that.
How do I get the sensor to output the correct values, and is my code correct for it to communicate with the relay?
Thank you anyone who can help.