Agri IoT :: Prototype 3 : Overview & Actuator

Overview::

With prototype 3 of Agri IoT, attempt is to proceed further by creating a actuator node that can be controlled from Openhab. Pro mini 3,3v 8Mhz is selected because of its small form, low power consumption and NRF24L01+ will work with it as a radio. A 4 CH 5V relay module is used to switch on/off devices and to power the whole setup a breadboard 3.3v/5v power supply is used Mysensors v2.0 API is used to build and connect the blocks.  Prototype 3 actuator node setup is covered in this article, rest is in Agri IoT :: Prototype 2 : Gateway & Controller 

Prototype 1&2 is covered in below articles,

  1. Agri IoT :: Prototype 1 : Overview
  2. Agri IoT :: Prototype 2 : Overview

Objective ::

Actuator node should,

  • Be able to switch on/off the supply to devices according to input from Openhab2 controller

Components ::

  • Arduino pro mini 3.3v 8Mhz
  • NRF24L01+
  • CP2102 USB to TTL Serial
  • Relay module 5v
  • Breadboard power supply 3.3v/5v

How to ::

Idea is to power on actuator in the node with one of the Arduino digital out,

Hardware:

Relay

  • 1st relay input should be connected to the digital pin 3 of Arduino pro mini.
  • Relay power should be provided by 5v ourput of breadboard power supply.

Radio:

  • Connection should be made as described here
ARDUINO NRF24L01+
GND GND
5VReg
3.3V
VCC
9 CE
10 CSN/CS
13 SCK
11 MOSI
12 MISO
2 IRQ
  • Power to arduino and radio should be provided by 3.3v output of breadboard powersupply

Software:

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

Upload the sketch to actuator node. If you want to manually set the node ID specific the below line above #include <Mysensor.h>

#define MY_NODE_ID 2 // node id 
#include <MySensors.h>

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/build/relay
https://www.arduino.cc/en/Main/ArduinoBoardProMini
http://www.instructables.com/id/NRF24L01-Fixing-Connection-Issues/
https://forum.mysensors.org/topic/5174/solved-non-healing-tsm-msg-len-error-hours-into-run/8

Update : 21/05/2017

Lessons learned the hardway : If your actuator node is disconnecting and staying of the grid it can be because of the noise from the relay module. The message similar to below in your node serial output denotes this.

TSF:MSG:READ,76-76-76,s=76,c=4,t=76,pt=2,l=9,sg=1:19532
TSF:MSG:LEN,20!=32

Things that helped me to fix this

  • Check the earth line of your electrical connections with a tester and make sure there is no current leakage and its well grounded
  • Connect the relay module to a separate 5v DC power supply, make sure you have the ground lines connected across
  • Move the relay board away from the arduino/radio
  • Add a decoupling capacitor to the radio as described here . This helps to smooth en the spikes if any
  • Add the below line to your arduino code before #include <MySensors.h> . This will help in resetting the radio in case of connection issues.
#define MY_TRANSPORT_SANITY_CHECK

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

Agri IoT :: Prototype 1 : Gateway

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

Objectives ::

Gateway should,

  • Be mobile and compact ( not too many wires )
  • Capable enough to connect to sensor and controller ( RF and Wifi )
  • Have enough mem to expand the code. ( for future needs if any )

Based on the above  NodeMuc was selected which has ESP8266 a wifi chip and a capable microcontroller . Please check out mysensors docuemtation here for other gateway types.

Components ::

  • NodeMuc ESP8266
  • NRF24L01+
  • Micro usb cable.

Howto::

Hardware:

Connect NodeMuc and NRF24L01+ as described here.

NodeMCU Radio
GND GND
3V3 VCC
D2 CE
D8 CSN/CS
D5 SCK
D7 MOSI
D6 MISO

Completed setup would look like below. I’m using micro USB cable to power the gateway.

Software:

Install esp8266 board support on your Arduino IDE . Tools >> Board >> Board Manager is where you can install it. Once installed select NodeMuc board with Tools >> Board

The example mysensor GatewayESP8266MQTTClient code  ( You can find the same also on Examples >> Mysensor >> GatewayESP8266MQTTClient ) can be used with minor changes to program Gateway. Please change the below parts in the code according to your environment.


// Set WIFI SSID and password
#define MY_ESP8266_SSID "MySSID"
#define MY_ESP8266_PASSWORD "MyVerySecretPassword"

// Enable MY_IP_ADDRESS here if you want a static ip address (no DHCP)
#define MY_IP_ADDRESS 192,168,178,87

// If using static ip you need to define Gateway and Subnet address as well
#define MY_IP_GATEWAY_ADDRESS 192,168,178,1
#define MY_IP_SUBNET_ADDRESS 255,255,255,0
// MQTT broker ip address.
#define MY_CONTROLLER_IP_ADDRESS 192, 168, 178, 68

Testing & Troubleshooting::

Use Arduino IDE serial monitor and set the baud rate to 9600 . You can find gateway related debug output there, you’ll find sensor radio messages also if you have followed the sensor setup part.