0% found this document useful (0 votes)
17 views4 pages

Ex 7

The document outlines an experiment to simulate relay control using an Arduino UNO and Serial Monitor in Wokwi, focusing on sending commands to control a relay that switches an external load like an LED. It details the components used, circuit connections, code implementation, and the working principle, emphasizing the importance of input validation for reliability. The experiment serves as a foundational exercise for applications in home automation, industrial control, and IoT projects.

Uploaded by

prasadrohan966
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views4 pages

Ex 7

The document outlines an experiment to simulate relay control using an Arduino UNO and Serial Monitor in Wokwi, focusing on sending commands to control a relay that switches an external load like an LED. It details the components used, circuit connections, code implementation, and the working principle, emphasizing the importance of input validation for reliability. The experiment serves as a foundational exercise for applications in home automation, industrial control, and IoT projects.

Uploaded by

prasadrohan966
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Experiment 7: Simulation of Relay Control using Arduino UNO and Serial

Monitor (Wokwi)

Objective:

To simulate the control of a relay module using the Arduino UNO and Serial Monitor in
Wokwi. The goal is to learn how to send commands via serial communication to control a
relay that can switch an external load (e.g., an LED or motor). This experiment demonstrates
the use of digital output pins, serial communication, relay switching, and real-time user
interaction.

Introduction:

Relays are electrically operated switches commonly used to control high voltage devices (like
fans, bulbs, or motors) with a low-power controller like an Arduino. This ensures safety and
provides electrical isolation. In this simulation, we control a relay via the Arduino Uno, and
instead of connecting a high voltage device, we use an LED as an indicator to represent the
ON/OFF state of a load. The user sends the command through the Serial Monitor – typing 1
turns the relay ON and 0 turns it OFF.

We also use the Arduino’s built-in LED on pin 13 to give visual feedback that the relay has
been activated. This makes it easier to verify functionality without checking the relay
directly.

Components Used in Wokwi Simulation:

Component Quantity Description


Arduino UNO 1 Microcontroller board used for control logic
Relay Module 1 Acts as a switch, controlled by Arduino
LED 1 Simulated external load controlled by relay
Jumper Wires – For making electrical connections
Serial Monitor – Used for sending commands to Arduino

Circuit Diagram Overview:

Here’s how each component is connected:

 Relay Module:
o VCC → Arduino 5V

NAME: ROHAN PRASAD | ROLL NO: 52 | SY MECH | BATCH A3


o GND → Arduino GND
o IN → Arduino Digital Pin 7 (controls the relay switch)
 Relay Output to Load (LED):
o NO (Normally Open) terminal of relay → LED’s positive terminal
o LED’s negative terminal → GND
o When the relay is turned ON, the circuit completes and the LED glows.
 Arduino Onboard LED:
o Connected to pin 13
o Lights up as feedback when relay is ON

Code Used in Simulation:


cpp
CopyEdit
#define RELAY_PIN 7 // Pin connected to Relay
#define LED_PIN 13 // Built-in LED for feedback

void setup() {
pinMode(RELAY_PIN, OUTPUT); // Set relay pin as output
pinMode(LED_PIN, OUTPUT); // Set LED pin as output
Serial.begin(9600); // Start serial communication
digitalWrite(RELAY_PIN, LOW); // Ensure relay is OFF at startup
digitalWrite(LED_PIN, LOW); // Ensure LED is OFF at startup
Serial.println("Relay Control Ready. Enter '1' to turn ON, '0' to turn
OFF.");
}

void loop() {
if (Serial.available()) { // Check if data is available
char command = Serial.read(); // Read command from Serial
Monitor

if (command == '1') {
digitalWrite(RELAY_PIN, HIGH); // Turn ON relay
digitalWrite(LED_PIN, HIGH); // Turn ON LED (feedback)
Serial.println("Relay ON");
}
else if (command == '0') {
digitalWrite(RELAY_PIN, LOW); // Turn OFF relay
digitalWrite(LED_PIN, LOW); // Turn OFF LED (feedback)
Serial.println("Relay OFF");
}
else {
Serial.println("Invalid command! Enter '1' to turn ON, '0' to turn
OFF.");
}
}
}

Working Principle:

1. Upload the above code into the Wokwi Arduino Uno simulation.
2. Start the simulation.

NAME: ROHAN PRASAD | ROLL NO: 52 | SY MECH | BATCH A3


3. Open the Serial Monitor (set baud rate to 9600).
4. When you type and send 1, the Arduino receives the character, turns ON the relay,
and lights up the LED.
5. When you type and send 0, the relay turns OFF, and the LED goes OFF.
6. If you type any other character (like a, 2, or *), Arduino prints an error message
indicating invalid input.

Flow of Logic:

Setup()

o Sets both RELAY and LED pins as OUTPUT


o Starts Serial Monitor communication at 9600 baud rate
o Turns both relay and LED OFF initially
 Loop()
o Continuously checks if the user has sent a command
o If the input is 1, relay turns ON and feedback LED lights up
o If input is 0, relay turns OFF and LED goes OFF
o If input is invalid, user is notified via the Serial Monitor

Observation Table:

Input from Serial Relay Output LED Status Serial Feedback


1 ON ON Relay ON
0 OFF OFF Relay OFF
Any other input Unchanged Unchanged Invalid command message

Applications:

 Home Automation – Turning ON/OFF lights and fans using smartphones or


computers
 Industrial Automation – Remotely controlling heavy machinery through relays
 IoT Projects – Using sensors and relays to automate appliances
 Smart Agriculture – Controlling water pumps based on soil moisture sensor data
 Security Systems – Activating alarms or locks remotely

Advantages of Using Relay in Arduino Projects:

 Provides isolation between low voltage controller and high voltage appliances
 Offers a safe way to automate real-world electrical devices
 Easy to program and control using simple digitalWrite() function

NAME: ROHAN PRASAD | ROLL NO: 52 | SY MECH | BATCH A3


 Can be extended to multiple channels for more control options
 Helps in understanding real-time hardware and software interaction

Conclusion:

Through this experiment, we successfully simulated the control of a relay using Arduino and
Serial Monitor. We learned how to read serial input, control digital outputs, and provide
feedback using an onboard LED. This forms a basic yet important foundation for building
advanced systems like smart homes and industrial control setups. The use of proper input
validation also makes the project more reliable and user-friendly.

NAME: ROHAN PRASAD | ROLL NO: 52 | SY MECH | BATCH A3

You might also like