Pages: [1]   Go Down
Author Topic: ph amp and LM35 weird error  (Read 2124 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello
I am new arduino so please be patient  smiley-red

I am trying to read 2 analog imputes on the arduino. The first is a LM35 temperature sensor connected to pin A0 and the second is a ph amp (http://blea.ch/wiki/index.php/PH_Meter) connected to A3. I use a TL082 insted of 062.
Each of them work's fine separately  but when i try to read both in the same loop the temp sensor goes wild. I have also a LCD connected (works fine).

I guess that the problem lays in the code because all the parts stay connected to the arduino and powered on.

My code is :
Code:
#include <LiquidCrystal.h> // include the LCD library code:
LiquidCrystal lcd(10, 9, 8, 7, 6, 5); // initialize the library with the numbers of the interface pins

//thermometer
int LM35pin = A0;
float sensor = 0;
float celsius = 0;


//ph
int PHinputPin = A3; 
float ph1 = 0;
float PHvalue = 0;

void setup() {
   
lcd.begin(16, 2);// set up the LCD's number of columns and rows:
pinMode(13, OUTPUT); //led de test (hartbeat)
}

void loop()
{
  //thermometer
sensor = analogRead(LM35pin); // LM35 sensor output pin is connected to Arduino analogue pin 0
celsius =  (5.0 * sensor * 100.0)/1024.0;  // convert raw sensor value to Celsius

//ph
ph1 = analogRead(PHinputPin);
PHvalue = (ph1 * 0.015); //formula not final

//LCD DYSPLAY
//PH on lcd   
lcd.setCursor(0,0);
lcd.print("PH: ");
lcd.print(PHvalue, 3);

//temperature
lcd.setCursor(0,1);
lcd.print("Temp: ");
lcd.print(celsius, 2);

//heart beat
  digitalWrite(13, HIGH);   // set the LED on
  delay(500);              // wait
  digitalWrite(13, LOW);    // set the LED off     
  delay(500);
}

Running this code, the reported temperature fluctuates wildly from 0.001 to 50 c. The PH is fine.
If I comment the ph code (and no hardware changes) the thermometer works fine.  smiley-eek

It drive's me crazy. If you have a suggestion please help me.
Thank You 
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 224
Posts: 13917
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Can you provide a drawing how things are connected ?

Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

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

Hi,

The schematic is pretty strait forward. The amp is powered from a bipolar psu (+,- 5 V) and has a common ground with the arduino. the LM35 is powered from the same psu (only the positive side) and has also a common ground with the arduino. The PSU is capable of 1 Amp on each line.

here is the picture:
http://imageshack.us/photo/my-images/834/arduinos1.jpg


Logged

Montreal
Offline Offline
Faraday Member
**
Karma: 30
Posts: 2602
Per aspera ad astra.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Practically everyday someone reported issue with voltage measurements, when two or more ports engaged.
Common advise: take a first reading, discard it, than take 10 more in a loop and calculate average to get best accurate result for first analog port, then go to next one.  
« Last Edit: August 05, 2011, 05:24:41 pm by Magician » Logged

Dallas, Texas
Offline Offline
God Member
*****
Karma: 0
Posts: 861
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Have you measured the output of your pH amp to ensure it never goes negative? Have you tried disconnecting it from the Arduino A3 input rather than commenting out the code to see what happens?
Logged

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

First of all thanks for reply

@Magician
When the Ph amp is enabled in the code, the temp sensor value jumps from 0 to 50ish and everything in between. I don't think that an average of this will give me the correct value.

@EmilyJane
the output is positive and stable. When the ph electrode is in PH7 solution, i get a reading of 2.5v on the voltmeter. I haven't tried the code with the amp disconnected, but since the temp sensor works fine with the ph code commented, i don't think is a hardware issue.

Maybe is "gremlins" related, one can't know for sure smiley-grin

p.s. i tried other analog pin combinations too (same bug)
Logged

Dallas, Texas
Offline Offline
God Member
*****
Karma: 0
Posts: 861
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Well, I can't suggest anything else except that every time you go through loop, you need to clear out (write spaces) where your numbers go on your display else you'll have some weird displays sometimes.
Logged

Montreal
Offline Offline
Faraday Member
**
Karma: 30
Posts: 2602
Per aspera ad astra.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
take a first reading, discard it,
Read how ADC works , it would help to understand
Logged

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

thank you all for the help.

I could not find the cause for this bug. It might be something electrical, maybe high frequency noise, I don't know. If i can get my hands on an oscilloscope i will clear this suspicion. Until then I conclude that my LM35 is possessed  smiley-twist

In the meanwhile i switched to a digital DS18B20. No more problems  smiley. Everything works as it should. (Even if the code is more complex the benefits of digital sensors is worth it)

Any other ideas are welcomed, maybe exorcism...
Logged

Montreal
Offline Offline
Faraday Member
**
Karma: 30
Posts: 2602
Per aspera ad astra.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If you don't have oscilloscope available at the moment, check on a blog how to use arduino for this: http://oscilloscopeexpress.blogspot.com/
You can easily modify it to get charts for two sensors, and trace down the cause of your problem.

Logged

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

This is great Magician, i will defiantly use that. Thanks
Logged

United Kingdom
Offline Offline
Tesla Member
***
Karma: 227
Posts: 6637
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 changing your temperature reading code to this:

analogRead(LM35pin);
delay(10);
sensor = analogRead(LM35pin); // LM35 sensor output pin is connected to Arduino analogue pin 0
celsius =  (5.0 * sensor * 100.0)/1024.0;  // convert raw sensor value to Celsius

Generally, when doing an analog read from a pin with a high impedance source when you have previously read a different pin, you need to discard the initial reading, wait a little, and then read it again.
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.

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

and on the third day....  smiley-lol (well fifth)

This works awesome, I knew my bug was in the code.
 
When Magician said "take a first reading, discard it" i didn't get it.
This fix is so simple...

Thank You
Logged

Pages: [1]   Go Up
Jump to: