Google Assistant Controlled Smart Valve With NodeMCU to Water Your Garden

by MbsY in Circuits > Electronics

2799 Views, 34 Favorites, 0 Comments

Google Assistant Controlled Smart Valve With NodeMCU to Water Your Garden

IMG_20220821_160614.jpg

Hello makers,

I wanted something that can automatically water my garden. Anything I find on the internet is either not cool enough or too expensive. So built it up myself like the way I want. In this instructable, I will walk you through how you can make your own.

Supplies

IMG_20220821_155924.jpg

Hardware

  1. NodeMCU (esp8266)
  2. 1/2 inch Solenoid Valve
  3. L9110S H-Bridge Driver module
  4. Jumper wires
  5. Micro USB data cable for NodeMCU
  6. Led for on/off indication
  7. 5v DC supply
  8. Google Home/Google assistant
  9. Drip Irrigation Kit


Software

  1. Arduino IDE (with ESP8266 installed)
  2. Sinric pro account

Understand About the Components Used

NodeMCU

This is a tiny chip which has inbuilt WIFI and can connect to the internet. Also it is very affordable. I bought it from here.

1/2 inch solenoid valve

I chose a bistable solenoid valve since it is more power efficient because it can be stable in both the open/close states without continuous supply of power. 1/2 inch because it can be easily fit with existing household piping. I bought it from here.

L9110s Driver module

We need this to operate the solenoid valve. I bought it from here.

Jumper wires

These are required to connect the above components together. You can find them easily in local shops or online.

Micro USB data cable for NodeMCU

This is needed to program the NodeMCU and to supply power to it.

Led for on/off indication

This is optional. You can anyway view the state of the value in your google home app.

5v DC supply

You can use your old mobile charger for this like I did or if you don't have one you can use any mobile charger that supplies 5v.

Google Home/Google assistant

You can either use Google Home to control it or use the assistant in your mobile to control it. Also the device can be added to your google home app and can be made accessible to all the members of the room.

Sinricpro account

We are using sinricpro service to connect the device to control our device through the internet and with google home/assistant. You can use Blynk as well but I felt sinricpro is better as it directly communicates with your device and google assistant. We don't need any other 3rd party service like IFTTT in order to communicate with google assistant unlike Blynk. Also with sinric-pro the device can be added as a switch and will be available in your google home app.

To summarize

  1. Directly connect to google assistant service from sinric pro. No other 3rd party service like IFTTT required.
  2. Sinric pro app to setup schedules, scenes and more.
  3. Device will be visible in your assistant compatible devices in google home app. What it means is that the device can be shared across the family members as setup in google home app.

Drip Irrigation Kit

This is needed to supply water to your plants. You can easily find one on Amazon based on number of plants.I bought it from here .


Note : Most of the links are affliate links and would encorage me to do more DIY.

Setup Arduino IDE for NodeMCU

Steps

  1. Install Arduino IDE from here based on your system.
  2. Open Arduino IDE and choose Preferences in Filemenu.
  3. Add this http://arduino.esp8266.com/stable/package_esp8266com_index.json in Additional Boards Manager URLs and click ok. This is for Arduino IDE to recognise your NodeMCU.
  4. Search and install ESP8266 in Tools > Boards > Boards Manager. After complete installation, you will see INSTALLED label on ESP8266 boards.
  5. Now you will be able to see esp8266 based boards like NodeMCU. Choose NodeMCU 1.0 (ESP - 12E module) in Tools > Board > ESP8266 Boards.

Refer this for more detailed instructions.

Understanding the NodeMCU

node-mcu-pin-diagram.png

NodeMCU is an open-source Lua based firmware and development board specially targeted for IoT based Applications. It includes firmware that runs on the ESP8266 Wi-Fi SoC from Espressif Systems, and hardware which is based on the ESP-12 module.


NodeMCU ESP8266 Specifications & Features

  • Microcontroller: Tensilica 32-bit RISC CPU Xtensa LX106
  • Operating Voltage: 3.3V
  • Input Voltage: 7-12V
  • Digital I/O Pins (DIO): 16 (see the GPIO numbers in the above image)
  • Analog Input Pins (ADC): 1
  • UARTs: 1
  • SPIs: 1
  • I2Cs: 1
  • Flash Memory: 4 MB
  • SRAM: 64 KB
  • Clock Speed: 80 MHz
  • USB-TTL based on CP2102 is included onboard, Enabling Plug n Play
  • PCB Antenna
  • Small Sized module to fit smartly inside your IoT projects

It is very small in size and has inbuilt wifi and is also budget friendly making it the right fit for your DIY IoT projects.

Understanding and Controlling Solenoid Valve

Solenoid-Valve.jpeg

A solenoid works by producing an electromagnetic field around a movable core, called an armature. When compelled to move by the electromagnetic field, the motion of that armature opens and closes valves or switches and turns electrical energy into mechanical motion and force.


This solenoid valve we are using here has two stable states. What it means is that, it can stay in two different states without continuous supply of current. So being bi-stable makes our iot setup more power effecient.


Controlling this solenoid valve :

This particular solenoid valve operates at low voltage ranging between 3.6v to 6v. To shift the valve from one state to another, a short 25 millisecond DC voltage needs to be applied to the coil. To shift the valve back, a reverse polarity pulse needs to be applied. 

This might feel like can be done by using two GPIO's on the NodeMCU but the problem here it that the operating voltage of NodeMCU is 3.3v but remember? The solenoid valve nees atleast 3.6v. So, we need something whose input signal is around 3.3v and outputs voltage in 3.6v - 6v range. That is where the L9110S driver module comes in and gets the job done for us.

L9110S Driver Module

l9110-motor-driver-module.jpeg
l9110s-dc-stepper-motor-driver-board-tech8519-6974-1-550x550.jpg

The L9110S dual-channel h-bridge motor driver module is a compact board that can be used to drive stepper motors. This module is based on the L9110 Motor Driver IC. This module has two independent motor driver chips which can each drive up to 800mA of continuous current. The board can be operated from 2.5 volts to 12 Volt enabling this module to be used with both 3.3 Volts and 5 Volts microcontrollers. Our NodeMCU runs at 3.3v making this module best fit for us.

Solenoid valves and stepper motors have something in common. In order to change the direction of stepper motor, reverse polarity current needs to be applied. Same needs to be done with solenoid value in order to open/close it.

 A set of female header pins is used to connect this module to a microcontroller. The solenoid valve is attached via two sets of screw terminals. We provide 1 0 and 0 1 to the set of female header pins on the module to turn on/off the solenoid valve.

Configure SinricPro Account

Screenshot 2022-10-15 191958.png
Screenshot 2022-10-15 192401.png
Screenshot 2022-10-15 192522.png
Screenshot 2022-10-15 192802.png
Screenshot 2022-10-15 192926.png
  1. Go to https://sinric.pro/index.html and sign up for an account and then login.
  2. Select devices and add a device. Device type should be `Switch`. Follow the steps and complete adding the device. You will be able to configure the notifications and timers later in the app and the website.
  3. Copy your Device ID, App Key and App Secret and replace it in the code given in next step.

Connections

IMG_20220821_190636.jpg
IMG_20220821_152823.jpg
IMG_20220821_153613.jpg

Note: It is recommended to make the connections after uploading the code to NodeMCU. I observed the NodeMCU heatup and prevent code upload if connections are made first.


We will be using the following I/O ports:

D1 - 1st Control input for driver module

D2 - 2nd Control input for driver module

D7 - Valve status led pin

LED_BUILTIN - This is used to indicate the WIFI connection


NodeMCU to L9110S

Connect the

  1. Control pins D1 and D2 of NodeMCU to the A1-A and A1-B ports of L9110S.
  2. Vcc and GND pins of L9110S to 3V and G pin of NodeMCU.


L9110S to Solenoid Valve

Losen the screws and connect the two terminals of L9110S marked Motor A to the two wires of the solenoid valve. Adjust this and synchronize the actual on/off state of valve with the state shown in the sinric pro/google home app.


NodeMCU to Status LED (Optional)

Connect D7 to the long terminal of LED and any Gnd pin of NodeMCU to short terminal of LED.


Programming NodeMcu

  1. Make sure the following libraries are installed in your Arduino IDE. Go to Tools > Manage Libraries... . A popup will appear, search and install these libraries if they are not already.
  2. Arduino.h
  3. ESP8266WiFi.h
  4. SinricPro.h
  5. SinricProSwitch.h
  6. Copy the code to a new project or open the attached file in arduino ide.
  7. Update the defined constants as mentioned in comments of code.
  8. Upload the code to NodeMCU by connecting it via USB.

Connecting With Google Home

  1. Download and install `Google Home` app.
  2. Click on plus icon to the top left and select `Set up a device` -> `Works with Google`.
  3. Search for sinric pro here and login to your account.
  4. That is it. You will not be able to see the device in your Google Home app home page.

Setting Up in the Garden

Pack your NodeMCU connected to the valve in a box and connect it with your drip irrigation system. You can power the device using any of your old mobile charger and you are good to go.


Bonus:

Download sinric pro app and setup timers to automatically turn on and off and water your garden automatically.