Go Down

### Topic: analogue input problems (Read 2306 times)previous topic - next topic

#### spruce_m00se

##### Jun 22, 2012, 09:06 pm
HI all
I am fairly new to the world of arduino, although i have tinkered with it a bit, multiwii, ardupilot, etc,

i have decided to undertake my own project,
a voltage meter , thermometer and pwm output with all data shown on lcd screen

the plan is to have a 15v battery pack with a voltage divider hooked to the arduino, the voltage divider will divide 15V to 5V thus making scaling of the real and visible voltages easy to do.

the thermometer is using an lm35.

the pwm will be used to control fan speed.

I have successfully coded all of the parts seperately.  i have displayed the required data to the lcd in seperate projects.

BUT      here is the conundrum which i need help with.  When i try to combine the volt reading and the temp reading, the volt reading affects the temp reading.  When the voltage input goes higher, the error on the temp seems to jump up, and if i set the voltage to zero the temp works fine.

does anyone have any ideas to help me  ?
the code im using is the following:

#include <LiquidCrystal.h>
LiquidCrystal lcd(11, 12, 7, 8, 9,10);

float tempC;
int tempPin = A1;
int voltpin = A0;
float volt = 0.0;

void setup()
{
lcd.begin(16, 2);
pinMode(A0, INPUT);
pinMode(A1, INPUT);
}

void loop()
{
lcd.clear();
tempC = (5.0 * tempC * 100.0)/1024.0;

lcd.setCursor(0, 1);
lcd.print((float)tempC,1);

lcd.setCursor(0, 0);
lcd.print((float)volt,1);
delay(750);
}

#### Hecky11

#1
##### Jun 22, 2012, 09:26 pm
try this
#define tempPin 1
#define voltpin 0

int tempPin = A1;
int voltpin = A0;

Analog readings should not conflict, double check your hardware part. Also what do you exactly mean by combining both readings?

#### spruce_m00se

#2
##### Jun 22, 2012, 09:34 pm
by COMBINE i mean , combine the seperate volt meter project with the seperate Thermometer project,

when i do what you just suggested the voltpin completely dominated the temppin, and as soon as i move the pot (simulating the incoming 0 - 5 v) the temp on the screen displays the same as the volt

the whole thing is on a breadboard, including arduino, BUT, i dont think its a hardware issue, if i comment out the voltpin then it has absolutely no effect on the other,

#### AWOL

#3
##### Jun 22, 2012, 09:37 pm
Quote
try this

There's no practical difference between those two implementations.

Can we have a schematic, please?
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

#### spruce_m00se

#4
##### Jun 22, 2012, 09:44 pm
whats interesting is that i just moved the lm35 to pin a2, updated the code, and had the same problem,

so i added some code to print all three inputs, and all three are affected by the pot, even though there is nothing now connected to A1

I will try to make a schematic, but since i dont have one , or any software im afraid it will be in MSPAINT

#### Hecky11

#5
##### Jun 22, 2012, 09:46 pm
okay. As arduino analog input pins are of pretty high impedence so slight touch of electric field can cause erroneous reading(Moreover you are on breadbaord so there is greater chance for this to happen).
Now instead of using very adjacent pins try analog input pins that are farther i-e A0 and A5 .. give it a try!

#### Erni

#6
##### Jun 22, 2012, 09:47 pm
One way to solve this is to do the reading twice (maybe with  slight delay) and then only use the last reading.
The reason is tht the ADC need some time to "recover"

Code: [Select]
`tempC = analogRead(tempPin);           delay(20);tempC = analogRead(tempPin); `

#### spruce_m00se

#7
##### Jun 22, 2012, 09:54 pm
if i disconect the wiper of the pot from PIN 1 thus eliminating the possibility of a short, i still get a reading of 110 on the PIN1 input, and erroneus TEMP readings of 40 degrees when i know they shoudl be 21

#### Hecky11

#8
##### Jun 22, 2012, 10:08 pm
first of all you must check whether your arduino reads analog values correctly or not.. usually i do this with serial monitor. arduino>tools >serial monitor/

Connect two potentiometers to A0 and A1 and check readings using following code.

Code: [Select]
`void setup(){Serial.begin(9600);}voil loop(){int Pin1=analogRead(0);delay(5);int Pin2=analogRead(1);Serial.print("Pin1=");Serial.print(Pin1);Serial.print("    "); Serial.print("Pin2=");  Serial.println(Pin2);delay(100);}`

If readings are fine i-e 0 to 1023, there is no problem with controller part it can just sense well its pins.
As far as erroneous temp reading is concerned you may need some further scaling or conversion.

#### spruce_m00se

#9
##### Jun 22, 2012, 10:10 pm
i know that pin 0 reads well, the pot at max returns 1023 and min returns 0 to the lcd,
i can connect it to the other pin to see if the same is true

but i still woudlnt know why the pot on one pin affects the reading on the other,

#### AWOL

#10
##### Jun 22, 2012, 10:11 pm
Again, can we have a schematic, please?
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

#### Erni

#11
##### Jun 22, 2012, 10:18 pm

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1262906682

#### spruce_m00se

#12
##### Jun 22, 2012, 10:22 pm

Again, can we have a schematic, please?

im just drawing it

#13
heres the schem

#### spruce_m00se

#14
##### Jun 22, 2012, 10:29 pm

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1262906682

thanks, that seems to be the same problem , i will read it through and see what the result is,

although i have a residual reading of 95/1024 on my voltage input pin when nothign is attached , and it goes up according to the temp , when the pot wiper isnt attached, when i attach the wiper the reading goes to 0 when at zero

Go Up

Please enter a valid email to subscribe