0% found this document useful (0 votes)
7 views

Assignment2

Uploaded by

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

Assignment2

Uploaded by

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

National University of Sciences & Technology

School of Electrical Engineering and Computer Science


Department of Computing

CS 335: Internet of Things


Fall 2022
Class: BESE-10AB

Assignment 02:
Arduino Programming

Announcement Date
27th November 2022

Due Date
th
5 December 2022 12 PM on LMS

Instructor: Dr. Rafia Mumtaz

Name: Altaf Ahmad


Reg #: 314472
Section: BESE-10 B
CLO-4: Apply the knowledge and skills acquired during the course to build and test a
working IoT system involving prototyping, programming and data analysis
Question 1 [20 marks]
Design and code the prototype for smart irrigation system using Tinkercad simulation tool.
In this task you must implement the following:
1. The prototype should sense the temperature and moisture of the soil and display it
on LCD screen.
2. Define certain conditions/ranges for temperature and moisture and based on the
ranges defined for these parameters, turn on/off the water pump. The status of
water pump should be display on the LCD.
3. Alerts should be generated in case of low moisture. Alerts can be demonstrated
using LEDs, buzzer, or displaying message on LCD.
Instructions :
i. Describe all the components required for the project and why you are using
them. If the specific component is not available in Tinkercad, you can use a
component that closely match your needs or assist you in demonstrating your
proof of concept. 5marks
ii. Draw a neat circuit diagram. 5marks
iii. Write a neat and clear code with comments. 5marks
Deliverable:

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

This is an individual assignment. No submission will be accepted


after the deadline.

Plagiarism will be dealt very strictly

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:

//Include the library for LCD


#include<LiquidCrystal.h>

int soilMoisture = 0; //Initial Moisture


int moisturePercentage = 0; //Initial Moisture Percentage
int temperature = 0; //Initial Temperature
LiquidCrystal lcd(11, 12, 3, 4, 5, 6); //Set LCD
int pump = 8; //Initialize the pin for water pump
int buzzer = 2; //Initialize the pin for buzzer

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 moisture is less than 15 %, then water pump


should turn on independent of temperature*/
if(moisturePercentage < 15) {
digitalWrite(pump, HIGH);
lcd.setCursor(0,1);
lcd.print("PUMP ON ");
tone(buzzer, 1000);
delay(2000);
noTone(buzzer);
}

/*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);
}

/*if temperature is less (< 25), then a moisture of


70% is enough*/
if(moisturePercentage >= 70 && temperature <= 25){
digitalWrite(pump, LOW);
lcd.setCursor(0,1);

5|Page
lcd.print("PUMP OFF");
}

/*if temperature is high (>42), then we do not let moisture Percent


go below 60.*/
if(moisturePercentage <=60 && temperature >= 42){
digitalWrite(pump, HIGH);
lcd.setCursor(0,1);
lcd.print("PUMP ON ");
tone(buzzer, 1000);
delay(2000);
noTone(buzzer);
}

/* 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

You might also like