Project tutorial

Smart Plug © GPL3+

An outlet that can control your devices that need to be plugged in.

  • 2,893 views
  • 11 comments
  • 10 respects

Components and supplies

Apps and online services

About this project

This project is basically what it sounds like - a smart outlet. This smart outlet can apply to any device that has a plug FOR 120V only! (Targeted mainly at lamps using low amps.) This outlet is an outlet controlled by a 1-channel relay. This project also uses an RTC (real time clock) to determine what time it is and, based on the 24 hr clock, it will either turn on or off (depending on the time) because it actually has predetermined times to turn on and then to turn off. Also, another thing is that this will have a plug coming out of it that has to be plugged into a wall socket!

Link to the library: http://www.rinkydinkelectronics.com/library.php?id=73

IMPORTANT SAFETY INFORMATION!! PLEASE READ!

1) Use a Grounded Cord and Interrupt the Hot Wire

As can be seen in the pictures below, a 3-prong plug is used. The hot (black) wire from the line is connected to the common terminal of the relay module. The normally open (NO) output of the relay is then connected to the brass screw of the outlet. The white wire (neutral) connects to the silver screw and the green (ground) connects to the green screw of the outlet.

2) Use a Relay Module

A single-channel relay module from Elegoo was used to switch the hot wire. This module is identical to the Keyes SR1y module (http://www.techydiy.org/keyes-sr1y-relay-module) and contains a flyback diode connected to the control input (for back EMF), a transistor to control the relay coil and a series resistor to limit the current into the transistor. As the relay is only rated up to 10A, either limit the load connected to the outlet, or use a fuse in line with the hot wire. If possible, a single channel relay with an optocoupler would provide additional isolation for the Arduino.

3) Physical Separation

Make sure to mount the relay module in the plastic housing away from the high voltage wires ensuring that the solder side of the relay module faces the plastic housing so that low voltage wiring does not inadvertently come into contact with high voltage wiring if the unit is subjected to shock or vibration.

Image of the wiring on the inside of the smart plug (yours should look like this).

Close-up image of the relay module.

Code

The codeArduino
this is the code you need to run this complicated piece of smart tech.
#include <DS3231.h>

int Relay = 4;

DS3231  rtc(SDA, SCL);
Time t;

const int OnHour = 07;
const int OnMin = 15;
const int OffHour = 07;
const int OffMin = 20;

void setup() {
  Serial.begin(115200);
  rtc.begin();
  pinMode(Relay, OUTPUT);
  digitalWrite(Relay, LOW);
  //rtc.setTime(21,10,00);//set your time and date by uncomenting these lines
  //rtc.setDate(26,6,2018);
}

void loop() {
  t = rtc.getTime();
  Serial.print(t.hour);
  Serial.print(" hour(s), ");
  Serial.print(t.min);
  Serial.print(" minute(s)");
  Serial.println(" ");
  delay (1000);
  
  if(t.hour == OnHour && t.min == OnMin){
    digitalWrite(Relay,HIGH);
    Serial.println("LIGHT ON");
    }
    
    else if(t.hour == OffHour && t.min == OffMin){
      digitalWrite(Relay,LOW);
      Serial.println("LIGHT OFF");
    }
}

Custom parts and enclosures

The junction box
This is the box that you will house your outlet and electrical for the socket and the relay.
219n5cin41l jj0r0sgclh

Schematics

The schematic
Rtc bulb bb bq83ctxbkc

Comments

Similar projects you might like

Smart Vendy - Power By MediaTek Smart 7688 Duo

Project tutorial by Sainath Komakula

  • 249 views
  • 0 comments
  • 4 respects

LinkIt™ Smart 7688 Smart Room

Project tutorial by Muhammad Afzal

  • 563 views
  • 0 comments
  • 3 respects

Smart Energy Saver for Your Home

Project tutorial by Dhairya Parikh

  • 6,876 views
  • 14 comments
  • 23 respects

Smart Plug

Project tutorial by Md. Khairul Alam

  • 2,723 views
  • 0 comments
  • 16 respects

SUMO : Smart Pulse Monitor ( A Low Cost Smart ECG )

Project tutorial by Geeve George

  • 2,355 views
  • 3 comments
  • 18 respects

Elara: A Smart 'Airflow Detector' for Your Smart Home!

Project tutorial by Fike Rehman

  • 587 views
  • 1 comment
  • 8 respects
Add projectSign up / Login