Introduction:
In this tutorial, we will learn about the KY-019 module, what is a relay and we will build a simple project to control a light bulb by using KY-019 module and an Arduino.
5V Single Relay Module KY-019:
The KY-019 Module will be our main component for this tutorial. This module has a 5V relay mounted on a breakout board with additional circuitry. Figure 1 shows the module as seen in fritzing.
Pin Out:
The KY-019 module has three pins.
Component Pin | Description | Relay Output | Description | |
---|---|---|---|---|
(-) | GND | N.C. | Normall-Closed Contact | |
middle | +5V | COM | Common | |
S | Signal | N.O. | Normally-Open Contact |
What is a Relay?
A Relay is an electro-mechanical component that provides electrical isolation between 2 circuits. It makes it possible for the control circuit voltage to be much lower than the power circuit.
Project:
Arduino Light Flicker:
After learning about the KY-019 module and the relay, it is now time to build a project using the module. Our project will flicker the light bulb every 5 seconds.
Components:
For this project, we need the following components:
- Arduino Uno board (1 pc.)
- KY-019 5V Single Relay Module (1 pc.)
- Jumper wires
Wiring Diagram:
Figure 2 shows the connection between the Arduino Uno and the KY-019 5V Single Relay Module.
The KY-019 module pins are connected to the Arduino Uno board as follows:
Module | Arduino | Relay Output | Connected To | |
---|---|---|---|---|
(-) | GND | N.C. | No Connection | |
middle | +5V | COM | AC Source (L) | |
S | Pin 8 | N.O. | To light bulb (L) |
Note: Light bulb (N) to AC source (N)
Code:
Below is the Arduino sketch for our project. I have added comments to explain important parts of the code. Save the code as KY-019.ino and upload it to your Arduino board.
// Arduino and KY-019 module
void setup() {
pinMode(8, OUTPUT);
digitalWrite(8, LOW); // switch off relay:
// - relay COMMON connected to NC
// - relay COMMON disconnected to NO
}
void loop() {
delay(5000); // wait 5 sec
digitalWrite(8, HIGH); // switch on relay:
// - relay COMMON connected to NO
// - relay COMMON disconnected to NC
delay(5000);
digitalWrite(8, LOW); // switch off relay
}
Project Test:
Apply power to your Arduino Uno board and AC supply for the relay and bulb. The light bulb should switch on and off every 5 seconds.