0% found this document useful (0 votes)
16 views3 pages

FINAL2

The document contains code for an Arduino project that measures temperature, humidity, soil moisture, and water level using various sensors. It displays the sensor readings on an LCD screen and controls LEDs and a buzzer based on the water level.

Uploaded by

rania.belk5
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views3 pages

FINAL2

The document contains code for an Arduino project that measures temperature, humidity, soil moisture, and water level using various sensors. It displays the sensor readings on an LCD screen and controls LEDs and a buzzer based on the water level.

Uploaded by

rania.belk5
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

// DHT && temperature

#include <OneWire.h>
#include <DallasTemperature.h>
#include <DHT.h>
#define DHT11_PIN 7 // DHT11 data pin connected to Arduino pin 7
#define DHTTYPE DHT11 // DHT sensor type

DHT dht(DHT11_PIN, DHTTYPE);


#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
const int analogInPin = A0;
int sensorValue = 0;
float temperature = 0.0;
float humidity = 0.0;
// LCD
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);

#define ledGPin 3
#define ledBPin 4
#define ledRPin 5
#define BuzzerPin 6

bool Start = true;

void start() {
lcd.setCursor(0, 0);
lcd.print(" SMART IRRIGATION SYSTEM ON ");
lcd.setCursor(0, 1);
lcd.print("");
for (int positionCounter = 0; positionCounter < 17; positionCounter++) {
lcd.scrollDisplayLeft(); // scroll one position left:
delay(700); // wait a bit
}
}

void setup() {
pinMode(ledGPin, OUTPUT);
pinMode(ledBPin, OUTPUT);
pinMode(ledRPin, OUTPUT);
pinMode(BuzzerPin, OUTPUT);
sensors.begin(); // Start up the library
Serial.begin(9600);
lcd.init(); //set lcd i2c
lcd.begin(16, 2); //set lcd i2c
lcd.backlight();
start();
lcd.clear();
dht.begin(); // Initialize DHT sensor
}
void loop() {
if(Start){
float temperature = dht.readTemperature(); // Read temperature
float humidity = dht.readHumidity(); // Read humidity

if (isnan(temperature) || isnan(humidity)) {
Serial.println("DHT sensor reading failure");
} else {
lcd.setCursor(0, 0);
lcd.print("Temp: ");
lcd.print(temperature, 1);
lcd.print("C");

lcd.setCursor(0, 1);
lcd.print("Humidity: ");
lcd.print(humidity, 1);
lcd.print("%");
delay(2000);
lcd.clear();
}
Start=!Start;
delay(2000); // Delay to avoid overloading the DHT sensor
}
sensorValue = analogRead(A0);
lcd.setCursor(9, 0);
lcd.print("Val:");
lcd.print(sensorValue);
lcd.setCursor(9, 1);
lcd.print("WL:");
if (sensorValue == 0) {
digitalWrite(ledGPin, LOW);
digitalWrite(BuzzerPin, LOW);
digitalWrite(ledRPin, LOW);
digitalWrite(ledBPin, LOW);
lcd.print("EMT");
} else if (sensorValue > 1 && sensorValue < 350) {
digitalWrite(ledRPin, HIGH);
digitalWrite(BuzzerPin, HIGH);
digitalWrite(ledGPin, LOW);
digitalWrite(ledBPin, LOW);
lcd.print("LOW");
} else if (sensorValue > 350 && sensorValue < 400) {
digitalWrite(ledBPin, HIGH);
digitalWrite(BuzzerPin, LOW);
digitalWrite(ledGPin, LOW);
digitalWrite(ledRPin, LOW);
lcd.print("MED");
} else if (sensorValue > 400) {
digitalWrite(ledGPin, HIGH);
digitalWrite(ledBPin, LOW);
digitalWrite(ledRPin, LOW);
digitalWrite(BuzzerPin, LOW);
tone(BuzzerPin,500,300);
lcd.print("HIGH");
}
delay(100);
int value = analogRead(A1);
if (value < 300) {
lcd.setCursor(0, 1);
lcd.print("M:HIGH");
} else if (value > 300 && value < 460) {
lcd.setCursor(0, 1);
lcd.print("M:MED");
} else if (value > 460) {
lcd.setCursor(0, 1);
lcd.print("M:LOW");
}
// Send the command to get temperatures
sensors.requestTemperatures();
lcd.setCursor(0, 0);
lcd.print(sensors.getTempCByIndex(0));
lcd.print("C");
}

You might also like