Devices & Components
SG90 Micro-servo motor
Breadboard (generic)
SparkFun Breadboard Power Supply 5V/3.3V
Jumper wires (generic)
RYLR988
ESP32-WROOM-32
Software & Tools
Arduino IDE
Project description
Code
Remote Microcontroller
cpp
1#include <Arduino.h> 2 3#define LORA_RX 4 //Change these pins accordingly 4#define LORA_TX 5 //Change these pins accordingly 5 6HardwareSerial loraSerial(1); 7uint8_t buttonState; 8uint8_t lastButtonState = 0; 9uint8_t lastPressTime; 10 11void setup() { 12 loraSerial.begin(115200, SERIAL_8N1, LORA_RX, LORA_TX); 13 pinMode(2, INPUT_PULLUP); 14 15 delay(250); 16 loraSerial.write("AT+ADDRESS=0\r\n"); 17 delay(250); 18 loraSerial.write("AT+NETWORKID=18\r\n"); 19 delay(250); 20 loraSerial.write("AT+BAND=865000000\r\n"); 21} 22 23void loop() { 24 static bool doorState = false; 25 uint8_t currentReading = digitalRead(2); 26 27 if (lastButtonState != currentReading) { 28 if (currentReading == LOW) { 29 delay(150); 30 if (currentReading == LOW) { 31 doorState = !doorState; 32 loraSerial.print("AT+SEND=2,1," + String(doorState) + "\r\n"); 33 } 34 } 35 } 36 37 lastButtonState = currentReading; 38}
Garage Microcontroller
cpp
1#include <ESP32Servo.h> 2 3Servo S1; 4 5#define LORA_RX 26 //Change these pins accordingly 6#define LORA_TX 27 //Change these pins accordingly 7#define servoPin 14 //Change these pins accordingly 8HardwareSerial loraSerial(1); 9 10void driveServo(int a) { 11 static int position = 40; 12 13 if (a > position) { 14 while (a > position) { 15 S1.write(position++); 16 delay(10); 17 } 18 } else if (a < position) { 19 while (a < position) { 20 S1.write(position--); 21 delay(10); 22 } 23 } 24} 25void setup() { 26 loraSerial.begin(115200, SERIAL_8N1, LORA_RX, LORA_TX); 27 28 ESP32PWM::allocateTimer(0); 29 ESP32PWM::allocateTimer(1); 30 ESP32PWM::allocateTimer(2); 31 ESP32PWM::allocateTimer(3); 32 S1.setPeriodHertz(50); 33 S1.attach(servoPin, 500, 2500); 34 S1.write(40); 35 36 delay(250); 37 loraSerial.write("AT+ADDRESS=2\r\n"); 38 delay(250); 39 loraSerial.write("AT+NETWORKID=18\r\n"); 40 delay(250); 41 loraSerial.write("AT+BAND=865000000\r\n"); //Please change the band according to your country laws 42} 43 44void loop() { 45 if (loraSerial.available()) { 46 String data = loraSerial.readStringUntil('\n'); 47 data = data.substring(9, 10); 48 49 if (data == "1") driveServo(100); 50 else if (data = "0") driveServo(40); 51 } 52}
Downloadable files
Garage Door STL
Garage Door.stl
Garage Door Housing
Garage Housing.stl
Garage Side Connection Diagram
Untitled Sketch_bb.png

Remote Controller Connection Diagram
Untitled Sketch 2_bb.png

Comments
Only logged in users can leave comments