Arduino LoRaWan project for logging temperatures.
Code for reading temperatures from a DS18B20 temperature sensor was inspired by the hobbytronics DS1820 Temperature Sensor blog.
The LoRaWan part of this project will be based on the MicroChip RN2483 module. The datasheet and userguide are stored in the documentation folder of this project, together with other interesting documents and links.
The DS18B20-test project contains a little test project to get the temperature sensor working on pin D2 of the Arduino. For this to work you need to install the Arduino-Temperature-Control-Library and OneWire library into your Arduino IDE. After uploading the project to your Arduino it should start logging temperatures.
For the input pins on the RN2483, the pin leakage is specified at 50nA max. The pins are clamped with diodes against Vdd, and the clamp diodes can handle 20mA current max. This means we can send our bits to the RN2483 by using a simple resistor, making use of the clamping diodes of the RN2483. To go from 5V to 3.3V at 20mA would require a, 85 Ohm resistor, but that would be silly and risky. So I'd advise a 1k resistor on the RN2483 input pins.
For the output pins it's a bit different. In our case we use an Arduino Nano, which uses a ATmega 328. At 5V Vdd, the minimum voltage for a logical "1" is 3V. The RN2483 can drive 200mA for all pins combined, so we need to keep the current per pin roughly two orders of magnitude below that, 2mA. The internal pull-up resistors of the Arduino is somewhere between 20k and 50k, and would be safe to enable to pull the logical "1" up through the clamping diode. This will get the output up tp 3.3V + 0.6V = 3.9V. To prevent damage to either chip when misconfiguring, we add a 1k resistor on those lines too (Voltage calculation is left as an exercise to the reader).
Long story short: Connect all data lines between the 5V Arduino and the 3.3V RN2483 with 1k resistors and you won't break stuff.
Connect the RN2483 as follows:
Arduino pin | RN2483 pin | Remarks |
---|---|---|
3.3V | 34 and 12 - Vdd | direct |
10 | 6 - UART TX | 1k resistor |
11 | 7 - UART RX | 1k resistor |
12 | 32 - Reset | 1k resistor |
Gnd | Gnd | direct, see below |
A note on grounding: The RN2483 has a lot of Gnd pins, and all of them are electrically connected. For normal power, connecting the Gnd pins on the side of the module to the ground of the Arduino will suffice. However, please take special care that the antenna uses the ground pins next to the antenna outputs. Please see page 10 of the RN2383 datasheet to see how Microchip connects antennas. Do not connect the two antenna outputs to one single antenna.
Install mosquitto broker: sudo apt-get install mosquitto (not needed because TTN hosts that) Install mosquitto clients: sudo apt-get install mosquitto-clients More info on MQTT clients and debugging on Stackoverflow
Links to The Things Network (because their site navigation is, let's say "sub optimal")
- Your TTN user profile
- All your TTN applications Register your device and monitor the devices and their sent packets.
- Forum post about deleting devices Short answer: Not possible. Long answer: Removing an application is posible. If you have a small application and really want to delete devices, simply create a new app.
Help, tips and tricks:
- TTN Forum
- TTN Gateway Map
- Another Gateway Map
- Effects of antenna on RSSI
- Mosquitto subscribe to "up" messages:
mosquitto_sub -h staging.thethingsnetwork.org
-p 1883 -u <username> -P <password>
-t '+/devices/+/up' -v
Idea for sending temperatures from -10 to 50 degrees celcius with 1 byte (resolution 0,24 degrees, error about 4% max). Convert float temp to byte byte=ROUND((10+temp)*255/60;0). Convert byte to float temp=ROUND(byte*60/255-10;2).