Monday, December 30, 2019

Arduino Pro-Mini with 900MHz LoRa on board for environmental monitoring

Recently I started playing with LoRa modules for sending telemetry around. Last time I purchased a 433Mhz module and wired it up to an Arduino Nano Pro board but now I've found a board that has both the Arduino and the radio module on the same board. This is the 900Mhz version.


I'm using a temperature, humidity and air pressure sensor that is designed for the M5Stack system, but is easy to use on its own. The transmit side samples the environment and sends a packet with plain text containing the measurements.


One problem I ran in to was that the transmit side would re-boot when transmitting - the USB power isn't enough to handle the current on transmit. The solution is to lower the transmit power or attach a LiPo battery to the board. I turned the power down to 2dBm (from the default of 17).

Even on this very low power the packets can be reliably be received around my home block.


Here it is in action.


The code is simple and as always, my apologies for how it gets mangled by Blogger.

#include "DHT12.h"
//#include //The DHT12 uses I2C comunication.
#include "Adafruit_Sensor.h"
#include "Adafruit_BMP280.h"
#include "SPI.h"
#include "LoRa.h"

DHT12 dht12; //Preset scale CELSIUS and ID 0x5c.
Adafruit_BMP280 bme;

void setup() {
  // initialize both serial ports:
  Serial.begin(9600);
  Wire.begin();
 
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  Serial.println("Setting up LoRa...");
    if (!LoRa.begin(915E6)) {
      Serial.println("Starting LoRa failed!");
      while (1);
    }
    LoRa.setTxPower(2);
    Serial.println("LoRa ok.");
 
    Serial.println(F("ENV Unit(DHT12 and BMP280) test..."));

    while (!bme.begin(0x76)){
      Serial.println("Could not find a valid BMP280 sensor, check wiring!");
    }
    Serial.println("Env sensor ok");
}

void loop() {
    float tmp = dht12.readTemperature();
    float hum = dht12.readHumidity();
    float pressure = bme.readPressure();

    Serial.println("Starting LoRa packet");
    LoRa.beginPacket();
    LoRa.print("Temperature: ");
    LoRa.println(tmp);
    LoRa.print("Humidity:");
    LoRa.println(hum);
    LoRa.print("Pressure:");
    LoRa.println(pressure);
    LoRa.endPacket();
 
    Serial.print("Temperature:");
    Serial.println(tmp);
    Serial.print("Humidity:");
    Serial.println(hum);
    Serial.print("Pressure:");
    Serial.println(pressure);
    Serial.println();
    delay(1000);
}

No comments:

Post a Comment