The story must go on, and today we expand the earlier projects with water pump protection and more comfortable features: an LCD 1602 will show us the values and error messages in case of problems (not enough water in tank).
You will learn a bit on how to wire a display and change the brightness with a rotary potentiometer. Also, this will show you how to protect your water pump in case the water reduces. By the way, we look at the conditions of 'if then else' and 'else if'.
The components used can still be maintained at a favorable price. However, if you are looking for premium components, you can take a look at vegetronix.
For the interested reader, who passes by accident here, the basics for moisture measurement and Part 1 - the circuit configuration with relay - were documented in earlier projects. The enclosed code is complete and can be used directly.
On the basis of the 2 threshold values (one for measuring humidity and one for the difference between available water and the sensor (installed below the lid of the water tank). Individual settings can be set for your needs.
ConnectionsSchematic for LCD 1602 with Potentiometer and Ultrasonic HC-SR04 Echo you will find at the beginning of the code and here:
The circuit for LCD 1602:
- LCD RS pin to digital pin 12
- LCD Enable E pin to digital pin 11
- LCD D4 pin to digital pin 10
- LCD D5 pin to digital pin 9
- LCD D6 pin to digital pin 8
- LCD D7 pin to digital pin 7
- LCD R/W pin to ground
- LCD VSS pin to ground
- LCD VCC pin to 5V
- 10K resistor for potentiometer ends to +5V and ground
- LCD VO to pin signal from potentiometer
- LCD A to 5V
- LCD K to ground
Remember to include the necessary library named LiquidCrystal over your IDE (Editor-Menu - Libaries).
The circuit now looks quite jumpered, but we still need 4 more for the Ultrasonic Echo:
// Pin Definitions
#define trigPin 1
#define echoPin 2
At the beginning there's a few basic conditions, before the actual event comes and water flows:
if (distance >= 200 || distance <= 0){
Serial.println("Out of range! Check position from UltraSonic Sensor");
digitalWrite(relayPin, LOW);
lcd.setCursor(0, 1);
lcd.print("distance problem");
delay(3000);
lcd.clear();
}
else
{
The || means a logical "or".
Code for ControlNow the actual task of the event begins:
if ((water.toInt() >= pump_threshold) && (distance <= tank_threshold))
{
Serial.println("Too dry, we should water it.");
digitalWrite(relayPin, HIGH);
lcd.setCursor(0, 1);
lcd.blink();
lcd.setCursor(4, 1);
lcd.print("WATERING");
delay(3000);
}
else if ((water.toInt() >= pump_threshold) && (distance >= tank_threshold))
{
Serial.println("Too dry, but NOT ENOUGH WATER in TANK - ALARM!");
digitalWrite(relayPin, LOW); // we do not activate the pump - we dont have enough water in tank
lcd.setCursor(0, 1);
lcd.print("no water in tank");
delay(3000);
lcd.clear();
}
else if ((water.toInt() <= pump_threshold) && (distance >= tank_threshold))
{
Serial.println("It is wet enough, but NOT ENOUGH WATER in TANK - you should fill up!");
digitalWrite(relayPin, LOW); // we do not activate the pump - we dont have enough water in tank
lcd.setCursor(0, 1);
lcd.print("no water in tank");
delay(3000);
lcd.clear();
}
else
{
Serial.println("It is wet enough, no need to water it.");
digitalWrite(relayPin, LOW);
}
}
The && means a logical "and".
Cucumber PicturesGrow your cucumber now! The first yellow flowers are already visible.
The Ultrasonic Echo measures through a hole in the red cover the difference from the sensor to the available water. The variable is named "distance".
In the beginning, I recommend using a timer for the 12V circuit. For example, a fixed time could be set for which relay actually closes the pump circuit. The program runs during the rest of the time, the relay also switches, but the pump is not active.
Here is my Paypal link.
Send me some nice photos of your garden beds or tasty recipes for your vegetables.
Update 07.07.2017:
Follow this project which describes the next step: Part 3.
Update 14.06.2017:
Like my description? You will find more under my account. Follow me to be notified when I publish new projects!
Comments