Lab set Program-2
Develop a program to interface a relay with Arduino board
Objective
To control an LED through a relay module using Arduino. This simulates switching of loads via relay control.
Learning Outcomes
By the end of this experiment, students will be able to:
-
Understand how a relay works as an electronic switch.
-
Interface a relay with Arduino Uno.
-
Control external loads (here, LED) using digital output pins.
Components (from Tinkercad Palette)
-
Arduino Uno
-
Relay Module (5V, single channel)
-
LED (any color)
-
220Ω Resistor
-
Breadboard
-
Jumper wires
Circuit Wiring
-
Relay Module Connections
-
VCC → Arduino 5V
-
GND → Arduino GND
-
IN → Arduino Digital Pin 7
-
-
LED as Load (through Relay switching)
-
LED Anode (+) → Relay COM terminal (through 220Ω resistor)
-
LED Cathode (-) → Arduino GND
-
Relay NO (Normally Open) terminal → Arduino 5V
-
(This wiring makes the LED glow only when relay closes the circuit.)
Step-by-Step in Tinkercad
-
Open Tinkercad → Circuits → Create New Circuit.
-
Place Arduino Uno, Relay Module, LED, and Resistor.
-
Wire Arduino pin 7 to Relay IN pin.
-
Connect LED and resistor between relay COM and GND.
-
Connect Arduino 5V to Relay VCC and LED via NO terminal.
-
Simulate → LED will blink ON and OFF as relay switches.
Arduino Sketch
// Program: Relay with LED load
int relayPin = 7; // Relay control pin
void setup() {
pinMode(relayPin, OUTPUT); // Set relay pin as output
}
void loop() {
digitalWrite(relayPin, HIGH); // Relay ON → LED ON
delay(2000); // Keep ON for 2 sec
digitalWrite(relayPin, LOW); // Relay OFF → LED OFF
delay(2000); // Keep OFF for 2 sec
}
How It Works
-
The Arduino sends a digital signal to the relay input pin.
-
When signal is HIGH, relay coil energizes and closes the NO contact, completing the LED circuit → LED glows.
-
When signal is LOW, relay opens → LED goes OFF.
-
This demonstrates how Arduino can control devices through relays.
Common Mistakes & Quick Fixes
-
Relay not clicking? → Check VCC and GND connections.
-
LED never glows? → Ensure LED is connected via NO terminal and not NC.
-
LED very dim? → Use correct resistor (220Ω).
-
Wrong pin? → Verify relay IN is wired to pin 7 in both hardware and code.
Viva / Check-Your-Understanding
-
What is the role of a relay in circuits?
-
Why can’t we directly connect high-power loads to Arduino?
-
What is the difference between NO and NC contacts in a relay?
Extensions (Mini-Tasks)
-
Modify the code to blink LED faster (0.5 sec ON/OFF).
-
Use two LEDs and control them alternately using the relay.
-
Replace LED with a motor or lamp in simulation.
Lab Record (Suggested Headings)
-
Title of Experiment
-
Objective
-
Components Required
-
Circuit Diagram
-
Arduino Code
-
Output
Thinkercad Link:
https://www.tinkercad.com/things/ekpvaAzYTyT-labset-prog-2
Comments
Post a Comment