Introduction

  • In this article, I will explain about controlling the AC Light using relay with Arduino Mega.
  • It can be used to control the light by the relay.
  • The relay can act as a switch.
Parts Used
  • Arduino Mega 2560
  • AC Light
  • Relay
  • Bread Board
  • HookUp Wires
Connection
Step 1 Connect the light to the Arduino Mega 2560.
  • Connect the positive side to the positive side of the AC Supply
  • Connect the negative side to the negative side of the AC Supply.
Step 2 Connect the relay to the Arduino Mega 2560
  • Connect the vcc of the relay to the 5v of the Arduino board.
  • Connect the gnd of the relay to the Gnd of the Arduino Board.
  • Connect the vin of the relay to the pin 07 of the Arduino Board.
Programming
  1. digitalWrite(RELAY1, LOW); // Turns ON Relays 1
  2. Serial.println("Light ON");
  3. delay(2000); // Wait 2 seconds
  4. digitalWrite(RELAY1, HIGH); // Turns Relay Off
  5. Serial.println("Light OFF");
  6. delay(2000);
Explanation
  • When the relay is ON, the AC Light is also ON.
  • When the relay is OFF, the AC Light is also OFF.
  • We have set the time for the delay to be ON/OFF.
  • When the light is on, they will print in the serial monitor as "LIGHT ON".
  • When the light is off, they will print in the serial monitor as "LIGHT OFF".