Go Down

Topic: Trouble Reading three analog inputs on serial monitor  (Read 204 times) previous topic - next topic

Luke_Redwine

I am working on a project where I need to read three different analog inputs; one for each potentiometer.
When I upload the program to the board it only displays the first potentiometer value (A0).
Code: [Select]

//Analog Read with Serial Monitor

void setup() {

  Serial.begin(9600); //initialize serial communication at 9600 bits per second
}

void loop() {

  int RsensorValue = analogRead(A0);
  int GsensorValue = analogRead(A1);
  int BsensorValue = analogRead(A2);
 
 
  Serial.println(RsensorValue); //print out the value you read
  Serial.println(GsensorValue);
  Serial.println(BsensorValue);
 
  delay(100); //delay in between reads for stability
}

Idahowalker

What happens when you do this:
Code: [Select]

//Analog Read with Serial Monitor

void setup() {

  Serial.begin(9600); //initialize serial communication at 9600 bits per second
}

void loop() {

  // int RsensorValue = analogRead(A0);
  // int GsensorValue = analogRead(A1);
  int BsensorValue = analogRead(A2);
 
 
  // Serial.println(RsensorValue); //print out the value you read
  // Serial.println(GsensorValue);
  Serial.println(BsensorValue);
 
  delay(100); //delay in between reads for stability
}
?

slipstick


wvmarle

You can see much better what happens if you print the values on separate lines:

Code: [Select]

  Serial.print(F("R: "));
  Serial.print(RsensorValue); //print out the value you read
  Serail.print(F(", G: "));
  Serial.print(GsensorValue);
  Serial.print(F(", B: "));
  Serial.println(BsensorValue);


What is the source of your input signal?
Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

gilshultz

Try moving the delay between reads, you are reading the A/D to fast, it needs a bit of settling time for each read. I would interleave the sensor read then the sensor display color by color.  This response is to help you get started in solving your problem, not solve it for you.
Good Luck & Have Fun!
Gil
  
This response is to help you get started in solving your problem, not solve it for you.
Good Luck & Have Fun!
Gil

MarkT

Try moving the delay between reads, you are reading the A/D to fast, it needs a bit of settling time for each read.
This isn't true.  If the pots are 50k or lower then it will be perfectly fine reading them as fast as you can in turn without crosstalk, as the maximum impedance seen is 12.5k which is good enough (10k or less is ideal).

Even if the impedance is very high such that crosstalk is occuring simply waiting will not work, you have to do multiple analogReads with the same pin number to pre-charge the sample/hold capacitor, as the first read connects the S/H cap to the pin, the subsequent reads get the benefit of settling time.

If the input impedance to the analog pin is much above 10k, read the pin twice, discarding the first value.
If the input impedance is 10k or so or less, one analogRead() is always enough.

Quote
I would interleave the sensor read then the sensor display color by color.  This response is to help you get started in solving your problem, not solve it for you.
Good Luck & Have Fun!
Gil
 
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

Go Up