Arduino-Controlled Power Outlet: How To Build a Smart Power Outlet

In this article, we will build an Arduino-controlled power outlet that can turn on/off depending on the sensor input. Arduino boards unlock limitless possibilities and can be fun project tools once you learn how to …

Arduino-Controlled Power Outlet

In this article, we will build an Arduino-controlled power outlet that can turn on/off depending on the sensor input.

Arduino boards unlock limitless possibilities and can be fun project tools once you learn how to program them.

You can use these boards to make almost anything in your home smart, including your power outlets.

Let’s look at how you can convert this idea into a reality.

Table of Contents

What We Are Building

Let’s consider how you usually turn a power outlet on or off.

You must first have a reason to turn the switch.

We’ll refer to this reason as the trigger.

So when building the circuit, you need something to trigger the turning on/off.

Consider these ideas.

  • Remote smartphone control using a Bluetooth module
  • Sensors (humidity, temperature, light, etc.)
  • Wi-Fi module for over-the-internet control

Bluetooth and Wi-Fi modules give you more control over the system.

So they are ideal for making Arduino-controlled power outlets for TVs, sound systems, and other similar home appliances.

But sensors introduce the element of automation.

For instance, you can build an Arduino-controlled power outlet that switches on the lights when it’s dark.

Or you can develop an outlet that senses the temperature, then turns the AC on/off.

Also, you can use a DHT11 humidity/temperature sensor to monitor moisture levels and turn your humidifier/dehumidifier on/off.

A DHT11 humidity/temperature sensor

A DHT11 humidity/temperature sensor

The other critical device in the setup is the relay module.

Since you’ll be controlling 110/120V or 230/240V AC, you must use a relay to handle the switching.

The Arduino board cannot handle such voltages and supply enough power to run these appliances.

So the Arduino board will control the relay, which will handle the power outlet.

Think of how you need a motor driver to control motors using Arduino.

Arduino-Controlled Power Outlet Project

In our project, we will build an automated Arduino-controlled power outlet using an LDR or photoresistor as the trigger.

Photoresistors

Photoresistors

Here is a list of the components you’ll need.

  • Arduino UNO
  • 5V relay module
  • Photoresistor
  • Switch
  • AC power supply
  • Power cord/connecting wires
  • Power strip/ power outlet with a power outlet box
  • Light bulb
  • Corded light socket

Hardware Connections

Connect the devices as shown below.

Arduino UNO5V Relay Module
5VVcc
GNDGND
D8Input
Arduino UNOPhotoresistor
5VFirst pin (via 10KΩ resistor)
GNDSecond pin
A0Between the first pin and 10KΩ resistor
5V Relay ModuleAC Power Connection
Common ContactAC Line In
Normally OpenAC Line Out

Circuit Diagram

An Arduino-controlled power outlet circuit diagram

An Arduino-controlled power outlet circuit diagram

Be careful when building this circuit because you’ll be dealing with high-voltage AC.

Ensure you don’t have any components plugged in when doing the wiring.

And connect the power supply after double-checking the circuit connections.

For the power outlet, we’ve used a 240V, 6A unit.

So you should be able to run any appliance rated at 1000-1200W max (the bulb uses way less).

The relay module operates at 5V, so power it using the Arduino 5V pin.

If you can’t get this module, use the following components to make one.

  • 5V relay
  • NPN transistor (BC547)
  • PN junction diode (1N4007)
  • ¼-watt 1KΩ resistor

This module is an active-low type, meaning a logic zero signal from the Arduino board will turn it ON. On the other hand, a logical one will turn it OFF.

The Arduino board makes this logic zero and one decision based on the input from the LDR.

But if you look at the circuit diagram keenly, you’ll note this component connects to a 10Ω resistor in parallel.

This connection creates a voltage divider.

It produces a varying voltage signal that we pick up using the A0 pin on the microcontroller board.

Why Use a Voltage Divider?

You must wonder why we haven’t connected the LDR directly to the A0 pin.

After all, this analog pin measures the voltage signal changes depending on the photoresistor’s resistance or impedance.

And this resistance/impedance change depends on the light intensity hitting the LDR.

But the direct connection won’t work.

If you use a multimeter to detect resistance changes across the LDR pins, you will note a high variance. It can go from 1MΩ to 100KΩ.

So alone, the component has a high impedance.

This resistance will reduce the electric current flow between the 5V DC supply and A0.

As such, the voltage drop will be too small for the Arduino board to notice.

Therefore, the A0 pin will always measure a voltage close to 5V regardless of the light intensity on the photoresistor.

Such readings won’t be of any use in the project.

But adding another resistor to create a voltage divider solves the issue.

Voltage divider rule in electronics

Voltage divider rule in electronics

What The Code Should Do

The board will continuously monitor the analog voltage readings from the photoresistor when the circuit is operational.

When a high light intensity hits the LDR, its resistance will decrease, causing the analog voltage signal to reduce.

And when the light intensity reduces, the resistance across the LDR will increase, resulting in an analog input voltage increase.

Remember, the relay module is an active-low type. So we will set the code to output a logic low when the voltage increases.

Therefore, when the light outside reduces, the power outlet will be on and switch on the bulb.

But when it becomes bright outside, the code will output a logic high to the relay terminal.

This output will make the relay cut off the power.

Here’s how you translate this reasoning into code.

Code

Code Explanation

We don’t need to import any libraries for this project. So begin by declaring the variables for the analog pin A0, digital output pin D8, and sensor value.

In the setup function, start by initiating the serial connection with your computer (9600 bits per second).

Next, set the D8 pin as an output because it should send control signals to the power relay module.

After that, send the logic high digital signal to the relay to cut off the electrical connection when starting.

The fun happens in the loop function.

First, the code captures the analog voltage signal from the voltage divider and converts it to a digital number.

The analog read function handles this conversion, giving a digital value between 0 and 1023.

This value gets stored in the sensor value variable created earlier, and you’ll see it printed on the serial monitor.

Since this value is between 0 and 1023, we can assume that 400 is a center switching point.

It is not the middle point between 0 and 1023, but it is enough light intensity to consider switching the relay on.

So if the sensor value exceeds 400 (voltage is close to 5V), we set the digital pin D8 to low.

A logic low activates the relay, turning it and the power outlet on.

Remember, the resistance and voltage increase when light intensity reduces on the LDR.

So when the system senses darkness, the light will turn on.

Otherwise (when the sensor value is less than 400), Arduino will set D8 to a logic high, cutting off the power supply.

Other Vital Points To Consider

The light strip or power outlet has its switch to give you manual control over the light bulb circuit.

So if you want to change the bulb or modify this section, cut off the power supply there.

We’ve also included a switch along the AC hot wire to cut power to the entire system.

Ensure you have and use it if you want to make modifications/repairs to the relay.

Setting smart plug using the phone

Setting smart plug using the phone

Wrap Up

As you can see, building an Arduino-controlled power outlet is one of the easiest projects.

The circuit and code are straightforward, so you should get the setup running quickly.

Once it works, try incorporating more control using a Wi-Fi or Bluetooth module.

Smartphone power outlet switching will give you ultimate control over the system. 

That’s it for this article. Contact us if you encounter any challenges, and we’ll be in touch to assist. 

Categories How