# Arduino AC input sensing by PC817 Opto-Coupler

#### imranahmed

Please let me know that I want to measure AC mains 220VAC by using PC817. I googled but only I found zero-crossing detector circuit but I want to measure AC Voltage.
I built circuit for measuring AC but I am slightly confuse that is it right approach I used in attached circuit. Please comment your suggestions for more improvement.

#### Attachments

• 25.3 KB Views: 19

#### codemaster11

##### Member level 5
what's the value of the voltage at R8 = 20k if input = 308vdc, 2nd the 27k resistor at the pc817
is much greater to turn it on, reduce it to 1k, adjust the divider so that 5vdc appear at R8 it will turn pc817
turn on but still there will be slight variation with 5vdc put a 47uf/50vdc electrolyte capacitor.

### imranahmed

points: 2

#### betwixt

##### Super Moderator
Staff member
You can do it that way but it requires calibration and the results will likely be different from one PC817 to another.
What you are doing is creating a DC current from the AC supply then converting it into a voltage with the optocoupler. The result will depend on the individual device and temperature, not really useful and not repeatable.

A better strategy is to convert the AC voltage to a digital format then pass the result through the optocoupler.

Brian.

imranahmed

### imranahmed

points: 2

Some possibilities depending on accuracy you are trying to achieve -

Or use V to F >> coupler >> F to V ( a processor measuring period/freq) on receive side.

Regards, Dana.

Last edited:

#### KlausST

##### Super Moderator
Staff member
Hi,

I´d make it more simple while more precise/linear.

I´d omit C1 and R8.
Then make R7+R4 = 330k
make C2 = 100F

Then I´d expect about 3V output @ 220V sine RMS input. (= average rectified)
(CTR = 50%)

Fur sure it depends on type, batch, temperature, age....

Klaus
--- Updated ---

Btw:

RV1 = 1k is not useful for real life.

Klaus

imranahmed

### imranahmed

points: 2

A simple low cost approach would be to use an ATTINY85 on sense side, measure V with its
A/D and a divider, convert that to pulse width or freq, and send that thru a standard coupler
to receive side. Receive side use a processor to measure freq or pulse width. Again depends
on accuracy you are seeking. There are processors that have +/- .1% Vref on them which is
>> accuracy that the Atmel parts. At greater cost of course.

The bridge could be eliminated, just a single diode , a zener and R for ATTINY85 Vdd.. a cap for
ATTIONY85 Vdd......

Regards, Dana.

Last edited:

#### imranahmed

Hi,

I´d make it more simple while more precise/linear.

I´d omit C1 and R8.
Then make R7+R4 = 330k
make C2 = 100F

Then I´d expect about 3V output @ 220V sine RMS input. (= average rectified)
(CTR = 50%)

Fur sure it depends on type, batch, temperature, age....

Klaus
--- Updated ---

Btw:

RV1 = 1k is not useful for real life.

Klaus

#### KlausST

##### Super Moderator
Staff member
Hi,

It's just an example. Do the simulation on your own.

Klaus

#### imranahmed

Hi,

It's just an example. Do the simulation on your own.

Klaus
Ok

#### imranahmed

Please let me know why 100k resistors got heat up but touchable current through both resistor is 1.5mA and voltage across each resistor is 140 V in real circuit not simulation.
V = sqrt(PR) = sqrt(1 x 100000) = 316.22V maximum safe operating voltage for 100k1 watt resistor.
I = sqrt(P/R) = sqrt(1 / 100000) = 3.162mA maximum safe operating current for 100k 1 watt resistor.

#### Attachments

• 29.9 KB Views: 7
• 97.1 KB Views: 7

P = I^2xR = .225W
P = R^2 / R = 19600 / 100000 = .196W

In both cases I assumed your I and V were RMS values.....

So they are << 1W, should not be hot.

Regards, Dana.