Relay Module with Arduino

In this tutorial, we will learn how to use and interface relay module with Arduino.

In the below article, we turn on/off a light bulb when LDR detects light intensity and darkness with the help of 5v relay and Arduino.

relay module
2 Channel Relay Module

Components Needed

  • Arduino Uno.
  • Relay Module 5V.
  • LDR Sensor.
  • Jumper Wires.
  • Bulb.

Introduction of Relay Module

A relay is an electric switch that can be turned on or off. Relays are used to control a circuit by a separate low power signal or, controlled several circuits by one signal.

relay module pinout
  • GND:- It connects to the ground pin of Arduino.
  • IN1:- It connects to the digital pin of Arduino to control the first relay.
  • IN2:- It connects to Arduino digital pin to controls the second relay (if we using the second relay).
  • VCC:- connects to 5V of Arduino.

Main Voltage Connections

relay output pin

COM:- This is a common pin.

NO (Normally Open):- According to the name Normally Open (NO) pin has no direct connection with the Common pin. If we trigger the relay, NO connects with the COM pin and provided power supply. We connect the lamp or the appliance wire with it.

NC (Normally Closed):- There is a direct connection between the common pin and the normally closed pin, even the relay is off. If we trigger the relay, NC disconnects with COM pin and no supply provided to load.

About LDR Sensor

An LDR sensor (Light Dependent Resistor) is a device that is used to detect light. It has a (variable) resistance that changes with the light intensity that falls upon it.

This allows them to be used in light sensing circuits. They are used in many consumer products to determine the intensity of light.

Must See: LDR Sensor with Arduino.

ldr sensor

Circuit Diagram for Relay with Arduino

circuit diagram for relay with arduino

Code for Relay with Arduino

The working of the above sketch is as when the LDR senses darkness i.e. light intensity below 500 then the relay module gets input from Arduino through pin 9  and there is a connection between the COM and NO pin is established and turns on the light.

When LDR senses light intensity above 500 than the connection between COM and NO pin is broked and the light turns off.

Some More Articles For You:

Scroll to Top