Hey guys,
I'm fairly new to arduino, I have made a few projects however I have normally copied the code from other projects, typing them out manually to try and learn the language. However this time I decided to start from scratch on my code, to try and get my head around programming myself. While I managed to get the project to work in a basic principle, I am wanting to upgrade it and make it a little 'smarter'.
This is what I have so far:
const int AirValue = 614; //you need to replace this value with Value_1
const int WaterValue = 241; //you need to replace this value with Value_2
int intervals = (AirValue - WaterValue)/3;
int soilMoistureValue = 0;
// Relay pin is controlled with D8. The active wire is connected to Normally Closed and common
int relay = 8;
void setup() {
// Pin for relay module set as output
pinMode(relay, OUTPUT);
digitalWrite(relay, HIGH);
Serial.begin(9600); // open serial port, set the baud rate to 9600 bps
}
void loop() {
soilMoistureValue = analogRead(A0); //put Sensor insert into soil
if(soilMoistureValue > WaterValue && soilMoistureValue < (WaterValue + intervals))
{
Serial.println("Very Wet");
digitalWrite(relay, HIGH);
}
else if(soilMoistureValue > (WaterValue + intervals) && soilMoistureValue < (AirValue - intervals))
{
Serial.println("Wet");
}
else if(soilMoistureValue < AirValue && soilMoistureValue > (AirValue - intervals))
{
Serial.println("Dry");
digitalWrite(relay, LOW);
}
delay(2500);
}
This project uses an Arduino, a relay connected to the pump, and a Capacitive Moisture Sensor V1.2 - And that is it so far!
I set the delay to 2500, to try and save a bit of battery life (rightly or wrongly?), however this is great when the pump is off, hower it seems to take alot longer to turn the pump off again, by which point alot of water has obviously been pumped through. Is there a way to set the delay shorter while the relay is LOW?
I would also like to use a secondary sensor to sense if the water level in the storage container is too low, and stop the relay from running if it is, to save damaging the pump.
Is there also a way that the program doesn't run during the night, then switches back on again on sunrise?
As you can see, I can write a basic code, but add more than one variable and I start to confuse myself!
I also have other plans to expand this project, however these are not important at the minute. These include:
- LCD screen showing hydration level.
- Temperature sensor to test inside to outside air temperature, and possible control a fan and / or vent
- Light controller, to really maximise growth
Just to clarify, this is being used for vegetables, and NOT for anything that could be considered illegal!
Thanks in advance guys!
[/list]