top of page

Building an (outdoor) plant sensor

Time to cook: 120min

Difficulty: +++++

With this recipe, you can build your own (outdoor) plant sensor. The communication is based on LoRaWAN. LoRaWAN is a ‘Low Power Wide Area Network’ protocol which is ideal for connecting battery powered sensors in the field over a long distance.

This sounds ideal for our (outdoor) plant sensor. We want to run this device on a battery in combination with a small solar panel for energy harvesting.



  • Sodaq One EU (RN2483)

  • Sodaq One base Shield

  • Grove Moisture Sensor

  • Grove Sunlight sensor

  • Grove TPH sensor

  • Solar Panel 1.5W

  • LiPo battery 800mAh

  • Enclosure


  • The plant sensor is based on a LoRaWAN network for communication. You can make use (free-of-charge) of the crowd sourced LoRaWAN network of The Things Network, orr or alternatively setup your own LoRaWAN network infrastructure.


  • Arduino IDE


The Building Plan

Assembling the hardware

For this project, I used a board from Sodaq. The Sodaq One is equipped with a ATSAMD21G18, 32-Bit ARM Cortex M0+, hosts a LoRaWAN RN2483 microchip SOC and has everything it needs for our energy harvesting. The board has even a GPS and accelerometer on board, but we are not going to use these for our project.

To connect the Grove sensors, I used a Sodaq one base shield, which allows to connect the Grove sensors using the 4wire Grove cables.

  • Connect the Grove Moisture sensor on pins 6/7 of the Sodaq One base shield

  • Connect the Grove TPH sensor on one of the I2C connector of the Sodaq One base shield

  • Connect the Grove Sunlight sensor on one of the I2C connector of the Sodaq One base shield


Make sure that the TPH sensor is exposed to the ambient temperature. Drill a hole in the enclosure and protect it with a membrane, allowing the air to flow through it, but keeps the insects out!

Next make sure that the Sunlight sensor is exposed to ambient light.

Setting up your device on The Things Network

Before we are going to dig into the code, we need to create the device on the network infrastructure of The LoRaWAN provider. For this tutorial we are going to use The Things Network infrastructure ( This is a crowd sourced LoRaWAN network, which we can use for free. If you are lucky, you can profit from a neighborhood gateway to get your message delivered, if not, you might need to install your own gateway

Create an account on The Things Network

Go to The Things Network console and register an account.

Add an application

  • Select Applications

  • Click + add application

  • Choose Application ID, a unique identifier for your application

  • Let other fields stay on their defaults

  • Click Add application

Add AllThingsTalk integration

  • Select the Integrations tab

  • Click + add integration

  • Select the AllThingsTalk Maker tile

  • Choose a Process ID for the integration, for example talk-to-attalk

  • Select the default key as Access Key

  • Click Add integration


  • In the Application, register your device

    • Enter a Device ID (example: plant sensor)

    • Under Device EUI, click on the sign, this will The Things Network trigger to deliver you with a Unique DEVEUI for your device. You might otherwise, read the existing DEVEUI from the RN2483 and use that one.

    • The APP Key and APP EUI are generated by TheThingsNetwork.

    • Click Register

The result will look similar to the following screen:

The Arduino Sketch

Next, we are going to have a look at the software on our device. The Sodaq One can be programmed using the popular Arduino language. The sketch samples the sensors periodically and sends the data using a binary payload over the radio. Besides sampling the data, the most important task is to conserve energy, this is achieved by putting most of the electronic components into sleep mode.

The AllThingsTalk IoT platform is the ideal platform to onboard LPWAN devices. The platform has integrations for most popular LPWAN service providers such as The Things Network and allows you to decode the binary payload back into understandable information.

To send the data, the sketch makes use of the AllThingsTalk LoRaWAN SDK.

The following additional libraries are used:

Add these libraries to your Arduino IDE.

The plant sensor sketch:

The sketch exists of a keys.h file and the sketch itself.

The keys.h file allows you to enter all LoRaWAN specific device parameters. From the device created on The Things Network, copy the DEVEUI, APPEUI and APPKEY in the OTAA credentials of the keys.h file.

Download ZIP • 5KB

Setting up the device on AllThingsTalk Maker

The next step is to create the digital representative of the plant sensor on AllThingsTalk Maker.

Create an account on AllThingsTalk Maker

Go to and register an account.

Add a device

  • Select your playground

  • Click + add device

  • Select your own LoRa device

  • Select The Things Network as network provider

  • Give your device a name

  • Enter the DEVEUI & Application ID which you have used in the TTN environment

  • Select OTAA as Activation method

  • Click connect

Create the necessary assets under your device

  • Select your device

  • Click + new asset

  • Add an asset of kind sensor called bat and choose type Integer

  • Do the same for a sensor called soil of type Integer

  • Do the same for a sensor called temperature of type number

  • Do the same for a sensor called pressure of type number

  • Do the same for a sensor called humidity of type number

  • Do the same for a sensor called vis of type number

  • Do the same for a sensor called ir of type number

  • Do the same for a sensor called uv of type number

The result should looks as follows:

Payload conversion

Next we need to configure the payload conversion. The device will send over the data in binary format. An example is given below. This binary payload needs to be converted into understandable information for the sensors.

Example payload: 0000000141A67AE1447BF64F42787D0043828000437F00000000000000000064

To setup the payload conversion:

  • Select your device

  • In the settings menu, select Payload formats

  • Check Use ABCL to convert custom binary data

  • Copy paste the code below

  • Click Save

{ "sense": [ { "asset": "soil", "value": { "byte": 0, "bytelength": 4, "byteorder": "big", "type": "integer" } }, { "asset": "temperature", "value": { "byte": 4, "bytelength": 4, "byteorder": "little", "type": "number" } }, { "asset": "pressure", "value": { "byte": 8, "bytelength": 4, "byteorder": "little", "type": "number" } }, { "asset": "humidity", "value": { "byte": 12, "bytelength": 4, "byteorder": "little", "type": "number" } }, { "asset": "vis", "value": { "byte": 16, "bytelength": 4, "byteorder": "little", "type": "number" } }, { "asset": "ir", "value": { "byte": 20, "bytelength": 4, "byteorder": "little", "type": "number" } }, { "asset": "uv", "value": { "byte": 24, "bytelength": 4, "byteorder": "little", "type": "number" } }, { "asset": "bat", "value": { "byte": 28, "bytelength": 4, "byteorder": "big", "type": "integer" } } ] }

Download TXT • 1KB

Test your Setup

Now it is time to test your setup. When you upload the sketch on your device, The Plant sensor will first try to join the network with a join request, then it sends each 5 minutes a payload with the sensor data.

In your TTN account, under your device you should see the join request and the payload:

When this is fine, you can look on the AllThingsTalk Maker platform and open the debug window under your device. You should see the payload coming in and the conversion towards the asset info.

Exposing the data towards other Applications

If you want to access the data from the plant sensor within other applications, you can make use of the AllThingsTalk Message broker. In chapter 2 ->The ALSO AllThingsTalk Cloud -> The Message broker is outlined how you can access the data using MQTT topics. Alternatively you can make use of the AllThingsTalk APIs or Webhooks in the rule Manager.

2 views0 comments

Recent Posts

See All


bottom of page