# Soil moisture sensor

**URL:** <https://www.thethingsnetwork.org/forum/t/soil-moisture-sensor/48740>\
**Category:** Uncategorized\
**Created:** [June 12, 2021, 9:11pm UTC](https://www.thethingsnetwork.org/forum/t/soil-moisture-sensor/48740 "2021-06-12T21:11:35Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![IoT\_Marco](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/iot_marco/32/45432_2.png) [@IoT\_Marco](https://www.thethingsnetwork.org/forum/u/IoT_Marco)\
**Post date:** [June 12, 2021, 9:11pm UTC](https://www.thethingsnetwork.org/forum/t/soil-moisture-sensor/48740/1 "2021-06-12T21:11:35Z")

</div>

![Onderdelen](https://www.thethingsnetwork.org/forum/uploads/default/original/3X/1/1/11e0e3b10d29e3b843dbad1e9f0414a3c89de3b9.jpeg)

My new soil moisture sensors based on the RFM95, [ATtiny84a](https://www.iot-lab.org/blog/101/) and the capacitive [SoilWatch10](https://pino-tech.eu/soilwatch10/) soil moisture sensor.

![Compleet1](https://www.thethingsnetwork.org/forum/uploads/default/original/3X/5/5/5513b9fe8a998340ca028d1c7d6b2ca900f1dd7c.jpeg)

The enclosure is 32mm pvc pipe and 3D printed parts.

![Antenne-VSWR-Grafiek](https://www.thethingsnetwork.org/forum/uploads/default/original/3X/d/f/df8857bc938dfc64cba5a4d9b86c583317b83048.jpeg)

The antenna is a [J-Pole](https://www.thethingsnetwork.org/forum/t/antenna-experiment-868mhz-j-pole/3620) made from 2.5mm VD Cable.

![20210612_133806](https://www.thethingsnetwork.org/forum/uploads/default/original/3X/0/1/01c92defc3b583e70610ac82c3ce2c8f16846410.jpeg)

![20210612_133948](https://www.thethingsnetwork.org/forum/uploads/default/original/3X/f/7/f7531be930a14d48d74bb7c7b7adfc3bf583b1e6.jpeg)

These sensors are placed in my allotment +/- 3km outside of the city and every hour I receive their values.

![Screenshot_20210612-214612_WallPanel](https://www.thethingsnetwork.org/forum/uploads/default/original/3X/2/e/2e3ac7285cad1e18cf866ef3f1dbd050010ad2df.jpeg)

With a flow in nod-RED I made the dashboard and I use [WallPanel](https://play.google.com/store/apps/details?id=com.thanksmister.iot.wallpanel&hl=nl&gl=US) for my Android phone and a Pushover node sends a message if the plants needs water 😉

---

<div class="post-metadata">

**Author:** ![descartes](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/descartes/32/47220_2.png) [@descartes](https://www.thethingsnetwork.org/forum/u/descartes)\
**Post date:** [June 12, 2021, 9:40pm UTC](https://www.thethingsnetwork.org/forum/t/soil-moisture-sensor/48740/2 "2021-06-12T21:40:57Z")

</div>

Interesting work, but not recommended for use with TTS CE - no downlinks means no ADR.

An ATtiny3216 in SOIC format is a third of the price of an ATtiny85A and has the capacity to run the latest version of LMIC which works with TTS. You can hand solder it to your own design PCB or use one of the adapter PCB’s from the usual sources.

---

<div class="post-metadata">

**Author:** ![IoT\_Marco](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/iot_marco/32/45432_2.png) [@IoT\_Marco](https://www.thethingsnetwork.org/forum/u/IoT_Marco)\
**Post date:** [June 13, 2021, 7:20am UTC](https://www.thethingsnetwork.org/forum/t/soil-moisture-sensor/48740/3 "2021-06-13T07:20:19Z")

</div>

> [@descartes](#):
>
> ATtiny3216

Yes, too bad, I still have a few of these old ones on the shelf. For those I may have inspired take a look at [ATtiny3216](https://www.attno.de/12-attnode_v3)

---

<div class="post-metadata">

**Author:** ![Wingertsau](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/wingertsau/32/35697_2.png) [@Wingertsau](https://www.thethingsnetwork.org/forum/u/Wingertsau)\
**Post date:** [June 13, 2021, 3:56pm UTC](https://www.thethingsnetwork.org/forum/t/soil-moisture-sensor/48740/4 "2021-06-13T15:56:44Z")

</div>

Hi Marco,  
thanks for sharing!  
I am currently looking for something similar (Soil moisture , Temp, Humidity measuring - remote location with no power supply and no Wifi nearby but TTN)  
I am just starting into the TTN world 🙂

Do I get this right that your link posted in the last post provides everything required but with the improved Attiny 3216?  
Any reason why you did chose this specific soil moisture sensor?

Any longterm results (sensor accuracy, failures, etc)?

Thanks  
Eckhard

---

<div class="post-metadata">

**Author:** ![IoT\_Marco](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/iot_marco/32/45432_2.png) [@IoT\_Marco](https://www.thethingsnetwork.org/forum/u/IoT_Marco)\
**Post date:** [June 13, 2021, 9:02pm UTC](https://www.thethingsnetwork.org/forum/t/soil-moisture-sensor/48740/5 "2021-06-13T21:02:57Z")

</div>

Hi Eckhard,

Yes, the ATTnodes are complete but with such a sensor it is recommended to use a rechargeable battery as you can see I also use an AA LifeP04 (3.2V 700mAh) battery taking into account the max. voltage of the RFM95.

The SoilWatch10 sensors are left over from another project and these are capacitive instead of resistive sensors. Capacitive are more accurate and do not suffer from corrosion.

For several years I have a sensor for temperature and humidity (BME280) in my greenhouse but that humidity sensor is actually not suitable and at the moment it is broken again.

![Greenhouse](https://www.thethingsnetwork.org/forum/uploads/default/original/3X/7/b/7bb0da1ca56c26b1041e65c5e0514054b36a09da.jpeg)

---

<div class="post-metadata">

**Author:** ![dreimal8](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/dreimal8/32/35697_2.png) [@dreimal8](https://www.thethingsnetwork.org/forum/u/dreimal8)\
**Post date:** [June 14, 2021, 7:19am UTC](https://www.thethingsnetwork.org/forum/t/soil-moisture-sensor/48740/6 "2021-06-14T07:19:22Z")

</div>

> [@IoT\_Marco](#):
>
> (BME280) in my greenhouse but that humidity sensor is actually not suitable and at the moment it is broken again.

Hi,

i also use a BME280 and the humidity Sensor got problems when outside for a longer time in high humidity. Think it is a corrosion problem.  
I now use the BME only for pressure and temperature - for humidity i added a GY21 Si7021. It has a build in heater that can be used a few seconds every Minute to prevent condensate.  
That one is doing fine now for a long time.

---

<div class="post-metadata">

**Author:** ![Wingertsau](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/wingertsau/32/35697_2.png) [@Wingertsau](https://www.thethingsnetwork.org/forum/u/Wingertsau)\
**Post date:** [June 14, 2021, 9:28pm UTC](https://www.thethingsnetwork.org/forum/t/soil-moisture-sensor/48740/7 "2021-06-14T21:28:14Z")

</div>

Hi Marco,  
I would like to build your Device using Attnode3. Do you know where to get the PCB? As I am also not good in soldering SMDs a pre-populated PCB at least with the SMDs required would be also fine.

Thanks in advance  
Eckhard

---

<div class="post-metadata">

**Author:** ![wolfp](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/wolfp/32/45304_2.png) [@wolfp](https://www.thethingsnetwork.org/forum/u/wolfp)\
**Post date:** [June 15, 2021, 5:19am UTC](https://www.thethingsnetwork.org/forum/t/soil-moisture-sensor/48740/8 "2021-06-15T05:19:03Z")

</div>

Have a look at [https://www.attno.de/](https://www.attno.de/) . Maybe Steffen can help you.

---

<div class="post-metadata">

**Author:** ![IoT\_Marco](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/iot_marco/32/45432_2.png) [@IoT\_Marco](https://www.thethingsnetwork.org/forum/u/IoT_Marco)\
**Post date:** [June 15, 2021, 6:42am UTC](https://www.thethingsnetwork.org/forum/t/soil-moisture-sensor/48740/9 "2021-06-15T06:42:40Z")

</div>

I ordered my pcb’s from [jlcpcb.com](http://jlcpcb.com). Great pcb’s and good price.

---

<div class="post-metadata">

**Author:** ![Wingertsau](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/wingertsau/32/35697_2.png) [@Wingertsau](https://www.thethingsnetwork.org/forum/u/Wingertsau)\
**Post date:** [June 15, 2021, 6:57am UTC](https://www.thethingsnetwork.org/forum/t/soil-moisture-sensor/48740/10 "2021-06-15T06:57:23Z")

</div>

So is it ok to use the PCB layout and send it to JLCPCB (no IP issues?)? They even offer to solder SMDs on it. That would be great! I have heard about JLCPCB but not yet ordered there.

Thanks  
Eckhard

---

<div class="post-metadata">

**Author:** ![Caspar](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/caspar/32/46719_2.png) [@Caspar](https://www.thethingsnetwork.org/forum/u/Caspar)\
**Post date:** [June 15, 2021, 9:14am UTC](https://www.thethingsnetwork.org/forum/t/soil-moisture-sensor/48740/11 "2021-06-15T09:14:09Z")

</div>

JLCPCB works great, bigger problem is that the ATTINY3216-SN is nowhere available, or anyone got a hint where to look for them (in germany, europe)?

---

<div class="post-metadata">

**Author:** ![descartes](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/descartes/32/47220_2.png) [@descartes](https://www.thethingsnetwork.org/forum/u/descartes)\
**Post date:** [June 15, 2021, 9:51am UTC](https://www.thethingsnetwork.org/forum/t/soil-moisture-sensor/48740/12 "2021-06-15T09:51:18Z")

</div>

> [@Caspar](#):
>
> ATTINY3216-SN

Farnell / Element-14 have 500+

# Some clarity and a reality check:

Yes, it’s a nice little node and the DIP package for the ATtiny84a is very convenient - but this node requires you to use a code base that has had changes made to fool TTS in to believing it is behaving like a compliant node. Principally, it can not handle downlinks so has to answer as if it heard them.

The ATtiny3126 is **NOT** a drop in replacement for the ATtiny84a - it’s just a more up to date ATmega328P - and even then would require some diligence to get the MCCI LMiC running smoothly - something I am happy to help with - but you shouldn’t have expectations of running more than a couple of I2C sensors off it.

A better alternative would be the ATmega4808 which also comes in a SOIC hand-soldering friendly package but has 48K flash(half as much again) and 6K of memory (three times more).

Either device can be programmed using the Arduino IDE but will need their own PCB.

More info on getting this design working on TTS can be found at [https://www.iot-lab.org/blog/663/](https://www.iot-lab.org/blog/663/)

To be clear, as the post author suggests, some may not be happy with this implementation. I am not saying I’m unhappy but I’m not keen on it, I’m saying that buying PCB’s for this design is like buying a brand new leaded petrol only car.

I’ll look at altering my 4808+RFM95 design for hand-soldering only and sharing the PCB asap.

---

<div class="post-metadata">

**Author:** ![Wingertsau](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/wingertsau/32/35697_2.png) [@Wingertsau](https://www.thethingsnetwork.org/forum/u/Wingertsau)\
**Post date:** [June 15, 2021, 11:01am UTC](https://www.thethingsnetwork.org/forum/t/soil-moisture-sensor/48740/13 "2021-06-15T11:01:42Z")

</div>

Nick,  
sounds like a plan!  
I will wait for your changes.  
Could you please recommend a good source to learn/understand the 4808+RFM95 solution?

Thanks  
Eckhard

---

<div class="post-metadata">

**Author:** ![descartes](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/descartes/32/47220_2.png) [@descartes](https://www.thethingsnetwork.org/forum/u/descartes)\
**Post date:** [June 15, 2021, 12:05pm UTC](https://www.thethingsnetwork.org/forum/t/soil-moisture-sensor/48740/14 "2021-06-15T12:05:07Z")

</div>

> [@Wingertsau](#):
>
> Could you please recommend a good source to learn/understand the 4808+RFM95 solution?

[GitHub - mcci-catena/arduino-lmic: LoraWAN-MAC-in-C library, adapted to run under the Arduino environment](https://github.com/mcci-catena/arduino-lmic) - this is the core LoRaWAN software

And this is a very fine wrapper to simplify the LMIC but hasn’t been run against a 4808 yet:

> **[GitHub - lnlp/LMIC-node: LMIC-node | One example to rule them all. LMIC-node...](https://github.com/lnlp/LMIC-node)**
>
> LMIC-node | One example to rule them all. LMIC-node is an example LoRaWAN application for a node that can be used with The Things Network. It demonstrates how to send uplink messages, how to receiv...

---

<div class="post-metadata">

**Author:** ![Wingertsau](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/wingertsau/32/35697_2.png) [@Wingertsau](https://www.thethingsnetwork.org/forum/u/Wingertsau)\
**Post date:** [June 28, 2021, 1:08pm UTC](https://www.thethingsnetwork.org/forum/t/soil-moisture-sensor/48740/15 "2021-06-28T13:08:17Z")

</div>

Nick,  
thanks for the links!

I have now made one Heltec WiFi LoRa 32 V2 running but it is to bulky in size and it sucks up the battery in two days. (Maybe someone could guide me to a link where I can find (Using Arduino IDE) instructions how to reduce power consumption). And it is kind of expensive for the solution I have in mind.

My favorite would be a Raspberry Pi Pico solution - in combination with a RFM95W (as I am a big fan of Raspberry Pi). I have seen that the LMIC is supporting it. Any thoughts on that? I am a little bit heasitating as I am new to Pico.

Thanks  
Eckhard

---

<div class="post-metadata">

**Author:** ![descartes](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/descartes/32/47220_2.png) [@descartes](https://www.thethingsnetwork.org/forum/u/descartes)\
**Post date:** [June 28, 2021, 2:58pm UTC](https://www.thethingsnetwork.org/forum/t/soil-moisture-sensor/48740/16 "2021-06-28T14:58:35Z")

</div>

> [@Wingertsau](#):
>
> and it sucks up the battery in two days

Yeah, I hear that, but I’m told that it is possible to get the current down. There are posts on the forum to search for that could help.

> [@Wingertsau](#):
>
> My favorite would be a Raspberry Pi Pico solution

The lowest I’ve got a Pico after altering the power is 900uA which is not good, so not really a battery powered option.

I am (literally) having nightmares with a node design at present due to the world wide shortage of MCU’s and radio modules. When (if) I come to any conclusions I’ll repost.

---

<div class="post-metadata">

**Author:** ![Wingertsau](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/wingertsau/32/35697_2.png) [@Wingertsau](https://www.thethingsnetwork.org/forum/u/Wingertsau)\
**Post date:** [July 5, 2021, 5:29pm UTC](https://www.thethingsnetwork.org/forum/t/soil-moisture-sensor/48740/17 "2021-07-05T17:29:51Z")

</div>

I finally got the Raspberry Pi Pico running but due to the decision to use CircuitPython the deep sleep mode is not (not yet, acc. to Adafruit) available. As Nick also stated, 900uA might be still to high for a battery powered node.

I also got a ready made unit from a friend of mine to get it up and running:  
A Lora Soil Moisture Sensor from Makerfabs [Link](https://www.makerfabs.com/wiki/index.php?title=Lora_Soil_Moisture_Sensor)  
It runs on a Atmega328P in combination with RFM95W.  
I got it running with their firmware: [Lora-Soil-Moisture-Sensor/LoraTransmitterADCAHT10 at master · Makerfabs/Lora-Soil-Moisture-Sensor · GitHub](https://github.com/Makerfabs/Lora-Soil-Moisture-Sensor/tree/master/LoraTransmitterADCAHT10)  
but without connection to TTS

or  
with the LMIC-node (My first experience with platformio 🙂 )  
with OTAA connection established to TTS !

My challenge now is to get them both together.  
I have tried to extend the LMIC-node.cpp but I was not successful

Any thoughts / hints / helpful examples to get this done?

Thanks  
Eckhard

---

<div class="post-metadata">

**Author:** ![descartes](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/descartes/32/47220_2.png) [@descartes](https://www.thethingsnetwork.org/forum/u/descartes)\
**Post date:** [July 5, 2021, 5:51pm UTC](https://www.thethingsnetwork.org/forum/t/soil-moisture-sensor/48740/18 "2021-07-05T17:51:38Z")

</div>

> [@Wingertsau](#):
>
> but I was not successful
> 
> Any thoughts / hints / helpful examples to get this done?

We could suggest, but it would be simpler if you told us what you tried just in case you had a near miss.

Fundamentally you need to fish out the sensor reading bits from the first sketch and drop that in to the LMIC-node.

---

<div class="post-metadata">

**Author:** ![Wingertsau](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/wingertsau/32/35697_2.png) [@Wingertsau](https://www.thethingsnetwork.org/forum/u/Wingertsau)\
**Post date:** [July 5, 2021, 6:46pm UTC](https://www.thethingsnetwork.org/forum/t/soil-moisture-sensor/48740/19 "2021-07-05T18:46:08Z")

</div>

I have taken this from the Makerfabs Code and put it into the first USER CODE section:

```auto
#include <SPI.h>
#include "I2C_AHT10.h"
#include <Wire.h>
AHT10 humiditySensor;

int sensorPin = A2; // select the input pin for the potentiometer
int sensorValue = 0; // variable to store the value coming from the sensor
int sensorPowerCtrlPin = 5;

void sensorPowerOn(void)
{
  digitalWrite(sensorPowerCtrlPin, HIGH);//Sensor power on 
}
void sensorPowerOff(void)
{
  digitalWrite(sensorPowerCtrlPin, LOW);//Sensor power on 
}

```

The next USER CODE Section seems to be my Problem Child. I don’t know how to get the Sensor data collected and prepared to be uploaded to the TTS:

```auto
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
//float humidity = 6.18;//dht.readHumidity();
// Read temperature as Celsius (the default)

sensorPowerOn();//
delay(100);
sensorValue = analogRead(sensorPin);
delay(200);

if (humiditySensor.available() == true)
{
    //Get the new temperature and humidity value
    temperature = humiditySensor.getTemperature();
    humidity = humiditySensor.getHumidity();

    //Print the results
    Serial.print("Temperature: ");
    Serial.print(temperature, 2);
    Serial.print(" C\t");
    Serial.print("Humidity: ");
    Serial.print(humidity, 2);
    Serial.println("% RH");

}
    // Check if any reads failed and exit early (to try again).
if (isnan(humidity) || isnan(temperature)) {
    Serial.println(F("Failed to read from AHT sensor!"));
    //return;
}

delay(100);
//sensorPowerOff();

Serial.print(F("Moisture ADC : "));
Serial.println(sensorValue);

//Serial.print(F("Humidity: "));
//Serial.print(humidity);
//Serial.print(F("% Temperature: "));
//Serial.print(temperature);
//Serial.println("Humidity is " + (String)humidity);
//Serial.println("Temperature is " + (String)temperature);

String message = "#"+(String)packetnum+" Humidity:"+(String)humidity+"% Temperature:"+(String)temperature+"C"+" ADC:"+(String)sensorValue;
Serial.println(message);
packetnum++;
    Serial.println("Transmit: Sending to rf95_server");

// Send a message to rf95_server

uint8_t radioPacket[message.length()+1];
message.toCharArray(radioPacket, message.length()+1);

radioPacket[message.length()+1]= '\0';

```

The last USER CODE portion (Init section) is:

```auto
  //digitalWrite(sensorPowerCtrlPin, LOW);//Sensor power on 
  sensorPowerOn();
    
    Wire.begin(); //Join I2C bus
    //Check if the AHT10 will acknowledge
    if (humiditySensor.begin() == false)
    {
        Serial.println("AHT10 not detected. Please check wiring. Freezing.");
        //while (1);
    }
    else
        Serial.println("AHT10 acknowledged.");

```

Platformio seems not have a loop section where I could put the respective code and LMIC seems to arrange the data for sending different than Radiohead.  
So my data I am looking for is in the variables

- SensorValue
- humidity
- temperature

And the update is done by (I assume):

- 

```
temperature = humiditySensor.getTemperature();

```

- 

```
humidity = humiditySensor.getHumidity();

```

- sensorValue = analogRead(sensorPin);

Any thoughts?

---

<div class="post-metadata">

**Author:** ![descartes](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/descartes/32/47220_2.png) [@descartes](https://www.thethingsnetwork.org/forum/u/descartes)\
**Post date:** [July 5, 2021, 7:24pm UTC](https://www.thethingsnetwork.org/forum/t/soil-moisture-sensor/48740/20 "2021-07-05T19:24:20Z")

</div>

Read this:

[https://www.thethingsnetwork.org/docs/devices/bytes/](https://www.thethingsnetwork.org/docs/devices/bytes/)

and look the code related to the payloadBuffer:

> <https://github.com/lnlp/LMIC-node/blob/b4142760a52c5a53a17367a2c9376aefd3947f98/src/LMIC-node.cpp#L772>

[Next page](https://www.thethingsnetwork.org/forum/t/soil-moisture-sensor/48740.md?page=2)
