How do i make readings from a high voltage AC source

Hello, this is my first time working with arduino and im working on a project where i have to take readings from a piezoelectric damper and control a switching circuit using the arduino. Switching has to occur at every zero crossing. The source can generate readings of up to 200V and i know that arduino can only accept voltages in the range of 0 to 5V.

How can i take voltage inputs from the piezo so that i can realiably do the required switching at the zero crossings? Im guessing I would need some sort of external circuitry to step down the voltage before giving it to the arduino as an input.

Is the 200V signal coming directly from the Piezo or from the power line? Are you trying to switch the AC power line at the zero crossing?

Any connections to the power line need to be electrically isolated for safety.

If the 200V is coming from the Piezo, you can simply use a [u]voltage divider[/u] (2 resistors) and a pair of [u]protection diodes[/u] to knock-down the voltage. (The protection diodes are in case the voltage is not 100% predictable or controlled.) Isolation isn't required for the voltage directly from a Piezo. It isn't dangerous to you because it has very low current capability. But, it can kill your Arduino.

If you need to switch AC power at the zero-crossing, you can get a [u]zero-crossing solid state relay[/u]. A relay provides electrical isolation, and with this type of relay, your Arduino doesn't need to "know" where the zero-crossing is... You activate the relay and it switches-on at the next zero-crossing (and it will also wait for a zero-crossing before it turns off).

If you are confident building power-line circuits, you can build your own solid state relay with a special [u]zero-crossing opto-isolator[/u] and a TRIAC.

You load up the sensor with a parallel resistor to reduce the peak voltage. It is also best to buffer the signal with an op amp. Or use catcher diodes to each rail to clamp the sensor voltage.

DVDdoug:
Is the 200V signal coming directly from the Piezo or from the power line? Are you trying to switch the AC power line at the zero crossing?

Any connections to the power line need to be electrically isolated for safety.

If the 200V is coming from the Piezo, you can simply use a [u]voltage divider[/u] (2 resistors) and a pair of [u]protection diodes[/u] to knock-down the voltage. (The protection diodes are in case the voltage is not 100% predictable or controlled.) Isolation isn’t required for the voltage directly from a Piezo. It isn’t dangerous to you because it has very low current capability. But, it can kill your Arduino.

If you need to switch AC power at the zero-crossing, you can get a [u]zero-crossing solid state relay[/u]. A relay provides electrical isolation, and with this type of relay, your Arduino doesn’t need to “know” where the zero-crossing is… You activate the relay and it switches-on at the next zero-crossing (and it will also wait for a zero-crossing before it turns off).

If you are confident building power-line circuits, you can build your own solid state relay with a special [u]zero-crossing opto-isolator[/u] and a TRIAC.

Hey mate, thanks a lot for the reply. The 200V would come directly from the piezo. If i implemented a voltage divider and then used that as an input to the arduino, would it be able to read the small values accurately?

For example if i divided voltage by 200 and fed that to the arduino, would it be able to accurately detect a zero crossing? I would be providing an offset aswell to prevent negative voltages from entering the circuit so I need a way to measure the zero crossings accurately at an input rate of around 30hz (ie the piezo generates a signal at 30hz and my circuit needs to switch accordingly

For example if i divided voltage by 200 and fed that to the arduino, would it be able to accurately detect a zero crossing? I would be providing an offset aswell to prevent negative voltages from entering the circuit so I need a way to measure the zero crossings accurately at an input rate of around 30hz (ie the piezo generates a signal at 30hz and my circuit needs to switch accordingly

I was confused about your zero crossing... I wasn't sure if you wanted the zero crossing of the AC power or for the Piezo.

The Arduino has a 10-bit ADC which reads 0-1023. Please check my math, but if it's a sine wave with a 5V peak-to-peak amplitude (biased at 2.5V) that should give you a resolution of about 0.1 degree at the zero crossing.

If that's not accurate enough you may be able to interpolate... If everything is perfect, there is no noise in the 30Hz signal, it's a sine wave and the frequency & amplitude is constant, your bias is exactly 2.5V, and the ADC is perfect, the zero crossing would be equal to 511.5 (half of 1023). the ADC is integers but you can read the 511 time and the 512 time and then interpolate to find when the zero-crossing happened. Then since you know the frequency, you know exactly when the next zero-crossing is coming.

Of course, in the real world all of these things are not perfect and its a question if you can be accurate enough for your needs. i.e. A light dimmer's zero crossing/triggering can be off by a couple of degrees and it's no problem as long as the trigger isn't on the wrong side of the zero-crossing.

I did something similar when I made a light dimmer... I detected some point (maybe 5 or 10 degrees) and calculated when the next negative-going and next positive-going zero crossings were going to happen. (That project was a long time ago and it didn't use an Arduino.)

DVDdoug: I was confused about your zero crossing... I wasn't sure if you wanted the zero crossing of the AC power or for the Piezo.

The Arduino has a 10-bit ADC which reads 0-1023. Please check my math, but if it's a sine wave with a 5V peak-to-peak amplitude (biased at 2.5V) that should give you a resolution of about 0.1 degree at the zero crossing.

If that's not accurate enough you may be able to interpolate... If everything is perfect, there is no noise in the 30Hz signal, it's a sine wave and the frequency & amplitude is constant, your bias is exactly 2.5V, and the ADC is perfect, the zero crossing would be equal to 511.5 (half of 1023). the ADC is integers but you can read the 511 time and the 512 time and then interpolate to find when the zero-crossing happened. Then since you know the frequency, you know exactly when the next zero-crossing is coming.

Of course, in the real world all of these things are not perfect and its a question if you can be accurate enough for your needs. i.e. A light dimmer's zero crossing/triggering can be off by a couple of degrees and it's no problem as long as the trigger isn't on the wrong side of the zero-crossing.

I did something similar when I made a light dimmer... I detected some point (maybe 5 or 10 degrees) and calculated when the next negative-going and next positive-going zero crossings were going to happen. (That project was a long time ago and it didn't use an Arduino.)

I guess that would be accurate enough, Im working on a switching circuit so Id need to turn on a switch for a very brief moment at each zero crossing.

I had another query, what if i used an opamp (741) and then passed that through a RC series circuit and used these pulses for my switching instead? This way i would not need to use any offset and my divider circuit would not have to divide by that much. Would I still get decent accuracy using this setup?

Hi, If all you want the arduino to do is detect zero crossing and output a pulse, then I'd be looking at a hardware solution rather than a software. Google "zero crossing detector circuits"

Tom.. :)

If you are using an old style power supply:

I'm sure someone can chip in with "The 741 is old technology don't use that. Use something more modern like..."

A comparator might be the better choice. This is an opamp specifically designed for fast, accurate switching. Set up an input filter/protection/voltage divider circuit, feed it to the comparator and get clean 5V digital out the other end.

I've never designed a circuit for a comparator so I don't have any good part numbers to suggest but start reading datasheets and application notes - I'm sure an opamp manufacturer has published a circuit which will do almost exactly what you want.

curiosity14:
The 200V would come directly from the piezo.

The problem I have with the idea of an opto isolator is that I don’t think there is enough power from the output of this sensor to light the LED.

Good point.

Using a voltage divider (2 resistors) with AC will also give you a negative voltage on the analog input. According to the ATmega datasheet the maximum allowed negative input voltage for any pin is -0.5volts.

So your voltage divider should not give you more than 0.2 volts (just to be on the save side). As you just want to detect the zero-crossing you need to write a routine that gives you a signal when the zero crossing from positive to negative occurs and another signal when the negative to positive crossing occurs.

In other words, you want 2 signals - one when the input will give you an analog reading of 0 and one when it gets back to a value higher than zero. Your input signal will be on the negative side for half your puls lenght if your signal is symmetrical.

As you just want to detect the zero crossing, accuracy is not a problem, so a 0.2 volts input should be OK.

It is very important that your routine is fast enough that it will not loose the zero crossings.

As far as I know an analog input cannot generate interrupts when in analog mode, so in your case interrupts would not be a viable solution to compensate for long routines.

Another solution would be to use a rectifier diode in front of the voltage divider, that protects you from negative voltages. In this case you could use a higher input voltage for your analog input (up to 5 volts). This is only required when your input signal has a sinewave form, because in that case it might take some time between a 0 and a 1 or higher reading. In that case the frequency is also a factor. And in that case your analog output might never go down to zero (voltage divider in parallel with internal electronics). So your desired switching point migth be 3, 6 or even 10 (analog output value).

If you have a rectangle waveform, you do not have to care about this and the above 0.2 voltage solution will work perfectly.

Like always, there are several solutions.

Thanks for the replies guys, I think the best thing for me to do is to find a hardware solution as was stated by someone.

I tried to implement the zero crossing detector using a 741 but the pulses are being generated with some delay after the actual crossing. I attached the schematic i made. Used an online free site to make it but yeah its a pretty basic opamp circuit. I used a function generator to output a 5v 20hz sine wave and had 15v vcc. Is there any way to get a better output?

What are some alternative ICs i can use other than the 741? I was looking at the LM339 or 393, are these any better?

@polymorph: Can i use the circuit you provided with a piezo as the input? (talking about the second one) Do i just connect the positive and negative outputs to the IN1 and IN2? What if i only have one output?

schemeit-project.png

I used a function generator to output a 5v 20hz sine wave and had 15v vcc. Is there any way to get a better output?

Yes use a proper circuit and a proper op amp.

What on earth do you think that capacitor is doing? Why is there no feedback? Where do the "other end" of the components go? Are you using a virtual ground or one from the center tap of the op amps power supply.

I was looking at the LM339 or 393, are these any better?

Well apart from the fact that they are not op amps, yes they are a lot better.

You can use the little known internal comparator in the Arduino:- http://gammon.com.au/interrupts

Grumpy_Mike: Yes use a proper circuit and a proper op amp.

What on earth do you think that capacitor is doing? Why is there no feedback? Where do the "other end" of the components go? Are you using a virtual ground or one from the center tap of the op amps power supply. Well apart from the fact that they are not op amps, yes they are a lot better.

You can use the little known internal comparator in the Arduino:- http://gammon.com.au/interrupts

The capacitor is converting the square wave generated by the opamp (which goes into plus or minus vsat depending on the input) into pulses at the zero crossing. I take the output after the capacitor. Im not sure why i need feedback here, Would adding feedback give me a better output? Im just using the opamp as a comparator tbh

I am using the ground from my power supply, couldnt find this in the schematic generator.

The circuit just needs to turn on a switch for a certain amount of time at each zero crossing of the input piezo. Im stuck using the components available in this lab and its pretty outdated stuff here unfortunately apart from an arduino Atmega and Im afraid of frying that board since there is no replacement.

I apologize if my questions seem basic but Ive been searching online a lot and cant find anything that really seems to work well.

The capacitor is converting the square wave generated by the opamp (which goes into plus or minus vsat depending on the input) into pulses at the zero crossing.

That capacitor is generating negative voltage spikes into the Arduino input and thus in time will fry that input at least. There is no need to convert the square wave into pulses you can detect a positive or negative edge in software if you need to distinguish between them.

I am using the ground from my power supply, couldnt find this in the schematic generator.

So the ground is the negative rail of the op amp? You need to generate a virtual ground by using two resistors between +5V and ground, the junction should then be treated as a ground.
Unless the op amp is supplied with a single 5V power supply then the op amp’s output could exceed the 5V rail on your Arduino and again would fry the input. If you are using a higher voltage you must take steps not to exceed the Arduino’s power supply voltage on the input. This can be done with a potential divider and catcher diodes. See:-
http://www.thebox.myzen.co.uk/Tutorial/Protection.html
or
http://www.digikey.com/us/en/techzone/microcontroller/resources/articles/protecting-inputs-in-digital-electronics.html

Could you please show us what the input signal looks like. A hand drawn illustration would be fine. However, please add some information about the voltage (200V according to your post) and the TIMING.

Timing seems to be so important that you should give us a little bit more information.

And how does the signal look like. Piezo is used in cigarette lighters and other stuff.

Is THAT what you are talking about. In that case we have to think of high voltage spikes and nothing else.
ZERO crossings are only relevant in other waveforms (sine/sawtooth).

please, just give us more information.

arduinoaleman: Could you please show us what the input signal looks like. A hand drawn illustration would be fine. However, please add some information about the voltage (200V according to your post) and the TIMING.

Timing seems to be so important that you should give us a little bit more information.

And how does the signal look like. Piezo is used in cigarette lighters and other stuff.

Is THAT what you are talking about. In that case we have to think of high voltage spikes and nothing else. ZERO crossings are only relevant in other waveforms (sine/sawtooth).

please, just give us more information.

The input is a damped sine wave that can have voltage peaks of up to 200V at the highest. The frequency is around 20hz so i dont think it should be hard to detect zero crossings accurately. I need to make a circuit that will turn on a switch for a very short amount of time every time there is a zero crossing. What is the best way to do this? The source is a piezoelectric patch that acts as a vibration damper.

So far, Ive tried to implement a zero crossing detector using an opamp as a comparator followed by a series RC that converts the square wave into pulses. However, the pulses are not in line with the zero crossing for some reason (Im using the ua741 but i guess that is a shit opamp and should not be used, however the resources in this lab are fairly limited).

I also have an arduino atmega 2650 with me that i can use but im not sure how to do so without frying the board.

So I need a simple way to detect zero crossings in a 20hz sine wave and turn on a switch at each zero crossing or a brief amount of time. All solutions are appreciated.

How about an NE2 bulb with resistor, heat shrink to a phototransistor?

You said this is a 20Hz sine wave. Continuous? If so, you could use the time that the NE2 turns on and off again to determine the approximate zero crossing. The NE2 turns on at a somewhat higher voltage than it turns off, so it’ll be just a bit before the halfway point when the NE2 is dark.

How accurate must this be?

Or are these individual pulses, arriving at about 20Hz rate, but the pulses are much faster?

Hi,

You started by talking about a piezo “damper”, can you tell us the full application.
What is the damper connected to and what do you want the output of the arduino to control.
In other words what is the full application of your project.

What is the piezo you are using, and a picture of your project or its components will help immensely.

Tom… :slight_smile: