Hackster is hosting Hackster Holidays, Ep. 7: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Friday!Stream Hackster Holidays, Ep. 7 on Friday!
mdraber
Published © GPL3+

How to use RYLR998 LORA module with Arduino

Working with RYLR998 LORA and Arduino Pro Min 8v.

IntermediateFull instructions provided6,476
How to use RYLR998 LORA module with Arduino

Things used in this project

Hardware components

Arduino Pro Mini 328 - 3.3V/8MHz
SparkFun Arduino Pro Mini 328 - 3.3V/8MHz
×1
LilyPad LED Blue (5pcs)
SparkFun LilyPad LED Blue (5pcs)
×1
Tactile Switch, Top Actuated
Tactile Switch, Top Actuated
×1
RYLR998 LORA from Reyax
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Transmitter

Receiver

Code

Transmitter- sending the state of the pushbutton , controlling LED on the receiver

Arduino
int PushButton=7;
int LED=5;

int LED_state=LOW;
int Button_state=LOW;

int Button_newstate;

void setup() {
 Serial.begin(57600);
 pinMode(PushButton, INPUT);
 pinMode(LED, OUTPUT);
 Button_state=digitalRead(PushButton); 
} 
void loop() {
  Button_newstate=digitalRead(PushButton);
  if (Button_newstate > Button_state) {
    if (LED_state==LOW){
      digitalWrite(LED, HIGH); 
      LED_state=HIGH;
      Serial.println("AT+SEND=2,1,H");
    }
    else {
      digitalWrite(LED, LOW);
      LED_state=LOW;
      Serial.println("AT+SEND=2,1,L");
    }        
  }
  Button_state=Button_newstate;
}

Receiver - receiving the state of the pushbutton and setting LED state based on that information

Arduino
#define LEDPin 6
String incomingstring;

void setup() {
  pinMode(LEDPin,OUTPUT);
  Serial.begin(115200);
}
void loop() {
  if(Serial.available()){ 
    incomingstring= Serial.readString();
    if (incomingstring.indexOf("H") >0) {
      digitalWrite(LEDPin, HIGH);
    }
    else if (incomingstring.indexOf("L") >0) { 
      digitalWrite(LEDPin, LOW);
    }
  }
}

Receiving state of the pushbutton and controlling the LED with Displaying received data on OLED

Arduino
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

// Oled display size
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels


#define OLED_RESET     4 // Reset pin # (or -1 if sharing Arduino reset pin)
  Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);



#define LEDPin 6
String incomingstring;

 
String inString;

void setup() {
  Serial.begin(57600);
    // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
    Serial.println(F("SSD1306 allocation failed"));
    for(;;); // Don't proceed, loop forever
  }

  // Show initial display buffer contents on the screen --
  // the library initializes this with an Adafruit splash screen.
  display.display();
  delay(2000); // Pause for 2 seconds
  display.clearDisplay();
  display.setTextSize(1);           
  display.fillRect(0, 0, 128, 15, SSD1306_INVERSE);
  display.setTextColor(SSD1306_BLACK);  
  display.setCursor(4,4); 
  display.println("RECEIVING: ");
  display.println("");
  display.setTextColor(SSD1306_WHITE);
  display.display();
  pinMode(LEDPin,OUTPUT);
  digitalWrite(LEDPin,LOW);
}
int Received;

void loop() {
  if(Serial.available()){ 
    incomingstring= Serial.readString();
    display.print(incomingstring);
    display.display();
    if (incomingstring.indexOf("H") >0) { 
      digitalWrite(LEDPin, HIGH);
    }
    else if (incomingstring.indexOf("L") >0) { 
      digitalWrite(LEDPin, LOW);
    }
  }
}

Credits

mdraber
49 projects • 69 followers

Comments