0% found this document useful (0 votes)
19 views15 pages

Dayyan Project

Uploaded by

hu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views15 pages

Dayyan Project

Uploaded by

hu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 15

Step 1: Understanding the Basic Components

1. Microcontroller: The brain of the robot, typically an Arduino, Raspberry Pi, or similar
device.
2. Motors and Motor Drivers: Used for movement, typically DC motors with motor
drivers like L298N.
3. Power Supply: Batteries to power the robot.
4. Sensors: Sensors are crucial for detecting and following the human. Commonly used
sensors include:
o Ultrasonic Sensors: Measure distance by sending and receiving sound waves.
o Infrared (IR) Sensors: Detect obstacles or track objects.
o LIDAR: For more advanced distance and object detection.
o Camera with Computer Vision: For more sophisticated tracking.
5. Transmitters and Receivers: Used for wireless communication between the robot and
external devices, or for processing sensor data.
o RF Modules: For basic remote control.
o Bluetooth: For communication with a smartphone.
o Wi-Fi: For more advanced communication and remote monitoring.
o Zigbee: For low-power, long-range communication.

Step 2: Design the Robot

1. Chassis Assembly: Mount the motors on the chassis and connect the wheels. Attach the
motor driver to the chassis.
2. Mount Sensors: Place the sensors at the appropriate locations. For example, ultrasonic
sensors should be placed at the front to detect obstacles and measure distance to the
human.
3. Microcontroller Setup: Mount the microcontroller on the chassis, ensuring that it's
securely attached. Connect the microcontroller to the motor driver, sensors, and any other
peripherals.

Step 3: Transmitter and Receiver Configuration

1. Using RF Modules (e.g., 433MHz Transmitter and Receiver):


o Transmitter: Sends control signals (like moving forward, backward, left, right)
to the robot.
o Receiver: Receives signals and passes them to the microcontroller.

Connections:

o Connect the transmitter to a control device (like another microcontroller or


remote).
o Connect the receiver to the microcontroller’s input pins
CODE:
#include <VirtualWire.h>

void setup() {

Serial.begin(9600);

vw_set_rx_pin(2); // Set pin 2 as the receiver input

vw_setup(2000); // Bits per second

vw_rx_start(); // Start the receiver PLL

void loop() {

uint8_t buf[VW_MAX_MESSAGE_LEN];

uint8_t buflen = VW_MAX_MESSAGE_LEN;

if (vw_get_message(buf, &buflen)) { // Non-blocking

int i;

for (i = 0; i < buflen; i++) {

Serial.print(buf[i]);

Serial.println("");

}
2) Using Bluetooth Modules (e.g., HC-05):

 Transmitter and Receiver: The Bluetooth module handles both transmitting and
receiving data.
 Use a smartphone app or another Bluetooth-enabled device to control the robot.

Connections:

 Connect the HC-05 module to the microcontroller (TXD to RX, RXD to TX).

Code Example:

#include <SoftwareSerial.h>

SoftwareSerial BTSerial(10, 11); // RX | TX

void setup() {

Serial.begin(9600);

BTSerial.begin(9600);

void loop() {

if (BTSerial.available()) {

char c = BTSerial.read();

Serial.write(c);

if (c == 'F') { // Move Forward

// Add code to move forward


} else if (c == 'B') { // Move Backward

// Add code to move backward

} else if (c == 'L') { // Turn Left

// Add code to turn left

} else if (c == 'R') { // Turn Right

// Add code to turn right

3) Using Wi-Fi Modules (e.g., ESP8266 or ESP32):

 Transmitter and Receiver: Both are integrated into the Wi-Fi module. The robot can be
controlled over the network.
 This allows for more complex operations, like streaming video from a camera, using
computer vision algorithms, or remote control via a web interface.

Connections:

 Connect the Wi-Fi module to the microcontroller. It can also function as the
microcontroller itself (ESP32).

Code Example:

#include <ESP8266WiFi.h>

const char* ssid = "your_SSID";

const char* password = "your_PASSWORD";

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

WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {

delay(1000);

Serial.println("Connecting...");

Serial.println("Connected");

void loop() {

// Code to send/receive data over Wi-Fi

Step 4: Programming the Robot for Human Following

1. Sensor Data Processing:


o Use the sensors to detect the distance and direction of the human.
o Process the data and decide the robot's movement (forward, backward, stop, turn).

Example with Ultrasonic Sensor:

CODE:

const int trigPin = 9;

const int echoPin = 10;


void setup() {

pinMode(trigPin, OUTPUT);

pinMode(echoPin, INPUT);

Serial.begin(9600);

void loop() {

long duration, distance;

digitalWrite(trigPin, LOW);

delayMicroseconds(2);

digitalWrite(trigPin, HIGH);

delayMicroseconds(10);

digitalWrite(trigPin, LOW);

duration = pulseIn(echoPin, HIGH);

distance = (duration * 0.034) / 2;

if (distance < 20) {

// Move forward

} else if (distance > 50) {

// Move backward

} else {
// Stop

3) Movement Control:

se the motor driver to control the motors based on sensor input:

const int motorPin1 = 3;

const int motorPin2 = 4;

const int enablePin = 5;

void setup() {

pinMode(motorPin1, OUTPUT);

pinMode(motorPin2, OUTPUT);

pinMode(enablePin, OUTPUT);

digitalWrite(enablePin, HIGH);

void loop() {

// Example to move forward

digitalWrite(motorPin1, HIGH);

digitalWrite(motorPin2, LOW);

}
2nd Method:

 Objective: Build a robot that can follow a human using an ultrasonic sensor for distance
measurement and a Bluetooth module for remote control via a smartphone.
 Components:
o Arduino Uno (or similar microcontroller)
o L298N Motor Driver Module
o DC Motors (with wheels)
o Ultrasonic Sensor (HC-SR04)
o Bluetooth Module (HC-05)
o Chassis
o 12V Battery Pack
o Jumper Wires

Step 1: Assemble the Hardware

1. Chassis Setup:
o Attach the DC motors to the chassis.
o Mount the wheels on the motors.
o Attach the motor driver module to the chassis.
2. Ultrasonic Sensor Placement:
o Place the HC-SR04 ultrasonic sensor at the front of the robot to measure the
distance from the human.
3. Arduino and Bluetooth Module:
o Mount the Arduino on the chassis.
o Attach the HC-05 Bluetooth module to the Arduino.
4. Connections:
o Motor Driver (L298N):
 IN1 to Arduino Pin 8
 IN2 to Arduino Pin 9
 IN3 to Arduino Pin 10
 IN4 to Arduino Pin 11
 ENA to Arduino Pin 5 (for speed control of motor 1)
 ENB to Arduino Pin 6 (for speed control of motor 2)
 OUT1 and OUT2 to one motor
 OUT3 and OUT4 to another motor
 Connect VCC and GND to the battery pack
o Ultrasonic Sensor (HC-SR04):
 VCC to Arduino 5V
 GND to Arduino GND
 Trig to Arduino Pin 7
 Echo to Arduino Pin 6
o Bluetooth Module (HC-05):
 VCC to Arduino 5V
 GND to Arduino GND
 TXD to Arduino Pin 2 (RX)
 RXD to Arduino Pin 3 (TX)

Step 2: Arduino Code

Below is the complete Arduino code for the human-following robot with Bluetooth control. The
code reads distance data from the ultrasonic sensor and commands the motors accordingly. The
Bluetooth module allows remote control via a smartphone.

CODE:

#include <AFMotor.h>

#include <NewPing.h>

#include <SoftwareSerial.h>

// Motor connections to the L298N

#define ENA 5

#define ENB 6

#define IN1 8

#define IN2 9

#define IN3 10

#define IN4 11

// Ultrasonic sensor pins

#define TRIG_PIN 7
#define ECHO_PIN 6

// Bluetooth module pins

#define RX_PIN 2

#define TX_PIN 3

#define MAX_DISTANCE 200 // Max distance for the ultrasonic sensor

SoftwareSerial BTSerial(RX_PIN, TX_PIN); // RX | TX

NewPing sonar(TRIG_PIN, ECHO_PIN, MAX_DISTANCE); //


Initialize ultrasonic sensor

void setup() {

pinMode(IN1, OUTPUT);

pinMode(IN2, OUTPUT);

pinMode(IN3, OUTPUT);

pinMode(IN4, OUTPUT);

pinMode(ENA, OUTPUT);

pinMode(ENB, OUTPUT);

Serial.begin(9600); // Initialize serial communication for debugging


BTSerial.begin(9600); // Initialize Bluetooth communication

void loop() {

long distance = sonar.ping_cm(); // Measure distance in cm

if (distance > 0 && distance < 30) {

moveForward(); // Move forward if the human is detected within 30


cm

} else if (distance > 30 && distance < 100) {

moveBackward(); // Move backward if the human is detected between


30 cm and 100 cm

} else {

stopMotors(); // Stop if no human is detected

if (BTSerial.available()) {

char command = BTSerial.read(); // Read the command from


Bluetooth

if (command == 'F') {

moveForward();

} else if (command == 'B') {


moveBackward();

} else if (command == 'L') {

turnLeft();

} else if (command == 'R') {

turnRight();

} else if (command == 'S') {

stopMotors();

// Functions to control the motors

void moveForward() {

digitalWrite(IN1, HIGH);

digitalWrite(IN2, LOW);

digitalWrite(IN3, HIGH);

digitalWrite(IN4, LOW);

analogWrite(ENA, 200); // Speed control

analogWrite(ENB, 200); // Speed control

}
void moveBackward() {

digitalWrite(IN1, LOW);

digitalWrite(IN2, HIGH);

digitalWrite(IN3, LOW);

digitalWrite(IN4, HIGH);

analogWrite(ENA, 200); // Speed control

analogWrite(ENB, 200); // Speed control

void turnLeft() {

digitalWrite(IN1, LOW);

digitalWrite(IN2, HIGH);

digitalWrite(IN3, HIGH);

digitalWrite(IN4, LOW);

analogWrite(ENA, 150); // Speed control

analogWrite(ENB, 150); // Speed control

void turnRight() {
digitalWrite(IN1, HIGH);

digitalWrite(IN2, LOW);

digitalWrite(IN3, LOW);

digitalWrite(IN4, HIGH);

analogWrite(ENA, 150); // Speed control

analogWrite(ENB, 150); // Speed control

void stopMotors() {

digitalWrite(IN1, LOW);

digitalWrite(IN2, LOW);

digitalWrite(IN3, LOW);

digitalWrite(IN4, LOW);

Step 3: Smartphone Control via Bluetooth

To control the robot using Bluetooth, you can use a Bluetooth terminal app available on Android
or iOS. You can send the following commands to the robot:

 F: Move Forward
 B: Move Backward
 L: Turn Left
 R: Turn Right
 S: Stop

You might also like