Go Down

Topic: Reading one analog pins affects another analog pin (Read 1 time) previous topic - next topic


Hi everyone

(If there is a solution to this already, please point me in the right direction, I don't know what to search for.)

I have an itead studio LCD shield and a LM35 temp sensor. The LCD shield has 5 buttons connected to A0 with different resistances on each button.

If I read and display the temperature(Analog pin 4), it works 100%.  If I read and display the button that is pressed (Analog pin 0), it works 100%.
But as soon as I do both in the same sketch, the temp values jump around randomly and the button press affects the temp value.

What am I missing here?

This works:
Code: [Select]

void loop()

void readTemp()
  sensorValue = analogRead(TEMP_ADC_PIN);
  sensorValue = round((5.0 * sensorValue * 100.0)/1024.0);
  maxtemp = max(maxtemp, sensorValue);
  mintemp = min(mintemp, sensorValue);

void displayTemp()
  output = "Max: " + String(maxtemp) + "  " + "Min: " + String(mintemp);
  lcd.setCursor(0, 0);
  lcd.setCursor(0, 1);
  output = String(sensorValue) + " C";

and this works:
Code: [Select]

void loop()
  byte button;
  button = ReadButtons();
  lcd.print(String(button));  //Display button press in right bottom corner.

ReadButtons() I copied from this website http://www.freetronics.com/pages/16x2-lcd-shield-quickstart-guide#.UaHASbWNrg8,  but just doing a simple analogRead on pin A0 yields the same results.

Calling ReadButtons() and readTemp() in loop causes the temp values to be random and is affected by a button press.


This happens when the impedance of what is on the analogue input is too high for the sample and hold to come up to full voltage in the time between switching over the multiplexer and taking the reading.
A software fix is to read each channel twice and only use the second reading. Or in extreme cases read the channel, delay the read the channel again, use that second reading.


Thanks a million. That fixed my issue.  Just out of interest sake, what would a hardware fixed involve?


If it's a signal that varies only slowly, a hardware fix is to connect a 0.01uF capacitor between the analog input pin whose reading is being affected and ground.
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.


what would a hardware fixed involve?

Well I would have reduced the impedance of the analogue signals, by either reducing the values of the resistors or adding an op amp configured as a voltage follower on the temperature sensor's output.

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131