Hi,
i'm developing an automatic plant-watering system with the Uno. It uses moisture-sensors to detect the need for watering and relays to switch pumps on and off. The relays, sensors and pumps all work on 5V, which comes from a bench PSU into a rail on a breadboard. The Uno's ground is connected to the 5V rail ground so that there is a common ground.
I've written test code that monitors the moisture level (having converted it into a moisture percentage, akin to RH) and switches the relay to power the pump when the percentage is low, so it's simple code.
At the beginning of the test code i send the relay pin high for 1 second to test that it's working, this works fine, but when the relay is switched due to moisture levels being too low the relay doesn't switch, there's no click and no voltage at the outputs.
Thanks for reading, Gary.
i'm developing an automatic plant-watering system with the Uno. It uses moisture-sensors to detect the need for watering and relays to switch pumps on and off. The relays, sensors and pumps all work on 5V, which comes from a bench PSU into a rail on a breadboard. The Uno's ground is connected to the 5V rail ground so that there is a common ground.
I've written test code that monitors the moisture level (having converted it into a moisture percentage, akin to RH) and switches the relay to power the pump when the percentage is low, so it's simple code.
C:
int pump = 7;
int sensor = 1;
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
void setup() {
Serial.begin(9600);
lcd.begin(16, 2);
pinMode(pump, OUTPUT);
digitalWrite(pump, HIGH); Test the pump for 1 second, this works fine.
delay(1000);
digitalWrite(pump, LOW);
}
void loop() {
int val,mval;
val = analogread(sensor); // read moisture sensor value
mval = map(val,200,700,100,1); // convert to rough percentage
lcd.setCursor(0,0);
String str1 = String("RAW VALUE : ") + val + String(" "); // display sensor value
lcd.print(str1);
lcd.setCursor(0,1);
String str2 = String("PERCENTAGE : ") + mval + String(" "); // display rough percentage value
lcd.print(str2);
Serial.println((String)"VAL : " + val + " MVAL : " + mval); // display values on serial too
if (mval<=50) water_pump01(); // if the rough percentage is less than 51 then pump water
delay(2000);
}
void water_pump01(){
int val,mval;
String str1,str2;
digitalWrite(pump, HIGH); // turn the pump on, this is the current problem since it doesn't go on
Serial.println("PUMP ON"); // a message so that we know we've entered the pumping routine
str1 = String("PUMP ON ");
lcd.setCursor(0,0);
lcd.print(str1);
val = analogread(sensor);
mval = map(val,200,700,100,1);
while (mval<70) { // while the moisture level hasn't reached 70% then keep pumping
val = analogread(sensor);
mval = map(val,200,700,100,1);
Serial.println(val);
Serial.println(mval);
str2 = String("MOISTURE : ") + mval + String(" ");
lcd.setCursor(0,1);
lcd.print(str2);
delay(2000);
}
// moisture level has reached 70% so turn pump off
digitalWrite(pump, LOW);
str2 = String("PUMP OFF : "); // a message so we know pump is being turned off
lcd.setCursor(0,0);
lcd.print(str2);
Serial.println("PUMP OFF");
val = analogread(sensor); //connect sensor to Analog 0
mval = map(val,200,700,100,1);
str2 = String("MOISTURE : ") + mval + String(" ");
lcd.setCursor(0,1);
lcd.print(str2);
delay(1000);
}
Thanks for reading, Gary.
Last edited by a moderator: