Cirkit Designer Logo
Cirkit Designer
Your all-in-one circuit design IDE
Home / 
Project Documentation

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

Image 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

  • D1/TX: Connected to RXD of Bluetooth HC-06
  • D0/RX: Connected to TXD of Bluetooth HC-06
  • D3: Connected to input 2 of L293D Motor Driver
  • D4: Connected to input 3 of L293D Motor Driver
  • D10: Connected to ECHO of HC-SR04 Ultrasonic Sensor
  • D11/MOSI: Connected to TRIG of HC-SR04 Ultrasonic Sensor
  • D12/MISO: Connected to IN of Buzzer
  • GND: Connected to GND of Buzzer, LCD screen 16x2 I2C, Bluetooth HC-06, HC-SR04 Ultrasonic Sensor, and L293D Motor Driver
  • 5V: Connected to VCC of LCD screen 16x2 I2C, Bluetooth HC-06, HC-SR04 Ultrasonic Sensor, and vs of L293D Motor Driver
  • A5: Connected to SCL of LCD screen 16x2 I2C
  • A4: Connected to SDA of LCD screen 16x2 I2C

Bluetooth HC-06

  • RXD: Connected to D1/TX of Arduino Nano
  • TXD: Connected to D0/RX of Arduino Nano
  • GND: Connected to GND of Arduino Nano
  • VCC: Connected to 5V of Arduino Nano

LCD screen 16x2 I2C

  • SCL: Connected to A5 of Arduino Nano
  • SDA: Connected to A4 of Arduino Nano
  • VCC: Connected to 5V of Arduino Nano
  • GND: Connected to GND of Arduino Nano

Buzzer

  • IN: Connected to D12/MISO of Arduino Nano
  • GND: Connected to GND of Arduino Nano

HC-SR04 Ultrasonic Sensor

  • TRIG: Connected to D11/MOSI of Arduino Nano
  • ECHO: Connected to D10 of Arduino Nano
  • VCC: Connected to 5V of Arduino Nano
  • GND: Connected to GND of Arduino Nano

L293D Motor Driver

  • input 2: Connected to D3 of Arduino Nano
  • input 3: Connected to D4 of Arduino Nano
  • gnd: Connected to GND of Arduino Nano
  • vs: Connected to 5V of Arduino Nano
  • output 1: Connected to + of Electrolytic Capacitor and GND of Motor with Reducer
  • output 2: Connected to - of Electrolytic Capacitor and 3 - 6 VCC of Motor with Reducer
  • output 3: Connected to + of Electrolytic Capacitor and GND of Motor with Reducer
  • output 4: Connected to - of Electrolytic Capacitor and 3 - 6 VCC of Motor with Reducer

Motor with Reducer

  • GND: Connected to + of Electrolytic Capacitor and output 1 of L293D Motor Driver
  • 3 - 6 VCC: Connected to - of Electrolytic Capacitor and output 2 of L293D Motor Driver

Electrolytic Capacitor

  • +: Connected to GND of Motor with Reducer and output 1 of L293D Motor Driver
  • -: Connected to 3 - 6 VCC of Motor with Reducer and output 2 of L293D Motor Driver

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);