Introduction: Add a Sensor to Lora|Example: DHT 22


In my previous Instructable, i showed you how to make your own Lora-Node. Now its time to send some useful data. I use a DHT-22 temperatur/humidity sensor to measure the Temperature and i will send it over lora with my arduino.

You will need:

  1. Lora node (in my case Arduino nano and RN2483)
  2. Sensor ( in this instructable i will use a DHT22)
  3. Some jumper cables

Step 1: Hardware

First you need to connect the sensor to the Arduino.

In my case i bought the sensor from adafruit and they explained how to connect the sensor here. It depends on your sensor, but usually you have a GND pin which you have to connect to GND, a VCC which you either connect to 3.3v or 5v and a Signal pin. The Signal pin you have to connect to either an Analog input or a Digital input. In my case it is the digital input. Make sure to edit the Arduino sketch if you don't use the default pin.

The picture shows how i had to connect it. The 10k Resistor acts as a medium-strength pull up on the data line. If you have a sensor like the one on picture 2 you will probably see the little resistor built in.

Step 2: Software

In order to send Data we need to convert the data to a Lora compatible format.

In order to do this i added :

  //float a=(dht.readTemperature()); 
  float a=(dht.readTemperature()*100); 
  int b=(int)a;
  data = b;
  datastring +=dtostrf(data, 4, 2, databuf);
  strcpy((char *)dataoutgoing,databuf);

to the void loop.

You have to set float a to your sensors data. The second line removes the decimal places. If you dont have any significant decimalplaces you can uncomment the first line and comment the second line.

Now you have to Declarate the variables we used in void loop, import the library and definde the pins.

#include <DHT.h>

#define DHTPIN 2
#define DHTTYPE DHT22   // DHT 22  (AM2302), AM2321  


float data;
String datastring="";
char databuf[10];
uint8_t dataoutgoing[10];

At first we include the Library, then we define the Pin we used in the Previous step. I used the pin D2. Now we have to decide which Sensor we have. You have to change these 4 lines to your own library if you don't use a DHT sensor.

Now we have to declare the variables.

The whole script is on my GitHub Page.

Step 3: Start the Sketch

Now you can Upload the Sketch to your Arduino and it should print the temperature to your Serial monitor. You should also Receive the data on TTN.

Sensors Contest 2017

Participated in the
Sensors Contest 2017

Microcontroller Contest 2017

Participated in the
Microcontroller Contest 2017