[cpp] TX code for Arduino
Viewer
*** This page was generated with the meta tag "noindex, nofollow". This happened because you selected this option before saving or the system detected it as spam. This means that this page will never get into the search engines and the search bot will not crawl it. There is nothing to worry about, you can still share it with anyone.
- #include <SPI.h>
- #include <LoRa.h>
- #define analogPin A0 //flame sensor pin
- int flame;
- int counter = 0;
- void setup() {
- Serial.begin(9600);
- pinMode(analogPin, INPUT); // inicialization of flame sensor
- while (!Serial);
- Serial.println("LoRa Sender");
- if (!LoRa.begin(169E6)) { //input your frequency - 169 MHz
- Serial.println("Starting LoRa failed!");
- while (1);
- }
- //below are optional parameters for LoRa transmitter
- //use the same for Tx and Rx side
- LoRa.setTxPower(10);
- LoRa.setSpreadingFactor(7);
- LoRa.setSignalBandwidth(125E3);
- LoRa.setCodingRate4(5);
- pinMode(4, OUTPUT);
- pinMode(6, OUTPUT);
- pinMode(7, OUTPUT);
- digitalWrite(4, LOW); //FEM_CPS=0
- digitalWrite(6, LOW); //FEM_CTX=0
- digitalWrite(7, HIGH); //RXTX=1 (means it is transmitting)
- Serial.println("setup complete");
- }
- void loop() {
- int voltageSensor = analogRead(analogPin); //load flame sensor pin
- int flame = map(voltageSensor, 0, 1024, 0, 3);
- //0 = flame is close
- //1= there is flame nearby
- //2=no flame detected
- Serial.print("Sending packet: ");
- Serial.println(counter);
- Serial.println("Flame: ");
- Serial.println(flame);
- LoRa.beginPacket(); //start the packet
- LoRa.print(flame); //data of the packet - flame
- LoRa.endPacket(); //end the packet
- counter++;
- delay(1000);
- }
Editor
You can edit this paste and save as new: