Vous êtes sur la page 1sur 8

APPENDICES A

61
APPENDICES B

62
63
APPENDICES D

64
APPENDICES E

SOURCE CODE

Code of watering system

#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27,16,2);

int WATERPUMP = 5; //motor pump connected to pin 13

int sensor = A0; //sensor digital pin vonnected to pin 8

int val; //This variable stores the value received from Soil moisture sensor.

void setup() {

lcd.backlight();

Serial.begin(9600);

lcd.begin();

lcd.setCursor(0, 0);

lcd.print("Automatic Plant");

lcd.setCursor(0, 1);

lcd.print("Watering System");

delay(4000);

lcd.clear();

lcd.setCursor(0, 0);

lcd.print("Calibrating");

for (int i = 0; i < 10; i++) {

if (i == 4)

65
lcd.setCursor(0, 1);

lcd.print(".");

else lcd.print(".");

delay(200);

lcd.setCursor(5, 1);

lcd.print("done");

delay(1000);

lcd.clear();

lcd.setCursor(1, 0);

lcd.print("SENSOR ACTIVE");

delay(1500);

pinMode(5,OUTPUT); //Set pin 13 as OUTPUT pin

pinMode(A0,INPUT); //Set pin 8 as input pin, to receive data from Soil moisture sensor.

//Initialize serial and wait for port to open:

Serial.begin(9600); // opens serial port, sets data rate to 9600 bps

while (! Serial);// wait for serial port to connect. Needed for native USB

Serial.println("Speed 0 to 255");

66
void loop()

if (Serial.available()) //loop to operate motor

int speed = Serial.parseInt(); // to read the number entered as text in the Serial Monitor

if (speed >= 0 && speed <= 255)

analogWrite(WATERPUMP, speed);// tuns on the motor at specified speed

val = digitalRead(A0); //Read data from soil moisture sensor

if(val == LOW)

digitalWrite(5, LOW); //if soil moisture sensor provides LOW value send LOW value to

motor pump and motor pump goes off

lcd.setCursor(0,0);

lcd.print("Water Pump: OFF");

lcd.setCursor(0,1);

lcd.print("MOISTURE: WET");

delay(3000);

else

67
digitalWrite(5, HIGH); //if soil moisture sensor provides HIGH value send HIGH value

to motor pump and motor pump get on

lcd.setCursor(0,0);

lcd.print("Water Pump: ON ");

lcd.setCursor(0,1);

lcd.print("MOISTURE: DRY");

delay(3000);

delay(400); //Wait for few second and then continue the loop.

68

Vous aimerez peut-être aussi