init: first commit
This commit is contained in:
commit
ea5608dac3
5 changed files with 342 additions and 0 deletions
69
02-water-pump/diagram.json
Normal file
69
02-water-pump/diagram.json
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
{
|
||||
"version": 1,
|
||||
"author": "Anonymous maker",
|
||||
"editor": "wokwi",
|
||||
"parts": [
|
||||
{ "type": "wokwi-arduino-nano", "id": "nano", "top": -4.8, "left": -0.5, "attrs": {} },
|
||||
{
|
||||
"type": "wokwi-resistor",
|
||||
"id": "r1",
|
||||
"top": 139.2,
|
||||
"left": -10.15,
|
||||
"rotate": 90,
|
||||
"attrs": { "value": "10000" }
|
||||
},
|
||||
{
|
||||
"type": "wokwi-led",
|
||||
"id": "led2",
|
||||
"top": -128.4,
|
||||
"left": 3.8,
|
||||
"attrs": { "color": "green", "flip": "1" }
|
||||
},
|
||||
{
|
||||
"type": "wokwi-led",
|
||||
"id": "led3",
|
||||
"top": -128.4,
|
||||
"left": 100.2,
|
||||
"attrs": { "color": "yellow", "flip": "1" }
|
||||
},
|
||||
{ "type": "wokwi-gnd", "id": "gnd1", "top": 201.6, "left": 229.8, "attrs": {} },
|
||||
{
|
||||
"type": "wokwi-resistor",
|
||||
"id": "r3",
|
||||
"top": -62.4,
|
||||
"left": 210.65,
|
||||
"rotate": 90,
|
||||
"attrs": { "value": "1000" }
|
||||
},
|
||||
{
|
||||
"type": "wokwi-resistor",
|
||||
"id": "r4",
|
||||
"top": -24,
|
||||
"left": 181.85,
|
||||
"rotate": 90,
|
||||
"attrs": { "value": "1000" }
|
||||
},
|
||||
{
|
||||
"type": "wokwi-slide-potentiometer",
|
||||
"id": "pot1",
|
||||
"top": 259.2,
|
||||
"left": -39.2,
|
||||
"rotate": 90,
|
||||
"attrs": { "travelLength": "30" }
|
||||
}
|
||||
],
|
||||
"connections": [
|
||||
[ "nano:GND.1", "gnd1:GND", "black", [ "v0" ] ],
|
||||
[ "led2:A", "nano:12", "green", [ "v0" ] ],
|
||||
[ "led2:C", "r4:1", "green", [ "v0" ] ],
|
||||
[ "nano:4", "led3:A", "green", [ "v0" ] ],
|
||||
[ "led3:C", "r3:1", "green", [ "v0" ] ],
|
||||
[ "r3:2", "gnd1:GND", "green", [ "h0" ] ],
|
||||
[ "r4:2", "gnd1:GND", "green", [ "h0" ] ],
|
||||
[ "nano:5V", "r1:1", "red", [ "v0" ] ],
|
||||
[ "r1:2", "pot1:SIG", "green", [ "h0" ] ],
|
||||
[ "pot1:VCC", "gnd1:GND", "red", [ "v0" ] ],
|
||||
[ "nano:A0", "pot1:SIG", "green", [ "v0" ] ]
|
||||
],
|
||||
"dependencies": {}
|
||||
}
|
||||
78
02-water-pump/sketch.ino
Normal file
78
02-water-pump/sketch.ino
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
|
||||
/*
|
||||
|
||||
C1 : humidité du sol
|
||||
C2 : remplissage du réservoir
|
||||
|
||||
I1 : Circuit alimenté si On
|
||||
I2 : Substrat sec si On
|
||||
I3 : Réservoir vide si On
|
||||
|
||||
P1 : Pompe réservoir -> substrat
|
||||
|
||||
*/
|
||||
|
||||
#define AHUMITY A0
|
||||
#define AWATER_LEVEL A1
|
||||
|
||||
#define LED_POWER 12
|
||||
#define LED_DRY 10
|
||||
#define LED_ALERT 8
|
||||
#define PUMP 6
|
||||
|
||||
#define HUMIDITY_THRESHOLD 530
|
||||
#define WATER_LEVEL_THRESHOLD 530
|
||||
|
||||
// Durations in seconds
|
||||
#define DURATION_PUMP 30
|
||||
#define DURATION_DELAY 1800
|
||||
#define SECOND 3 // OR 1000
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
int humity = analogRead(AHUMITY);
|
||||
int water_level = analogRead(AWATER_LEVEL);
|
||||
|
||||
digitalWrite(LED_POWER, HIGH);
|
||||
|
||||
bool is_dry = humity > HUMIDITY_THRESHOLD;
|
||||
bool is_empty = water_level > WATER_LEVEL_THRESHOLD;
|
||||
|
||||
if (is_dry){
|
||||
Serial.print("The soil is DRY (");
|
||||
digitalWrite(LED_DRY, HIGH);
|
||||
|
||||
}else{
|
||||
Serial.print("The soil is WET (");
|
||||
digitalWrite(LED_DRY, LOW);
|
||||
}
|
||||
|
||||
Serial.print(humity);
|
||||
Serial.println(")");
|
||||
|
||||
// if the water is too low, never pump
|
||||
if( is_empty ){
|
||||
Serial.println("The water level is LOW ");
|
||||
digitalWrite(LED_ALERT, HIGH);
|
||||
}else{
|
||||
Serial.println("The water level is HIGH");
|
||||
digitalWrite(LED_ALERT, LOW);
|
||||
if( is_dry){
|
||||
Serial.println("Starting the pump");
|
||||
digitalWrite(PUMP, HIGH);
|
||||
delay(DURATION_PUMP * SECOND);
|
||||
digitalWrite(PUMP, LOW);
|
||||
Serial.println("Stopped the pump");
|
||||
}
|
||||
}
|
||||
|
||||
Serial.println("Sleeeping");
|
||||
delay(DURATION_DELAY * SECOND);
|
||||
Serial.println("Slept");
|
||||
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue