A relay is an electromagnetic switch that allows a low-power control signal from a microcontroller to operate high-power electrical devices such as fans, bulbs, or motors. The ATmega16 microcontroller cannot directly drive these high-current loads, so a relay is used along with a transistor and a diode to safely control the external circuit. In this article, we will understand the working of an electromechanical relay, study its internal structure, learn about the driver circuit, and finally write a C program to control the relay using the ATmega16 microcontroller. An animated diagram will also help you visualize how the relay coil energizes and toggles the load connection based on the microcontroller output.
Understanding Relay Operation
A relay consists of a coil, an armature, a spring, and a set of contacts — Common (COM), Normally Open (NO), and Normally Closed (NC). When current flows through the coil, it generates a magnetic field that attracts the armature, changing the contact position. This allows the relay to switch between connecting the COM terminal to either the NO or NC terminal. Thus, by energizing or de-energizing the coil, we can turn ON or OFF an external circuit.
Interfacing Circuit Description
- ATmega16 pin (PB0) → Base of NPN transistor through 1kΩ resistor.
- Transistor collector → One end of relay coil.
- Relay other end → +5V supply.
- Diode (1N4007) → Across relay coil (cathode to +5V).
- COM terminal → 230V AC load common line.
- NO terminal → Connected to AC load device (like bulb).
- Microcontroller GND → Common ground with driver circuit.
C Program to Control Relay using ATmega16
#include <avr/io.h>
#include <util/delay.h>
int main(void)
{
DDRB |= (1 << PB0); // Configure PB0 as output pin
while(1)
{
PORTB |= (1 << PB0); // Turn relay ON (energize coil)
_delay_ms(1000); // Wait 1 second
PORTB &= ~(1 << PB0); // Turn relay OFF
_delay_ms(1000); // Wait 1 second
}
}
Animated Circuit Diagram — Relay Interfacing with ATmega16
Working Principle
When the microcontroller sets PB0 HIGH, the transistor conducts and energizes the relay coil. The magnetic field pulls the armature, connecting the Common (COM) terminal to the Normally Open (NO) contact, turning the external load (like a lamp) ON. When PB0 goes LOW, the coil de-energizes, returning the armature to its resting position and turning the load OFF. The diode across the relay coil absorbs the voltage spike generated by the collapsing magnetic field, protecting the transistor and microcontroller.
Applications of Relay Interfacing
- Controlling AC appliances using microcontrollers.
- Home automation projects.
- Industrial automation and switching control.
- Motor and solenoid valve control circuits.
Conclusion
Relay interfacing with ATmega16 demonstrates how microcontrollers can control high-voltage or high-current devices safely through isolation. Using a transistor and diode as supporting components ensures safe switching and circuit reliability. This experiment forms the base for advanced automation projects where microcontrollers manage electrical systems in homes, industries, and robotics.
Comments
Post a Comment
Subscribe to Post Comments [Atom]