Assignment2
Assignment2
Assignment 02:
Arduino Programming
Announcement Date
27th November 2022
Due Date
th
5 December 2022 12 PM on LMS
i. Please submit the solution using this same MS word on LMS until 5th December 2022
12 PM afternoon.
ii. Please submit the printed version of the solved assignment on 5th December 2022 until
3 pm in office A-203 faculty block
2|Page
Components Required:
1. Arduino Uno R3: Arduino used for this system.
2. Breadboard: Breadboard used for making connections from Arduino to the
individual components used for this system.
3. Relay SPDT: The relay used for automatically turning the pump on or off.
4. LCD 16x2: The LCD used for displaying the values of moisture and temperature
and the status of the water pump.
5. Buzzer: The buzzer used to sound when moisture and temperature reach a critical
value.
6. DC Motor: DC Motor used instead of water pump due to unavailability. It
represents the water pump in a real scenario.
7. Soil Moisture Sensor: Used to measure the moisture in the soil.
8. Temperature Sensor (TMP36): Used to measure the temperature.
9. Wire and Resistors: Used for making connections between Arduino, breadboard
and components.
Description:
The system consists of a LCD which displays the values of moisture (in percentage), the
value of temperature (in Celsius) and the status of the water pump (On or Off). The
minimum value of moisture is 0% (0 being the lowest moisture, the sensor can measure)
and the maximum value of moisture is 100% (100 being the highest moisture, the sensor
can measure). The DC Motor (acting as a water pump) is connected to the Arduino using a
relay, so that it can turn on or off automatically depending on the sensor values. The buzzer
also turns on when the moisture is critically low (depending on temperature as well). A
temperature sensor and soil moisture sensor are used to calculate the values of the
moisture and temperature.
The critical values:
When the temperature is high (42 oC or higher), then the water pump turns on if the
moisture decreases to or below 60 %).
When the temperature is low (25 oC or lower), then the water pump turns on if the
moisture is 30 % or less.
When the temperature is low (25 oC or lower), if the moisture reaches a value of
70%, we turn off the water pump automatically.
If the moisture goes to 15% or below, we turn on the water pump independent of
the temperature value.
If the moisture goes to 90% or above, we turn off the water pump independent of
the temperature value.
Circuit Link:
https://www.tinkercad.com/things/gppgBQYRVf6
3|Page
Circuit Diagram:
Code:
void setup()
{
pinMode(pump,OUTPUT);
pinMode(buzzer, OUTPUT);
Serial.begin(9600);
lcd.begin(16,2);
lcd.setCursor(0,0);
lcd.print("M:");
lcd.setCursor(5,0);
4|Page
lcd.print("%");
lcd.setCursor(7,0);
lcd.print("T:");
lcd.setCursor(12,0);
lcd.print("C");
}
void loop()
{
soilMoisture = analogRead(A0); //Read moisture from sensor
//Convert the moisture value into percentage (0-100)%
moisturePercentage = map(soilMoisture, 0, 876, 0, 100);
lcd.setCursor(2,0);
lcd.print(moisturePercentage);
Serial.println(moisturePercentage);
//Read the temperature from temperature sensor and convert to Celsius
temperature = map(((analogRead(A1) - 20) * 3.04), 0, 1023, -40, 125);
lcd.setCursor(9,0);
lcd.print(temperature);
/*if temperature is less (< 25), then we can wait till moisture
to decrease to 30% and then turn on the water pump*/
if(moisturePercentage <= 30 && temperature <= 25){
digitalWrite(pump, HIGH);
lcd.setCursor(0,1);
lcd.print("PUMP ON ");
tone(buzzer, 1000);
delay(2000);
noTone(buzzer);
}
5|Page
lcd.print("PUMP OFF");
}
/* If moisture goes upto 90%, then we turn off the pump independent of
temperature
*/
if(moisturePercentage > 90) {
digitalWrite(pump, LOW);
lcd.setCursor(0,1);
lcd.print("PUMP OFF");
}
delay(1000);
}
6|Page