Go Down

Topic: Termostat problems (Read 3632 times) previous topic - next topic



Im new to Arduino and got my starter kit yesterday. Im trying to build a termostat with a LM35 temperature sensor, a pot meter and a led. The temperature works perfect, until i connect the pot meter to the 5V pin. When i turn up the pot meter i get wierd reading from my temperatur sensor on the serial port (I use it for debuging). I get both higher and lower values from the temperatur sensor. Why is it like this? What can i do to get it working?


we need a diagram of how you have wired things up


we need a diagram of how you have wired things up

Or a photo.
And a link to the starterkit.


Here is how i have connected it up. Sorry for bad wiring, i know its a mess, but you can se how i have done it.

Here is the code, and it works, but i get strange readings from the temp sensor when i have connected the pot.

Code: [Select]
int tempPin = 0;
int ledPin = 12;
int potPin = 1;
int pot;
int termostat;
float tempC;

void setup() {
  pinMode(tempPin, OUTPUT);
  pinMode(ledPin, OUTPUT);
  pinMode(potPin, INPUT);

void loop() {
  tempC = analogRead(tempPin);
  tempC = (5.0 * tempC * 100.0)/1024.0;
  Serial.print("Temperatur: ");
  Serial.println(" grader");
  pot = analogRead(potPin);
  termostat = map(pot, 0, 1023, 20, 30);
  Serial.print("Termostat: ");
  Serial.println(" grader.");
  if (tempC > termostat) {
     digitalWrite(ledPin, HIGH);
  } else {
     digitalWrite(ledPin, LOW);


Thanks for the picture and code.
Your connections look okay to me.
But in your code you mix analog with digital.

pinMode(1) sets the digital pin '1'. That's mixing digital with analog.
For an analog input, using analogRead(), you don't need to set it with pinMode().
The led is the only digital output, so use pinMode() only for the led.
Remove the two other pinMode() and see what it does.


I removed pinMode for everyting but the LED. It didnt help. Here is my reading from serial monitor:

Temperatur: 21.48 grader
Termostat: 30 grader.
Temperatur: 42.97 grader
Termostat: 30 grader.
Temperatur: 31.74 grader
Termostat: 30 grader.
Temperatur: 27.83 grader
Termostat: 30 grader.
Temperatur: 24.90 grader
Termostat: 30 grader.
Temperatur: 43.46 grader
Termostat: 30 grader.
Temperatur: 40.04 grader
Termostat: 30 grader.
Temperatur: 33.20 grader
Termostat: 30 grader.
Temperatur: 36.62 grader
Termostat: 30 grader.

Its normaly reads 22 when the pot is not connected. Btw, the pot works, but the temperature is wierd.


There appears nothing obviously wrong with your diagram - are you 100% certain your wiring is connected as shown. 


Jul 11, 2012, 10:41 pm Last Edit: Jul 11, 2012, 10:43 pm by rolvs Reason: 1
Yes, i am. Everything works, the pot, the led and the temperature sensor. Can it be too little power or anyting? Noise from the pot? I dont know.


Is the pot 100 Ohms ?
Do you use the USB to supply the 5V.

A pot of 10k would be normal.
You could try a adapter of 6...12V as power supply.


THe pot is a 100k from the fritzing starter kit.

I use 5V from the USB port.

I can try using a other power source of you think that will help, but i dont have any here now.


Jul 13, 2012, 03:02 pm Last Edit: Jul 13, 2012, 03:07 pm by lax123 Reason: 1
when you remove code with // about the pot, do the temp values go back to normal?


No, it doesnt work if i dont remove the + wire from the pot.


Jul 14, 2012, 08:39 pm Last Edit: Jul 14, 2012, 08:41 pm by dc42 Reason: 1
Try making 2 analogRead calls in succession from the temp sensor. Throw away the first reading and use the second.

Also check that your Arduino is not resting on a conductive surface, and you don't have a short between the 2 analog inputs you are using.
Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.


You don't show how you are powering the system.  USB, battery and if the latter what voltage, type and size.

There is a possibility (remote ?) that the pot wires are inducing noise into your temperature sensor input circuit.  Perhaps placing 0.1 capacitors between ground and each of your 2 inputs will dampen any noise.


I have tried both with USB power and a 9 V battery with the same result.

But now i made a new setup, just swaped the pot meter with a LDR. I have the same led, and temp. sensor. I have the same problem with the temp sensor when i have the LDR connected. Can it be a bug in Arduino when i use 2 analog ports?

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131