I am simply trying to get a digital signal to my Mega256 Arduino board that will indicate whether or not a 120v AC circuit is live. I realize I can just use an AC relay, but I already have a couple ZMPT101B modules sitting around. So I am wondering if those can be used to detect if the circuit is on or not. Preferably using a digital signal.
The ZMTP101B AC Single Phase Voltage Sensor Module should be used for its design purpose. If you don't know what that is, have a look at the data sheet or product manual.
what do you mean by circuit is on or not?
if you wish to detect if circuit is on and current is flowing a SCT-013 current clamp is worth considering - it is none invasive just clipping around ONE of the supply leads
The output is a sinewave with an offset of half the supply voltage. There is a potentiometer to adjust the sensitivity.
Here is some code that takes 50 analogRead( ) samples at 0.5ms intervals (to ensure that we are monitoring at least one whole period of the incoming 50 Hz or 60Hz input).
It finds the maximum and minimum values measured and subtracts the minimum from the maximum to calculate the amplitude.
The code then turns an output high if the amplitude is above a threshold.
code here
const byte inputPin = A0;
const byte outputPin = 12;
int input = 0;
int minInput = 1023;
int maxInput = 0;
int amplitude = 0;
int threshold = 100;
void setup() {
Serial.begin(115200);
pinMode(inputPin, INPUT);
pinMode(outputPin, OUTPUT);
}
void loop() {
minInput = 1023;
maxInput = 0;
for (int i = 0; i <= 50; i++) {
input = analogRead(inputPin);
if (input >= maxInput) {
maxInput = input;
}
if (input <= minInput) {
minInput = input;
}
delayMicroseconds(500);
}
amplitude = maxInput - minInput;
if (amplitude >= threshold) {
digitalWrite(outputPin, HIGH);
}
else {
digitalWrite(outputPin, LOW);
}
Serial.print(minInput);
Serial.print(", ");
Serial.print(maxInput);
Serial.print(", ");
Serial.println(amplitude);
// You can do something else here,
// but it will slow down the response time.
}
I don't have a ZMPT101B module, so I have used a function generator to test the code:
The ZMPT101B is mainly used for measuring AC voltage rather than just detecting if a circuit is live. While it might work, using an AC relay or an optocoupler would be a simpler and more reliable way to get a clear digital signal for your Mega2560. Hope this helps!
on the PCB there is a track between the L and N inputs
Maybe the wiring diagram didn't keep up with the board rev.
I guess UL (TUV, et al.) would not be favorably impressed - but it's not like anyone is asking them.
I bought them for another project a while back, I am completely aware of what they are intended to be used for. I just figured if they can sense the voltage level, maybe it was worth looking into if they can be used to sense when there is or is not voltage at all. Rather than buying a different module.