Measuring 230v

Hello all, this is my first visit here and I haven't even got my Arduino in hand yet (bought but not yet delivered) so please excuse stupid stuff.

First up, I have lots of experience with mains and higher voltage but zero with microcontrollers etc apart from doing a programming course at school on an Apple IIe a year or two back.

I have built a hydroelectric plant on a waterfall on my property, the output is 230v and I use it directly in the house although only on rugged resistance loads until it is better regulated.

When the load (demand from the house) is too high the torque from the generator slows the turbine and the voltage and frequency drop. I am starting to design a system to turn off items in a priority order based on the voltage. By chance, I bought an Arduino starter kit to play with with my daughter and realise it could be a better and cheaper solution than the current/voltage sensing relays I was planning on using.

There are bound to be more questions as I look into this but the first one is. If I buy a wall wart and bypass the capacitor will I have a signal that I can read from an analog input to determine the voltage from my generator? The best way I can see to control the load shedding is by voltage as the output of the generators change with the water level so the max current can change day to day, however, the frequency and voltage seem to be linear so if the voltage is constant the frequency will be as well.

That's a lot of writing for my first post.

Thanks for any help/advice.

I think there is no problem using voltage divider (with large resistors and protection diodes to Vcc and GND) directly from mains. You must provide between 0V and 5V to Arduino. On the other hand measuring frequency using zero crossing detection would be easier in my opinion. Look at this app note. But I never tried to do anything with more than 20V - you say you have experience with high voltage so I hope you know what you are doing.

I don't know what "wall wart" is. Wikipedia says it is any AC/DC or AC/AC adapter. It depends on type if and how you can hack it to get readings. Again possibly safest way would be to use some that let mains frequency to pass and measure the frequency. This way you may stay isolated and get the result (you say frequency and voltage are linear).

You could also look here for ideas.

I would offer that you sound like an inventive person and before long, you will explore the abilities of your Arduino.

voltage is about as simple as it gets. put in two resistors of equal value, and you get exaclty half voltage when you measure voltage over one of them.
get 3, and you get 1/3 when you measure voltage over one.
get a 10,000 ohm and a 1,000 ohm and you get 1/10 voltage.
it is called a voltage divider.

the only concern I would offer is the resistor rating of max voltage. the actual area of the resistor is rather small and the ability of 230 volts to jump that gap is high. if you use two 10,000 resistors in series, and one 1,000 as the third, you can reduce the voltage drop over each of the first two is just under half of your 230volts. as a note, the max voltage rating across a single resistor is about 150 volts. resistors are pennies, so putting 3 resistors in series would cost less than a nickle.

most of us never get that high voltage so rarely pay attention to this small detail.

lots and lots and lots of calculators on the net about voltage dividers.

resistance and voltage are two of the 3 parts of Ohm's law so this is a fundamental building block.

BTW, if you are buying these things there are lots of suppliers.
tadya offers many of the basic parts,
search this list for suppliers and you will find there are a dozen that cater to us hobbyists.

e-bay and aliexpress come from China and can take weeks. you trade cost for time. sometimes the cost is not even better.

for resistors, if you take two 1,000 ohm or 1k resistors and twist the ends together (parallel), you have an effective 500 ohm unit, twist 3 and you have a 333 ohm. starts to look ugly, but is functional.

10k, 1k are the ones we all have in bulk. (100 pack)

Resistors come in power ratings. 99% of our toys/projects are under 1/2 watt, with probably 80% under 1/4 watt.

more than you asked for, I'm sure.

Wow, great response time. I'm sure there is an Arduino joke in there that's not too corny. Thanks all for the very helpful comments.

I did do some research before asking the question and I probably shouldn't be scared to try building a voltage divider, I even did the math already for the ratio of resistors I would need. I just thought a wall wart would be pre-built and cheap and save some time but hey, I bought the Arduino to start on an electronics learning journey so I should give it a go. I would also need to figure out how to convert to DC which I have seen explained on this forum.

Dave thanks for your excellent reply. You say "as a note, the max voltage rating across a single resistor is about 150 volts". Is that common to all resistors? If I go to my local electronics store and buy your bag of 100 1k will they be good up to 150v? This is a question I had asked myself as I was looking into building a voltage divider.

...get a 10,000 ohm and a 1,000 ohm and you get 1/10 voltage.


10:1 = 1/11

If I go to my local electronics store and buy your bag of 100 1k will they be good up to 150v?

Uhh. no.
There is also a power rating. About 0.5watt max for common through-hole resistors.
A 1k resisor connected to 150volt would use 150volt^2 / 1000ohm = 22.5watt, and burn up in seconds.

The question about the resistor is not only about voltage but also about the current. Any small 0.25W resistor is good to use with 230V. Usually it is up to 500V. You have to choose the value of resistor in respect of its power rating (U.I).

EDIT: Wawa was faster.:slight_smile:

Any small 0.25W resistor is good to use with 230V. Usually it is up to 500V.

Early TV/VCR switching supplies (eighties) had a single 150k/0.5watt startup resistor from the rectified mains to the base of a chopper transistor (~310volt DC across). Many failed within a few years.
Later models has two resistors in series.

Measuring AC Voltage with an AC to AC power adapter

Thanks Bill, that article answers my question perfectly and is just what I need to get going in the right direction.

Early on I would see 300v with no load so I will adjust based on a fudge factor over 300v just in case and will still have plenty of resolution to get the accuracy I need.

It is best to transformer-isolate and step-down the voltage.

Since you are comfortable around line voltage, I'm not too worried about you, but here's the thing about line voltage, voltage dividers, and SAFETY... Power-line neutral isn't always ground and ground isn't always earth ground. Neutral is supposed to be connected to ground at the breaker box, and power ground is supposed to be earth ground. But wires can get crossed and ground connections can be broken, and if something goes wrong (a mis-wired outlet or mis-wired extension cord) you can end-up with 220V on the Arduino's ground and on your body. That's obviously dangerous to you and it can fry your computer or anything else you connect to the Arduino.

So, it's generally ILLEGAL to SELL anything that has a direct connection to the power line unless it's completely enclosed & insulated. i.e. You can make a voltage monitor with an LCD display as long as there are no "wires" coming out of it, or as long as any connections coming-out are transformer or optically isolated. I realize that you are not selling what you are building, but please keep these safety considerations in mind, and be careful during development because even if your final product is enclosed & safe, it won't be safe while you're working on it.

Early on I would see 300v with no load so I will adjust based on a fudge factor over 300v just in case and will still have plenty of resolution to get the accuracy I need.

An [u]over-voltage protection circuit[/u] might be a good idea too. (That's to protect the Arduino, not humans. :slight_smile: )

Thanks Doug, all very good points. I like the article on voltage protection however it looks like it will affect the voltage I measure so no good for this particular application. If I go the voltage divider route I will build it so that 400v > 5v or similar.

I am seeing more and more possibilities with the Arduino and my hydro project and I will be sure to look at voltage protection for anything using on/off signals.

A note about max voltage. if you go to DigiKey, they offer data sheets on every part.
a search for through-hole resistors
Results: 284,944
240,206 Remaining using only Yago and Visahy, seems like the two largest suppliers.
35,992 Remaining for 1/2 watt rating
194 Remaining for 1k rating
for the carbon film. the cheaper of the offerings they start at 150 volts.

for the metal film, they start at 200 volts

XIRCOM is another poplular name

I submit that if you buy any non-name brand, you will not be getting a higher rating.
the 250 volt rated metal film are twice the cost. Digikey is asking 44 cents each for a 250v rated 10k resistor.

If the name brand offer their most common resistors for 150 volts max, I would not expect that anyone would offer an off-brand product for a much lower cost that was rated higher in an area that rarely is ever approached.

Once you start laying out your own PCB's and you want to put line voltage on it for relays or some such, you become very aware of the gaps needed to isolate voltages.

All that said, placing 3 or 4 resistors on a PCB to get what you want is going to cost 20 cents.
Here in the States, we can get blue plastic electric boxes, normally for switches, that have feet and a way to put on a cover. makes your life even simpler. And, when you get into multiple gang boxes (2 switches or more), there is a place (two parallel lines) to insert a divider, or PC board to hold it in place.

Thanks Dave, I guess if I assume 150v max for each resistor and give myself a margin over that I should be fine. Like you say it costs pennies to string a few together.

You never know what little gems of info will be gleaned from your post. A google search for Digikey shows they have a French web site so I now have somewhere to look for parts other than Amazon with a no drama delivery option.

For measuring power mains I'd always go for some isolation - like the transformer in #9. Simple voltage dividers are likely to destroy your Arduino.

The main problem is the ground/neutral line on the power supply. It's almost guaranteed a different ground than the ground of your Arduino's power supply. For any sensible measurements you must connect the two together, and that may cause all kinds of trouble.

Loads on the power are likely to cause spikes when switching on and off, those spikes may pass right through your transformer and kill your Arduino. Get some overvoltage protection, a simple zener diode may be enough for that (assuming you get DC out of the transformer).

Thanks for the advice wvmarle, that's exactly the info I am looking for (as are previous posts) and why I thought it a good idea to go to a forum and ask questions.

I had briefly contemplated the neutral problem but decided my knowledge of how the circuits work is not good enough to worry about it until I have it in front of me and can play around a bit. I will probably power the Arduino of the same supply I'm measuring which should be pretty stable with the Arduino controlling the loads. The note about spikes is noted and I will start with voltage protection in place for the detection circuit, and the power supply of course, and see how the measurements go.

I finally get the Arduino today but will spend some time making basic circuits and sketches, learning with my daughter, before I get into the the main project.

Use a simple switching supply such as a usb charger to power your Arduino, then the input voltage doesn't matter much. They can handle something like 100-240v normally and the output remains stable.

A simple transformer will mirror the voltage of the mains. A doorbell transformer will drop the voltage to a very low value, but consume power. if power use is not any concern, then a transformer is a great way to drop the incoming voltage. see post #9

You can rectify that to get DC and even use a zener to limit the max voltage of the peaks.

An older wall charger will have a transformer and drop voltage and be a lower power use device. you would only need to get voltage before the regulator.

I'm still working on this and think I might have a nice solution. I have 3 meters attached to the output of the generators each with a TTL port. I contacted the manufacturer who emailed me specs which I will put in a separate post below just to keep it clear. There is a table of functions which I will include as a pic as it does not copy and paste well.

I'm on my way home after a business trip and will measure the voltage of the port and start playing around when I get back. I'm sure all info I need is online but any tips or advice is appreciated. I feel I have a steep learning curve ahead (I am reading an Arduino programming guide on the plane)

A few of things that immediately come to mind you all might like to comment on:
I do not see anything mentioned about a baud rate, I guess I will need to specify it? is it important?
The TTL port of the meter has a Vcc and GND pin, is that likely to be to power another device?
Will the TX and RX of the meters TTL conect directly to the RX and TX port on my UNO.

Screen Shot 2017-07-15 at 2.46.56 AM.png