Go Down

Topic: Termostat problems (Read 1 time) 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.

Go Up