Agriculture Automation

Today, agriculture production has all the characteristics of a modern production line. One has to continuoulsy monitor the production, select the right materials and machines, experiment for improving the product quality, and try to minimize the energy consumption. Towards this context, Pamvotis can implement advanced solutions in order to achieve all the above. Exploit the automation technologies, the communication networks and the smart phones, in order to achieve the maximum...


HMI/SCADA Software

HMI stands for Human Machine Interaction. SCADA stands for Supervisory Control and Data Acquisition.Every modern industry must have the ability to: Monitor the production line in graphical interface Control the production line remotely Log vital parameters through measurement devices, and analyze data in order to produce results about the performance of the overall production Log and analyze data concerning energy consumption Produce alarms in case of malfunction Utilizing the beauty of web design, the...


Home automation / Green automation

Home automation refers to the use of computer and information technology to control home appliances and features (such as windows or lighting). A home automation system integrates electrical devices in a house with each other. The techniques employed in home automation include those in building automation as well as the control of domestic activities, such as home entertainment systems, houseplant and yard watering, pet feeding, changing the ambiance "scenes" for...


Industrial automation

Industrial automation deals with the optimization of energy-efficient drive systems by precise measurement and control technologies. Pamvotis offers a variety of design and consulting solutions in order to create or upgrade existing automation procedures. Make your production line productive: Configuration of drives. Programming of PLCs. Design of electrical distrubution boards. Design of control and automation panels. Power consumption optimization with modern process control. Provision, installation and maintenance of measurement equipment. Development of HMI/SCADA software. Pamvotis is here to...


IT & Network Support

Pamvotis qualified personnel is here to provide support to IT infrastructure of your enterprise, which include: Design and implementation of new IT solutions. Technical support, improvement and extension of existing IT infrastructures. We are able to support almost every IT application / sector, among which are: Computers: Desktop PCs, laptops Peripherals: Printers (inkjet, laser, dot matrix), Copiers, Scanners, Plotters, FAX machines Telephony: Cabling, ISDN centers, VoIP telephony, Mobile telephony Networking: Cabling, configuration of switches, routers, modems...


Mobile Applications

Today's mobile phones are, more or less, compact computers. Advanced hardware components give the ability to develop and run applications that can do things one cannot imagine. Pamvotis works towards building custom applications for smartphones. If you own a business and an a smartphone, then take the chance to contact us. Our team will offer you a set of applications customized exactly to your business needs, in order to have: Minimum...


Network & Traffic modelling

Pamvotis researchers are specialized in network and traffic modelling, based on advanced queuing theory and stochastic processes. Our team works towards building accurate models of network protocols in order to analyze their performance, and models of telecommunication traffic, in order to test and predict the operation of various networking solutions.


Network design & Analysis

Communications and IT is an integral part of every modern company. Fortunately, there exist many infrastructure solutions from which enterprises can choose. We are here to help you design and implement networking solutions that best fit your application's needs, with the minimum cost. We use combinations of networking protocols in order to cover the most demanding applications with the maximum user satisfaction. Some of them include: xDSL Leased lines (E1 / E3) Ethernet...


Network Simulation

Have you heard about Pamvotis WLAN Simulator? It is a free, open source project, aimed to build a platform for simulation of IEEE 802.11 ad hoc networks. Have a look here (! Our experienced telecom engineers, along with our developers are working towards building accurate, fast, scalable network simulators for: Performance testing of existing networks Design of new networks of extension of existing ones. Research use for validation of network models.


Resource management of 4G networks

A 4G system provides mobile ultra-broadband Internet access, and integration of various wireless technologies, like 3GPP LTE, mobile WiMAX and IEEE 802.11n. Conceivable applications include amended mobile web access, IP telephony, gaming services, high-definition mobile TV, video conferencing and 3D television. Pamvotis research activities in 4G networks include network modelling, implementation of radio resource management algorithms for handovers and call admission control, extension of MAC protocols for improving network throughput...


Web Design

Pamvotis offers a variety of web applications, ranging from websites for individuals, blogs, commercial sites, to complex e-commerce solutions. Update your existing website. If your site is outdated, you came to the right place. Pamvotis offers you the ability to update it according to today's business needs. Advertise yourself. All our web applications are Search Engine Optimized.


AC PWM Library for Atmel Atmega8/168/328 AVR microcontrollers and Arduino

This library was created for tuning AC power with Pulse Width Modulation (PWM technique) and zero cross detection using Atmel® Atmega8/168/328 AVR microcontrollers and the Arduino® prototyping board.

Download the library and start using it, or see below for more details.            download


Instructions of use


Example of use

Latching adjustment


Background information 

What is AC power control and what do we need to achieve it? 

What is PWM and how can we control AC power with that? 

What is zero cross detection? 

Why do I need the microcontroller?

Useful links 


What is AC power control and what do we need to achieve it?

Mains power is an alternative current (AC) with a sinusoidal wave of a specific frequency (50 or 60Hz), and a specific amplitude (from 110 to 240V). Parameters are specific for each country (see here). Of course, we are talking about one phase power. 3 phase power is a different case, not considered here.

Suppose we have a load (e.g. a lighting bulb) connected to mains power. How do we make the bulb light less? The answer is that we must feed the bulb with less power than the maximum it gets. And that is exactly what AC power control means; The means of regulating (tuning) AC mains power with an efficient manner in order to limit the energy provided to a load connected (e.g. lights, thermal units, audio devices, motors  e.t.c.).

In order to build a circuit that controls the AC power with PWM, your will need:

  • A switching element like an opto-TRIAC or a SSR.
  • A zero crossing detection circuit
  • A micro-controller that produces the PWM driving pulse.
  • Each one of the aforementioned elements is explained below.


What is PWM and how can we control AC power with that?

The first way to do that is to shrink the amplitude of the power. In other words, lower the voltage. This can be done by adding a variable resistor in series for example. But this has the disadvantage that the power consumed is actually the same (the sum of the load power and the variable resistor power).

The second, and most effective way is to tune the frequency. Suppose we add a switch between the light and the mains power socket, in order to close the switch (light on) for 5 seconds and open the switch (light off) for another 5 seconds sequentially. Then, the power we consume is 50% of the maximum power consumed. If we do that with a frequency as high as the human eye cannot understand, then we have the bulb light with 50% luminance. Believe it or not, this is how dimmers work.

The rapid switching of the light is achieved with the use of a driving, periodic pulse. When the pulse is OFF, the switch is open and the light is OFF. When the pulse is ON, the switch is closed, and the light is ON. Depending on the width of the pulse, we can tune the percentage of time the switch is OFF and ON state. And this is exactly what AC power control with Pulse Width Modulation is. In the following figures, we can see three different ways to limit the power to 1/3 (33%) of its maximum.


In all cases, the percentage of OFF period is 2/3, and the percentage of ON period is 1/3. What is different is the period of the pulse. In the first figure, this is 6 AC waves. In the second figure it is 3 AC waves, and in the last figure it is 1/2 AC wave. Respectively, the duration of the ON time is 2 AC waves in the first case, 1 AC wave in the second case, and 1/6 AC wave in the third case. The duration of the ON period of a PWM pulse is called duty cycle, and it is a vital parameter for the power control.

The only thing we need now is a switching element that can stand enough power and can be switched fast enough, in order to get what we expect. These elements are called solid state devices. Among them, opto-TRIACs and Solid State Relays (SSRs) are the most popular for one phase AC power control. These devices have a contact which makes the switching of the load, and a gate, which closes / opens the contact, depending if voltage is applied or not, respectively. Well, things are a little more complicated, so we recommend some background reading on what TRIACs and SSRs are and how they work.


What is zero cross detection?

Considering the above, one would say that the faster we switch a load, the better the results. So, we can switch the mains many times in an AC wave period. Well, this is generally true, but there are some limitations. When we switch off AC mains at a point in time where the amplitude of the sinus wave is high, then spikes and EMI (electromagnetic interference) are created. Hence, the optimum point to switch off an element is when the amplitude of the mains sine wave is near zero. This point is called zero crossing point, and happens twice in every AC cycle. This limits us to switch the mains only once every half sine wave. Furthermore, this limits the frequency of the driving pulse to 2 times the frequency of the AC mains. This is the third case of the figure above.

However, another problem no rises; How do we know when the amplitude of the sine wave is zero (zero crossing point)? This is exactly the meaning of a zero crossing detection circuit. It is a circuit that is fed with mains power, and low voltage (e.g. 5V) DC pulse at every zero crossing point. The pulse can be momentary (e.g. delta pulse) or square wave pulse. Note that, in most cases, zero cross detection is necessary for avoiding unexpected situations. There are many patterns available for building a zero cross detection circuits easily, with low cost, using diodes and opto-couplers. Some examples can be found herehere and  here. There are also ICs for this purpose, like the Atmel® AVR182 zero cross detector.


Why do I need the microcontroller?

The microcontroller is the ‘smart’ element that performs the whole operation. It takes an input from the zero crossing detector and produces an output pulse which drives the gate of the switching element. Usually, an intermediate element is necessary between the AC switching unit and the microcontroller.

Moreover, the microcontroller provides the interface with the user, through LED displays or touch screens, push buttons, rotary tuners, switches e.t.c. After all, mains control may not be the only operation of your project, so the microcontroller may be doing other staff as well.


The library

There are many libraries available for AC power control with PWM, each one having its own advantages. Towards this direction, our purpose was to build an integrated library for the ATMega Atmega8/168/328 chipset, with support of zero cross detection. The library allows the definition of many parameters, in order to be easily used with a large scale of electronic devices. The use of the library requires minimum to zero knowledge of programming, and probably, the user will not need to modify the source code of the library.


Instructions of use

Use of the library is just a three-step process:

  1. Unzip and place the extracted folder inside the libraries folder of your Arduino setup.
  2. At the start of your code, use the following statement to include the library in your sketch: #include <ACPWM.h>
  3. Use the methods provided with the following statement: ACpwm.method();   where method() is the name of the method you want to use.

See below for a list of supported methods.



The library is constituted of the following methods:


void initialize(int frequency, int zeroControlPin, int zeroPulseMode, int pwmPin, int scale);

This method is used once, at the setup() function of your sketch. It defines the parameters of your PWM operation.

frequency: The AC mains power frequency, e.g. 50 for 50Hz.

zeroCrossPin: The Arduino pin that accepts the zero crossing pulse. e.g. 2 for pin 2.

zeroPulseMode: Four modes are supported, that describe the zero pulse:

LOW: Zero cross happens whenever the pulse is LOW.

CHANGE: Zero cross happens whenever the pulse changes.

RISING: Zero cross happens whenever the pulse goes from LOW to HIGH.

FALLING: Zero cross happens whenever the pulse goes from HIGH to LOW.

These modes are the same exactly as the modes of the Arduino’s mainInterrupt() function (see specs).

Example of use: CHANGE: When the pulse is square wave. RISING: When the pulse is Delta.

pwmPin: The Arduino pin that produces the PWM pulse. E.g. 9 for pin 9. Attention: This pin must be either pin 9 or pin 10. If other pin is defined, pin 9 will be used.

Scale: The scaling of the duty cycle. For example, if scale=255, the duty cycle can have 256 distinct values (0-255), expressed as a percentage of the PWM pulse.


void setLatch(int basicLatch, int onLatch);

Some times electronics don’t work as we expect. In our case, there may be some delay to the response of the zero cross detection circuit or the ON and OFF switching of the switching element. This is called latching. If this delay is small, there is no problem. However, there are cases where unexpected problems occur. In order not to have you change your circuit, this library provides the setLatch() method, which absorbs the latching of your circuit. This method is (optionally) used once, right after the use of the initialize() function.

  • basicLatch: The latching of the pwm pulse at the zero crossing point.
  • offLatch: The latching of the PWM pulse at the transition from the OFF to the ON state.

The use of this function is optional. If not used, zero latching is assumed. For more information on using this function, see latch adjustment, at the end of this page.


void setDutyCycle(int dutyCycle);

This method can be used dynamically, whenever and whenever you want, in your sketch. It sets the duty cycle of your PWM operation, in respect to the scaling you set on the initialize() function. Example: If you set scale=255 and dutyCycle=80, then you provide a mains power of 80/255 = 31.3% of the maximum power the load consumes. Obviously: 0 <= dutyCycle <= scale.


Example program

The following program uses a potentiometer, a zero crossing detector and a switching unit (e.g. TRIAC) to dim a light with the use of Arduino. 



 /* AUTHOR: Dimitris El. Vassis - 2013 */


 #include <ACPWM.h>

 #define ZERO_PIN 2 //Input pin from zero cross detector
 #define PWM_PIN 9 //Output pin to TRIAC / SSR

 int SET_PIN = A0; //Analog pin for setting the dutyCycle value with a pontentiometer


 void setup()
    pinMode(ZERO_PIN, INPUT);
    pinMode(PWM_PIN, OUTPUT);
    //Initialize PWM operation.
    //Mains frequency: 50Hz.
    //Zero crossing point reached whenever pulse to PIN2 changes
    //Duty cycle = 0..255. 0:always off. 255: always on. 150: 59% on.
    //Latching when voltage is positive: 3 microseconds.
    //Latching when voltage is negative: 5 microseconds.


 void loop() {
    //Adjust the power with the potentiometer
    //Set the duty cycle equal to the value of the potentiometer.



Latching adjustment

 As explained above, latching is the delay faced by electronic devices (zero cross detector, switching unit) to respond. If you face latching problems in your circuit, use the setLatch() function to absorb them. You will need an oscilloscope with two channels in order to see what’s going on. Connect channel1 of the oscilloscope to the AC mains, and the other one to the pwm pin of the Arduino board.

(a) Observe the delay between the zero crossing point and the fall of PWM pulse from ON to OFF state. If the falling of the PWM pulse is before the zero crossing point of the AC mains, set the basicLatch parameter to a positive value, in MICROSECONDS. If the falling of the PWM pulse comes after the zero crossing point of the AC mains, set the basicLatch parameter to a negative value, in MICROSECONDS. Obviously, if the two points coincide, set the onLatch parameter to zero. Load the script and test. Readjust if necessary.

(b) Set the duty cycle to 50%. Observe the PWM pulse on the oscilloscope and calculate the difference d = onPeriod - offPeriod. Set the onLatch parameter to onLatch = d, in MICROSECONDS (may be negative as well).