Le programme Arduino
- coud nico
- 13 déc. 2020
- 1 min de lecture

// include the library code:
#include <LiquidCrystal.h>
const int moistureSensor=A0;
int arrosage =1;
int sensorValue=0;
// LCD
int scrollMax = 16;
// on initialise la librairie avec les pin arduino utilisés
LiquidCrystal lcd(9, 8, 5, 4, 3, 2 );
const int buzzer = 7;
const int ZERO = 0;
int bp_counter = 0; // Innitialisation du compter
int compt_etat_actuel = 0;
int compt_etat_precedent = 0;
int delayT=500;
int refreshT=1000;
int greenLed=13;
int yellowLed=12;
int redLed=11;
int relais=10;
void setup()
{
//configurer le nombre de colonnes et de lignes de l'écran LCD:
lcd.begin(16,2);
lcd.clear();
pinMode(relais,OUTPUT);
pinMode(redLed,OUTPUT);
pinMode(greenLed,OUTPUT);
pinMode(yellowLed,OUTPUT);
pinMode(buzzer,OUTPUT);
Beep(200);
Serial.begin(9600);
}
void loop()
{
sensorValue=analogRead(moistureSensor);
if (sensorValue>500 )
{
Serial.println(" TROP SEC - ACTIVATION ARROSAGE "); // Affiche la phrase entre ""
for(int arrosage = 1 ; arrosage <= 3 ; arrosage = arrosage+1)
{
Serial.print(arrosage);
Serial.print(" arrosage ");
Serial.print(" ; ");
Serial.println(sensorValue);
digitalWrite(relais,HIGH);
{// Affichage du compteur
sensorValue=analogRead(moistureSensor);
compt_etat_actuel = digitalRead(relais);
if (compt_etat_actuel == HIGH) {
bp_counter++;
lcd.print(bp_counter);
lcd.print(" Nbr Arrosage ");
Serial.print(" compteur Nbre Arrosage ");
Serial.print(" ; ");
Serial.println(bp_counter);
}
if (bp_counter == 6)//Nombre de fois pour la mise a 0
{
Serial.println(bp_counter);
bp_counter=ZERO ;} //reset zéro pour recommencer
delay(50);
lcd.setCursor(0, 0);
compt_etat_precedent = compt_etat_actuel;
}//fin Affichage du compteur
delay(10000); // durée fixe activation pompe
digitalWrite(relais,LOW);
delay(2000); // pause pompe pour laisser a l'eau le tps de pénétrer la terre
Beep (300); // Buzzer fonctionne quand la pompe fonctionne
digitalWrite(greenLed,LOW);
digitalWrite(yellowLed,LOW);
digitalWrite(redLed,HIGH);
}}
else if(sensorValue<500 && sensorValue>360)
{
digitalWrite(greenLed,LOW);
digitalWrite(redLed,LOW);
digitalWrite(relais,HIGH);
digitalWrite(yellowLed,HIGH);
}
else if(sensorValue<360)
{
digitalWrite(yellowLed,LOW);
digitalWrite(greenLed,HIGH);
digitalWrite(redLed,LOW);
digitalWrite(relais,HIGH);
}
Serial.print(" sensorValue= " );
Serial.print(sensorValue);
Serial.print("\n");
delay(delayT);
//LCD
lcd.setCursor(0, 1);
lcd.print("Val sonde ");
lcd.print((int)sensorValue);
lcd.print(" %");
lcd.setCursor(0, 0);
}
//Buzzer
void Beep(int dTime)
{
tone(buzzer, 500);
delay(dTime);
noTone(buzzer);
}
Commentaires