3

I'm new to this forum, so hello to everyone out there.

So I have an Uno with A0 connected to the positive end of a chain of LEDs (they light up when a motion sensor goes off, clunky, but it works), and the negative end is hooked up to the GND of the analog side of the Uno. It runs the following code:

void setup() 
{
  Serial.begin(115200);
  pinMode(A0, INPUT);
  pinMode(A1, INPUT);
}

void loop() 
{

  Serial.println(printVals(A0));
}

float printVals(uint8_t pin)
{
  int sensorValue = analogRead(pin);
  float voltage = sensorValue * (5.00 / 1023.00);
  return voltage;
}

And when I open the Serial Plotter, I get a weird square wave for the voltage (when there is 0V on the LEDs, I used a volt meter). Out of curiosity, I added a jumper cable from A2 to +5V (the red wire in the diagram) and added plotting for A2, and this solved the problem - except now, the read on A0 is about 0.53.

Now, I'm more of a software guy, so I figure just subtract 0.53 and move on (varies only +- 0.03V), but I want to know: What in the world did that jumper cable do?enter image description hereenter image description hereenter image description here

8
  • 1
    There is a tiny capacitance in the ADC sampler, and if the signal you are measuring is weak, the stored charge in the ADC can affect the reading, depending on what else is going on. Like multiplexing readings from A0 and A2.
    – Dave X
    Dec 24, 2017 at 4:24
  • 3
    A0 connected to the positive end of a chain of LEDs - you did what? Can you sketch up a schematic?
    – Nick Gammon
    Dec 24, 2017 at 5:04
  • A square wave of what values?
    – Mark Smith
    Dec 24, 2017 at 6:58
  • The square wave is between 0 and roughly 0.5, and when I added the jumper, it was a mostly straight line at about 0.5V. Dec 24, 2017 at 17:32
  • 1
    It is better to use an optocoupler. This will give the galvanic isolation between the devices. And use a digital input instead of an analog. Since the indicator has only two states.
    – AltAir
    Dec 24, 2017 at 19:32

2 Answers 2

1

@Ferba, my chain of LEDs is actually part of a circuit board for a driveway monitor receiver. When it detects motion, the LEDs light up and the voltage measured by analogRead increases by about a volt.

Also, as it turns out, the jumper to +5v was functioning as a pull-up wire... not a good idea. It burned out the chip in the driveway monitor by backfeeding an output. In the end, I added an "_PULLUP" after the INPUT in setup and that solved the problem.

0

Why are you connecting a chain of leds to a pin setted as an input and then connected to GND? I think that is like connect the pin to nothing. in the documentation of arduino they have a note about the funcion analogRead() and a fluctuation of data. https://www.arduino.cc/reference/en/language/functions/analog-io/analogread/ i think if you need to read an input put a button (or maybe i didnt understand you scheme)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.