1

I have a project planned which is related to home automation. I want to be able to control the lights using an app on phone while also maintaining full manual switch control in case the relay or anything else that is used to control lights using mobile breaks up.

I also want this module to be small, so I can install it inside my switch board without too much issues. I searched the internet for projects like this and wasn't able to find a lot of good answers.

I did come across a video:

https://youtu.be/5SgB6wzgxY0

This guy uses a diode in series with a resistor to feed into the analog input pin for nodemcu.

This is very similar to what I want to do, I wanted to ask is, how is it working? Is it safe? And if there are some other alternative circuits I should use.

I'm sorry if the formatting is not proper or I didn't give enough information, I'm posting this from a phone.

If you need, I can post the circuit design I have in mind but it's very similar to the one used in video.

Any help on this will be very much appreciated Thanks :)

1
  • 4
    using a resistor and a diode is a bad idea because it connects line voltage to the mcu and makes it dangerous to touch .... it is much safer to use an opto coupler .... you can google line sensing with optocoupler
    – jsotola
    Jun 8, 2019 at 1:45

1 Answer 1

2

I would use a current transformer. A current transformer is typically a toroidal magnetic core through which one power wire is threaded, with a few hundreds turns wrapped around the core. A current transformer causes the current in the secondary to be equal to one over the turns ratio times the current in the primary.

If there are 500 turns on the secondary, and the primary consists of one turn, then a 1 A primary current induces a 1/500 or .002 A current in the secondary. That current is directed through a resistor, and the voltage is measured by the microcontroller. Note that the secondary is completely isolated from the primary, and the voltage developed is a function of the turns ratio and the load resistor.

Remember that this is an AC signal, but being completely isolated from everything else, the reference could be any convenient voltage, such as a voltage divider between the analog max and min voltages. For the ESP32, which could be a divider between 3.3V and ground. If you need an accurate power measurement, then you must also get an isolated voltage reading and multiply the instantaneous voltage and current.

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.