Cool CAR Garage Detector System
This new car garage detection system using Arduino and LoRa. A smart solution for monitoring the presence of your Car in the garage.
Components and supplies
1
Ultrasonic Sensor - HC-SR04
1
0.91 inch OLED 128 X 32 display
1
ESP32
2
RYLR998 LORA from Reyax
2
Resistor 10k ohm
2
Resistor 4.75k ohm
2
LED (generic)
1
Arduino Nano
Tools and machines
1
drill
Apps and platforms
1
Arduino IDE
Project description
Code
CAR Detector RYLR998 Receiver
c
CAR Detector RYLR998 Receiver
1/* 2 * RYLR998 Check your CAR RECEIVER (In or out of the garage?) 3 * February 5th 2023 4 * Carlo Stramaglia 5 * https://www.youtube.com/c/CarloStramaglia 6 * To change the Password, change the 8 digits in the below function LoRa.print("AT+CPIN=11223344\r\n"); 7 * You need to have the same password on both Receiver and Transmitter 8 */ 9 10#include <NTPClient.h> 11#include <SoftwareSerial.h> 12#include <U8g2lib.h> 13#include <WiFi.h> 14#include <WiFiUdp.h> 15#include "arduino_secrets.h" 16 17WiFiUDP ntpUDP; 18NTPClient timeClient(ntpUDP); 19 20U8G2_SSD1306_128X32_UNIVISION_F_SW_I2C u8g2(U8G2_R0, /* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE); // Adafruit Feather ESP8266/32u4 Boards + FeatherWing OLED 21SoftwareSerial LoRa(19, 23); // RX, TX 22 23///////please enter your sensitive data in the Secret tab/arduino_secrets.h 24char ssid[] = SECRET_SSID; // your network SSID (name) 25char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) 26int keyIndex = 0; // your network key index number (needed only for WEP) 27 28int status = WL_IDLE_STATUS; 29 30String msg = "", received_msg = ""; 31int waiting = 200; 32 33 34void setup() { 35 Serial.begin(57600); 36 LoRa.begin(57600); 37 38 WiFi.begin(ssid, pass); 39 40 while (WiFi.status() != WL_CONNECTED) { 41 delay(500); 42 Serial.print("."); 43 } 44 45 Serial.println(""); 46 Serial.println("WiFi connected"); 47 Serial.println("IP address: "); 48 Serial.println(WiFi.localIP()); 49 50 u8g2.begin(); 51 set_AT_commands ("50","18"); 52 msg=""; 53 u8g2.clearBuffer(); // clear the internal memory 54 u8g2.setFont(u8g2_font_ncenB08_tr); // choose a suitable font 55 u8g2.drawStr(0,8,"Ready to Receive"); // write something to the internal memory 56 u8g2.sendBuffer(); // transfer internal memory to the display 57 58 timeClient.begin(); 59 delay (3000); 60 u8g2.clearBuffer(); // clear the internal memory 61} 62 63void loop() { 64 delay (50); 65 get_serial_data(); 66 if(msg != ""){ 67 Serial.print("Data Arrived: "); 68 Serial.println(msg); 69 int delimiter_1, delimiter_2; 70 delimiter_1 = msg.indexOf("@"); 71 delimiter_2 = msg.indexOf("$", delimiter_1 + 1); 72 73 received_msg = msg.substring(delimiter_1 + 1, delimiter_2); 74 int str_len = received_msg.length() + 1; 75 char messageLocal[str_len]; 76 77 received_msg.toCharArray(messageLocal, str_len); 78 79 u8g2.setFont(u8g2_font_ncenB08_tr); // choose a suitable font 80 81 if (messageLocal[0] == 0x31) { 82 u8g2.clearBuffer(); // clear the internal memory 83 u8g2.drawStr(0,8,"The CAR is IN"); // write something to the internal memory 84 timeClient.update(); 85 u8g2.drawStr(0,20,"Last time IN: "); // write something to the internal memory 86 Serial.println(timeClient.getFormattedTime()); 87 Serial.println(timeClient.getDay()); 88 display(); 89 } 90 else 91 u8g2.drawStr(0,8,"The CAR is OUT"); // write something to the internal memory 92 u8g2.sendBuffer(); // transfer internal memory to the display 93 94 95 } 96} 97 98 99void get_serial_data(){ 100 if (LoRa.available()){ 101 msg = LoRa.readString(); 102 } 103} 104 105void set_AT_commands(String address, String network_ID){ 106 LoRa.print("AT\r\n"); // Just a check if the module is well connected 107 delay(waiting); 108 LoRa.print("AT+ADDRESS=" + address + "\r\n"); // Device Address will be stored in Flash 109 delay(waiting); 110 LoRa.print("AT+NETWORKID="+network_ID+"\r\n"); // Network ID will be stored in flash 111 delay(waiting); 112 LoRa.print("AT+PARAMETER=9,7,1,12\r\n"); // Default data. Can be deleted 113 delay(waiting); 114 LoRa.print("AT+IPR=57600\r\n"); // Lower serial speed. My Arduino was not working properly at 115200 115 delay(waiting); 116 LoRa.print("AT+RESET\r\n"); // Reset is required otherwise seems not to work properly at startup 117 delay(waiting); 118 LoRa.print("AT+BAND=868100000\r\n"); // Eurpean Bandwdth 119 delay(waiting); 120 LoRa.print("AT+CPIN=11223344\r\n"); // Encrypted password should be the same as the receiver 121 delay(waiting); 122} 123 124// Display Ora a data 125void display() 126{ 127 char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}; 128 char buf[40]; 129 char dayWord[40]; 130 131 u8g2.setFont(u8g2_font_ncenB08_tr); 132 133 sprintf(dayWord, daysOfTheWeek[timeClient.getDay()]); 134 135 Serial.print ("Day: "); 136 Serial.println(dayWord); 137 u8g2.drawStr(80,20, dayWord); 138 139 sprintf(buf, "%.2d:%.2d:%.2d GMT", timeClient.getHours(), timeClient.getMinutes(), timeClient.getSeconds()); 140 Serial.print ("Time: "); 141 Serial.println(buf); 142 u8g2.drawStr(0,30, buf); 143 144 u8g2.sendBuffer(); 145 146 delay(1000); 147 148}
arduino_secrets.h
c
Arduino Secrets for WiFi Connection
1#define SECRET_SSID "SSID Name" 2#define SECRET_PASS "Password"
CAR Detector RYLR998 Transmitter
c
Receiver code for CAR Garage Detector
1/* 2 * RYLR998 Check your CAR TRANSMITTER (In or out of the garage?) 3 * February 5th 2023 4 * Carlo Stramaglia 5 * https://www.youtube.com/c/CarloStramaglia 6 * To change the Password, change the 8 digits in the below function LoRa.print("AT+CPIN=11223344\r\n"); 7 * You need to have the same password on both Receiver and Transmitter 8 */ 9 10#include <SoftwareSerial.h> 11#include <HCSR04.h> 12 13SoftwareSerial LoRa(6, 5); // First (6) connected to TX of RYLR998, Second (5) to RX of RYLR998 14 15#define PIN_LED_RED 7 16//#define PIN_LED_RED 13 17#define PIN_LED_GREEN 8 18byte triggerPin = 9; 19byte echoPin = 10; 20 21int ledState = LOW; 22 23String msg = ""; 24int waiting = 200; 25int j=0; 26char messageNumber[10] = ""; 27 28 29void setup() { 30 Serial.begin(57600); 31 HCSR04.begin(triggerPin, echoPin); 32 pinMode(PIN_LED_RED, OUTPUT); 33 pinMode(PIN_LED_GREEN, OUTPUT); 34 digitalWrite(PIN_LED_GREEN, ledState); 35 digitalWrite(PIN_LED_RED, ledState); 36 LoRa.begin(57600); 37 set_AT_commands ("51","18"); 38 delay(2000); 39 LoRa.print("AT+BAND=868100000\r\n"); // Placed this command because sometimes the board was going back to US standard 40 delay(2000); 41} 42 43void loop() { 44 double* distances = HCSR04.measureDistanceCm(); 45 Serial.print("1: "); 46 Serial.print(distances[0]); 47 Serial.println(" cm"); 48 49 Serial.println("---"); 50 if (distances[0] > 100 or distances[0] == -1) { 51 j=0; 52 sprintf (messageNumber, "@%i$",j); 53 send_AT_message("50", messageNumber); 54 digitalWrite(PIN_LED_RED, HIGH); 55 digitalWrite(PIN_LED_GREEN, ledState); 56 } 57 else 58 { 59 j=1; 60 sprintf (messageNumber, "@%i$",j); 61 send_AT_message("50", messageNumber); 62 digitalWrite(PIN_LED_RED, ledState); 63 digitalWrite(PIN_LED_GREEN, HIGH); 64 } 65 delay(3000); 66 67} 68 69 70void get_serial_data(){ 71 if (LoRa.available()){ 72 msg = LoRa.readString(); 73 } 74} 75 76void set_AT_commands(String address, String network_ID){ 77 LoRa.print("AT\r\n"); // Just a check if the module is well connected 78 delay(waiting); 79 LoRa.print("AT+ADDRESS=" + address + "\r\n"); // Device Address will be stored in Flash 80 delay(waiting); 81 LoRa.print("AT+NETWORKID="+network_ID+"\r\n"); // Network ID will be stored in flash 82 delay(waiting); 83 LoRa.print("AT+PARAMETER=9,7,1,12\r\n"); // Default data. Can be deleted 84 delay(waiting); 85 LoRa.print("AT+IPR=57600\r\n"); // Lower serial speed. My Arduino was not working properly at 115200 86 delay(waiting); 87 LoRa.print("AT+RESET\r\n"); // Reset is required otherwise seems not to work properly at startup 88 delay(waiting); 89 LoRa.print("AT+BAND=868100000\r\n"); // Eurpean Bandwdth 90 delay(waiting); 91 LoRa.print("AT+CPIN=11223344\r\n"); // Encrypted password should be the same as the receiver 92 delay(waiting); 93 94} 95 96 97void send_AT_message(String address, char* textmessage){ 98 int Lenght=0; 99 Lenght = strlen (textmessage); 100 LoRa.print("AT+SEND=" + address + "," + Lenght + "," + textmessage + "\r\n"); 101 delay(waiting); 102}
RYLR998 Setup for changing the Baud Rate from 115200 to 57600
c
Load this first to both Receiver and transmitter
1/* 2 * DO THIS ONLY ONCE ON BOTH RECEIVER AND TRANSMITTER 3 * RYLR998 Setup code for 57600 baud communication 4 * December 31st 2022 5 * Carlo Stramaglia 6 * https://www.youtube.com/c/CarloStramaglia 7 * 8 */ 9 10#include <SoftwareSerial.h> 11 12SoftwareSerial LoRa(6, 5); // First (6) connected to TX of RYLR998, Second (5) to RX of RYLR998 13 14 15String msg = ""; 16int waiting = 200; 17int i=0, j=0; 18char messageNumber[10] = ""; 19 20 21void setup() { 22 LoRa.begin(115200); 23 set_AT_commands ("100","18"); 24 delay(5000); 25} 26 27void loop() { 28 29} 30 31 32void get_serial_data(){ 33 if (LoRa.available()){ 34 msg = LoRa.readString(); 35 } 36} 37 38void set_AT_commands(String address, String network_ID){ 39 LoRa.print("AT\r\n"); // Just a check if the module is well connected 40 delay(waiting); 41 LoRa.print("AT+ADDRESS=" + address + "\r\n"); // Device Address will be stored in Flash 42 delay(waiting); 43 LoRa.print("AT+NETWORKID="+network_ID+"\r\n"); // Network ID will be stored in flash 44 delay(waiting); 45 LoRa.print("AT+PARAMETER=9,7,1,12\r\n"); // Default data. Can be deleted 46 delay(waiting); 47 LoRa.print("AT+IPR=57600\r\n"); // Lower serial speed. My Arduino was not working properly at 115200 48 delay(waiting); 49 LoRa.print("AT+RESET\r\n"); // Reset is required otherwise seems not to work properly at startup 50 delay(waiting); 51 LoRa.print("AT+BAND=868100000\r\n"); // Eurpean Bandwdth 52 delay(waiting); 53 54}
Downloadable files
Car Park Transmitter diagram
Car Park Transmitter diagram
CarParkTX.pdf
Car Park Receiver Diagram
Car Park Receiver Diagram
CarParkRX.pdf
Comments
Only logged in users can leave comments