Agri IoT :: Prototype 1 : Sensor

This article is a part of a series that I’m doing to build agriculture based IoT system.

Objective ::

Sensor node should,

  • Be able to collect the soil moisture data.
  • Send the collected data via RF network to gateway.
  • Be battery operated.

Components ::

  • Arduino nano
  • Mini B usb cable
  • NRF24L01+
  • Soil Moisture sensor
  • Jumper wires
  • Breadboard

How to ::

Hardware:

Connection between Arduino nano and radio module ( NRF24L01+ ) should be done as suggested here .

Arduino NRF24L01+
GND GND
5VReg
3.3V
VCC
9 CE
10 CSN/CS
13 SCK
11 MOSI
12 MISO
2 IRQ

Connect soil moisture Analog pin to the A0 pin of Arduino, tt can be powered with the  Arduino 5V pin

Arduino Soil Sensor
GND GND
5V VCC
A0 A0 ( pin at the opposite end of VCC)

Arduino nano  can be powered with  7v to 12v . I’m using a 9V 6F22 battery

Arduino Battery
VIN Positive terminal
GND Negative terminal

Quick and dirty breadboard setup :

Software:

Connect the arduino via Mini usb cable. Make sure you select the right options as mentioned here

Upload the below sketch to sensor node.


#define MY_NODE_ID 1 // node id
#define MY_RADIO_NRF24 // enabling support for NRF radio module
#define MY_DEBUG // enabling debug
#define NODE_ID 1 // sensor id
#include <MySensors.h>
#include <SPI.h>
MyMessage msg(NODE_ID, V_LEVEL); // constructing the msg

const int VAL_PROBE = 0; // initializing the moisture variable

void presentation()
{
present(NODE_ID, S_MOISTURE); // presenting the sensor
sendSketchInfo("SoilSensor", "0.1"); //meta data
}

void loop()
{
int moisture = analogRead(VAL_PROBE); //measuring the moisture
send(msg.set(moisture)); // sending the data
sleep(10000); // sleeping for 10 sec
}

Testing & Troubleshooting::

Use Arduino IDE serial monitor and set the baud rate to 115200. You can find sensor node related debug output there.

Reference :: 
https://www.mysensors.org/build/connect_radio
https://www.mysensors.org/download/
https://www.arduino.cc/en/Main/ArduinoBoardNano