•   about 7 years ago

Hardware Hack Submission - Philip Voronin, Rishabh Patel, Raki Jeyaraman

#include
#include
#include

Servo servo;
int pos = 0;

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

dht DHT;
#define DHT11_PIN 7

const int trigPin = 8;
const int echoPin = 10;

void setup() {
Serial.begin(9600);
lcd.begin(16, 2);
servo.attach(9);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}
long microsecondsToCentimeters(long microseconds) {
return microseconds / 29 / 2;
}

void loop() {
long duration, cm;
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(5);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
cm = microsecondsToCentimeters(duration);
double waterLevel = 16 - int(cm);
int check = DHT.read11(DHT11_PIN);
lcd.setCursor(0, 0);
lcd.print(DHT.temperature);
lcd.print((char)223);
lcd.print("C ");
lcd.print(DHT.humidity);
lcd.print("%");
lcd.setCursor(0, 1);
lcd.print("Water Level:");
lcd.print(waterLevel);

//Debugging--------------
if (waterLevel <= 9) {
lcd.setCursor(13, 1);
lcd.print(" ");
}
else {
delay(5);
}
//debugging -------------

Serial.print("Temperature: ");
Serial.println(DHT.temperature);
Serial.print("Humidity: ");
Serial.println(DHT.humidity);
Serial.print("Ping .cm: ");
Serial.println(waterLevel);

//if the humidity is below 80 and the temperature-
//is above 25, we need to water the plants
if (DHT.humidity <= 80) {
if (DHT.temperature >= 25) {
if (pos < 90) {
for (pos = 0; pos <= 90; pos += 1) {
servo.write(pos);
delay(10);
}
}
else {
delay(5);
}
check = DHT.read11(DHT11_PIN);
}
}
else {
pos = 0;
servo.write(pos);
}
delay(2000);
}

  • 0 comments

Comments are closed.