Chat freely about anything...

User avatar
By Ashutosh choudhary
#33825 I am trying to read the voltage supplied to my ceiling fan through ADC pin of esp 12.
I know esp can read only 1V max, that is way I am using 1M Ohm and 4.7K Ohm resistor combination which converts 220VAC to 1VAC when the fan is at full speed and the 1V drops accordingly to the step regulator

I am getting right values when I test it using my Multi-meter. The problem is I get random values when I try to read from ADC pin.

I tried supplying DC power (between 0 to 1 V) to the ADC pin of esp and every time it gave me the accurate value.
So I though maybe because of the AC sine wave it's giving me the random value. Therefore I read 100 values from the adc read and printed the max values out of all (that should give me the peak value of the AC sine wave). But still I get random values.

Any idea how to solve this issue?
Attachments
Regulator.jpg
User avatar
By krzychb
#33830 I think you freaked out everybody (at least me :D ) showing this schematics where ESP is connected directly to the mains power :shock:

First I would apply some basic galvanic isolation to protect myself (and anybody else who may try this schematics) in case I touch a wrong pin prototyping this circuit. For example please check bottom part (with IC2 optocoupler) of circuit taken from this nice project http://www.esp8266-projects.com/2015/05 ... -with.html.
0_0 - MPDMv2 - Schematic - 0_0.jpg
MPDMv3 - Schematic from www.esp8266-projects.com


Then verify if you read “100 values” over the period of the whole 50Hz sine valve that is over 20ms (or 16.67 ms if your mains is 60Hz). This is likely why you are now sampling just random values.

Good luck and take care – I like your clear and organized description and hope to hear again from you :D

Krzysztof
User avatar
By trackerj
#33833 <joke mode on >
Looks like a evil geek combination of Scary Movie 5 and Final destination 7.
</joke mode off - no offence intended!>

Now let's get serious.

First: You don't want something like that. Ever. MAINS power line means that without a proper isolation you are looking for trouble. Big trouble.

Second: I think what you want there is maybe to measure the Current not the voltage?
In this case, one of the easiest way to do it is to use a dedicated sensor like ACS : ESP8266 - ACS712 Current sensor example
User avatar
By Barnabybear
#33838 Hi, I don't normally comment on mains powered projects - but as you have seen from the previous two comments the method you are using is not safe. Please disconnect it now ensuring the power is off.
Secondly, the plan that you had was good and in theory would work but it is so dangerious you will never see it done, I strongly urge you to leave this as theory and try a much safer direction.
I agree with trackerj, if you are wanting to measure the amount of work the fan is doing, current will give you a better indication than voltage.
Below are two links to what are called current transformers used with Arduinos. Think of these as a current divider, like your voltage divider. But much safer.
http://www.homautomation.org/2013/09/17 ... d-arduino/
http://openenergymonitor.org/emon/build ... -interface
There are lots of current transformer projects online to guide you.