Automated watering system

Thread Starter

Beltana Bunyip

Joined Jan 5, 2021
3
I was wondering if someone could help and guide me in a little project that I am working on.

I am making an automated watering system for my wife.

I can't seem to wrap my head around the 'C' script/code.

This is what I want to happen.

Using an LDR I wish to determine weather it is day or night. If it is night time, the program will wait 60 minutes and try again. This time if it is day time it will check the soil moisture. If the soil moisture is too wet, then it will wait 60 minutes and then restart the program. When the soil moisture is dry enough it flicks a relay that turns on a solidnoid and the water is turned on for 30 minutes. Then the software will restart.

Sounds complicated, but I have it all drawn up, it's just the 'C' I am having troubles with.

Could anyone please spend a little time for me and help out.
 

zazas321

Joined Nov 29, 2015
936
You can definately get that working on Raspberry PI , maybe you find Python easier? Also, ESP32 with Arduino IDE is also a good choise. If you are making this for your home, you can also make a some MQTT or bluetooth server and monitor data realtime if you use either ESP32 or bluetooth :)

Regarding to your code issue, I would just recommend you to start coding bit by bit and you will soon realize that it is not that complicated. First program the LDR part, make sure your readings are as expected, then try to control the relay and water pump or whatever you are planning to use..

Post your results/questions here and I might be able to assist you further
 

Picbuster

Joined Dec 2, 2013
1,047
I was wondering if someone could help and guide me in a little project that I am working on.

I am making an automated watering system for my wife.

I can't seem to wrap my head around the 'C' script/code.

This is what I want to happen.

Using an LDR I wish to determine weather it is day or night. If it is night time, the program will wait 60 minutes and try again. This time if it is day time it will check the soil moisture. If the soil moisture is too wet, then it will wait 60 minutes and then restart the program. When the soil moisture is dry enough it flicks a relay that turns on a solidnoid and the water is turned on for 30 minutes. Then the software will restart.

Sounds complicated, but I have it all drawn up, it's just the 'C' I am having troubles with.

Could anyone please spend a little time for me and help out.
This a 'state machine' job.

Make a list of states like wet , night fix that in a number.
state
0= no action
1= day
2= night
3=wet
4=dry


build state by collecting the values and execute the switch.
in C

switch (state)
{
case 0:
// switch off all and go to sleep
break;
case 3: // this day +night oops error
state=99;
break;
case 4: // day+wet
// the things needed
break;
.
. // and so on
.
.
case x: // condition to switch on
pump_on() ; //function
break;
case y:
pump_off(); //==>> or Pump(n); n=0; off n=1; on
// or in project .h file #define Run=1 now write Pump(Run); makes it more readable
// or in project .h file #define Stop=0 now write Pump(Stop); makes it more readable
break;
case 99: // error
// raise error and decide what to do ignore => state=0; or make a lot of noise
break;

default: // things not covered by case = wrong
state=99;
}

loop the lot.
//function to handle pump
void Pump(int Run)
{
if (run)
{
// set relays on and check is running ( eq, speed detect(best) or current detector )
}
else
{
// set relays off check stop
}
}

Picbuster
 

Thread Starter

Beltana Bunyip

Joined Jan 5, 2021
3
This a 'state machine' job.

Make a list of states like wet , night fix that in a number.
state
0= no action
1= day
2= night
3=wet
4=dry


build state by collecting the values and execute the switch.
in C

switch (state)
{
case 0:
// switch off all and go to sleep
break;
case 3: // this day +night oops error
state=99;
break;
case 4: // day+wet
// the things needed
break;
.
. // and so on
.
.
case x: // condition to switch on
pump_on() ; //function
break;
case y:
pump_off(); //==>> or Pump(n); n=0; off n=1; on
// or in project .h file #define Run=1 now write Pump(Run); makes it more readable
// or in project .h file #define Stop=0 now write Pump(Stop); makes it more readable
break;
case 99: // error
// raise error and decide what to do ignore => state=0; or make a lot of noise
break;

default: // things not covered by case = wrong
state=99;
}

loop the lot.
//function to handle pump
void Pump(int Run)
{
if (run)
{
// set relays on and check is running ( eq, speed detect(best) or current detector )
}
else
{
// set relays off check stop
}
}

Picbuster
Thanks a million m8.
James
 

ApacheKid

Joined Jan 12, 2015
1,610
I was wondering if someone could help and guide me in a little project that I am working on.

I am making an automated watering system for my wife.

I can't seem to wrap my head around the 'C' script/code.

This is what I want to happen.

Using an LDR I wish to determine weather it is day or night. If it is night time, the program will wait 60 minutes and try again. This time if it is day time it will check the soil moisture. If the soil moisture is too wet, then it will wait 60 minutes and then restart the program. When the soil moisture is dry enough it flicks a relay that turns on a solidnoid and the water is turned on for 30 minutes. Then the software will restart.

Sounds complicated, but I have it all drawn up, it's just the 'C' I am having troubles with.

Could anyone please spend a little time for me and help out.
Frankly I'd just buy a system. You'd be better of decoupling the learning of C and stuff from the delivery of a working robust system.

Tackle a project like that after you are already proficient, burdening yourself with all the learning and at the same time, the expectation to deliver a non-trivial working and reliable system could put off the subject for life!
 
Top