#include <WiFi.h>
#include <ESP32Servo.h>
Servo myservo; //create servo object to control servo
int pos = 0; //variable to store server position
static const int servoPin = 18;
const int LED = 12;
String command;
void setup(){
Serial.begin(115200);
WiFi.mode(WIFI_STA);
//allow allocation of all timers
ESP32PWM::allocateTimer(0);
ESP32PWM::allocateTimer(1);
ESP32PWM::allocateTimer(2);
ESP32PWM::allocateTimer(3);
myservo.setPeriodHertz(50); //standard 50hz servo
myservo.attach(servoPin, 10, 2800); // attaches the servo on pin 18 to the servo object
pinMode(LED, OUTPUT);
Serial.println("Door is ");
}
void loop(){
while (Serial.available() >0 ){
String command = Serial.readString();
if (command == "OPEN"){
Serial.println(command);
for (pos = 0; pos<=180; pos+=1){
myservo.write(pos);
digitalWrite(LED,HIGH);
delay(15);
}
}
if (command == "CLOSED"){
Serial.println(command);
for (pos = 180; pos>=0; pos-=1){
myservo.write(pos);
digitalWrite(LED,LOW);
delay(15);
}
}
}
}
//Serial.print(pos);
esp:VIN
esp:GND.2
esp:D13
esp:D12
esp:D14
esp:D27
esp:D26
esp:D25
esp:D33
esp:D32
esp:D35
esp:D34
esp:VN
esp:VP
esp:EN
esp:3V3
esp:GND.1
esp:D15
esp:D2
esp:D4
esp:RX2
esp:TX2
esp:D5
esp:D18
esp:D19
esp:D21
esp:RX0
esp:TX0
esp:D22
esp:D23
led1:A
led1:C
r1:1
r1:2
servo1:GND
servo1:V+
servo1:PWM