220/380V AC Frequency Meter with Arduino

This project shows how to measure AC source frequency using Arduino UNO board where frequency and period values are printed on 1602 LCD screen.
This frequency counter can easily measure frequency of AC lines with voltages 110/220/380V – 50/60Hz.

No warranty is provided with this project, do it at your own risk!

Frequency is number of cycles (complete turns) per 1 second. Its main unit of measurement is Hertz (Hz).
Period is time required to complete 1 cycle (turn), its main unit is second.
Frequency = 1/Period.

Home alternating current (AC) frequency is 50 or 60Hz, most countries use 50Hz.
For frequency of 50Hz the period is 20 milliseconds and for 60Hz the period is about 16.67 milliseconds.

Hardware Required:
This is a list of all components required to build this project.

  • Arduino UNO board   —-> Atmega328P datasheet
  • 16×2 LCD screen
  • 330 ohm resistor
  • 10k ohm variable resistor or potentiometer
  • PC817 optocoupler   —-> datasheet
  • 120k ohm -2W resistor
  • 10k ohm
  • 1N4007 diode (or equivalent)
  • Breadboard
  • Jumper wires

Arduino frequency counter with 230/400V 50Hz system

Arduino frequency meter circuit:
Project circuit diagram is shown below.

The 16×2 LCD screen (2 rows and 16 columns) is used to display the values of frequency and period of the input voltage where:
RS —> Arduino digital pin 3
E   —> Arduino digital pin 4
D4 —> Arduino digital pin 5
D5 —> Arduino digital pin 6
D6 —> Arduino digital pin 7
D7 —> Arduino digital pin 8
VSS, RW, D0, D1, D2, D3 and K are connected to Arduino GND,
VEE to the 10k ohm variable resistor (or potentiometer) output,
VDD to Arduino 5V and A to Arduino 5V through 330 ohm resistor.

VEE pin is used to control the contrast of the LCD. A (anode) and K (cathode) are the back light LED pins.

Arduino frequency meter circuit 220V 380V

The AC input is connected to the circuit as shown where diode 1N4007 is used to eliminate negative half cycles because the PC817 optocoupler maximum reverse voltage is 6V.

The optocoupler is connected to AC main through 120k ohm resistor (and also the 1N4007 diode) which limits the current that passes through the optocoupler LED (IF).
With the 120k ohm resistor and with source of 220V, the peak forward current is equal to (neglecting diode voltages):
220x√2/120k = 2.59 mA and the RMS current (half wave) = 2.59/2 = 1.3 mA.

The output of the PC817 optocoupler is connected to the Arduino as follows:
The emitter is connected to Arduino GND,
The collector is connected to Arduino digital pin 2. This pin is also for external interrupt 0.
The collector is connected to Arduino +5V pin through pull up resistor of 10k ohm.

When the optocoupler LED is forward biased, its output is (transistor collector) is attached to GND (logic 0). During signal negative cycles the PC817 output is logic 1.
With the optocoupler high voltage side is isolated from low voltage side.

Arduino frequency meter code:
In this project I used external interrupt 0 to detect falling(going from high to low) of the optocoupler output. This interrupt is initialized as shown below:

When there is an interrupt the Arduino directly executes the function timer1_get().
Measuring the frequency idea is simple, Timer1 module is used to measure time between 2 successive interrupts which means we have the time between 2 successive falling events. When the function timer1_get() is called, it stores Timer1 value on a variable named: tmr1.

Timer1 module is configured to increment by 2 every 1 microsecond (prescaler = 8) and its overflow interrupt is enabled in order to reset the variable tmr1 (helps when signal is removed).
With prescaler = 8, the clock input of Timer1 module is equal to: Timer1_CLK = 16MHz/8 = 2MHz.

With these configuration the lowest frequency that the Arduino can measure is about 31Hz.

Signal period:
Period (in us) = Timer1_Value/Timer1_CLK = Timer1_Value/16000000/8
Period(in us) = 8 x Timer1_Value/16000000
Period (in ms) = 8 x Timer1_Value/16000

Signal frequency:
Frequency = 1/Period
Frequency (in Hz) = 16000000/(8 x Timer1_Value)

Full Arduino code:

The video below shows a protoboard circuit of the project:

Related Project:
Arduino Frequency Counter | Arduino Projects

Discover more from Simple Circuit

Subscribe to get the latest posts sent to your email.

5 thoughts on “220/380V AC Frequency Meter with Arduino”

  1. Hi, I implemented your scketch and its working fine on genuine arduino uno, but on arduino mega 2560 on pin 21 with the same timer results are different. What I’m doing wrong? For example from Arduino Uno I obtain 49.99 .. 50.1 Hz and from Mega results are 50.37.. 50.5

    1. Olaide Ayodeji Agbolade

      Hello, I implemented this circuit on my arduino uno board but the frequency i obtained from the serial monitor is 0 Hz. The period is also 0 Hz. Please what could be wrong.

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top