Offline
Newbie
Karma: 0
Posts: 7
|
 |
« on: July 11, 2012, 10:04:58 am » |
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
Edison Member
Karma: 6
Posts: 1053
Arduino rocks
|
 |
« Reply #1 on: July 11, 2012, 11:52:43 am » |
we need a diagram of how you have wired things up
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Edison Member
Karma: 9
Posts: 1000
|
 |
« Reply #2 on: July 11, 2012, 11:54:21 am » |
we need a diagram of how you have wired things up
Or a photo. And a link to the starterkit.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 7
|
 |
« Reply #3 on: July 11, 2012, 02:04:22 pm » |
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. 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); }
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Edison Member
Karma: 9
Posts: 1000
|
 |
« Reply #4 on: July 11, 2012, 02:21:20 pm » |
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
Newbie
Karma: 0
Posts: 7
|
 |
« Reply #5 on: July 11, 2012, 02:32:22 pm » |
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
Edison Member
Karma: 6
Posts: 1053
Arduino rocks
|
 |
« Reply #6 on: July 11, 2012, 03:31:52 pm » |
There appears nothing obviously wrong with your diagram - are you 100% certain your wiring is connected as shown.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 7
|
 |
« Reply #7 on: July 11, 2012, 03:41:20 pm » |
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
Edison Member
Karma: 9
Posts: 1000
|
 |
« Reply #8 on: July 11, 2012, 05:53:40 pm » |
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
Newbie
Karma: 0
Posts: 7
|
 |
« Reply #9 on: July 12, 2012, 08:05:01 am » |
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
Full Member
Karma: 1
Posts: 224
|
 |
« Reply #10 on: July 13, 2012, 08:02:23 am » |
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
Newbie
Karma: 0
Posts: 7
|
 |
« Reply #11 on: July 13, 2012, 03:17:37 pm » |
No, it doesnt work if i dont remove the + wire from the pot.
|
|
|
|
|
Logged
|
|
|
|
|
United Kingdom
Offline
Faraday Member
Karma: 131
Posts: 4681
|
 |
« Reply #12 on: July 14, 2012, 01:39:24 pm » |
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. http://www.eschertech.com
|
|
|
|
SW Scotland
Offline
Edison Member
Karma: 6
Posts: 1053
Arduino rocks
|
 |
« Reply #13 on: July 14, 2012, 02:28:02 pm » |
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
Newbie
Karma: 0
Posts: 7
|
 |
« Reply #14 on: July 21, 2012, 12:53:34 pm » |
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
|
|
|
|
|
|