Introduction: IOT Based DOL Starter Controller for Irrigation Pumpset

Hello Friends

This instructable is about how to remotely monitor and control an irrigation pump set over the internet.

Story: In my farm I get power supply from the local grid only for about 6 hours a day. Timings are not regular, availability of power can be early morning or late in the evenings or even midnight. Every time going to the bore well location to check power availability, start or stop the motor was very painful process. Also I had to ensure motor runs at least 2-3 hours every day to supply adequate water for the drip system. Quite some time i was exploring options to solve this problem by remotely operating the motor and also know the status. There are devices available in market which will start the motor as soon as there is a power supply, but they don’t have the feature to stop the motor whenever we want. And also there is no way to know the status of motor ON/OFF at any point of time. This usually leads to over irrigation, leading to loss of soil fertility and also waste of electricity. Finally I built a solution myself where I can start and stop the motor remotely from mobile/tablet/PC ANY TIME ANYWHERE...!!. Also I can monitor availability of power supply from the gird as well the motor status (ON/OFF) all the time. Hope it will help farm owners on the country side to manager their irrigation systems without the need of going to the starter location all the time.

Supplies

Prerequisites:

  • The location where you want to install this device must have internet availability ( broadband with wifi/mobile internet)

Things you need:

  1. NodeMCU /ESP12
  2. Two channel relay
  3. WCS1700 – Current sensor
  4. TP4056 battery charging module
  5. LD313, Capacitor – 1000uF Register – Two registers of 5k ohm
  6. Any (Old ) Smartphone with hotspot /internet.


How it works:

Its a simple cloud based IOT solution using NodeMCU/ESP12 and remote MQTT broker. NodeMCU works as an IOT gateway, also controls the DOL starter. It connects to remote MQTT broker over the internet. An app running on an Android mobile connects to the broker through which we can monitor and control our irrigation pump set all the time.
I used free available MQTT broker from Adafruit IO. There are many free brokers available like mosquitto , cloudmqtt etc. You can choose any broker provided you change the server and the port number in the code. NodeMCU connects to internet using WiFi from the mobile hotspot. Yon can use any old or low cost mobile to provide wifi access through hotspot or any other means of providing internet through wifi. Mobile should be connected to charger as it should be on 24X7.

NodeMCU is interfaced with two relays to control start and stop operation of the motor. To sense the current in the motor I used WCS1700 current sensor. The analog output from the sensor is used to know motor is ON or OFF. It also senses the power availability from the grid and publishes it to the broker so that we can know the grid status any time. The device subscribes for two feeds to receive the request for motor ON and motor OFF. By sending specific values to these feeds we can control the motor to START or STOP.

Lastly I installed MQTT Dash app on my android phone and configured it to connect to the MQTT broker and use the feeds on its dashboard/gui. The app has very good icons with buttons,gauge,switch etc to create attractive dashboard. However you can use any IOT home automation mobile app that supports mqtt protocol.

How WCS1700 works:

WCS1700 is basically a Hall effect sensor which will produce output voltage proportionate to the magnetic field created as the current flows through the coil. The coil here is a power supply line that will be connected to motor. It can measure AC current up to 70 Amps. Operating voltage is between 3.3 to 12 V. Refer to its data sheet for more details. As I am using ESP12 I used the same power supply of 3.3V as operating voltage for WCS1700. As specified in the data sheet at 3.3 V the device should produce a differential voltage of about 32 to 38 mV per amp of current through the coil. But it may vary based on coil size / air gap and variations in the device. Hence I had to calibrate it by testing it with Ampere Meter. I am not happy about the accuracy of the device but its good enough to decide on the status of Motor as ON/OFF. The output pin of WCS1700 is connect to A0 of ESP12. When there is no current the ESP12 should read the value around 556. As the current increase in the coil the voltage can very either side based on how the cable passes through sensor. In the code I took the difference of the values as absolute value of (x - 556). By dividing the result with 15 i got approximate current flowing through the sensor. You will have to experiment this to get the right number for you. Any current measurement by the device above 5 Amps I consider as motor ON and below 5 Amp as motor is in OFF. You can use the right number for your device by experimenting. You need to change WCS1700_CONST and MIN_CURRENT in the code accordingly.

Step 1: Device Construction

The diagram above gives a complete details on how to wire all the components.

Power supply: I used TP4056 to charge the batteries and LM313 to regulate the 3.7V - 4.2V of battery output to 3.3 V to power NodeMCU. Used 1000mF capacitor between Vin and ground of LM313 to get stable supply of 3.3V. You can use regular USB mobile charger to power TP4056. It has battery protection circuit to protect the battery from over charging.

Grid Power supply sensing: The 5k ohm voltage divider will reduce 5 V to 2.5 V . Pin D5 of NodeMCU will sense the voltage.

Output pin of WCS1700 is connected to A0 to read the analog voltage from the sensor. The Grid Power line has to pass through the hole to measure the current. I used 0.01 uF capacitor get the stable reading form WCS1700.

D1 and D2 of NodeMCU to be connected to IN0 and IN1 of the relay input pins.

Step 2: DOL Starter Connections

I tweaked control circuit of the DOL starter to introduce another set of START and STOP switch. This change will not affect the manual start/stop operation and they continue to work as is.

Caution !!!! As DOL starter is a High Voltage device ensure the main switch is turned off before opening the box. Direct contact with live wire could be dangerous. If you are not confident take help of electrician to make the connections.

I used 2 channel 5 V relay module as START and STOP switch. These relays will be controlled by ESP12.

Relay – 0 will work as START switch - wired as NO ( Normally Open).

Relay-1 will work as STOP switch - wired as NC ( Normally Closed). The starter will already have a wire connecting from top contactor to the NVC. You will have to remove it and replace with relay -1 wires as shown .

Ensure the connections between the starter and the Relay modules are completely insulated for safety. I programmed ESP to hold both relays for 2 seconds to emulate push of START/STOP button.

Step 3: Create an Account With Adafruit IO (io.adafruit.com)

I used Adafruit io mqtt broker which is free to use with few limitations but its OK for our use. I prefer this because I used it in other projects too and found quite reliable and also has many other feature like Dashboard with nice GUI and even we can use triggers. To use Adafruit io you need to create an account and note the Username and Active Key.

Step 4: Build and Install the Software

Complete code is available in the sketch. You need to open this in Arduino IDE and make few changes before compile and upload the firmware. Choose the board type as NodeMCU 1.0 . Installation of IDE and related libraries are not in the scope of this documentation.

Modify the following lines in the code as fallows.

#define WLAN_SSID "xxx" // Your mobile Hotspot WiFi SSID

#define WLAN_PASS "……" //

/************************* Adafruit.io Setup *********************************/

#define AIO_SERVER "io.adafruit.com"

#define AIO_SERVERPORT 1883 // use 8883 for SSL

#define AIO_USERNAME "xyz" // Your adafruit account user name

#define AIO_KEY "abcd……" // your Active key...

About MQTT Feeds : The device and client (mobile app) exchange information through message feeds using pub sub model through MQTT broker. Any client or device in order to receive a message, it has to subscribe for a predefined feed and has to use publish method to send a message to a feed. For our project we require about 5 feeds. Below is the explanation on each of the feed as you see in the code and how they works.

Grid Status: Availability of power supply from the grid is published on the feed /feeds/grid.
Adafruit_MQTT_Publish grid_stat = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/grid");

0 indicates power supply not available and 1 for power supply is available.

Motor Status: The device will publish the status of the motor on the feed .../feeds/grid.

Adafruit_MQTT_Publish motor_status = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/motor")

Value of 0 for OFF and 1 for ON

Motor ON Button: This feed is used to receive the motor start request. The device will subscribes for the feed to receive motor start request with value = 1 and use the same feed to publish acknowledge message as 0. That way we can confirm the start request message was actually received by device.

Adafruit_MQTT_Subscribe motoronbutton = Adafruit_MQTT_Subscribe(&mqtt, AIO_USERNAME "/feeds/motor_on");

Motor OFF Button:

Similar to Start request this feed is used to receive the motor stop request. The device will subscribes for the feed to receive the stop request with value = 1 and use the same feed to publish acknowledge message as 0.

Adafruit_MQTT_Subscribe motoroffbutton = Adafruit_MQTT_Subscribe(&mqtt, AIO_USERNAME "/feeds/motor_off");

Connection:

This is a special feed with “last will” option enabled. When the device is working fine at every fixed interval it will publish connection=1 to tell the user everything is fine . In case the system went down or the connection is lost then device will not be able to communication with the broker. In such cases MQTT broker itself will publish to the feed as connection=0 to let user know something went wrong and device is not reachable over the internet. We have to physical go and check the device. The code is very simple. Refer to MQTT documentation for more details on how “ Last Will” works.

if(itr <= 0)

{

mqtt.publish(AIO_USERNAME "/feeds/connection","1", 1);

itr = CON_LIVE_ITR;

}

Rest of the code is self explanatory and no modifications required. Feel free to comment in case you need more info.

Step 5: Install and Configure MQTT Dash APP on Your Mobile

  1. Install MQTT Dash on your android phone and open the app
  2. Click on the + icon at top right corner to add a device.
  3. As shown in the first image above give some name to your device say "MyFarm-IPSet". Address field as io.adafruit.com and port as 1883 , user name should be your adafruit username and password should be your Active Key from adafruit. Leave the rest of the fields as is. Lastly click on save.
  4. You got your device created. Now click on it to add dashboard to it.
  5. Click on + and select type as switch/button. As shown above enter sys in name field. and enter the feed name in the topic field. every feed should start with username/feeds/. for this we <username> /feeds/connection . Ensure Enable Publish is disabled. By clicking on the icon to display you can choose the type of icon you want on the dashboard to look like. For value 1 select one of the colors (say green) and for value 0 select color as gray or red. Finally click on save at the top right corner. Similarly create two more icons one for Grid with username/feeds/grid as topic and Motor with username/feeds/motor. Ensure Enable Publish is disabled.
  6. Lastly create Motor ON button. Its again the same as type as switch/button. The topic should be /feeds/motor_on and ensure Enable Publish is enabled this time and QOS =1. Similarly create another button for Motor OFF. The topic should be /feeeds/motor_off.

Step 6: Last Step :-) Testing and Finetuning.

  1. To be safe you need to test the device first for its START and STOP operations before connecting the relays to DOL starter. Enable Hotspot on the mobile with internet enabled. Connect the laptop having development environment directly to NodeMCU USB port with another charger connected to TP4056 at the same time. If the device is successfully connected to internet you should see 1 device connected to hotspot on the smartphone.
  2. On the other smartphone where you have installed MQTT Dash open the app dashboard. You should see that the NET icon in green and Grid icon also in green with their values as 1. The motor icon should show as motor off with value as 0 .
  3. As you click on the Motor ON button the start relay should make two click sounds at an interval of two seconds. Similarly the Motor OFF button also.
  4. For safety now switch off the main supply to DOL starter and connect the relays to DOL starter as shown above step-2. Ensure motor is off. Push the reset button on NodeMCU. From the serial monitor output , you can see debug statements that print values from WC1700 sensor, delta and the calculated current in the coil. With motor in off state and " #define WCS1700_CONST 15 " the maxCur should be less than 2 consistently. If it show greater than 2 then try with higher values of WCS1700_CONST. Every time you will have to recompile the code and load the firmware.
  5. Now switch ON the motor and look for the current readings again. Leave the motor ON for about 10 -15 minutes and note down the stable current reading. The current may vary between 10 to 20 Amps roughly and need not be accurate.
  6. Go back to the code and set " #define MIN_CURRENT X . Where X is 40 percent of max current approximated to numeric value. In my case I set MIN_CURRENT to 5. Compile and reload the firmware to NodeMCU again.
  7. Remove the USB cable from NodeMCU. Switch OFF and Swtich ON the device with USB charger connected to TP4056. Clicking on the Motor ON button on the mobile app should start the motor. Once the motor is on the status of the motor should reflect on the app dashboard as ON. Clicking on the stop button should stop the motor .

Enjoy !!!!

IoT Challenge

Participated in the
IoT Challenge