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

Arduino 101-Based Obstacle Avoidance Robot with Ultrasonic Sensor and Bluetooth Control

View and Edit Project In Cirkit DesignerImage of Arduino 101-Based Obstacle Avoidance Robot with Ultrasonic Sensor and Bluetooth Control

Circuit Documentation

Summary

This document provides a detailed overview of a circuit that includes an Arduino 101 microcontroller, an HC-SR04 Ultrasonic Sensor, a TSOP312 IR Receiver, a Micro Servo 9G, a Bluetooth HC-06 module, an L293D motor driver, multiple Hobby Gearmotors, a TP4056 battery charger, a set battery (7V), and a solar cell. The circuit is designed to control motors and servos, receive IR signals, and communicate via Bluetooth. It also includes a solar charging system for the battery.

Component List

HC-SR04 Ultrasonic Sensor

Arduino 101

L293D

Hobby Gearmotor with 48:1 gearbox

Solar cell

TP4056

Set battery (7V)

Bluetooth HC-06

TSOP312 IR Receiver

Micro Servo 9G

Wiring Details

HC-SR04 Ultrasonic Sensor

Arduino 101

L293D

Hobby Gearmotor with 48:1 gearbox

Solar cell

TP4056

Set battery (7V)

Bluetooth HC-06

TSOP312 IR Receiver

Micro Servo 9G

Code Documentation

Arduino 101 Code

#include <AFMotor.h>
#include <IRremote.h>
#include <Servo.h>

// Pin definitions
#define IN1 5
#define IN2 6
#define IN3 9
#define IN4 10
#define ENA 3
#define ENB 11

// Motor speed
int speed = 255;  // Max speed

// Ultrasonic sensor pins
#define TRIG_PIN 3
#define ECHO_PIN 4

// Servo pin
Servo myservo;
#define SERVO_PIN 7

// IR Remote Pin
#define RECV_PIN 2

// IR receiver object
IRrecv irrecv(RECV_PIN);
decode_results results;

// Motor initialization
AF_DCMotor motor1(1);
AF_DCMotor motor2(2);
AF_DCMotor motor3(3);
AF_DCMotor motor4(4);

void setup() {
  // Serial monitor for debugging
  Serial.begin(9600);

  // Motor initialization
  motor1.setSpeed(speed);
  motor2.setSpeed(speed);
  motor3.setSpeed(speed);
  motor4.setSpeed(speed);

  // Set motor driver pins as outputs
  pinMode(IN1, OUTPUT);
  pinMode(IN2, OUTPUT);
  pinMode(IN3, OUTPUT);
  pinMode(IN4, OUTPUT);
  pinMode(ENA, OUTPUT);
  pinMode(ENB, OUTPUT);

  // Initialize the IR receiver
  irrecv.enableIRIn();

  // Initialize ultrasonic sensor
  pinMode(TRIG_PIN, OUTPUT);
  pinMode(ECHO_PIN, INPUT);

  // Initialize servo motor
  myservo.attach(SERVO_PIN);
}

void loop() {
  // Check for incoming IR signals
  if (irrecv.decode(&results)) {
    long int decCode = results.value;
    Serial.println(decCode);

    // Example: Control motors with IR remote
    if (decCode == 0xFF02FD) { // Forward
      moveForward();
    }
    else if (decCode == 0xFF03FC) { // Backward
      moveBackward();
    }
    else if (decCode == 0xFF01FE) { // Turn Left
      turnLeft();
    }
    else if (decCode == 0xFF08F7) { // Turn Right
      turnRight();
    }
    else if (decCode == 0xFF09F6) { // Stop
      stopMotors();
    }

    irrecv.resume();  // Receive the next value
  }

  // Obstacle avoidance using the servo-controlled ultrasonic sensor
  scanForObstacles();
}

// Motor Control Functions
void moveForward() {
  digitalWrite(IN1, HIGH);
  digitalWrite(IN2, LOW);
  digitalWrite(IN3, HIGH);
  digitalWrite(IN4, LOW);
  motor1.run(FORWARD);
  motor2.run(FORWARD);
  motor3.run(FORWARD);
  motor4.run(FORWARD);
}

void moveBackward() {
  digitalWrite(IN1, LOW);
  digitalWrite(IN2, HIGH);
  digitalWrite(IN3, LOW);
  digitalWrite(IN4, HIGH);
  motor1.run(BACKWARD);
  motor2.run(BACKWARD);
  motor3.run(BACKWARD);
  motor4.run(BACKWARD);
}

void turnLeft() {
  digitalWrite(IN1, LOW);
  digitalWrite(IN2, HIGH);
  digitalWrite(IN3,