Control your room bulb with a relay ⚡

Updated: May 5, 2020


Know it

How can we control the room bulb that is runs on 240V with an Arduino board that can only give 5V?

The answer is by using something called a Relay!


A Relay is simply a light switch that we can control using the Arduino. You can say that a Relay is an electronic switch that you can control using a small voltage (5V) to switch ON/OFF a much higher voltage (240V).


As we do the project, you will further understand the concept.


⚠️Caution ⚠️ We love you and we don't want anything bad to happen to you! This project requires high voltage connections that are dangerous. Please ask for help if you are not familiar with high voltage!


Wire it

Connecting a the relay requires only three wires, so it's simple. However, connecting the light bulb and the high voltage requires us to take a lot of provocations and be careful.


Do all the connections in the picture but without have the power on! Keep everything off, inspect the circuit multiple times with another person.


Connecting the relay:

  • Arduino pin GND Relay GND pin

  • Arduino pin 5V Relay VCC pin

  • Arduino pin 6 Relay Signal pin (far right pin)


After you done wiring, try ONLY Controlling the relay without plugging the plug into electricity. We you feel that the relay is working fine with the code below, then you can try plugging into the wall socket.

Code it

Controlling the relay via the Arduino is easy, it's like you are controlling an LED.

In this sketch, we will control the relay to turn on for 5 sec and then turn off for 5 sec and repeat.


Let's try it out:


/*      
Turing ON/OFF an LED      

Tutorial link: https://www.learn.voltaat.com/post/relay
This sketch was written by Voltaat Store   

This is a simple example sketch that turns on an LED for one second, off for one second, and repeats forever.      

Components Needed:   
1. Relay module ...x1  

Connections:   

- Arduino pin GND → Relay GND pin
- Arduino pin 5V → Relay VCC pin
- Arduino pin 6 → Relay Signal pin (far right pin)

*/

int relay = 6; // LED is connected to pin 13


// This routine runs only once upon reset
void setup() {  
  pinMode(relay, OUTPUT); // Initialize 13 pin as output 
  }  
  
// This routine loops forever
  
void loop() {   

digitalWrite(relay, HIGH);  // Turn ON the LED

delay(1000);   // Wait for 5000mS = 5 second

digitalWrite(relay, LOW);   // Turn OFF the LED

delay(1000);              // Wait for 1 second 
}

Learn

Arduino Starter kit

Contact us

Doha, Qatar

Company

© 2020, Voltaat Store for Trading