Devices & Components
RYLR998 LORA from Reyax
Arduino Pro Mini 328 - 3.3V/8MHz
LilyPad LED Blue (5pcs)
Tactile Switch, Top Actuated
Software & Tools
Arduino IDE
Project description
Code
Transmitter- sending the state of the pushbutton , controlling LED on the receiver
arduino
1int PushButton=7; 2int LED=5; 3 4int LED_state=LOW; 5int Button_state=LOW; 6 7int Button_newstate; 8 9void setup() { 10 Serial.begin(57600); 11 pinMode(PushButton, INPUT); 12 pinMode(LED, OUTPUT); 13 Button_state=digitalRead(PushButton); 14} 15void loop() { 16 Button_newstate=digitalRead(PushButton); 17 if (Button_newstate > Button_state) { 18 if (LED_state==LOW){ 19 digitalWrite(LED, HIGH); 20 LED_state=HIGH; 21 Serial.println("AT+SEND=2,1,H"); 22 } 23 else { 24 digitalWrite(LED, LOW); 25 LED_state=LOW; 26 Serial.println("AT+SEND=2,1,L"); 27 } 28 } 29 Button_state=Button_newstate; 30} 31
Receiver - receiving the state of the pushbutton and setting LED state based on that information
arduino
1#define LEDPin 6 2String incomingstring; 3 4void setup() { 5 pinMode(LEDPin,OUTPUT); 6 Serial.begin(115200); 7} 8void loop() { 9 if(Serial.available()){ 10 incomingstring= Serial.readString(); 11 if (incomingstring.indexOf("H") >0) { 12 digitalWrite(LEDPin, HIGH); 13 } 14 else if (incomingstring.indexOf("L") >0) { 15 digitalWrite(LEDPin, LOW); 16 } 17 } 18} 19
Receiver - receiving the state of the pushbutton and setting LED state based on that information
arduino
1#define LEDPin 6 2String incomingstring; 3 4void setup() { 5 pinMode(LEDPin,OUTPUT); 6 7 Serial.begin(115200); 8} 9void loop() { 10 if(Serial.available()){ 11 12 incomingstring= Serial.readString(); 13 if (incomingstring.indexOf("H") 14 >0) { 15 digitalWrite(LEDPin, HIGH); 16 } 17 else if (incomingstring.indexOf("L") 18 >0) { 19 digitalWrite(LEDPin, LOW); 20 } 21 } 22} 23
Transmitter- sending the state of the pushbutton , controlling LED on the receiver
arduino
1int PushButton=7; 2int LED=5; 3 4int LED_state=LOW; 5int Button_state=LOW; 6 7int 8 Button_newstate; 9 10void setup() { 11 Serial.begin(57600); 12 pinMode(PushButton, 13 INPUT); 14 pinMode(LED, OUTPUT); 15 Button_state=digitalRead(PushButton); 16} 17 18void loop() { 19 Button_newstate=digitalRead(PushButton); 20 if (Button_newstate 21 > Button_state) { 22 if (LED_state==LOW){ 23 digitalWrite(LED, HIGH); 24 25 LED_state=HIGH; 26 Serial.println("AT+SEND=2,1,H"); 27 } 28 29 else { 30 digitalWrite(LED, LOW); 31 LED_state=LOW; 32 Serial.println("AT+SEND=2,1,L"); 33 34 } 35 } 36 Button_state=Button_newstate; 37} 38
Receiving state of the pushbutton and controlling the LED with Displaying received data on OLED
arduino
1#include <SPI.h> 2#include <Wire.h> 3#include <Adafruit_GFX.h> 4#include 5 <Adafruit_SSD1306.h> 6 7// Oled display size 8#define SCREEN_WIDTH 128 // 9 OLED display width, in pixels 10#define SCREEN_HEIGHT 64 // OLED display height, 11 in pixels 12 13 14#define OLED_RESET 4 // Reset pin # (or -1 if sharing Arduino 15 reset pin) 16 Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); 17 18 19 20#define 21 LEDPin 6 22String incomingstring; 23 24 25String inString; 26 27void setup() 28 { 29 Serial.begin(57600); 30 // SSD1306_SWITCHCAPVCC = generate display voltage 31 from 3.3V internally 32 if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 33 0x3D for 128x64 34 Serial.println(F("SSD1306 allocation failed")); 35 for(;;); 36 // Don't proceed, loop forever 37 } 38 39 // Show initial display buffer contents 40 on the screen -- 41 // the library initializes this with an Adafruit splash screen. 42 43 display.display(); 44 delay(2000); // Pause for 2 seconds 45 display.clearDisplay(); 46 47 display.setTextSize(1); 48 display.fillRect(0, 0, 128, 15, SSD1306_INVERSE); 49 50 display.setTextColor(SSD1306_BLACK); 51 display.setCursor(4,4); 52 display.println("RECEIVING: 53 "); 54 display.println(""); 55 display.setTextColor(SSD1306_WHITE); 56 display.display(); 57 58 pinMode(LEDPin,OUTPUT); 59 digitalWrite(LEDPin,LOW); 60} 61int Received; 62 63void 64 loop() { 65 if(Serial.available()){ 66 incomingstring= Serial.readString(); 67 68 display.print(incomingstring); 69 display.display(); 70 if (incomingstring.indexOf("H") 71 >0) { 72 digitalWrite(LEDPin, HIGH); 73 } 74 else if (incomingstring.indexOf("L") 75 >0) { 76 digitalWrite(LEDPin, LOW); 77 } 78 } 79}
Receiving state of the pushbutton and controlling the LED with Displaying received data on OLED
arduino
1#include <SPI.h> 2#include <Wire.h> 3#include <Adafruit_GFX.h> 4#include <Adafruit_SSD1306.h> 5 6// Oled display size 7#define SCREEN_WIDTH 128 // OLED display width, in pixels 8#define SCREEN_HEIGHT 64 // OLED display height, in pixels 9 10 11#define OLED_RESET 4 // Reset pin # (or -1 if sharing Arduino reset pin) 12 Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); 13 14 15 16#define LEDPin 6 17String incomingstring; 18 19 20String inString; 21 22void setup() { 23 Serial.begin(57600); 24 // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally 25 if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64 26 Serial.println(F("SSD1306 allocation failed")); 27 for(;;); // Don't proceed, loop forever 28 } 29 30 // Show initial display buffer contents on the screen -- 31 // the library initializes this with an Adafruit splash screen. 32 display.display(); 33 delay(2000); // Pause for 2 seconds 34 display.clearDisplay(); 35 display.setTextSize(1); 36 display.fillRect(0, 0, 128, 15, SSD1306_INVERSE); 37 display.setTextColor(SSD1306_BLACK); 38 display.setCursor(4,4); 39 display.println("RECEIVING: "); 40 display.println(""); 41 display.setTextColor(SSD1306_WHITE); 42 display.display(); 43 pinMode(LEDPin,OUTPUT); 44 digitalWrite(LEDPin,LOW); 45} 46int Received; 47 48void loop() { 49 if(Serial.available()){ 50 incomingstring= Serial.readString(); 51 display.print(incomingstring); 52 display.display(); 53 if (incomingstring.indexOf("H") >0) { 54 digitalWrite(LEDPin, HIGH); 55 } 56 else if (incomingstring.indexOf("L") >0) { 57 digitalWrite(LEDPin, LOW); 58 } 59 } 60}
Comments
Only logged in users can leave comments