Étape 11 : CODES
PROGRAMME À DISTANCE :
#include < glcd.h >
#include < SoftwareSerial.h >
SoftwareSerial xbee(2,3) ;
#include « fonts/SystemFont5x7.h »
int p ;
int s, UA ;
char a, b, c ;
void setup()
{
Serial.Begin(9600) ;
XBee.Begin(9600) ;
pinMode(A5,INPUT) ;
pinMode(12,INPUT) ;
pinMode(13,INPUT) ;
GLCD. Init() ;
GLCD. CursorTo(6,1) ;
GLCD.print("DREAMERS") ;
GLCD. CursorTo(3,3) ;
GLCD.print ("apportant DREAMS") ;
GLCD. CursorTo(6,5) ;
GLCD.print ("à la réalité ») ;
Delay(2000) ;
GLCD. ClearScreen() ;
}
void loop()
{
if(XBee.available())
{
un = xbee.read() ;
b = xbee.read() ;
c = xbee.read() ;
}
Serial.Print("a:") ;
Serial.Print(a) ;
Serial.Print("\t") ;
Serial.Print("b:") ;
Serial.Print(b) ;
Serial.Print("\t") ;
Serial.Print("c:") ;
Serial.Print(c) ;
Serial.Print("\t") ;
Serial.println() ;
btn1 int = analogRead(A5) ;
btn2 int = digitalRead(12) ;
int btn3 = digitalRead(13) ;
Si (btn3 == 1)
{
UA = 49 ;
p = 48 ;
s = 48 ;
}
ElseIf (btn3 == 0)
{
UA = 48 ;
Si (btn1 > 1000)
{
p = 49 ;
}
d’autre
{
p = 48 ;
}
Si (btn2 == 1)
{
s = 49 ;
}
d’autre
{
s = 48 ;
}
}
XBee.Write(au) ;
XBee.Write(p) ;
XBee.Write(s) ;
Si (btn3 == 1)
{
GLCD. ClearScreen() ;
GLCD. CursorTo(4,0) ;
GLCD.print ("MODE automatique") ;
}
ElseIf (btn3 == 0)
{
GLCD. ClearScreen() ;
GLCD. CursorTo(5,0) ;
GLCD.print ("MODE manuel") ;
Si (btn1 > 1000)
{
GLCD. CursorTo(0,2) ;
GLCD.print ("pompe sur") ;
}
d’autre
{
GLCD. CursorTo(0,2) ;
GLCD.print (« pompe arrêtée ») ;
}
Si (btn2 == 1)
{
GLCD. CursorTo(0,4) ;
GLCD.print ("arroseur sur") ;
}
d’autre
{
GLCD. CursorTo(0,4) ;
GLCD.print ("arroseur OFF") ;
}
}
Si (a == « 1 » & & UA == 49)
{
GLCD. CursorTo(0,2) ;
GLCD.print ("pompe sur") ;
GLCD. CursorTo(0,4) ;
GLCD.print ("arroseur sur") ;
}
else if (a == « 0 » & & au == 49)
{
GLCD. CursorTo(0,2) ;
GLCD.print (« pompe arrêtée ») ;
GLCD. CursorTo(0,4) ;
GLCD.print ("arroseur OFF") ;
}
Delay(10) ;
}
PROGRAMME SUR LE TERRAIN :
#include < SoftwareSerial.h >
SoftwareSerial Rxbee(2,3) ;
int pompe ;
int sprink ;
au char, b, c, m, lev ;
void setup()
{
Serial.Begin(9600) ;
Rxbee.Begin(9600) ;
pinMode(8,OUTPUT) ;
pinMode(A0,INPUT) ;
pinMode(A1,INPUT) ;
pinMode(A2,INPUT) ;
pinMode(A3,INPUT) ;
pinMode(A4,INPUT) ;
}
void loop()
{
if(Rxbee.available())
{
UA = Rxbee.read() ;
Serial.Print(au) ;
Serial.Print("\t") ;
b = Rxbee.read() ;
Serial.Print(b) ;
Serial.println("\t") ;
c = Rxbee.read() ;
Serial.println(c) ;
}
Si (UA == « 1 »)
{
int temp = analogRead(A0) ;
flotteur t = temp *. 48828125 ;
Serial.Print("t:") ;
Serial.println(t) ;
Si (lev == 48)
{
if(MOS < 1000)
{
digitalWrite(8,LOW) ;
pompe = 48 ;
Serial.Print ("pompe auto off") ;
}
d’autre
{
pompe = 49 ;
digitalWrite(8,HIGH) ;
Serial.Print ("pompe auto sur") ;
}
d’autre
{
pompe = 48 ;
digitalWrite(8,LOW) ;
}
}
ElseIf (UA == « 0 »)
{
Si (b == « 1 » & & c == « 1 »)
{
digitalWrite(8,HIGH) ;
Serial.println ("homme fois sur") ;
}
ElseIf (b == « 1 » & & c == « 0 »)
{
Serial.println ("pompe d’homme sur") ;
digitalWrite(8,HIGH) ;
}
ElseIf (b == « 0 » & & c == « 1 »)
{
Serial.println (« homme sprink sur") ;
digitalWrite(8,HIGH) ;
}
ElseIf (b == « 0 » & & c == « 0 »)
{
Serial.println (« homme les deux off ») ;
digitalWrite(8,LOW) ;
}
d’autre
{
Serial.println("no") ;
digitalWrite(8,LOW) ;
}
}
int lev0 = analogRead(A1) ;
int lev1 = analogRead(A2) ;
lev2 int = analogRead(A3) ;
mos int = analogRead(A4) ;
Serial.println(lev0) ;
Serial.println(Lev1) ;
Serial.println(Lev2) ;
Serial.println(MOS) ;
indicateur de niveau d’eau ***
Si ((lev0 < 1000) & & (lev1 < 1000) & & (lev2 < 1000))
{
Serial.println (« niveau d’eau complet") ;
Lev = 51 ;
}
sinon si ((lev0 < 1000) & & (lev1 < 1000))
{
Serial.println (« niveau 2 ») ;
Lev = 50 ;
}
ElseIf (lev0 < 1000)
{
Serial.println ("niveau 1") ;
Lev = 49 ;
}
d’autre
{
Serial.println ("pas d’eau") ;
Lev = 48 ;
}
/ *** valeur d’humidité *** /
if(MOS > 1005)
{
Serial.Print ("mos sans eau") ;
m = 48 ;
}
d’autre if(mos >990)
{
Serial.Print ("champ partiellement humide") ;
m = 49 ;
}
ElseIf (mos > 980)
{
Serial.Print ("champ humide") ;
m = 50 ;
}
ElseIf (mos > 960)
{
Serial.Print ("suffisamment d’eau") ;
m = 51 ;
}
d’autre
{
Serial.Print ("débordement") ;
m = 52 ;
}
Rxbee.Write(Pump) ;
Rxbee.Write(Lev) ;
Rxbee.Write(m) ;
Delay(10) ;
}