0

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:

enter image description here

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.

1

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. – user2985955 Oct 29 '15 at 20:37
0

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:

enter image description here

Split rail:

enter image description here

  • 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. – user2985955 Oct 29 '15 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 Oct 29 '15 at 20:06
0

I figured it out. I had the temperature sensors wired wrong.

Old (Bad):

enter image description here

Good:

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.