Ardunio analogRead Voltage Fluctuating Wildly

I am working on a project where I take input from an AC output and I am attempting to read if the line to the sprinkler is getting powered. The board outputs a ~28VAC when it is on. For this project, I am using a MID400M chip which is an optocoupler. The MID chips output ~1.8VDC when the board output is off and ~0.4VDC when it is on

I tested the circuit with LEDs and it works fine, but I am starting to get issues when I hook up the circuit to and Arduino MEGA. 2 really weird things:

  1. The voltage is always read at around ~0.60VDC no matter the board being on or off
  2. Randomly the Arduino reads that the voltage climbs up to ~4.9VDC even though i cross check with a multimeter and at the time it reads a voltage increase there is no voltage increase

It seems like a lot of people on this forum have voltage fluctuation issues, but mine are like really really wild from 0.6 to 4.9 down to 0.6 again. This is my serial output

Here is my code and schematic, any help would be much appreciated. Thanks!

Code:

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  Serial.println("READY!!!");
}
 
void loop() {
  // put your main code here, to run repeatedly:
  Serial.println((analogRead(A0))* (5.0/1023.0));
  Serial.println("");
 
  delay(1000);
}

Schematic:

I'm probably going to get beat up here, but try configuring A0 for INPUT to see if it stabilizes. I see you have a pullup resistor on the end of the A0 jumper wire. What is the MID400M? Opto-isolator?

void setup() {
.
  pinMode(A0, INPUT);
.
}

The MID400 delivers a logic output. You should use digitalRead.

The LED at pin 6 is clipping the output voltage, and you are not using a limiting resistor. What happens if you remove it altogether?

I tried, but no use. the MID400M is really just a chip that outputs a DC signal if there is AC voltage

I used digitalRead but it wouldn't work. I if I remove it all together, it still doesn't work

I Think the 300 ohm resistor is acting as a pullup and current limiter for the LED.

The 28K ohm resistor is for 120V, for 28volts you could get away with about 6K

How would that help me with the fluctuations?

All Arduino I/o pins default to INPUT.

1 Like

Here is the suggested circuit from the datasheet:

I followed this circuit and it works, but my Arduino is register fluctuations which are not present on a multimeter.

It doesn't output any voltage.

When an AC voltage is present at the inputs, the output is pulled to ground. When no AC is present, the output floats.

The AC is a sine wave (presumably). It's got two zero-crossings per cycle, and for part of the cycle the voltage is too low to turn-on the LED inside the opto-coupler. (The opto-isolator is not linear. The DC isn't proportional to the AC.)

The meter will have some delay and possibly "smoothing" whereas the Arduino reads the instantaneous voltage every time through the loop,

No, you have an led connected between the output and ground.

From the datasheet:

The
switching times are intentionally designed to be slow in
order to enable the MID400M, when used as an AC line
monitor, to respond only to changes in input voltage
exceeding many milliseconds. The short period of time
during zero−crossing which occurs once every half cycle of
the power line is completely ignored.

Sorry if I seem to be contradicting everyone's attempts to help. I am trying to help too.

I haven't figured out what the problem is either, but so far, I don't think any of the suggestions are the answer...

But the circuit works. When I only have the LED, the LED turns on and off perfectly. I still dont understand why there would be an issue from it when I replace the LED with an line to the ardunio

So the analog readings you posted were taken with the led removed from the circuit? If so, sorry, I missed that.

What happens when you try reducing the 22K, as suggested earlier?

Does the led turn off when the AC voltage is present? That's what I would expect, from the datasheet.

Mostly the same thing, but the resting moved up from 0.6 to ~1 VDC

Yes, it does.

1 Like