Featured Image Relay On Light Bulb Socket

How to turn on light bulbs using an Arduino with a relay module

Controlling small LED lights with an Arduino can be a fun project to start your journey of learning DIY electronics. But do you know what’s more fun? Powering light bulbs with a custom designed Arduino project: Large, high power, room bright light bulbs!

However, the Arduino can’t emit more than 5 volts from any of its pins, let alone enough to power a light bulb that needs 30-40 times the voltage of an LED. That’s why you’re supposed to use a paging unit instead. Here’s how to do it using an Arduino.

What is a paging unit?

A relay unit (or relay, for short) is an electromagnetic switch that allows you to control something electrically connected to the mains with a low-power microcontroller, such as Arduino Uno or ESP32.

5vdc . relay module

Relays have two types of terminals: one that accepts high voltage (think 220V) and one that only accepts low voltage output.

Spdt Pinout Relay Module

When you pass an electric current through the low-voltage pins, you’re turning on an electromagnet that pulls a “switch,” turning it on or off, depending on the configuration you’re using.

An SPDT relay always has six pins: usually with three male pins for connection to the Arduino and three screw terminal pins for mains connection.

Connecting the relay unit to the Arduino

The relay module should have vertical pins marked with three signs: Signal, 5V and GND. These are the pins that you are supposed to connect to the Arduino using jumper wires.

The pins work as follows:

  1. Signal: Turn the relay on or off.
  2. 5 volts: accepts 5V to power the relay.
  3. GND: Connects to the Arduino’s GND pin.

Connect the relay unit to a light bulb

On the other side of the relay unit is a screw terminal with three holes. It must contain three marks: NC, NO, and Common Ground. Each hole is connected to a copper wire that carries high-voltage electricity to and from the light bulb.

These holes do the following:

  1. NC (normally closed): Connects to a light bulb. Locked while the relay is off.
  2. No (usually open): Connects to a light bulb. Unlock while the relay is off.
  3. common ground: Connects to the mains.

You can only connect NC or NO to the light bulb – not both at the same time. If you do this, it will never turn off, as the electricity will go through the other wire.

warning: If you are using relays, you are tampering with the high voltage electricity. This can be dangerous, as you risk shocking yourself. Please exercise caution and take safety precautions at all times. If you are not 100% sure what you are doing, it is best to abandon the project until you learn more about working on it safely. Instead, consider enlisting the help of someone who knows their way around the relays.

Choose the relay unit

Your local electronics dealer may have many different types of relay units on their shelves. Unfortunately, most of these commonly available things don’t work with Arduino.

If you’re shopping online, you should choose one that has “5VDC” in its model name. would be for example SRD-05VDC-SL-Cwhich is an SRD 5V type relay module.

Another thing to check is whether it is an SRD or SSR relay. SRD relays are much cheaper than SSR relays at about half the price, but the benefit is that they are silent when turned on and off. SRD relays beep and click when their electromagnets move between these positions.

Finally, you should get one in unit form. Regular SPDT relays do not have pins that connect to the microcontroller. You will need these to connect it to your Arduino.

What will you need

Here is the full list of items you’ll need before you get started on the relay module with the Arduino:

  • SPDT 5VDC relay
  • Arduino (any model)
  • Copper cable (should run 12 AWG, length depends on how long you want it)
  • light bulb
  • light bulb socket
  • AC power plug

On top of that, you’ll need some additional tools on hand:

  • Wire cutter, to cut wires to your preferred length.
  • Screwdriver, to loosen and tighten the ends of the screws.
  • Wire stripper, to separate plastic cans from wires.

Using the paging module with Arduino

Once you have all the required equipment, create your setup.

1. Payload Preparation

A “load” is a part of a circuit that takes electrical energy in the form of a current and converts it into other forms, such as light and heat. For the purposes of this tutorial, we are using a light bulb as a load.

Standard bulb and socket
  1. Between the electrical plug and the light bulb, you should have a pair of cables. One of the cables goes directly from the electrical socket to the light bulb. The other is cut somewhere halfway and connected to the relay unit. Measure the lengths you wish to use.
Arduino relay circuit
  1. Using a wire stripper, expose about an inch of wire on either side. The light bulb socket and relay must have screw terminals to fit them.
  1. Cut the cables according to your measurements. The distance of the relay module from the load does not matter here – what matters is that you have enough cable length to reach the nearest AC outlet.
  1. Thread one of the plug cables to one end of the screw in the socket. Leave the other cable free for now.
Light bulb terminal screw socket and power outlet
  1. Connect the other cable to the relay: you can choose either NC or NO.
Light bulb socket and relay
  1. Attach another wire to the terminal between NC and NO.
  2. Connect the other piece of cable to the screw terminal of the light bulb socket to complete the circuit.
Light bulb socket tension relay

2. Prepare your Arduino

  1. Open the Arduino IDE and paste the following code. Don’t worry, because we’ll go over what each line does later.
const int relayPin = 7;
void setup() {
	pinMode(relayPin, OUTPUT);
void loop() {
	digitalWrite(relayPin, HIGH);
	digialWrite(relayPin, LOW);

NB: This code should work on all Arduino and 5V boards that bore the Arduino.

  1. Save it to something like ‘arduino-relay.ino’, but anything will work as long as it ends with the ‘.ino’ file type.
  1. Upload the code to the Arduino. Use the USB cable that came with the Arduino board to connect it to your computer.
  1. Go to “Draw -> Upload” or tap control + yo on the keyboard to start the download.
  2. if I were PlatformIO user, the Create and Upload button is in the blue tray at the bottom between the radio buttons and the Trash. It’s the arrow pointing to the right.
Visual Studio Code Platformio at the bottom of the bottom tray
  1. If all goes according to plan, you should get a “Uploaded” notification on your Arduino.
Arduino message loaded
  1. Disconnect the Arduino from the computer.

Understanding the blog

The first line in the code is used to identify the pin used in this setup. Pin 7 is easy to find on the Arduino, so we’re using that.

  • const: Defines something that will not change during the code. int Indicates that it will be an integer.
  • relayPin: is the name of an immutable number that we define. We’ll use this later to call this immutable number.
  • 7: is the value of relayPin and the immutable integer.
void setup() {
	pinMode(relayPin, OUTPUT);
  • void setup() {...}: This function allows you to run the code once. Here, we have defined what relayPin aka pin 7 does.
  • pinMode(): a function that takes two parameters: the secret number and whether it is an input or an output. by default, All Arduino pins are virtual as inputs Except for the power pins. Here, we direct the Arduino to allow relayPin to become the output pin.
void loop() {
	digitalWrite(relayPin, HIGH);
	digialWrite(relayPin, LOW);
  • void loop() {...}: Allows you to run your code indefinitely.
  • digitalWrite(): Takes a secret number and passes it to either of them HIGH or LOW. pin on HIGH 5V emits while pin is on LOW It sits at 0V. By sending 5 volts from the Arduino to the relay’s magnetic coils, we are effectively powering a small 5 volt electromagnet.
  • delay(): stops the entire code. It takes a number as a parameter, which is how long in milliseconds you want your code to pause. In this case, we pause the code for 1500 milliseconds every or 1.5 seconds.

3. Connect to your Arduino

In the last step you will connect the load to the Arduino.

  1. Using jumper pins, connect each pin of the relay to each Arduino pin as follows: IN to Pin 7, VCC to 5V, and GND to GND.
Arduino Uno Pinot
  1. To get this all done, plug the electrical plug into an AC socket and connect the Arduino to a 5V power source. This can be a power bank, a DC battery, or a power adapter used for phones.

NB: When messing around with things that could crash your computer (including the Arduino), it’s always a good idea to connect the board to a power source that isn’t your computer’s USB port.

  1. The lamp should light up and die every 1.5 seconds. You can modify the code to make it do other things or connect it to sensors.

Frequently Asked Questions

What is the position of SPDT in relays?

SPDT stands for single pole, double throw. In a circuit, poles are paths of things that are connected to them and consist of a path from the power source to the load. Meanwhile, the throws are the number of ways to connect the shafts. The SPDT relay has one pole but two ways (throws) to connect them (one ending with NC and one ending with NO).

What is the voltage pickup relay?

The pickup voltage refers to the number of volts it takes to make the relay’s electromagnet pull the switch to its side. If the voltage is too low, the electromagnet will not have enough force to pull it off.

What pickup voltage do I need for a relay with an Arduino?

The Arduino can fire 5V through its output pins. Any relay must operate with a pickup voltage of less than 5V.

All screenshots by Terenz Jomar Dela Cruz.

Is this article helpful?

Subscribe to our newsletter!

Our latest lessons delivered straight to your inbox

#turn #light #bulbs #Arduino #relay #module

Leave a Comment

Your email address will not be published. Required fields are marked *