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

Arduino Nano-Based Bluetooth-Controlled Robotic System with Ultrasonic Sensor and LCD Display

View and Edit Project In Cirkit DesignerImage of Arduino Nano-Based Bluetooth-Controlled Robotic System with Ultrasonic Sensor and LCD Display

Circuit Documentation

Summary

This circuit involves multiple Arduino Nano microcontrollers, a Bluetooth module, an LCD screen, a buzzer, an ultrasonic sensor, a motor driver, and motors with reducers. The circuit is designed to control a motor based on commands received via Bluetooth and display status messages on an LCD screen. Additionally, it uses an ultrasonic sensor to detect obstacles and stop the motor if an object is too close.

Component List

  1. Arduino Nano

    • Description: A small, complete, and breadboard-friendly board based on the ATmega328P.
    • Pins: D1/TX, D0/RX, RESET, GND, D2, D3, D4, D5, D6, D7, D8, D9, D10, D11/MOSI, D12/MISO, VIN, 5V, A7, A6, A5, A4, A3, A2, A1, A0, AREF, 3V3, D13/SCK
  2. Bluetooth HC-06

    • Description: A Bluetooth module for wireless communication.
    • Pins: VCC, GND, TXD, RXD
  3. LCD screen 16x2 I2C

    • Description: A 16x2 character LCD display with I2C interface.
    • Pins: SCL, SDA, VCC, GND
  4. Buzzer

    • Description: An electronic device that produces a sound.
    • Pins: GND, IN
  5. HC-SR04 Ultrasonic Sensor

    • Description: An ultrasonic sensor for distance measurement.
    • Pins: VCC, TRIG, ECHO, GND
  6. L293D Motor Driver

    • Description: A motor driver IC to control motors.
    • Pins: enable 1, input 1, output 1, gnd, output 2, input 2, vs, vss, input 4, output 4, output 3, input 3, enable 2
  7. Motor with Reducer

    • Description: A motor with a gear reducer.
    • Pins: 3 - 6 VCC, GND
  8. Electrolytic Capacitor

    • Description: A capacitor with a capacitance of 1 µF.
    • Pins: -, +

Wiring Details

Arduino Nano

Bluetooth HC-06

LCD screen 16x2 I2C

Buzzer

HC-SR04 Ultrasonic Sensor

L293D Motor Driver

Motor with Reducer

Electrolytic Capacitor

Code Documentation

Arduino Nano (Primary Controller)

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

// Initialize the LCD with the I2C address 0x27 and 16x2 display
LiquidCrystal_I2C lcd(0x27, 16, 2);

// Pin definitions
const int buzzerPin = 12; // Buzzer connected to D12/MISO
const int motorInput1 = 3; // Motor driver input 1 connected to D3
const int motorInput2 = 4; // Motor driver input 2 connected to D4
const int trigPin = 11; // Ultrasonic sensor TRIG connected to D11/MOSI
const int echoPin = 10; // Ultrasonic sensor ECHO connected to D10

// Distance threshold in centimeters
const int distanceThreshold = 20;

void setup() {
  // Initialize serial communication for Bluetooth
  Serial.begin(9600);

  // Initialize the LCD
  lcd.begin();
  lcd.backlight();
  lcd.setCursor(0, 0);
  lcd.print("Waiting for cmd");

  // Initialize pins
  pinMode(buzzerPin, OUTPUT);
  pinMode(motorInput1, OUTPUT);
  pinMode(motorInput2, OUTPUT);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
}

void loop() {
  // Check if data is available from Bluetooth
  if (Serial.available()) {
    char command = Serial.read();
    delay(10); // Debounce input

    // Process the received command
    switch (command) {
      case '1':
        // Turn on the buzzer
        digitalWrite(buzzerPin, HIGH);
        lcd.clear();
        lcd.setCursor(0, 1);
        lcd.print("Buzzer ON ");
        break;
      case '0':
        // Turn off the buzzer
        digitalWrite(buzzerPin, LOW);
        lcd.clear();
        lcd.setCursor(0, 1);
        lcd.print("Buzzer OFF");
        break;
      case 'F':
        // Move motor forward
        moveMotorForward();
        lcd.clear();
        lcd.setCursor(0, 1);
        lcd.print("Motor FWD ");
        break;
      case 'B':
        // Move motor backward
        moveMotorBackward();
        lcd.clear();
        lcd.setCursor(0, 1);
        lcd.print("Motor BWD ");
        break;
      case 'S':
        // Stop motor
        stopMotor();
        lcd.clear();
        lcd.setCursor(0, 1);
        lcd.print("Motor STOP");
        break;
      default:
        lcd.clear();
        lcd.setCursor(0, 1);
        lcd.print("Invalid cmd");
        break;
    }
  }

  // Check the distance to the nearest object
  int distance = measureDistance();
  if (distance < distanceThreshold) {
    // Stop the motor if the object is too close
    stopMotor();
    lcd.clear();
    lcd.setCursor(0, 1);
    lcd.print("Object Detected");
  }
}

int measureDistance() {
  // Send a 10us pulse to trigger the ultrasonic sensor
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);