I have a weird problem where my plant watering system is not stopping watering the plants. This might not be code related i think.
I am following this tutorial with some changes. I am using a 12V DC motor as the plants are indoor and i have a big drum of water where i have placed the submersible pumps. I have a few with the moisture sensor that work fine and a few others where i just click a button to water them from Arduino cloud Dashboard.
I have the levels set at 30%. I see that the motor stops when the moisture sensor reads >30%. But the water is still slowly coming out of the pipes. This is flooding the entire plant and will eventually flood the floor
I previously used the 5V pumps but they were not powerful enough to pump water out of the drum. I noticed that with the 5V pumps when they were not working the water receded back to the drum. In the 12v motor it does not. Maybe that is the problem that water is not flowing in the backward direction once the motor is switched off.
Anyone faced similar issue ?
Not sure if this is a code related issue. Pasting for reference -
#include "thingProperties.h"
#include <Adafruit_ADS1X15.h>
Adafruit_ADS1115 ads;
void setup() {
pinMode(2, OUTPUT);
pinMode(D0, OUTPUT);
pinMode(D3, OUTPUT);
pinMode(D5, OUTPUT);
pinMode(D6, OUTPUT);
pinMode(D7, OUTPUT);
digitalWrite(2, HIGH);
digitalWrite(D3, HIGH);
digitalWrite(D5, HIGH);
digitalWrite(D6, HIGH);
digitalWrite(D7, HIGH);
Serial.begin(115200);
delay(1500);
if (!ads.begin()) {
Serial.println("Failed to initialize ADS.");
while (1);
}
// Defined in thingProperties.h
initProperties();
// Connect to Arduino IoT Cloud
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
}
void loop() {
ArduinoCloud.update();
// Your code here
onMoistureSensor0Change();
onMoistureSensor1Change();
onMoistureSensor2Change();
onMoistureSensor3Change();
}
/*
Since Led is READ_WRITE variable, onLedChange() is
executed every time a new value is received from IoT Cloud.
*/
void onLedChange() {
// Add your code here to act upon Led change
if(led==1){
digitalWrite(2, LOW);
digitalWrite(D0, HIGH);
}
if(led==0){
digitalWrite(2, HIGH);
digitalWrite(D0, LOW);
}
}
/*
Since MoistureSensor0 is READ_WRITE variable, onMoistureSensor0Change() is
executed every time a new value is received from IoT Cloud.
*/
void onMoistureSensor0Change() {
// Add your code here to act upon MoistureSensor0 change
int16_t adc0;
adc0 = ads.readADC_SingleEnded(0);
int16_t moisture_percentage = map(adc0, 15500, 7000, 0, 100);
moisture_sensor0 = moisture_percentage;
if(moisture_sensor0 < 30) {
digitalWrite(D3, LOW);
}
else {
digitalWrite(D3, HIGH);
}
delay(500);
}
/*
Since MoistureSensor1 is READ_WRITE variable, onMoistureSensor1Change() is
executed every time a new value is received from IoT Cloud.
*/
void onMoistureSensor1Change() {
// Add your code here to act upon MoistureSensor1 change
int16_t adc1;
adc1 = ads.readADC_SingleEnded(1);
int16_t moisture_percentage = map(adc1, 15500, 7000, 0, 100);
moisture_sensor1 = moisture_percentage;
// Not triggering here since this is just to read moisture value. The pump is the same as Sensor0 at D3
delay(500);
}
/*
Since MoistureSensor2 is READ_WRITE variable, onMoistureSensor2Change() is
executed every time a new value is received from IoT Cloud.
*/
void onMoistureSensor2Change() {
// Add your code here to act upon MoistureSensor2 change
int16_t adc2;
adc2 = ads.readADC_SingleEnded(2);
int16_t moisture_percentage = map(adc2, 15500, 7000, 0, 100);
moisture_sensor2 = moisture_percentage;
if(moisture_sensor2 < 30) {
digitalWrite(D5, LOW);
}
else {
digitalWrite(D5, HIGH);
}
delay(500);
}
/*
Since MoistureSensor3 is READ_WRITE variable, onMoistureSensor3Change() is
executed every time a new value is received from IoT Cloud.
*/
void onMoistureSensor3Change() {
// Add your code here to act upon MoistureSensor3 change
int16_t adc3;
adc3 = ads.readADC_SingleEnded(3);
int16_t moisture_percentage = map(adc3, 15500, 7000, 0, 100);
moisture_sensor3 = moisture_percentage;
// Not triggering here since this is just to read moisture value. The pump is the same as Sensor2 at D5
delay(500);
}
/*
Since Relay1 is READ_WRITE variable, onRelay1Change() is
executed every time a new value is received from IoT Cloud.
*/
void onRelay1Change() {
// Add your code here to act upon Relay1 change
if(relay1==1){
Serial.print("Relay1: "); Serial.println(relay1);
digitalWrite(D3, LOW);
}
if(relay1==0){
Serial.print("Relay1: "); Serial.println(relay1);
digitalWrite(D3, HIGH);
}
delay(5000); // Water for 5 seconds
relay1=0;
digitalWrite(D3, HIGH);
}
/*
Since Relay2 is READ_WRITE variable, onRelay2Change() is
executed every time a new value is received from IoT Cloud.
*/
void onRelay2Change() {
// Add your code here to act upon Relay2 change
if(relay2==1){
Serial.print("Relay2: "); Serial.println(relay2);
digitalWrite(D5, LOW);
}
if(relay2==0){
Serial.print("Relay2: "); Serial.println(relay2);
digitalWrite(D5, HIGH);
}
delay(5000); // Water for 5 seconds
relay2=0;
digitalWrite(D5, HIGH);
}
/*
Since Relay3 is READ_WRITE variable, onRelay3Change() is
executed every time a new value is received from IoT Cloud.
*/
void onRelay3Change() {
// Add your code here to act upon Relay3 change
if(relay3==1){
Serial.print("Relay3: "); Serial.println(relay3);
digitalWrite(D6, LOW);
}
if(relay3==0){
Serial.print("Relay3: "); Serial.println(relay3);
digitalWrite(D6, HIGH);
}
delay(5000); // Water for 5 seconds
relay3=0;
digitalWrite(D6, HIGH);
}
/*
Since Relay4 is READ_WRITE variable, onRelay4Change() is
executed every time a new value is received from IoT Cloud.
*/
void onRelay4Change() {
// Add your code here to act upon Relay4 change
if(relay4==1){
Serial.print("Relay4: "); Serial.println(relay4);
digitalWrite(D7, LOW);
}
if(relay4==0){
Serial.print("Relay4: "); Serial.println(relay4);
digitalWrite(D7, HIGH);
}
delay(5000); // Water for 5 seconds
relay4=0;
digitalWrite(D7, HIGH);
}