One of the most practical applications of the Arduino is controlling devices like box fans, light bulbs, and other home appliances. Since the Arduino operates at 5V, it cannot control these higher voltage (120-240V) devices directly. However, we can get around this problem by using a 5V relay to switch the 120-240V current and programming the Arduino to control the relay.

The best part about using an Arduino to control these devices is that we can program the Arduino to output a signal to the relay when a particular event occurs. For example, we can program the Arduino to turn the relay on if the temperature reading from a thermistor reaches 30° C or greater. We can program the Arduino to turn the relay off when the resistance from a photoresistor drops below 400 Ohms. Any sensor can be used to trigger the relay to turn on or off. The trigger doesn’t even need to be from a sensor, it can also be based on time or any other variable.

I’ll be using the SRD-05VDC-SL-C 5V Relay to demonstrate here because it’s very popular among Arduino and Raspberry Pi users. Now let’s dive into how the 5V relay works and how to set it up on the Arduino.

5V Relay Basics and Operation

5V Relay Pinout

NC= Normally closed 120-240V terminal

NO= Normally open 120-240V terminal

C= Common terminal

The 5V relay I’ll be using here is called the SRD-05VDC-SL-C 5V relay. Inside the unit is a 120-240V switch that is connected to an electromagnet. When the relay receives a HIGH signal at its signal pin, the electromagnet becomes charged and moves the contacts of the 120-240V switch open or closed.

Here’s the datasheet:

Circuit Basics PDF Icon SRD-05VDC-SL-C Datasheet

Normally Open vs. Normally Closed

This relay actually has two different types of electrical contacts inside – normally open (NO) and normally closed (NC). The one you use will depend on whether you want the 5V signal to turn the switch on or turn the switch off. The 120-240V supply current enters the relay at the common (C) terminal in both configurations. To use the normally open contacts, use the NO terminal. To use the normally closed contacts, use the NC terminal.

Normally Open

In the normally open configuration, the 120-240V electrical contacts are open until the relay receives the signal that closes the contacts and allows current to flow. So if we want the signal to turn on the current, we use the normally open terminal when wiring the outlet:

5V Relay Normally Open Terminal

Normally Closed

In the normally closed configuration, the electrical contacts are closed until the relay receives the signal, which opens the contacts and interrupts the current. Thus, if we want the signal to turn off the 120-240V current, we use the normally closed terminal:

5V Relay Normally Closed Terminal

Temperature Dependent Switch for 120-240V Devices

Thermistors are useful components to use with 5V relays since you can use them to turn on or off appliances when they reach a certain temperature. For example, you could turn off a large motor if gets too hot, or turn on a heater if the temperature gets too cold.


In this example, I will use an Arduino coupled with thermistor and a 5V relay to turn off a light bulb when the temperature around the thermistor reaches 150 °F. The set up is simple:

Arduino Temperature Dependent Light Bulb With 5V Relay

Connect the power wire of the light bulb cord to the NO (normally open) terminal of the relay, and connect the neutral power wire of the cord to the C (common) terminal of the relay.

The thermistor part of the circuit above is a voltage divider, so the value of the resistor should be the same order of magnitude as the value of the thermistor. For example, I used a 10K Ω thermistor, so the resistor should be 10K Ω as well. If you use a 100K Ω thermistor, use a 100K Ω resistor. If you use a 100K Ω thermistor, you’ll need to change line 7 in the code below to Temp = log(100000.0*((1024.0/RawADC-1)));. See our article on Making an Arduino Temperature Sensor for more setup information.

After everything is connected, upload this code to the Arduino:

#include <math.h>

int pinOut = 10;

double Thermistor(int RawADC) {
 double Temp;
 Temp = log(10000.0*((1024.0/RawADC-1))); 
 Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp ))* Temp );
 Temp = Temp - 273.15;          
 Temp = (Temp * 9.0)/ 5.0 + 32.0; 
 return Temp;

void setup() {
  pinMode(10, OUTPUT);

void loop() {             
  int val;                
  double temp;            
  Serial.print("Temperature = ");
  Serial.println(" F");
  if (temp >= 150){
    digitalWrite(pinOut, LOW);
  else {
    digitalWrite(pinOut, HIGH);

In this example, the relay stays activated and current flows through the light bulb until the temperature at the thermistor reaches 150 °F, at which point the relay shuts off and the current stops. Once the temperature drops below 150 °F, the relay will be activated, and it will switch the power back on. You can change the temperature that the relay turns on and off in line 27 (if (temp >= 150){).

Arduino Temperature Sensitive Relay Switch

Watch the video for this project:

One really useful way to use the 5V relay is to build a power outlet box with the relay inside to control the current to the outlet. That way you don’t need to cut into a device’s power supply to control it with your Arduino, you can just plug it into the outlet.  You can also control multiple devices at the same time. See our tutorial “Turn Any Appliance into a Smart Device with an Arduino Controlled Power Outlet” to see how we built one.

Hope this is useful for you! Leave a comment if you have any questions, and be sure to share it if you know someone that would find it helpful.

Need an easy-to-use way to design circuits and layout PCBs?