Pages: [1] 2   Go Down
Author Topic: Termostat problems  (Read 1851 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi!

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?
Logged

SW Scotland
Offline Offline
Edison Member
*
Karma: 17
Posts: 1405
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

we need a diagram of how you have wired things up
Logged

Offline Offline
Edison Member
*
Karma: 9
Posts: 1016
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

we need a diagram of how you have wired things up
Or a photo.
And a link to the starterkit.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
int tempPin = 0;
int ledPin = 12;
int potPin = 1;
int pot;
int termostat;
float tempC;

void setup() {
  Serial.begin(9600);
  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.print(tempC);
  Serial.println(" grader");
  pot = analogRead(potPin);
  termostat = map(pot, 0, 1023, 20, 30);
  Serial.print("Termostat: ");
  Serial.print(termostat);
  Serial.println(" grader.");
  if (tempC > termostat) {
     digitalWrite(ledPin, HIGH);
  } else {
     digitalWrite(ledPin, LOW);
  }
  delay(1000);
}


* termostat.jpg (56.64 KB, 971x647 - viewed 49 times.)
Logged

Offline Offline
Edison Member
*
Karma: 9
Posts: 1016
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

SW Scotland
Offline Offline
Edison Member
*
Karma: 17
Posts: 1405
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: July 11, 2012, 03:43:33 pm by rolvs » Logged

Offline Offline
Edison Member
*
Karma: 9
Posts: 1016
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Full Member
***
Karma: 2
Posts: 226
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

when you remove code with // about the pot, do the temp values go back to normal?

« Last Edit: July 13, 2012, 08:07:41 am by lax123 » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

United Kingdom
Offline Offline
Tesla Member
***
Karma: 227
Posts: 6639
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: July 14, 2012, 01:41:12 pm by dc42 » Logged

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.

SW Scotland
Offline Offline
Edison Member
*
Karma: 17
Posts: 1405
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Pages: [1] 2   Go Up
Jump to: