You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm working on a project using LoRa module Ra-01 Ai-thinker which is operating at 433 Mhz connected to an Arduino Nano.
i used the example codes in RH_RF95 to transmit and receive data between 2 nodes.
However i only can achieve a range of approx 30meters. Anybody can help me out how can i achieve further range?
Tried adjusting the transmitting power still but still no improvement.
What I am doing is that:
-Sender will send "on/off" or "blink" to turn on/off or blink the receiver's LED
-Receiver receives data from sender and turns on/off or blink LED
-Then it sends back an acknowledgement back to the sender
typedef enum
{
Bw125Cr45Sf128 = 0, ///< Bw = 125 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on. Default medium range
Bw500Cr45Sf128, ///< Bw = 500 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on. Fast+short range
Bw31_25Cr48Sf512, ///< Bw = 31.25 kHz, Cr = 4/8, Sf = 512chips/symbol, CRC on. Slow+long range
Bw125Cr48Sf4096, ///< Bw = 125 kHz, Cr = 4/8, Sf = 4096chips/symbol, CRC on. Slow+long range
} ModemConfigChoice;
int lastButtonState1 = HIGH;
int lastButtonState2 = HIGH;
int buttonState1;
int buttonState2;
unsigned long lastDebounceTime1 = 0;
unsigned long lastDebounceTime2 = 0;
unsigned long debounceDelay = 20;
const int onoffbuttonpin = 4;
const int blinkbuttonpin = 5;
String data;
int redPin = 6;
int greenPin = 7;
int bluePin = 8;
int info;
int flag = 0;
// Singleton instance of the radio driver
RH_RF95 SX1278;
void setup() {
Serial.begin(9600);
while (!Serial) ;
if (!SX1278.init())
Serial.println("Notice:init failed");
SX1278.setFrequency(433.0);
SX1278.setTxPower(20);
bool setModemConfig(ModemConfigChoice Bw125Cr48Sf4096);
digitalWrite(redPin, HIGH); // turn on RED during setup
}
void loop() {
uint8_t on[] = "on";
uint8_t off[] = "off";
int reading1 = digitalRead(onoffbuttonpin);
int reading2 = digitalRead(blinkbuttonpin);
if (reading1 != lastButtonState1) {
lastDebounceTime1 = millis();
}
if ((millis() - lastDebounceTime1) > debounceDelay) {
if (reading1 != buttonState1) {
buttonState1 = reading1;
if (buttonState1 == LOW) {
SX1278.send(on, sizeof(on));
Serial.println((char*)on);
SX1278.waitPacketSent();
digitalWrite(redPin, LOW);
digitalWrite(greenPin, HIGH);
flag = 1;
}
}
}
lastButtonState1 = reading1;
if (reading2 != lastButtonState2) {
lastDebounceTime2 = millis();
}
if ((millis() - lastDebounceTime2) > debounceDelay) {
if (reading2 != buttonState2) {
buttonState2 = reading2;
if (buttonState2 == LOW) {
SX1278.send(off, sizeof(off));
Serial.println((char*)off);
SX1278.waitPacketSent();
digitalWrite(redPin, LOW);
digitalWrite(greenPin, HIGH);
flag = 1;
}
}
}
lastButtonState2 = reading2;
if(flag = 1){
if (SX1278.available())
{
// Should be a message for us now
uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];
uint8_t len = sizeof(buf);
if (SX1278.recv(buf, &len)){
String data = (char*)buf;
Serial.println(data);
Serial.println("RSSI");
Serial.println(SX1278.lastRssi(), DEC);
typedef enum
{
Bw125Cr45Sf128 = 0, ///< Bw = 125 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on. Default medium range
Bw500Cr45Sf128, ///< Bw = 500 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on. Fast+short range
Bw31_25Cr48Sf512, ///< Bw = 31.25 kHz, Cr = 4/8, Sf = 512chips/symbol, CRC on. Slow+long range
Bw125Cr48Sf4096, ///< Bw = 125 kHz, Cr = 4/8, Sf = 4096chips/symbol, CRC on. Slow+long range
} ModemConfigChoice;
uint8_t ack[] = "ack";
RH_RF95 SX1278;
void setup() {
Serial.begin(9600);
while (!Serial) ; // Wait for serial port to be available
pinMode(3,OUTPUT);
digitalWrite(3,LOW);
if (!SX1278.init())
Serial.println("init failed");
SX1278.setFrequency(433.0);
SX1278.setTxPower(20);
bool setModemConfig(ModemConfigChoice Bw125Cr48Sf4096);
}
void loop() {
if (SX1278.available())
{
// Should be a message for us now
uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];
uint8_t len = sizeof(buf);
int flag = 1;
if (SX1278.recv(buf, len))
{
Serial.println((char*)buf);
String data = (char*)buf;
if (data == "on"){
Serial.println("1");
Serial.println("RSSI");
Serial.println(SX1278.lastRssi(), DEC);
I'm working on a project using LoRa module Ra-01 Ai-thinker which is operating at 433 Mhz connected to an Arduino Nano.
i used the example codes in RH_RF95 to transmit and receive data between 2 nodes.
However i only can achieve a range of approx 30meters.
Anybody can help me out how can i achieve further range?
Tried adjusting the transmitting power still but still no improvement.
What I am doing is that:
-Sender will send "on/off" or "blink" to turn on/off or blink the receiver's LED
-Receiver receives data from sender and turns on/off or blink LED
-Then it sends back an acknowledgement back to the sender
Sender code
`
#include <SPI.h>
#include <RH_RF95.h>
#define RH_RF95_LONG_RANGE_MODE 0x80
typedef enum
{
Bw125Cr45Sf128 = 0, ///< Bw = 125 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on. Default medium range
Bw500Cr45Sf128, ///< Bw = 500 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on. Fast+short range
Bw31_25Cr48Sf512, ///< Bw = 31.25 kHz, Cr = 4/8, Sf = 512chips/symbol, CRC on. Slow+long range
Bw125Cr48Sf4096, ///< Bw = 125 kHz, Cr = 4/8, Sf = 4096chips/symbol, CRC on. Slow+long range
} ModemConfigChoice;
int lastButtonState1 = HIGH;
int lastButtonState2 = HIGH;
int buttonState1;
int buttonState2;
unsigned long lastDebounceTime1 = 0;
unsigned long lastDebounceTime2 = 0;
unsigned long debounceDelay = 20;
const int onoffbuttonpin = 4;
const int blinkbuttonpin = 5;
String data;
int redPin = 6;
int greenPin = 7;
int bluePin = 8;
int info;
int flag = 0;
// Singleton instance of the radio driver
RH_RF95 SX1278;
void setup() {
Serial.begin(9600);
while (!Serial) ;
if (!SX1278.init())
Serial.println("Notice:init failed");
SX1278.setFrequency(433.0);
SX1278.setTxPower(20);
bool setModemConfig(ModemConfigChoice Bw125Cr48Sf4096);
pinMode(onoffbuttonpin, INPUT_PULLUP);
pinMode(blinkbuttonpin, INPUT_PULLUP);
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
digitalWrite(redPin, HIGH); // turn on RED during setup
}
void loop() {
uint8_t on[] = "on";
uint8_t off[] = "off";
int reading1 = digitalRead(onoffbuttonpin);
int reading2 = digitalRead(blinkbuttonpin);
}
if ((millis() - lastDebounceTime1) > debounceDelay) {
}
lastButtonState1 = reading1;
if (reading2 != lastButtonState2) {
}
if ((millis() - lastDebounceTime2) > debounceDelay) {
}
lastButtonState2 = reading2;
if(flag = 1){
if (SX1278.available())
{
// Should be a message for us now
uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];
uint8_t len = sizeof(buf);
if (SX1278.recv(buf, &len)){
String data = (char*)buf;
Serial.println(data);
Serial.println("RSSI");
Serial.println(SX1278.lastRssi(), DEC);
}
} //end loop
`
Receiver code
`
#include <SPI.h>
#include <RH_RF95.h>
#define RH_RF95_LONG_RANGE_MODE 0x80
typedef enum
{
Bw125Cr45Sf128 = 0, ///< Bw = 125 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on. Default medium range
Bw500Cr45Sf128, ///< Bw = 500 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on. Fast+short range
Bw31_25Cr48Sf512, ///< Bw = 31.25 kHz, Cr = 4/8, Sf = 512chips/symbol, CRC on. Slow+long range
Bw125Cr48Sf4096, ///< Bw = 125 kHz, Cr = 4/8, Sf = 4096chips/symbol, CRC on. Slow+long range
} ModemConfigChoice;
uint8_t ack[] = "ack";
RH_RF95 SX1278;
void setup() {
Serial.begin(9600);
while (!Serial) ; // Wait for serial port to be available
pinMode(3,OUTPUT);
digitalWrite(3,LOW);
if (!SX1278.init())
Serial.println("init failed");
SX1278.setFrequency(433.0);
SX1278.setTxPower(20);
bool setModemConfig(ModemConfigChoice Bw125Cr48Sf4096);
}
void loop() {
if (SX1278.available())
{
// Should be a message for us now
uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];
uint8_t len = sizeof(buf);
int flag = 1;
if (SX1278.recv(buf, len))
{
Serial.println((char*)buf);
String data = (char*)buf;
if (data == "on"){
Serial.println("1");
Serial.println("RSSI");
Serial.println(SX1278.lastRssi(), DEC);
}
}
}
void led_on(){
digitalWrite(3, HIGH);
//delay(1000);
}
void led_off(){
digitalWrite(3, LOW);
//delay(1000);
}
void led_blink(){
for(int i = 0; i<5; i++){
digitalWrite(3, HIGH);
delay(100);
digitalWrite(3, LOW);
delay(100);
}
}
void send_ack(){
SX1278.send(ack, sizeof(ack));
Serial.println("sending ack");
Serial.println((char*)ack);
SX1278.waitPacketSent();
}
`
The text was updated successfully, but these errors were encountered: