All programs
IoT - Lab Manual (Simplified) · BCS7O3 IoT (Arduino · C++)

Problem Statement Program 6

Develop a program to classify Dry and Wet Waste using Moisture Sensor.

To develop a Smart Waste Classification System using an Arduino Uno and a Moisture Sensor. The system automatically detects the moisture content of waste and classifies it as Wet Waste or Dry Waste. The classification result is displayed on an LCD, and a servo motor is used to sort the waste automatically.

Components Required Hardware

Arduino Uno Board – 1
Soil Moisture Sensor (or DHT22 as per kit) – 1
HC-SR04 Ultrasonic Sensor – 1
Servo Motor (SG90) – 1
16×2 LCD Display with I2C Module – 1
Breadboard – 1
Jumper Wires – As Required
USB Cable – 1
Arduino IDE Software

Procedure Step by step

Step 1:

Take an Arduino Uno board, Moisture Sensor, HC-SR04 Ultrasonic Sensor, Servo Motor, LCD Display, breadboard, jumper wires, and USB cable.

Step 2:

Connect the Arduino 5V pin to the breadboard positive rail and GND to the negative rail.

Step 3:

Connect the Moisture Sensor VCC to Arduino 5V.

Step 4:

Connect the Moisture Sensor GND to Arduino GND.

Step 5:

Connect the Moisture Sensor Analog Output to Arduino Analog Pin A0.

Step 6:

Connect the HC-SR04 VCC to Arduino 5V.

Step 7:

Connect the HC-SR04 GND to Arduino GND.

Step 8:

Connect the TRIG pin of the ultrasonic sensor to Digital Pin 9.

Step 9:

Connect the ECHO pin of the ultrasonic sensor to Digital Pin 10.

Step 10:

Connect the Servo Motor Signal wire to Digital Pin 11.

Step 11:

Connect the Servo Motor VCC to 5V and GND to Arduino GND.

Step 12:

Connect the 16×2 LCD (I2C)

SDA → Arduino SDA (A4)
SCL → Arduino SCL (A5)
VCC → 5V
GND → GND
Step 13:

Connect the Arduino Uno to the computer using a USB cable.

Step 14:

Open the Arduino IDE.

Step 15:

Select Tools → Board → Arduino Uno.

Step 16:

Select the correct COM Port.

Step 17:

Copy and paste the Arduino program.

Step 18:

Compile and upload the program.

Step 19:

Place a waste object near the ultrasonic sensor.

Step 20:

Observe the moisture value, LCD display, and servo motor movement for wet or dry waste classification.

Circuit Connection Wiring

Moisture Sensor VCC → Arduino 5V
Moisture Sensor GND → Arduino GND
Moisture Sensor AO → Arduino Analog Pin A0
HC-SR04 TRIG → Arduino Digital Pin 9
HC-SR04 ECHO → Arduino Digital Pin 10
HC-SR04 VCC → Arduino 5V
HC-SR04 GND → Arduino GND
Servo Signal → Arduino Digital Pin 11
Servo VCC → Arduino 5V
Servo GND → Arduino GND
LCD SDA → Arduino A4 (SDA)
LCD SCL → Arduino A5 (SCL)
LCD VCC → Arduino 5V
LCD GND → Arduino GND

Circuit Diagram 1 image

Download the clean, watermark-free circuit diagram — ₹1.00

Arduino Code (C++) Source

program6.cpp
#include <Servo.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

const int trigPin = 9;
const int echoPin = 10;
const int soilMoisturePin = A0;

Servo myservo;
LiquidCrystal_I2C lcd(0x27,16,2);

long duration;
int distance;

const int distanceThreshold = 100;
const int moistureThreshold = 500;

void setup()
{
  Serial.begin(9600);

  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);

  myservo.attach(11);

  lcd.init();
  lcd.backlight();
}

void loop()
{
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);

  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);

  digitalWrite(trigPin, LOW);

  duration = pulseIn(echoPin, HIGH);

  distance = duration * 0.034 / 2;

  int moistureValue = analogRead(soilMoisturePin);

  lcd.clear();

  lcd.setCursor(0,0);
  lcd.print("Moist:");
  lcd.print(moistureValue);

  if(distance > 0 && distance < distanceThreshold)
  {
    if(moistureValue > moistureThreshold)
    {
      myservo.write(0);

      lcd.setCursor(0,1);
      lcd.print("Wet Waste");

      Serial.println("Wet Waste");
    }
    else
    {
      myservo.write(90);

      lcd.setCursor(0,1);
      lcd.print("Dry Waste");

      Serial.println("Dry Waste");
    }
  }

  delay(1000);
}
Protected content · © VTU Developer · Unauthorised distribution is prohibited