Introduction: Never Forget It on - Energy Saver

I have got tired and frustrated forgeting my bathroom heater on, this device sense the lack of movement in the bathroom and turns the heater off after a preset time.

Energy (and money) saved !

Step 1: Parts

Arduino nano (or other)
PIR Sensor Module
Relay Module
2 220ohm Resistors
1 PNP Transistor
Main case (I used an old Lacie hard drive box)
Small case (for the PIR sensor)
2 female headphones jacks
1 Potentiometer
1 Push Button
1 Led
SM-LB03 Module (Buck Converts 220v AC to 5v DC)
An Outlet - 1 male, 1 female
Some wires and connectors

Step 2: IMPORTANT NOTE

220v electricity might defently kill you or hurt you !
Don't do it if you are not familiar with the safety of working with it and not comfortable with the use of it!
The Responsibility of making it safe to use is yours !

Step 3: Cycles

There are two cycles of electricity in this project that are separate.
220v comes from the wall outlet through the relay and to the project outlet.
The second one is the arduino cycle wich take 5v from the the SM-LB03 Converter through the Arduino and electronic and back to the SM-LB03.

Most electronics will not except 220v (Arduino included) - Watch what you're doing!

Step 4: Circuiting

Buck Converter converts 220v AC to 5v DC, at its AC side, L connects to LOAD and N connects to NEUTRAL.
At its DC side, GND connects to the Arduino GND, the leds shorter pin, the potentiometer GND pin, the pull-down resistor that comes from the PressButton, the transistor collector pin, and the audio jack ring pin.
the VCC connects to Arduino VIN pin, to the Relay VCC pin, to the Push Button volt side, to the potentiometer VCC pin, and to the audio jack sleeve pin.

Arduino connects as follow :
D3 => transistor gate (middle pin)
D4 => Push Button and the pull down resistor
D5 => audio jack tip pin
D13 => to a resistor and then to the Led
A0 => potentiometer middle pin

PIR Sensor Module
VCC => audio jack sleeve
GND => audio jack ring
OUTPUT => audio jack tip

NOTE : dont forget the connecting the EARTH from the wall OUTLET to the output Outlet !

Step 5: The Code

const int ledPin = 13;
const int buttonPin = 4;
const int pirPin = 5;
const int rellayPin = 3;
const int potPin = 0;
boolean onMode = true;
long timeStamp;
long stillTime;
int oldPot, pot;
void setup() {
  Serial.begin (9600);
  pinMode (ledPin, OUTPUT);
  pinMode (buttonPin, INPUT);
  pinMode (rellayPin, OUTPUT);
  pinMode (pirPin, INPUT);
  timeStamp = millis ();
}
void loop() {
  oldPot = map (analogRead (potPin), 1, 1000, 1, 8);
  if (pot / 5 != oldPot) {
    for (int i=1; i<=oldPot; i++) {
      digitalWrite (ledPin, HIGH);
      delay (200);
      digitalWrite (ledPin, LOW);
      delay (200);
    }
    delay (1000);
  }
  pot = oldPot * 5;
  stillTime = pot * 60000; // = Minuts
  //stillTime = 30000;
  Serial.print ((millis () - timeStamp) / 60000);
  Serial.print (" Out of ");
  Serial.println (stillTime / 60000);
  if (onMode) {
    if (digitalRead (pirPin)) {
      timeStamp = millis();
      digitalWrite (ledPin, HIGH);
      delay (1000);
      digitalWrite (ledPin, LOW);
      Serial.println ("*** Move Registered ***");
    }
    if (millis () - timeStamp >= stillTime) {
      onMode = false;
      Serial.println ("** No movement registered for too long **");
    }
    digitalWrite (rellayPin, LOW); // = ON
    digitalWrite (ledPin, LOW);
    //Serial.println (" +++ Electric Belt is ON ++ ");
  }
  if (!onMode) {
    digitalWrite (rellayPin, HIGH); // = OFF
    digitalWrite (ledPin, HIGH);
    Serial.println (" --- Electric Belt is OFF ---");
    if (digitalRead (buttonPin)) {
      onMode = true;
      timeStamp = millis ();
      Serial.println (" RESET ");
    }
  }
}
Arduino Contest 2016

Participated in the
Arduino Contest 2016

Green Electronics Contest 2016

Participated in the
Green Electronics Contest 2016