Hardware components | ||||||
![]() |
| × | 1 | |||
![]() |
| × | 1 | |||
![]() |
| × | 2 | |||
| × | 2 | ||||
| × | 1 | ||||
| × | 1 | ||||
![]() |
| × | 2 | |||
![]() |
| × | 2 | |||
Software apps and online services | ||||||
![]() |
| |||||
Hand tools and fabrication machines | ||||||
![]() |
|
This new car garage detection system using Arduino and LoRa technology to communicate can be a smart solution for monitoring the presence of a car in the garage. Here's how it works:
A detector sensor is placed on the wall of the garage, and an Arduino microcontroller is connected to the sensor to read the data. When a car enters the garage, the sensor detects the change in presence and sends a signal to the microcontroller.
The Arduino is connected to a LoRa (Long Range) communication module, which enables wireless communication over long distances. The LoRa module sends the data collected from the sensor to a remote device.
The data sent by the LoRa module is received by a remote device. The remote device or server processes the data and displays the information about the presence of the car in the garage.
The remote device displays the information about the presence of the car in the garage through a user-friendly interface. It tells you when the sensor last sent the data and, if the car is not in the garage, it tells you last time it was in.
This system can provide real-time information about the presence of the car in the garage and can be especially useful for families with multiple cars or for those who want to ensure the safety and security of their vehicles. The use of LoRa technology enables the system to have a long range of communication, making it possible to monitor the car from a remote location.
/*
* RYLR998 Check your CAR RECEIVER (In or out of the garage?)
* February 5th 2023
* Carlo Stramaglia
* https://www.youtube.com/c/CarloStramaglia
* To change the Password, change the 8 digits in the below function LoRa.print("AT+CPIN=11223344\r\n");
* You need to have the same password on both Receiver and Transmitter
*/
#include <NTPClient.h>
#include <SoftwareSerial.h>
#include <U8g2lib.h>
#include <WiFi.h>
#include <WiFiUdp.h>
#include "arduino_secrets.h"
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP);
U8G2_SSD1306_128X32_UNIVISION_F_SW_I2C u8g2(U8G2_R0, /* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE); // Adafruit Feather ESP8266/32u4 Boards + FeatherWing OLED
SoftwareSerial LoRa(19, 23); // RX, TX
///////please enter your sensitive data in the Secret tab/arduino_secrets.h
char ssid[] = SECRET_SSID; // your network SSID (name)
char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP)
int keyIndex = 0; // your network key index number (needed only for WEP)
int status = WL_IDLE_STATUS;
String msg = "", received_msg = "";
int waiting = 200;
void setup() {
Serial.begin(57600);
LoRa.begin(57600);
WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
u8g2.begin();
set_AT_commands ("50","18");
msg="";
u8g2.clearBuffer(); // clear the internal memory
u8g2.setFont(u8g2_font_ncenB08_tr); // choose a suitable font
u8g2.drawStr(0,8,"Ready to Receive"); // write something to the internal memory
u8g2.sendBuffer(); // transfer internal memory to the display
timeClient.begin();
delay (3000);
u8g2.clearBuffer(); // clear the internal memory
}
void loop() {
delay (50);
get_serial_data();
if(msg != ""){
Serial.print("Data Arrived: ");
Serial.println(msg);
int delimiter_1, delimiter_2;
delimiter_1 = msg.indexOf("@");
delimiter_2 = msg.indexOf("$", delimiter_1 + 1);
received_msg = msg.substring(delimiter_1 + 1, delimiter_2);
int str_len = received_msg.length() + 1;
char messageLocal[str_len];
received_msg.toCharArray(messageLocal, str_len);
u8g2.setFont(u8g2_font_ncenB08_tr); // choose a suitable font
if (messageLocal[0] == 0x31) {
u8g2.clearBuffer(); // clear the internal memory
u8g2.drawStr(0,8,"The CAR is IN"); // write something to the internal memory
timeClient.update();
u8g2.drawStr(0,20,"Last time IN: "); // write something to the internal memory
Serial.println(timeClient.getFormattedTime());
Serial.println(timeClient.getDay());
display();
}
else
u8g2.drawStr(0,8,"The CAR is OUT"); // write something to the internal memory
u8g2.sendBuffer(); // transfer internal memory to the display
}
}
void get_serial_data(){
if (LoRa.available()){
msg = LoRa.readString();
}
}
void set_AT_commands(String address, String network_ID){
LoRa.print("AT\r\n"); // Just a check if the module is well connected
delay(waiting);
LoRa.print("AT+ADDRESS=" + address + "\r\n"); // Device Address will be stored in Flash
delay(waiting);
LoRa.print("AT+NETWORKID="+network_ID+"\r\n"); // Network ID will be stored in flash
delay(waiting);
LoRa.print("AT+PARAMETER=9,7,1,12\r\n"); // Default data. Can be deleted
delay(waiting);
LoRa.print("AT+IPR=57600\r\n"); // Lower serial speed. My Arduino was not working properly at 115200
delay(waiting);
LoRa.print("AT+RESET\r\n"); // Reset is required otherwise seems not to work properly at startup
delay(waiting);
LoRa.print("AT+BAND=868100000\r\n"); // Eurpean Bandwdth
delay(waiting);
LoRa.print("AT+CPIN=11223344\r\n"); // Encrypted password should be the same as the receiver
delay(waiting);
}
// Display Ora a data
void display()
{
char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
char buf[40];
char dayWord[40];
u8g2.setFont(u8g2_font_ncenB08_tr);
sprintf(dayWord, daysOfTheWeek[timeClient.getDay()]);
Serial.print ("Day: ");
Serial.println(dayWord);
u8g2.drawStr(80,20, dayWord);
sprintf(buf, "%.2d:%.2d:%.2d GMT", timeClient.getHours(), timeClient.getMinutes(), timeClient.getSeconds());
Serial.print ("Time: ");
Serial.println(buf);
u8g2.drawStr(0,30, buf);
u8g2.sendBuffer();
delay(1000);
}
#define SECRET_SSID "SSID Name"
#define SECRET_PASS "Password"
/*
* RYLR998 Check your CAR TRANSMITTER (In or out of the garage?)
* February 5th 2023
* Carlo Stramaglia
* https://www.youtube.com/c/CarloStramaglia
* To change the Password, change the 8 digits in the below function LoRa.print("AT+CPIN=11223344\r\n");
* You need to have the same password on both Receiver and Transmitter
*/
#include <SoftwareSerial.h>
#include <HCSR04.h>
SoftwareSerial LoRa(6, 5); // First (6) connected to TX of RYLR998, Second (5) to RX of RYLR998
#define PIN_LED_RED 7
//#define PIN_LED_RED 13
#define PIN_LED_GREEN 8
byte triggerPin = 9;
byte echoPin = 10;
int ledState = LOW;
String msg = "";
int waiting = 200;
int j=0;
char messageNumber[10] = "";
void setup() {
Serial.begin(57600);
HCSR04.begin(triggerPin, echoPin);
pinMode(PIN_LED_RED, OUTPUT);
pinMode(PIN_LED_GREEN, OUTPUT);
digitalWrite(PIN_LED_GREEN, ledState);
digitalWrite(PIN_LED_RED, ledState);
LoRa.begin(57600);
set_AT_commands ("51","18");
delay(2000);
LoRa.print("AT+BAND=868100000\r\n"); // Placed this command because sometimes the board was going back to US standard
delay(2000);
}
void loop() {
double* distances = HCSR04.measureDistanceCm();
Serial.print("1: ");
Serial.print(distances[0]);
Serial.println(" cm");
Serial.println("---");
if (distances[0] > 100 or distances[0] == -1) {
j=0;
sprintf (messageNumber, "@%i$",j);
send_AT_message("50", messageNumber);
digitalWrite(PIN_LED_RED, HIGH);
digitalWrite(PIN_LED_GREEN, ledState);
}
else
{
j=1;
sprintf (messageNumber, "@%i$",j);
send_AT_message("50", messageNumber);
digitalWrite(PIN_LED_RED, ledState);
digitalWrite(PIN_LED_GREEN, HIGH);
}
delay(3000);
}
void get_serial_data(){
if (LoRa.available()){
msg = LoRa.readString();
}
}
void set_AT_commands(String address, String network_ID){
LoRa.print("AT\r\n"); // Just a check if the module is well connected
delay(waiting);
LoRa.print("AT+ADDRESS=" + address + "\r\n"); // Device Address will be stored in Flash
delay(waiting);
LoRa.print("AT+NETWORKID="+network_ID+"\r\n"); // Network ID will be stored in flash
delay(waiting);
LoRa.print("AT+PARAMETER=9,7,1,12\r\n"); // Default data. Can be deleted
delay(waiting);
LoRa.print("AT+IPR=57600\r\n"); // Lower serial speed. My Arduino was not working properly at 115200
delay(waiting);
LoRa.print("AT+RESET\r\n"); // Reset is required otherwise seems not to work properly at startup
delay(waiting);
LoRa.print("AT+BAND=868100000\r\n"); // Eurpean Bandwdth
delay(waiting);
LoRa.print("AT+CPIN=11223344\r\n"); // Encrypted password should be the same as the receiver
delay(waiting);
}
void send_AT_message(String address, char* textmessage){
int Lenght=0;
Lenght = strlen (textmessage);
LoRa.print("AT+SEND=" + address + "," + Lenght + "," + textmessage + "\r\n");
delay(waiting);
}
RYLR998 Setup for changing the Baud Rate from 115200 to 57600
Arduino/*
* DO THIS ONLY ONCE ON BOTH RECEIVER AND TRANSMITTER
* RYLR998 Setup code for 57600 baud communication
* December 31st 2022
* Carlo Stramaglia
* https://www.youtube.com/c/CarloStramaglia
*
*/
#include <SoftwareSerial.h>
SoftwareSerial LoRa(6, 5); // First (6) connected to TX of RYLR998, Second (5) to RX of RYLR998
String msg = "";
int waiting = 200;
int i=0, j=0;
char messageNumber[10] = "";
void setup() {
LoRa.begin(115200);
set_AT_commands ("100","18");
delay(5000);
}
void loop() {
}
void get_serial_data(){
if (LoRa.available()){
msg = LoRa.readString();
}
}
void set_AT_commands(String address, String network_ID){
LoRa.print("AT\r\n"); // Just a check if the module is well connected
delay(waiting);
LoRa.print("AT+ADDRESS=" + address + "\r\n"); // Device Address will be stored in Flash
delay(waiting);
LoRa.print("AT+NETWORKID="+network_ID+"\r\n"); // Network ID will be stored in flash
delay(waiting);
LoRa.print("AT+PARAMETER=9,7,1,12\r\n"); // Default data. Can be deleted
delay(waiting);
LoRa.print("AT+IPR=57600\r\n"); // Lower serial speed. My Arduino was not working properly at 115200
delay(waiting);
LoRa.print("AT+RESET\r\n"); // Reset is required otherwise seems not to work properly at startup
delay(waiting);
LoRa.print("AT+BAND=868100000\r\n"); // Eurpean Bandwdth
delay(waiting);
}
Comments
Please log in or sign up to comment.