Everyone of us wants to control a bulb, a fan etc at some point in time. We will look at driving single phase AC devices with a Relay using Atmega32.

Basics

The relay is driven using a simple transistor switch circuit. You may look at the schematic of the driver circuit from Ultra AVR Dev Board Schematic. It is a common collector transistor switch circuit. It provides additional current required to drive the relay. The current from the controller port pin is not sufficient, hence the driver is used.

Be careful while driving AC loads. It can be quite dangerous. Do not turn on the mains power while hooking up the circuit. You've been warned!

Hookup

The Ultra AVR Dev board comes with Relays on board. You simply need to hook up the relay inputs with the the port pins as shown in the figure below.

Code

The code turns ON and OFF the relays, every 5 seconds.

Demo