AnalogRead and voltage measurmet

I am reading the voltage of a separate pcb with A0.

Based on the voltage i am turning on a RGB LED with a different color.

int redPin = 11;
int greenPin = 10;
int bluePin = 9;
int ledPin = 7;
//uncomment this line if using a Common Anode LED
#define COMMON_ANODE

bool running = false;
// the setup routine runs once when you press reset:
void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
  pinMode(redPin, OUTPUT);
  pinMode(greenPin, OUTPUT);
  pinMode(bluePin, OUTPUT);
  pinMode(ledPin, OUTPUT);

  setColor(0, 0, 0); // green
  Serial.println(running);
}




// the loop routine runs over and over again forever:
void loop() {



  // read the input on analog pin 0:
  int sensorValue = analogRead(A0);
  // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
  float voltage = sensorValue * (5.0 / 1023.0);
  // print out the value you read:

  

  if (voltage < 0.20 ) {

    setColor(0, 255, 0); // green
    delay(500);

    Serial.println("Good Cap less than 0.28");
    Serial.println(voltage);
    delay(500);
    
  } 
  
  else 
  if (running ==false){
    setColor(0,0,0);
  }else 
  if (voltage >0.20) {
    running == true;
    if (running ==true){
      setColor(255, 0, 0); // red
    delay(500);
    Serial.println("BAD CAP Equal to 0.28");
    Serial.println(voltage);
    delay(500);
    }
    
  }

  //else {
   // setColor(255, 0, 0); // red
   // delay(500);
   // Serial.println("bad cap It is greater than 0.28");
   // delay(500);
   // Serial.println(voltage);
   // delay(500);
   //}
 
  


}//end of loop
void setColor(int red, int green, int blue)
{
#ifdef COMMON_ANODE
  red = 255 - red;
  green = 255 - green;
  blue = 255 - blue;
#endif
  analogWrite(redPin, red);
  analogWrite(greenPin, green);
  analogWrite(bluePin, blue);
  analogWrite(ledPin, HIGH);

}
  }

The voltage point on the OTHER PCB i am measuring has about 4.0v on it , until i connect the prob to it.
THen it drops.

Problem:
When the arduino is powered on it is reading the voltage(4.0v) from the other PCB and turning on the RGB with red.

Question: How can i not have the RGB LED turned on until i start probing ?
Question: Can i turn the A0 pin off to stop the measuring until I start probing ?

Question: How can i not have the RGB LED turned on until i start probing ?
Question: Can i turn the A0 pin off to stop the measuring until I start probing ?

If you don't want to write to the LED or read from A0 then simply don't do it

Incidentally, the code that you posted does not compile

This: analogWrite(ledPin, HIGH);
should be "digitalWrite" ? for an Arduino Uno ?
But then there are still problems. Is pin 7 the common pin for three leds of 20 mA ? An Arduino Uno pin can only do 20 mA (40 mA shortcut current).

The analog input A0 is very high impedance, it will not lower the voltage of what is measured.

Thanks for the comments and the info about the arduino pin current limits.

Koepel:
The analog input A0 is very high impedance, it will not lower the voltage of what is measured.

Not true. The following is taken from section 28.6.1 of the ATMEGA328P datasheet:-

The ADC is optimized for analog signals with an output impedance of approximately 10 kΩ or less. If such
a source is used, the sampling time will be negligible. If a source with higher impedance is used, the
sampling time will depend on how long time the source needs to charge the S/H capacitor, with can vary
widely. The user is recommended to only use low impedance sources with slowly varying signals, since
this minimizes the required charge transfer to the S/H capacitor.

The OP may need to add some high impedance buffering to their circuit.

Ian

  if (voltage >0.20) {
    running == true;  //comparison
    if (running ==true){

If voltage > 0.20 compare running to true, do nothing with the result of that comparison, then compare it again.

If it should be

 if (voltage >0.20) {
    running = true;  //assignment
    if (running ==true)  //how could it not be?{

then check if the assignment of running to true actually worked?

@evanmars
Thanks for the reply..
The code seems to be working as expected here

 else 
  if (running ==false){
    setColor(0,0,0);
    running = true;
  }else 
  if (voltage >0.20) {
    running = true;
    if (running ==true){
      setColor(2, 0, 0); // red
    delay(500);
    Serial.println("BAD CAP Equal to 0.28");
    Serial.println(voltage);
    delay(500);

while the other PCB is powered up there is all ways more than 0.20v on the test point so the red led will be turned on.

solution i am looking for is.

  1. when program runs no led lights are on.
  2. if voltage is less than 0.20 light the green led.
  3. if voltage is more tnat 0.20 light the red led .

No

if (voltage >0.20) {
    running == true;

Yes

if (voltage >0.20) {
    running = true;

IanCrowe:
Not true....The OP may need to add some high impedance buffering to their circuit.

@IanCrowe, this is when using an Arduino and about reading a voltage.

The analog inputs are very high impedance. However, the ADC requires a little charge from the analog input.
There is no internal resistance from A0 to GND that might lower the voltage, there is only that little charge.

That means that with a fast changing input signal, the circuit impedance for a signal should be 10k or less.
The Arduino analogRead() is slow, so a fast changing input signal can not be measured anyway.
When using the average of many samples with analogRead(), the circuit impedance can be higher than 10k, even 1M is no problem.

Adding an extra buffer will probably not be as high impedance as the analog input of an Arduino board. It will introduce extra noise and extra inaccuracy.

Therefor: The analog input A0 is very high impedance, it will not lower the voltage of what is measured.
(assuming that no ESP8266 is used).

Thanks for all the coments