But how?
Where? What to write?
@salman sir, I have made the LoRa sender and receiver sketches for vibration sensor, and I’m attaching them with this message. The good thing is that I have successfully established communication between the two radios, along with vibration sensor and when the vibration sensor (on the first arduino, with transmitter) is getting any jerk or vibration, the led (on the second Arduino, with receiver) is lighting up. I am able to get the measurements of vibrations on the serial monitor of radio transmitter, but I need them on the serial monitor of the radio receiver also, then only a transmission will be taking place.
It took me 3.2 hours to prepare these two sketches. Kindly guide me, I’ll provide you with every required information.
LoRa_Sender (Vibration Sensor)
#include <SoftwareSerial.h>
#include <RH_RF95.h>
int EP = 2;
// Singleton instance of the radio driver
SoftwareSerial ss(5, 6);
RH_RF95 rf95(ss);
void setup() {
pinMode(EP, INPUT); //set EP input for measurment
Serial.begin(115200); //init serial 9600
Serial.println("----------------------Vibration demo------------------------");
if (!rf95.init())
{
Serial.println(“init failed”);
while(1);
}
rf95.setFrequency(434.0);
}
void loop() {
long measurement = TP_init();
delay(10);
Serial.print("measurment = ");
Serial.println(measurement);
if (measurement > 50) {
delay(200);
// Send a message to rf95_server
uint8_t data[] = “measurement”;
rf95.send(data, sizeof(data));
delay(6000);
rf95.waitPacketSent();
}
// Now wait for a reply
uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];
uint8_t len = sizeof(buf);
if(rf95.waitAvailableTimeout(3000))
{
// Should be a reply message for us now
if(rf95.recv(buf, &len))
{
Serial.print("got reply: ");
Serial.println((char*)buf);
}
else
{
digitalWrite(ss, LOW);
}
}
}
long TP_init() {
delay(10);
long measurement = pulseIn (EP, HIGH); //waits for the pin to get HIGH and returns measurement
return measurement;
}
LoRa_Receiver (Vibration Sensor)
#include <SoftwareSerial.h>
#include <RH_RF95.h>
// Singleton instance of the radio driver
SoftwareSerial ss(5, 6);
RH_RF95 rf95(ss);
int ledPin = LED_BUILTIN;
void setup()
{
pinMode(ledPin, OUTPUT);
Serial.begin(115200); //init serial 115200
Serial.println("-----------------------Pole - Urban Area - GHY_1---------------");
if(!rf95.init())
{
Serial.println("init failed");
while(1);
}
rf95.setFrequency(434.0);
}
void loop()
{
long measurement = TP_init();
delay(10);
Serial.print("measurment = ");
Serial.println(measurement);
if(rf95.available())
{
delay(200);
// Should be a message for us now
uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];
uint8_t len = sizeof(buf);
if(rf95.recv(buf, &len))
{
Serial.print("GOT VIBRATION: ");
Serial.println((char*)buf);
digitalWrite(ledPin, HIGH);
delay(6000);
// Send a reply
uint8_t data[] = "Thanks for the Data";
rf95.send(data, sizeof(data));
rf95.waitPacketSent();
Serial.println("Sent a reply");
digitalWrite(ledPin, LOW);
}
else
{
Serial.println("recv failed");
}
}
}
long TP_init() {
delay(10);
long measurement = pulseIn (ss, HIGH); //wait for the pin to get HIGH and returns measurement
return measurement;
}