Pages: [1] 2   Go Down
Author Topic: analogue input problems  (Read 1064 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Sr. Member
****
Karma: 0
Posts: 376
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 = analogRead(tempPin);           
tempC = (5.0 * tempC * 100.0)/1024.0;

volt = analogRead(voltpin);


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

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

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

try this
#define tempPin 1
#define voltpin 0

instead of

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

Offline Offline
Sr. Member
****
Karma: 0
Posts: 376
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 309
Posts: 26504
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
try this
There's no practical difference between those two implementations.

Can we have a schematic, please?
Logged

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

Offline Offline
Sr. Member
****
Karma: 0
Posts: 376
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Logged

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

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

Denmark
Offline Offline
Edison Member
*
Karma: 36
Posts: 1084
Happy Hobbyist
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
tempC = analogRead(tempPin);          
delay(20);
tempC = analogRead(tempPin);
         
Logged

Offline Offline
Sr. Member
****
Karma: 0
Posts: 376
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Logged

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

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

Offline Offline
Sr. Member
****
Karma: 0
Posts: 376
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 309
Posts: 26504
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Again, can we have a schematic, please?
Logged

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

Denmark
Offline Offline
Edison Member
*
Karma: 36
Posts: 1084
Happy Hobbyist
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


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

Offline Offline
Sr. Member
****
Karma: 0
Posts: 376
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Again, can we have a schematic, please?

im just drawing it
Logged

Offline Offline
Sr. Member
****
Karma: 0
Posts: 376
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

heres the schem


* breadboard schem.jpg (40.38 KB, 966x553 - viewed 29 times.)
Logged

Offline Offline
Sr. Member
****
Karma: 0
Posts: 376
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


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
Logged

Pages: [1] 2   Go Up
Jump to: