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:
The voltage is always read at around ~0.60VDC no matter the board being on or off
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);
}
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?
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,
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.
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