Just a quickie to show what I have done with Blynk so far.
Everything is connected to the internet nowadays so I thought I’d add my toolbox to the list.
I replaced the original lock and mechanism with a couple of cheap rc type servo motors.
Knocked up a quick circuit and threw it in a box and Bob’s your uncle.
The lock and unlock angle can be tweaked using the adjusters at the bottom of the page.
/*************************************************************
*
* Toolbox lock project
* Author: B Crawford
* Date: 12/04/19
* Version: 1.0
*
*************************************************************/
#define servoPin D8
#define relayPin D6
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <Servo.h>
char auth[] = "XXXX";
char ssid[] = "XXXX";
char pass[] = "XXXX";
Servo servo;
WidgetLCD lcd(V0);
BlynkTimer timer;
bool locked = false;
int unlockedPos = 165;
int lockedPos = 15;
bool transition = false;
BLYNK_WRITE(V1){
if (param.asInt() == 1){
lock();
}
}
BLYNK_WRITE(V2){
if (param.asInt() == 1){
unlock();
}
}
BLYNK_WRITE(V3)
{
lockedPos = param.asInt();
}
BLYNK_WRITE(V4)
{
unlockedPos = param.asInt();
}
void setup()
{
pinMode(relayPin, OUTPUT);
digitalWrite(relayPin, LOW);
Blynk.begin(auth, ssid, pass);
Blynk.syncAll();
lcd.clear();
timer.setTimeout(1000L, lock);
}
void loop()
{
Blynk.run();
timer.run();
}
void lock()
{
if (locked == false && transition == false)
{
servoOn();
timer.setTimeout(250L, moveServo, (void*)lockedPos);
}
}
void unlock()
{
if (locked == true && transition == false)
{
servoOn();
timer.setTimeout(250L, moveServo, (void*)unlockedPos);
}
}
void servoOn()
{
servo.attach(servoPin);
digitalWrite(relayPin, HIGH);
transition = true;
}
void moveServo(void* pos)
{
int sPos = (int)pos;
servo.write(sPos);
timer.setTimeout(1500L, servoOff);
}
void servoOff()
{
int servoPos = servo.read();
if (servoPos == unlockedPos)
{
locked = false;
}
else if (servoPos == lockedPos)
{
locked = true;
}
digitalWrite(relayPin, LOW);
servo.detach();
setLcdStatus();
}
void setLcdStatus()
{
lcd.clear();
switch (locked)
{
case false:
lcd.print(0,0,"Status:");
lcd.print(0,1,"Unlocked");
break;
case true:
lcd.print(0,0,"Status:");
lcd.print(0,1,"Locked");
break;
}
transition = false;
}