Hey, first of all a small description of my project...
I've got a smart irrigation system, arduino, lcd and 3 sensors are powered by a li-ion battery connected to CN3065, a charger that allows me to use solar panels to charge my batteries.The output is connected to a 5V usb step_up that allows me to power up arduino, and it works ok.
The 5v water pump connected to a 5v relay and 4 buttons are powered by another li ion battery connected to another charger and 5V step_up for the breadboard.The problem is, when water pump starts everything freezes and LCD screen goes crazy.If I don't use the pump everything works ok.
Links to the hardware:
Relay : 5V Single-Channel Relay Module - Pin Diagram, Specifications, Applications, Working
Water Pump: https://5.imimg.com/data5/IQ/GJ/PF/SELLER-1833510/dc-mini-submersible-water-pump.pdf
The 5V step_ups:0.9V-5V input, 5V USB Output Boost Regulator Module [CE8301] - US $0.70 : HAOYU Electronics : Make Engineers Job Easier
https://de.aliexpress.com/i/4001143782139.html?gatewayAdapt=glo2deu
Charger: CN3065 Datasheet(PDF) - Shanghai Consonance Electronics Incorporated
Any advice would help me!
A fritzing drawing to show an idea about how I wired my circuit:
I've tried in KiCad to do a schematic, I'm still learning:
This is the code:
#include <LiquidCrystal.h>
#include <DHT.h>
// set the DHT Pin
#define DHTPIN 6
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
float tempC;
float hum;
int motorPin = 7; // pin that turns on the motor
int watertime = 10; // how long it will be watering (in seconds)
int moisturelevel = 40; //when the pump starts
//initialize buttons
const int b1incrtime = 13;
const int b2decrtime = 10;
const int b3incrlevel = 9;
const int b4decrlevel = 8;
int button1State = 0;
int button2State = 0;
int button3State = 0;
int button4State = 0;
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 4);
dht.begin();
//buttons
pinMode(b1incrtime, INPUT);
pinMode(b2decrtime, INPUT);
pinMode(b3incrlevel, INPUT);
pinMode(b4decrlevel, INPUT);
}
void loop() {
//buttons
button1State = digitalRead(b1incrtime);
button2State = digitalRead(b2decrtime);
button3State = digitalRead(b3incrlevel);
button4State = digitalRead(b4decrlevel);
// read humidity
hum = dht.readHumidity();
lcd.setCursor(0, 0);
lcd.print (hum, 1); lcd.print("%"); lcd.print(" "); lcd.print("Humidity");
// read temperature
tempC = dht.readTemperature();
lcd.setCursor(0, 1);
lcd.print(tempC, 1); lcd.print(" "); lcd.print("C");
lcd.print(" "); lcd.print(" "); lcd.print(" "); lcd.print(" "); lcd.print(" "); lcd.print(" "); lcd.print(" "); lcd.print(" "); lcd.print(" "); lcd.print(" ");
// read soil humidity
int moisturePin = analogRead(A0); //read analog value of moisture sensor
int moisture = ( 100 - ( (moisturePin / 1023.00) * 100 ) ); //convert analog value to percentage
lcd.setCursor(0, 2);
lcd.print (moisture, 1); lcd.print("%"); lcd.print(" "); lcd.print("Soil Level"); lcd.print(" "); lcd.print(" ");
//read water level
int waterPin = analogRead(A1);
int water = waterPin;
lcd.setCursor(0, 3);
lcd.print (water, 1); lcd.print(" "); lcd.print("Water Level");
//a function to stop water pump if water sensor goes below 100
if (button1State == HIGH & water > 100)
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Set Water Time");
lcd.setCursor(0, 1);
watertime = watertime + 1;
lcd.print(watertime); lcd.print(" "); lcd.print("seconds");
delay(200);
}
//4 functions that incremenent and decrement the seconds needed to water the plants and
when the water pump starts
if (button2State == HIGH & water > 100)
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Set Water Time");
lcd.setCursor(0, 1);
watertime = watertime - 1;
lcd.print(watertime); lcd.print(" "); lcd.print("seconds");
delay(200);
}
if (button3State == HIGH & water > 100)
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Set When");
lcd.setCursor(0, 1);
lcd.print("Irigation Start");
lcd.setCursor(0, 2);
moisturelevel = moisturelevel + 1;
lcd.print(moisturelevel); lcd.print(" "); lcd.print("Moisture");
delay(200);
}
if (button4State == HIGH & water > 100)
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Set When");
lcd.setCursor(0, 1);
lcd.print("Irigation Start");
lcd.setCursor(0, 2);
moisturelevel = moisturelevel - 1;
lcd.print(moisturelevel); lcd.print(" "); lcd.print("Moisture");
delay(200);
}
delay(1000); //delay
if (water < 100 )
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Error!");
lcd.setCursor(0, 1);
lcd.print("Water Level Low!");
lcd.setCursor(0, 2);
lcd.print("WaterPump Stops!");
digitalWrite(motorPin, LOW);
delay(2500); // delay
}
if (moisture < moisturelevel & water > 100 ) { //change the moisture threshold level based on your calibration values
digitalWrite(motorPin, HIGH); // turn on the motor
delay(watertime * 1000); // seconds
}
else
{
digitalWrite(motorPin, LOW);
delay(1000);
}
}