As a complete newbie I've been trying to understand the sketch supplied with an Elecrow watering kit (2.0), which is not a typical board as it's pretty much pre-assembled on a Leonardo board. I had to add the U8glib and RTClib files to the library and then uploading the sketch to the Arduino seems to make it work fine - at this point. The main parameters of interest are the moisture levels that trigger the watering system and the duration of the pumping function to each pot.
As I look through the sketch, it gets so confusing to me that I don't know how I get to the level of understanding required just to be able to change some of the variables. I've included a sample of the sketch below to see if I can get some guidance on "translating" it into plain enough English that I could modify it if I needed to. (I haven't planted anything in the pots yet, as I'm just working on the set-up.)
(In addition to the code in this box, I've also included the segment of code that follows it which seems to mostly deal with the display function.)
Thanks for any guidance. I can easily supply the rest of the sketch if needed, or it can be viewed on the Elecrow web site on the bottom of that page.
void setup()
{
//draw_elecrow();
//delay(5000);
Wire.begin();
RTC.begin();
Serial.begin(9600);
// declare relay as output
pinMode(relay1, OUTPUT);
pinMode(relay2, OUTPUT);
pinMode(relay3, OUTPUT);
pinMode(relay4, OUTPUT);
// declare pump as output
pinMode(pump, OUTPUT);
// declare switch as input
pinMode(button, INPUT);
//pinMode(ROTARY_ANGLE_SENSOR, INPUT);
// water_flower();
}
void loop()
{
// read the value from the moisture sensors:
read_value();
water_flower();
int button_state = digitalRead(button);
if (button_state == 1)
{
//read_value();
u8g.firstPage();
do
{
drawTH();
drawflower();
} while ( u8g.nextPage() );
delay(500);
}
else
{
u8g.firstPage();
do
{
drawtime();
u8g.drawStr(8, 55 , "www.elecrow.com");
} while (u8g.nextPage());
delay(500);
}
}
//Set moisture value
void read_value()
{
float value1 = analogRead(A0);
moisture1_value = (value1 * 120) / 1023; delay(20);
float value2 = analogRead(A1);
moisture2_value = (value2 * 120) / 1023; delay(20);
float value3 = analogRead(A2);
moisture3_value = (value3 * 120) / 1023; delay(20);
float value4 = analogRead(A3);
moisture4_value = (value4 * 120) / 1023; delay(20);
}
void water_flower()
{
if (moisture1_value < 30)
{
digitalWrite(relay1, HIGH);
relay1_state_flag = 1;
delay(50);
if (pump_state_flag == 0)
{
digitalWrite(pump, HIGH);
pump_state_flag = 1;
delay(50);
}
}
else if (moisture1_value > 55)
{
digitalWrite(relay1, LOW);
relay1_state_flag = 0;
delay(50);
if ((relay1_state_flag == 0) && (relay2_state_flag == 0) && (relay3_state_flag == 0) && (relay4_state_flag == 0))
{
digitalWrite(pump, LOW);
pump_state_flag = 0;
delay(50);
}
}
if (moisture2_value < 30)
{
digitalWrite(relay2, HIGH);
relay2_state_flag = 1;
delay(50);
if (pump_state_flag == 0)
{
digitalWrite(pump, HIGH);
pump_state_flag = 1;
delay(50);
}
}
else if (moisture2_value > 55)
{
digitalWrite(relay2, LOW);
relay2_state_flag = 0;
delay(50);
if ((relay1_state_flag == 0) && (relay2_state_flag == 0) && (relay3_state_flag == 0) && (relay4_state_flag == 0))
{
digitalWrite(pump, LOW);
pump_state_flag = 0;
delay(50);
}
}
if (moisture3_value < 30)
{
digitalWrite(relay3, HIGH);
relay3_state_flag = 1;
delay(50);
if (pump_state_flag == 0)
{
digitalWrite(pump, HIGH);
pump_state_flag = 1;
delay(50);
}
}
else if (moisture3_value > 55)
{
digitalWrite(relay3, LOW);
relay3_state_flag = 0;
delay(50);
if ((relay1_state_flag == 0) && (relay2_state_flag == 0) && (relay3_state_flag == 0) && (relay4_state_flag == 0))
{
digitalWrite(pump, LOW);
pump_state_flag = 0;
delay(50);
}
}
if (moisture4_value < 30)
{
digitalWrite(relay4, HIGH);
relay4_state_flag = 1;
delay(50);
if (pump_state_flag == 0)
{
digitalWrite(pump, HIGH);
pump_state_flag = 1;
delay(50);
}
}
else if (moisture4_value > 55)
{
digitalWrite(relay4, LOW);
relay4_state_flag = 0;
delay(50);
if ((relay1_state_flag == 0) && (relay2_state_flag == 0) && (relay3_state_flag == 0) && (relay4_state_flag == 0))
{
digitalWrite(pump, LOW);
pump_state_flag = 0;
delay(50);
}
}
}
Sketch segment 2.txt (5.18 KB)