Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino Nano Controlled Robotic Cleaner with Ultrasonic Sensors and I2C LCD Interface

View and Edit Project In Cirkit DesignerImage of Arduino Nano Controlled Robotic Cleaner with Ultrasonic Sensors and I2C LCD Interface

Circuit Documentation

Summary

The circuit in question is designed to control a robotic cleaning system equipped with various sensors and actuators. It includes a central Arduino Nano microcontroller that interfaces with ultrasonic sensors for navigation, a dust sensor for detecting cleanliness, a water level sensor for monitoring water supply during wet cleaning, and a motor driver to control the movement of the robot. The system can operate in both wet and dry cleaning modes, with an I2C LCD screen providing user feedback and mode selection.

Component List

Wiring Details

Battery 12V

Motor and Wheels

5V Mini Water Pump

Water Level Sensor

Dust Sensor

HC-SR04 Ultrasonic Sensor

L293D Motor Driver

Arduino Nano

LCD Screen 16x2 I2C

Documented Code

#include <NewPing.h>    // Import libraries for ultrasonic sensors
#include <LiquidCrystal_I2C.h>     // I2C LCD library
#include <Wire.h>                 // I2C library

// Initialize pin numbers for ultrasonic sensors
const int echo_L = 2;
const int trig_L = 3;
const int echo_M = 4;
const int trig_M = 5;
const int echo_R = 7;
const int trig_R = 8;

// Initialize pin numbers for motor control
const int L1 = 6;
const int L2 = 9;
const int R1 = 10;
const int R2 = 11;

// Pump control for wet cleaning
const int pump = 13;

// Additional sensor for crack detection
const int echo_Crack = A0;
const int trig_Crack = A1;

// SDS011 dust sensor pin
const int dustSensorPin = A2; // Dust sensor

// Water level sensor pin
const int waterLevelPin = A3;
const int waterLevelThreshold = 200; // Threshold for low water level

int motor_speed = 255;    // Speed of the motor can be set between 125 (minimum) and 255 (maximum)
int max_distance = 200;   // Max distance of ultrasonic sensors is set to 200cm

// Distance readings for sensors
int distance_L = 0;
int distance_M = 0;
int distance_R = 0;
int distance_Crack = 0;

bool isWetCleaning = false;  // Boolean flag for mode selection
bool isWaterLow = false;     // Boolean flag for low water level detection
unsigned long lastPumpTime = 0; // Timer to control pump intervals

// Initialize all the ultrasonic sensors
NewPing sonar_L(trig_L, echo_L, max_distance);
NewPing sonar_M(trig_M, echo_M, max_distance);
NewPing sonar_R(trig_R, echo_R, max_distance);
NewPing sonar_Crack(trig_Crack, echo_Crack, max_distance);  // Crack detection sensor

// Initialize I2C LCD with address 0x27 and display size of 16x2
LiquidCrystal_I2C lcd(0x27, 16, 2);  // I2C address for LCD, update if necessary

void setup() {
  // Initialize pins as output or input
  pinMode(L1, OUTPUT);
  pinMode(L2, OUTPUT);
  pinMode(R1, OUTPUT);
  pinMode(R2, OUTPUT);
  pinMode(pump, OUTPUT);

  // Set all motor control pins to LOW initially
  digitalWrite(L1, LOW);
  digitalWrite(L2, LOW);
  digitalWrite(R1, LOW);
  digitalWrite(R2, LOW);
  digitalWrite(pump, LOW); // Water pump is initially set to LOW

  lcd.begin(16, 2); // LCD setup
  lcd.print("Choose Mode");
  Serial.begin(9600);   // Begin serial communication at 9600 baud rate
  delay(2000);
}

void loop() {
  // Mode Selection - Dry or Wet
  if (Serial.available() > 0) {
    char mode = Serial.read();
    if (mode == '1') {
      isWetCleaning = false;  // Dry cleaning mode
      lcd.clear();
      lcd.print("Dry Cleaning");
    } else if (mode == '2') {
      isWetCleaning = true;  // Wet cleaning mode
      lcd.clear();
      lcd.print("Wet Cleaning");
    }
    delay(1000);
  }

  // Read distance from all the sensors
  distance_L = readSensor_L();
  distance_M = readSensor_M();
  distance_R = readSensor_R();
  distance_Crack = readSensor_Crack(); // Read surface crack distance

  // Check for surface cracks
  if (distance_Crack <= 10) {  // Assuming a crack is detected if the distance is less than 10 cm
    displayDistances();        // Display all distances on the LCD
    delay(2000);               // Delay for observation
  }

  // Robot movement logic
  if (distance_M <= 20) {    // If middle sensor distance is less than 20cm
    if (distance_R > distance_L) {   // Check if there is space at right or left
      if ((distance_R <= 20) && (distance_L <= 20)) {    // If there is no space on both sides
        moveStop();
        delay(200);
        moveBackward();   // Move back
        delay(2000);
      } else {
        moveBackward();  // Move back then turn right
        delay(500);
        moveRight();
        delay(2000);
      }
    } else if (distance_R < distance_L) {
      if ((distance_R <= 20) && (distance_L <= 20)) {
        moveStop();   // Move back
        delay(200);
        moveBackward();
        delay(2000);
      } else {
        moveBackward();   // Move back then turn left
        delay(500);
        moveLeft();
        delay(2000);
      }
    }
  } else if (distance_R <= 15) {    // If right sensor distance is less than 20cm
    moveLeft();   // Turn left
    delay(500);
  } else if (distance_L <= 15) {    // If left sensor distance is less than 20cm
    moveRight();    // Turn right
    delay(500);
  } else {
    moveForward();