How can we turn on an Led on the receiver end of an ESP32 Lora Module.

Hi Guys, Im building a a mailbox notifier using the following Code. I’m using 2 identical Esp32 Lora Modules (TTGO). One module is in the letterbox, the other is in the house.

One module is setup as Sender (indide the mailbox) the other is setup as Receiver. (inside the house) On the the Sender Esp32 Lora Module, I have an Infrared Sensor (input) to detect when mail has been inserted in the mailbox, it also triggers an led on the sending end when the infrared sensor is triggered. This then sends a notification to the Receiver Esp32 Lora Module and the oled on the receiver says “you have mail”.
The sketch works fine.

What I would like to do is when the receiver module receives the message “you have mail” I would like an LED to trigger high on the receiver module.

Could someone please help me with what code I should put in the receiver or the sender sketch to light up the Led on the receiving module upon the infrared being triggered at the sender module.

Here are the sketches on both modules.

Thanks in advance for your assistance.

Esp32 Lora Module - Receiver (located in the house)

#include <SPI.h>
#include <LoRa.h>
#include <Wire.h>
#include “SSD1306.h”
//#include “images.h”

#define SCK 5 // GPIO5 – SX1278’s SCK
#define MISO 19 // GPIO19 – SX1278’s MISO
#define MOSI 27 // GPIO27 – SX1278’s MOSI
#define SS 18 // GPIO18 – SX1278’s CS
#define RST 14 // GPIO14 – SX1278’s RESET
#define DI0 26 // GPIO26 – SX1278’s IRQ(Interrupt Request)
#define BAND 433E6

SSD1306 display(0x3c, 4, 15);
String rssi = “RSSI --”;
String packSize = “–”;
String packet ;

void loraData(){
display.clear();
display.setTextAlignment(TEXT_ALIGN_LEFT);
display.setFont(ArialMT_Plain_10);
display.drawString(0 , 15 , "Received “+ packSize + " bytes”);
display.drawStringMaxWidth(0 , 26 , 128, packet);
display.drawString(0, 0, rssi);
display.display();
}

void cbk(int packetSize) {
packet ="";
packSize = String(packetSize,DEC);
for (int i = 0; i < packetSize; i++) { packet += (char) LoRa.read(); }
rssi = "RSSI " + String(LoRa.packetRssi(), DEC) ;
loraData();
}

void setup() {
pinMode(16,OUTPUT);
digitalWrite(16, LOW); // set GPIO16 low to reset OLED
delay(50);
digitalWrite(16, HIGH); // while OLED is running, must set GPIO16 in high、

Serial.begin(9600);
while (!Serial);
Serial.println();
Serial.println(“LoRa Receiver Callback”);
SPI.begin(SCK,MISO,MOSI,SS);
LoRa.setPins(SS,RST,DI0);
if (!LoRa.begin(433E6)) {
Serial.println(“Starting LoRa failed!”);
while (1);
}
//LoRa.onReceive(cbk);
LoRa.receive();
Serial.println(“init ok”);
display.init();
display.flipScreenVertically();
display.setFont(ArialMT_Plain_10);

delay(1500);
}

void loop() {
int packetSize = LoRa.parsePacket();
if (packetSize) { cbk(packetSize); }
delay(10);
}

Esp32 Lora Module - Sender (inside the Mailbox)

#include <SPI.h>
#include <LoRa.h>
#include <Wire.h>
#include “SSD1306.h”
//#include “images.h”

#define SCK 5 // GPIO5 – SX1278’s SCK
#define MISO 19 // GPIO19 – SX1278’s MISO
#define MOSI 27 // GPIO27 – SX1278’s MOSI
#define SS 18 // GPIO18 – SX1278’s CS
#define RST 23 // GPIO23-- SX1278’s RESET
#define DI0 26 // GPIO26 – SX1278’s IRQ(Interrupt Request)
#define BAND 433E6

unsigned int counter = 0;

SSD1306 display(0x3c, 4, 15);
String rssi = “RSSI --”;
String packSize = “–”;
String packet ;

void setup() {
pinMode(16,OUTPUT);
pinMode(0,OUTPUT);
// insert infrared code 1
pinMode(12,INPUT); //SIGNAL FROM INFRARED
pinMode(14,OUTPUT); //5V TO POWER INFRARED
pinMode(32,OUTPUT); //GROUND TO POWER INFRARED
digitalWrite(14,HIGH); // INFRARED 5V
digitalWrite(32,LOW); // INFRARED GROUND
Serial.begin(9600);

digitalWrite(16, LOW); // set GPIO16 low to reset OLED
delay(50);
digitalWrite(16, HIGH); // while OLED is running, must set GPIO16 in high

Serial.begin(9600);
while (!Serial);
Serial.println();
Serial.println(“LoRa Sender Test”);

SPI.begin(SCK,MISO,MOSI,SS);
LoRa.setPins(SS,RST,DI0);
if (!LoRa.begin(433E6)) {
Serial.println(“Starting LoRa failed!”);
while (1);
}
//LoRa.onReceive(cbk);
// LoRa.receive();
Serial.println(“init ok”);
display.init();
display.flipScreenVertically();
display.setFont(ArialMT_Plain_10);

delay(1500);
}

void loop() {
Serial.println(analogRead(12));
//delay(1000);
if(analogRead(12) < 500 )
{
display.clear();
display.setTextAlignment(TEXT_ALIGN_LEFT);
display.setFont(ArialMT_Plain_10);

display.drawString(0, 0, "Sending packet: ");
display.drawString(90, 0, String(counter));
display.display();

LoRa.beginPacket();
LoRa.print(“You Have Mail”);
LoRa.endPacket();

counter++;
digitalWrite(0, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(0, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
else
{
}}

The sketch works fine

If part of the project is already working, it might be interesting to search for remote controls.

The LoRa Receiver Sketch

Now, grab another ESP32 and upload the following sketch (the LoRa receiver sketch). This sketch listens for LoRa packets with the sync word you’ve defined and prints the content of the packets on the Serial Monitor, as well as the RSSI. The RSSI measures the relative received signal strength.

(Text is roughly in the middle of the page):

Other remote control:

Control Home Appliances Over LoRa | LoRa Remote Control

Thanks, however could not work it out with my arduino skill level.