Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
ArtSuzhou
Published © CC BY-NC-SA

Smart Workbench Power

The device utilizes the Pyroelectric Infrared Sensor to automatically power down the electric power to the tools at the work bench if idle.

IntermediateFull instructions provided8 hours899
Smart Workbench Power

Things used in this project

Hardware components

Proximity Sensor- Pyroelectric Infrared Sensor Module
KEMET Electronics Corporation Proximity Sensor- Pyroelectric Infrared Sensor Module
×1
Wemos D1 Mini
Espressif Wemos D1 Mini
×1
Tactile Switch, Top Actuated
Tactile Switch, Top Actuated
×1
LED (generic)
LED (generic)
×2
Buzzer
Buzzer
×1
3.3V Relay Module For Arduino And Raspberry Pi
×1

Software apps and online services

Arduino IDE
Arduino IDE
Blynk
Blynk

Hand tools and fabrication machines

3D Printer (generic)
3D Printer (generic)
Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Custom parts and enclosures

Smart power front cover

Smart power PIR sensor dome

0.4mm cover

Smart power PIR snsor dome retainer

Smart power case

Smart power case rear cover

Wemos D1 mini mounting plate

Smart power push button retainer

Schematics

Smart power schematics

Code

Smart workbench power demo

Arduino
/**The MIT License (MIT)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

// You should get Auth Token in the Blynk App.
char auth[] = " ";

// Your WiFi credentials.
char ssid[] = " ";
char pass[] = " ";

// Set up no motion time-out value in seconds
#define timeSeconds 600

// Set pins for LED and PIR Motion Sensor
const int SensorPin = D1;
const int buttonPin =D6;
const int Relay = D5;
const int ledPw =D2;
const int ledPin =D7;
const int Buzzer =D8;

WidgetLED led1(V0);
WidgetLED led2(V2);

boolean vPinState =  false;        // Set the default virtual pin state  
boolean powerState = false;       // Set the power state
boolean startTimer = false;

int Sensor = 0;        
int buttonState;  // Set the PIR sensor input pin state
int lastButtonState = LOW;

unsigned long lastDebounceTime = 0;  // the last time the output pin was toggled
unsigned long debounceDelay = 50;    // the debounce time; increase if the output flickers

// Timer: Auxiliary variables
unsigned long now = millis();
unsigned long lastTrigger = 0;

void setup(){
  Serial.begin(9600);
  delay(10);
  Blynk.begin(auth, ssid, pass);  
    while (Blynk.connect() == false) {      
    // Wait until connected              
  }    
  pinMode(buttonPin, INPUT_PULLUP);
  pinMode(Relay, OUTPUT);
  pinMode(ledPin, OUTPUT);
  pinMode(Buzzer, OUTPUT);
  pinMode(ledPw, OUTPUT);
  
  // PIR Motion Sensor mode INPUT
  pinMode(SensorPin, INPUT);

  digitalWrite(Relay, HIGH);
  digitalWrite(ledPw, LOW);
  digitalWrite(ledPin, LOW);
  digitalWrite(Buzzer, LOW);
}

void loop(){

  int reading = digitalRead(buttonPin);

  if (reading != lastButtonState) {
    lastDebounceTime = millis();
  }

if ((millis() - lastDebounceTime) > debounceDelay) {
     if (reading != buttonState) {
      buttonState = reading;
      if (buttonState == LOW) {
        powerState = !powerState;
        if(powerState){
        startTimer = true;  //manually start power
        lastTrigger = millis();  
        buzzer2(2);
        }else{startTimer = false;  //manually turn off power
        buzzer2(3);
        }
      }
    }
  }

  lastButtonState = reading;

  Serial.print("Power State=  ");
  Serial.println(powerState);
  now = millis();
  if(powerState && startTimer && (now - lastTrigger < (timeSeconds*1000))) {
    Serial.println("Power on...");
    digitalWrite(ledPw, HIGH);
    digitalWrite(Relay, LOW);
    Blynk.virtualWrite(V1, HIGH);
    led1.on();
  }else{
    Serial.println("Power off...");
    digitalWrite(ledPin, LOW);
    digitalWrite(ledPw, LOW);
    digitalWrite(Relay, HIGH);
    Blynk.virtualWrite(V1, LOW);
    led1.off();
    if (powerState && startTimer && (now - lastTrigger > (timeSeconds*1000))){
    Serial.println("Power auto off has commenced...");
    Blynk.notify("Power auto off has commenced...");
    buzzer2(5); //Beep 5 times for automatic shutoff
    } 
    powerState = false;
    startTimer = false;
    }
   checkSensor();  
   Blynk.run();  
}

void checkSensor(){
    Sensor = digitalRead(SensorPin);
    if (Sensor == HIGH){
    Serial.println("MOTION DETECTED!!!");  
    digitalWrite(ledPin, HIGH);
    led2.on();
    startTimer = true;
    lastTrigger = millis();
    delay(500);
    }else{
    digitalWrite(ledPin, LOW);
    led2.off();
    }
} 

BLYNK_CONNECTED(){
    Blynk.virtualWrite(V1, LOW);
    led1.setColor("#D3435C");
    led2.setColor("#ED9D00");
  }

BLYNK_WRITE(V1)  
{  
  // Get the virtual input state  
  int vPinState = param.asInt();  
  // If the virtual input went high  
  if(vPinState==1)  
  {   
   Serial.println("Power remote on");
   powerState = true;
   startTimer = true;
   now = millis();
   lastTrigger = millis();
   Blynk.setProperty(V1, "onColor", "#D3435C");  //RED  
   buzzer2(2);
   Blynk.run();
  } 
  
  if(vPinState == 0){
   powerState = false;
   startTimer = false;
   Blynk.setProperty(V1, "offColor", "#5F7CD8");  //BLUE 
   Serial.println("Power remote off");   
   buzzer2(3);
   Blynk.run();
   } 
 }  

void buzzer2(int num){
  uint8_t i;
  for (i=0; i<num; i++){
    digitalWrite(Buzzer, HIGH);
    delay(100);
    digitalWrite(Buzzer, LOW);
    delay(100);
    }
 }
 

Credits

ArtSuzhou

ArtSuzhou

8 projects • 29 followers

Comments