tylerpeppy
Published © GPL3+

Smart Plug

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

IntermediateFull instructions provided17,413
Smart Plug

Things used in this project

Hardware components

Breadboard (generic)
Breadboard (generic)
×1
Arduino UNO
Arduino UNO
×1
USB-A to B Cable
USB-A to B Cable
×1
Jumper wires (generic)
Jumper wires (generic)
×1
DS3231M - ±5ppm, I2C Real-Time Clock
Maxim Integrated DS3231M - ±5ppm, I2C Real-Time Clock
×1
Relay Module (Generic)
×1
The wall cord
×1
The led light bulb
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

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.

Schematics

The schematic

Code

The code

Arduino
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");
    }
}

Credits

tylerpeppy

tylerpeppy

2 projects • 42 followers
Love Arduino and IoT projects!

Comments