ph amp and LM35 weird error

I am new arduino so please be patient :blush:

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 (PH Meter - ProjectWiki) 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 :

#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

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

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()
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

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

//PH on lcd   
lcd.print("PH: ");
lcd.print(PHvalue, 3); 

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     

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

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

Can you provide a drawing how things are connected ?


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:

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.

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?

First of all thanks for reply

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.

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:

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

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.

take a first reading, discard it,

Read how ADC works , it would help to understand

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:

In the meanwhile i switched to a digital DS18B20. No more problems :). 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...

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

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

Try changing your temperature reading code to this:

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.

and on the third day.... XD (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