-
Notifications
You must be signed in to change notification settings - Fork 0
/
Smart_doorLock.ino
62 lines (50 loc) · 1.04 KB
/
Smart_doorLock.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#define BLYNK_PRINT Serial
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
#include <SoftwareSerial.h>
#include <Servo.h>
char network_name[] = "YOUR NETWORK NAME";
char network_password[] = "YOUR PASSWORD";
char auth[] = "YOUR AUTH TOKEN";
int SERVO_PIN = 4;
int led = 5;
int lock_degree = 120;
int unlock_degree = 0;
Servo servo;
SoftwareSerial EspSerial(3, 2); //Rx, Tx
#define ESP8266_BAUD 9600
ESP8266 wifi(&EspSerial);
void Lock();
void Unlock();
BLYNK_WRITE(V1)
{
int pinValue = param.asInt();
if(pinValue == 1)
Lock();
else
Unlock();
}
void setup()
{
Serial.begin(9600);
EspSerial.begin(ESP8266_BAUD);
delay(10);
Blynk.begin(auth, wifi, network_name, network_password);
servo.attach(SERVO_PIN);
pinMode(led, OUTPUT);
servo.write(unlock_degree);
}
void loop()
{
Blynk.run();
}
void Lock()
{
servo.write(lock_degree);
digitalWrite(led, HIGH);
}
void Unlock()
{
servo.write(unlock_degree);
digitalWrite(led, LOW);
}