Devices & Components
1 relay module 5 Vdc 10A (assembled)
Arduino® UNO R4 WiFi
USB C to USB 3.1 Adapter Type C OTG Cable
12V Power Adapter
5v water pump
soil moisture sensor fc-28
connecting wires
Software & Tools
Arduino IDE
Blynk
Project description
Code
IoT Plant Watering System
cpp
Code for Remote Plant Watering System
1/************************************************************* 2 Blynk is a platform with iOS and Android apps to control 3 ESP32, Arduino, Raspberry Pi and the likes over the Internet. 4 You can easily build mobile and web interfaces for any 5 projects by simply dragging and dropping widgets. 6 7 Downloads, docs, tutorials: https://www.blynk.io 8 Sketch generator: https://examples.blynk.cc 9 Blynk community: https://community.blynk.cc 10 Follow us: https://www.fb.com/blynkapp 11 https://twitter.com/blynk_app 12 13 Blynk library is licensed under MIT license 14 This example code is in public domain. 15 16 ************************************************************* 17 This example shows how to use Arduino WiFi shield 18 to connect your project to Blynk. 19 20 Please update your shield firmware: 21 https://www.arduino.cc/en/Hacking/WiFiShieldFirmwareUpgrading 22 23 Feel free to apply it to any other example. It's simple! 24 *************************************************************/ 25 26/* Comment this out to disable prints and save space */ 27//#define BLYNK_PRINT Serial 28 29/* Fill in information from Blynk Device Info here */ 30#define BLYNK_TEMPLATE_ID "XXXXXXXXXXXX" 31#define BLYNK_TEMPLATE_NAME "XXXXXXXXXXXXX" 32#define BLYNK_AUTH_TOKEN "XXXXXXXXXXXXXXX" 33 34#include <SPI.h> 35#include <WiFiS3.h> 36#include <BlynkSimpleWifi.h> 37#include "Arduino_LED_Matrix.h" 38#include <EEPROM.h> 39 40#define moisture_sensor A0 41#define relay 7 42 43BlynkTimer timer; 44ArduinoLEDMatrix matrix; //Create an led matrix object 45 46// Your WiFi credentials. 47// Set password to "" for open networks. 48char ssid[] = "XXXXXXXXX"; 49char pass[] = "XXXXXXXXX"; 50 51int eeprom_addr = 0; //eeprom address 52int sensorValue = 0; // variable to store the value coming from the sensor 53int prev_pump_status = 0; 54int pump_status = 0; 55float moist_percent = 0.00; 56 57 58 59const uint32_t HAPPY_LED[] = { 60 0x3fc48a95, 61 0x58019fd9, 62 0x5889871 63}; 64 65const uint32_t NORMAL_LED[] = { 66 0x3fc40298, 67 0xd98d8019, 68 0x5889871 69}; 70 71const uint32_t SAD_LED[] = { 72 0x3fc48a9d, 73 0xd8898018, 74 0x71889905 75}; 76 77 78BLYNK_WRITE(V1){ //read data from Blynk cloud 79 pump_status = param.asInt(); 80 EEPROM.write(eeprom_addr,pump_status); 81 prev_pump_status = EEPROM.read(eeprom_addr); 82 Serial.println(prev_pump_status); 83 Serial.println(pump_status); 84} 85 86void sendSensor(){ //send data to Blynk cloud 87 Blynk.virtualWrite(V0,moist_percent); 88} 89 90void init_renesas_MCU_IO(){ 91 pinMode(relay, OUTPUT); 92 pinMode(moisture_sensor, INPUT); 93 analogReadResolution(12); //change to 12-bit resolution 94 matrix.begin(); //initialise the led matrix*/ 95} 96 97void track_soil_moisture(){ 98 99 // read the value from the sensor: 100 sensorValue = analogRead(moisture_sensor); 101 moist_percent = 100 - ((float)sensorValue / 4096.0) * 100; 102 103 if(moist_percent >= 0 && moist_percent < 33.33){ 104 Serial.println("DRY"); 105 matrix.loadFrame(SAD_LED); 106 } 107 else if(moist_percent >= 33.33 && moist_percent < 66.66){ 108 Serial.println("MODERATE"); 109 matrix.loadFrame(NORMAL_LED); 110 } 111 else if(moist_percent >= 66.66 && moist_percent <= 100){ 112 Serial.println("WET"); 113 matrix.loadFrame(HAPPY_LED); 114 } 115} 116 117void setup() 118{ 119 // Debug console 120 Serial.begin(9600); 121 122 Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass); 123 124 init_renesas_MCU_IO(); 125 126 timer.setInterval(1000L,sendSensor); 127 128 prev_pump_status = EEPROM.read(eeprom_addr); 129 pump_status = prev_pump_status; 130} 131 132void loop() 133{ 134 Blynk.run(); 135 timer.run(); 136 137 track_soil_moisture(); 138 if(pump_status == 0){ 139 Serial.println("Water pump is off"); 140 digitalWrite(relay, LOW); 141 } 142 else if(pump_status == 1){ 143 Serial.println("Water pump is on"); 144 digitalWrite(relay,HIGH); 145 } 146 delay(500); 147}
Comments
Only logged in users can leave comments