Monitor and control your irrigation system with a mobile app




Create your Blynk mobile app to monitor your garden and activate the irrigation.

Monitor and control your irrigation system with a mobile app

Things used in this project

Hardware components

Arduino MKR1000
Arduino MKR1000
× 1
Grove - Relay
Seeed Grove – Relay
× 1
Rural Hack Kit
Arduino Rural Hack Kit
× 1

Software apps and online services

Blynk
Blynk

Story

click on the plus icon on the top right to add a widget to your control panel.

Select the Value display. You should now see a empty box on your screen.

Double tap on it to edit its settings.

First of all we should configure the type of input. click on the PIN button and select Virtual as pin type; and V5 as pin number, Do you remember theBlynk.virtualWrite(V5, millis() / 1000); function in our Arduino code?

Now configure the reading rate. As we are controlling ourself how often the value get pushed to the board you can just set it to PUSH

Now you should be all set! go back to the project screen in your app and click on the play icon on the top right edge of the app.

You should see the value changing every second.

Getting the real data

Now that we know how to send a single value to the board, we can actually send the real value we read from the sensor to the Blynk app.

Connect the i2c soil moisture sensor to your Arduino as shown below.

Monitor and control your irrigation system with a mobile app schematics

Prepare the Blynk app to show one more value in the dashboard. And configure it as pin V6.

The provided code below reads the soil temperature and humidity values and sends the data to the Blynk app every 1s.

Just replace the auth, ssid, and pass value with your network and authentication settings.

#define BLYNK_PRINT SerialUSB 
#include <SPI.h> 
#include <WiFi101.h> 
#include <BlynkSimpleWiFiShield101.h> 
// You should get Auth Token in the Blynk App. 
// Go to the Project Settings (nut icon). 
char auth[] = "xxxxxxxx"; 
// Your WiFi credentials. 
// Set password to "" for open networks. 
char ssid[] = "xxxxxxxx"; 
char pass[] = "xxxxxxxx"; 
#include <I2CSoilMoistureSensor.h> 
#include <Wire.h> 
I2CSoilMoistureSensor soilMoistureSensor(0x60); 
float soilTemperature; 
int soilMoisture=; 
BlynkTimer timer=; 
// This function sends Arduino's up time every second to Virtual Pin (5). 
// In the app, Widget's reading frequency should be set to PUSH. This means 
// that you define how often to send data to Blynk App. 
void myTimerEvent() 
{ 
/////////////////////////////////////////////// 
//get all the data from the soul moisture sensor 
/////////////////////////////////////////////// 
while (soilMoistureSensor.isBusy()) delay(50); // available since FW 2.3 
soilMoisture=soilMoistureSensor.getCapacitance();  
soilTemperature=soilMoistureSensor.getTemperature()/(float)10;  
soilMoistureSensor.sleep(); // available since FW 2.3 
/////////////////////////////////////////////// 
//Send the data to blynk 
/////////////////////////////////////////////// 
// You can send any value at any time. 
// Please don't send more that 10 values per second. 
Blynk.virtualWrite(V5,soilMoisture ); 
Serial.println(soilMoisture); 
Blynk.virtualWrite(V6,soilTemperature ); 
Serial.println(soilTemperature); 
} 
void setup() 
{ 
// Debug console 
SerialUSB.begin(9600); 
Blynk.begin(auth, ssid, pass); 
// Setup a function to be called every second 
timer.setInterval(1000L, myTimerEvent); 
soilMoistureSensor.begin(); // reset sensor 
delay(1000); // give some time to boot up 
Serial.print("I2C Soil Moisture Sensor Address: "); 
Serial.println(soilMoistureSensor.getAddress(),HEX); 
Serial.print("Sensor Firmware version: "); 
Serial.println(soilMoistureSensor.getVersion(),HEX); 
Serial.println(); 
} 
void loop() 
{ 
Blynk.run(); 
timer.run(); // Initiates BlynkTimer 
} 

If everything goes as expected you should now see the two values appearing on your app one next to the other.

Controlling the relay

With the Blynk app we can also control our Arduino board. Add a button widget to your Blynk interface and configure it as virtual pin V1.

To get the information from the Blynk app to the arduino, the Blynk app provides you with a very handy function:

// This function will be called every time Slider Widget 
// in Blynk app writes values to the Virtual Pin 1 
BLYNK_WRITE(V1) { 
int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable 
// You can also use: 
// String i = param.asStr(); 
// double d = param.asDouble(); 
SerialUSB.print("V1 button is: "); 
SerialUSB.println(pinValue); 
if (pinValue == 1) { 
digitalWrite(relayPin, HIGH); 
} else { 
digitalWrite(relayPin, LOW); 
} 
} 

The function BLINK_WRITE(V1) will be executed every time you interact with a widget on your blynk interface that is mapped to the virtual pin V1.

READ  Photoplethysmography – IR Heart Rate Monitor

To start testing this you can just upload this new code to the board.

#define BLYNK_PRINT SerialUSB 
#include <SPI.h> 
#include <WiFi101.h> 
#include <BlynkSimpleWiFiShield101.h> 
// You should get Auth Token in the Blynk App. 
// Go to the Project Settings (nut icon). 
char auth[] = "xxxxxxxxx"; 
// Your WiFi credentials. 
// Set password to "" for open networks. 
char ssid[] = "xxxxxxxxx"; 
char pass[] = "xxxxxxxxx"; 
#include <I2CSoilMoistureSensor.h> 
#include <Wire.h> 
I2CSoilMoistureSensor soilMoistureSensor(0x60); 
float soilTemperature = ; 
int soilMoisture = ; 
int relayPin = 6; 
BlynkTimer timer; 
// This function sends Arduino's up time every second to Virtual Pin (5). 
// In the app, Widget's reading frequency should be set to PUSH. This means 
// that you define how often to send data to Blynk App. 
void myTimerEvent() 
{ 
/////////////////////////////////////////////// 
//get all the data from the soul moisture sensor 
/////////////////////////////////////////////// 
while (soilMoistureSensor.isBusy()) delay(50); // available since FW 2.3 
soilMoisture=soilMoistureSensor.getCapacitance(); 
soilTemperature=soilMoistureSensor.getTemperature()/(float)10; 
soilMoistureSensor.sleep(); // available since FW 2.3 
/////////////////////////////////////////////// 
//Send the data to blynk 
/////////////////////////////////////////////// 
// You can send any value at any time. 
// Please don't send more that 10 values per second. 
Blynk.virtualWrite(V5, soilMoisture ); 
Serial.println(soilMoisture); 
Blynk.virtualWrite(V6, soilTemperature ); 
Serial.println(soilTemperature); 
} 
// This function will be called every time Slider Widget 
// in Blynk app writes values to the Virtual Pin 1 
BLYNK_WRITE(V1) { 
int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable 
// You can also use: 
// String i = param.asStr(); 
// double d = param.asDouble(); 
SerialUSB.print("V1 button is: "); 
SerialUSB.println(pinValue); 
if (pinValue == 1) { 
digitalWrite(relayPin, HIGH); 
} else { 
digitalWrite(relayPin, LOW); 
} 
} 
void setup() 
{ 
// Debug console 
SerialUSB.begin(9600); 
Blynk.begin(auth, ssid, pass); 
// Setup a function to be called every second 
timer.setInterval(1000L, myTimerEvent); 
soilMoistureSensor.begin(); // reset sensor 
delay(1000); // give some time to boot up 
Serial.print("I2C Soil Moisture Sensor Address: "); 
Serial.println(soilMoistureSensor.getAddress(),HEX); 
Serial.print("Sensor Firmware version: "); 
Serial.println(soilMoistureSensor.getVersion(),HEX); 
Serial.println(); 
pinMode(2, OUTPUT); 
} 
void loop() 
{ 
Blynk.run(); 
timer.run(); // Initiates BlynkTimer 
} 

By pressing the button on the blynk interface you should now see the led switching on your mkr1000.




This Post / Project can also be found using search terms:

  • mobile app to monito plant health online

Leave a Comment

*
= 3 + 2

(Spamcheck Enabled)

Read previous post:
SmartWatering – Arduino plant watering
SmartWatering – Arduino plant watering

SmartWatering Particle Core based project in charge of taking care of my green plants This readme is subject to evolve....

Close
Scroll to top