I've designed this system which is supposed to turn on the LEDs when the temperature of a particular probe exceeds 32 degrees. From what I can tell, this should be functional but the analog sensor is always reading 0 when calling analogRead() on the pin.
Here is an image of my circuit:
and my code:
int length = 5;
float airTemp = 32;
void setup()
{
Serial.begin(9600);
}
void loop()
{
// loads current temperature into array
int reading;
float voltage;
float temp[length];
for (int i = 0; i < length; i++)
{
reading = analogRead(i);
Serial.print(reading);
voltage = reading * 5.0;
voltage /= 1024;
temp[i] = (voltage - 0.5) * 100;
}
// turns on/off fans based on current temperature
for (int i = 0; i < length; i++)
{
pinMode(i, OUTPUT);
if (temp[i] > airTemp)
{
digitalWrite(i + 8, HIGH);
}
else if(temp[i] <= airTemp)
{
digitalWrite(i + 8, LOW);
}
}
delay(1000);
}
I learned how to read the temperature from here. It's probably a dumb mistake, but I just started working with Arduino yesterday and I couldn't find information anywhere so thanks in advance.
-
Nice example @user2985955. Did you know you can improve the precision of the analog readings by using an aref voltage? See tronixstuff.com/2013/12/12/… and 123d.circuits.io/circuits/1147792-simple-temperature-sensorJan H– Jan H2015年10月29日 21:30:07 +00:00Commented Oct 29, 2015 at 21:30
3 Answers 3
The image on the linked tutorial has the middle pin of the TMP036 going to the analog input, whereas you have it going to 5V, so that is not going to help one bit.
In other words, it is wired wrongly.
-
Thanks. I realized this just before you answered and posted some pictures to help anyone else.Mikey G– Mikey G2015年10月29日 20:37:55 +00:00Commented Oct 29, 2015 at 20:37
Make sure your breadboard isn't one of the ones with split power rails. If the coloured lines on the + and GND rails have a break in them you will need to bridge that break with wire.
Solid rail:
Split rail:
-
Right now I've only designed the circuit online in an emulator which has a solid rail. I'm pretty sure it is a programming problem on my end.Mikey G– Mikey G2015年10月29日 20:01:08 +00:00Commented Oct 29, 2015 at 20:01
-
@user2985955 It would have been nice to know that little nugget before... Have you considered that the simulator you're using doesn't work? Try it on real hardware and then come back with your real results.Majenko– Majenko2015年10月29日 20:06:57 +00:00Commented Oct 29, 2015 at 20:06
I figured it out. I had the temperature sensors wired wrong.
Old (Bad):
Good:
Explore related questions
See similar questions with these tags.