Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe

Wireless PC Controlled Robot Using Bluetooth

By Ganesh Selvaraj August 13, 2013

 

 

In the previous tutorial I have explained how to setup a basic serial connection between an Atmega16 controller Board and a computer/laptop. In this article we’ll learn how to control a robot using the computer/laptop wirelessly through Bluetooth.

Components Required

          1. Atmega16 development board with 16MHz crystal

          2. Serial Bluetooth Module(AUBTM/HC-05/HC-04/BLUSMIRF)

}         3. PC/Laptop running Windows XP/7/8

}         4. USB Bluetooth(Not required if you laptop/PC has inbuilt hardware)

}         5. Motor Driver L293D

}         6. 2 X 12V 100RPM Geared DC motors

          7. 2 X Wheels

          8. Chassis

          9. Castor wheel

        10. Female jumper wires

Software Required

Serial Port Software on your PC (RealTerm/HyperTerminal/TeraTerm/Putty/ Your own Program)

Block-Diagram

Wireless Robot

Mechanical Construction:

 

Wireless PC Controlled Robot Using Bluetooth

 

Let us start with the hardware assembly part first. It should be simple since we are using a ready-made chassis. Start by attaching the motors and castor wheel to the chassis.

Wireless PC Controlled Robot Using Bluetooth

Next attach the wheels to the motor shafts using the screw provided on the wheel.

Wireless PC Controlled Robot Using Bluetooth

 

Wireless PC Controlled Robot Using Bluetooth

Connect the wires emerging from the two motors to the output pins of the L293D motor driver.

Wireless PC Controlled Robot Using Bluetooth

 

 After all connections are made, this is how it looks.

Wireless PC Controlled Robot Using Bluetooth

Remember: RX (PIN 14) of controller to TX of modem and TX (PIN 15) of controller to RX of modem.

 

Code and Set up Instruction

Code Explanation:

Let us start from the main function.

 ·Lower nibble of PORT A connected to motor driver are configured as outputs.

 ·USART of the microcontroller is initialized using the BlueInit() function which sets the baud rate, configures the character sizes and enables     the transmission and reception.

 ·Enter into an infinite while loop.

 · Read a byte from the RX line using the “BlueRdChar()” function(waits for a data to be available at the RX pin of the controller, reads it when      available and then returns the data which was read to the main function. Note that it is of “unsigned integer” type so it returns an ASCII code    value of the character sent) and store it in a variable named “value” which is of type “unsigned char”.

 · Write the same data which was stored in the variable “value” into the UDR and send it to the PC through the TX line of the microcontroller        using “BlueWrChar(unsigned char d)”  function (which waits until the UDR is ready and when it is, it loads the UDR with the data stored in        the variable “d” and then the data is sent to the PC through the TX pin of the controller.)

 · Check the character present in the variable “value”

   If it contains ‘w’ or ‘W’, set the output port such that both motors move forward.

   If it contains ‘s’ or ‘S’ , set the output port such that both motors move backward.

   If it contains ‘d’ or ‘D’ , set the output port such that left motor moves forward and right motor remains at rest.

   If it contains ‘a’ or ‘A’, set the output port such that right motor moves forward and left motor remains at rest.

   If it contains a <space> then set the output port such that both the motors stop.

Setup Instructions:

       1. You can either compile the code given using a suitable compiler like WINAVR with ATMEL STUDIO/AVR STUDIO or simply burn the “demo.hex” file give below. Before burning the hex file into you microcontroller, remember to change you Fuse bit Settings in order to make your microcontroller run at 16MHz using external crystal.

High fuse=0xC9

Low fuse=0xFF

(Warning: Be very careful while programming the fuse bits. If you set it with wrong values then the microcontroller may be permanently disabled.)

        2. Turn on the Bluetooth on your computer and also the circuit setup. Wait for few seconds to let the computer connect to your Development board’s Bluetooth device (Refer the previous tutorial if you are establishing a connection for the first time.)

       3. Open the serial communication software in your PC/Laptop i.e. RealTerm/HyperTerminal.

Note: I’m using my own software.                        

 4. If you are using RealTerm then go to the Port Tab and set it as follows.

Baud: 9600

Port: <The port where the Serial Bluetooth Modem is virtually connected to>

Data bits: 8

Parity: None

Stop bits: 1

Hardware Flow Control: None

       5.  Now try to send some characters. If you have done everything correctly then you should see the following happening:

Character Sent

Robot’s Motion

Message on the REALTERM Display

‘W’ or ‘w’

Forward

ROBOT MOVING FORWARD

‘D’ or ‘d’

Right turn

ROBOT MOVING RIGHT

‘S’ or ‘s’

Reverse

ROBOT MOVING REVERSE

‘A’ or ‘a’

Left turn

ROBOT MOVING LEFT

<spacebar>

Stop

ROBOT HAS STOPPED

Any other key

No change

COMMAND NOT FOUND

Note: If there is an error in the Robot’s motion, i.e. say the robot moves in reverse direction when we press ‘w’ key instead of moving forward then don’t worry. It’s just because of the wrong connections between the motor driver and Development Board. Just inter change those connections and check again.

 

 

Project Source Code

###


/*
 * BluePCRobo.c
 *
 * Created: 7/2/2013 6:02:08 AM
 * Author: GANESH SELVARAJ
 */ 
 
 
 
 
#define F_CPU 16000000UL
 
#define USART_BAUDRATE 9600
#define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 16UL))) - 1)
 
#include<avr/io.h>
#include<util/delay.h>
 
 
void BlueInit()
{
UCSRB |= (1 << RXEN) | (1 << TXEN);   // Enable transmission and reception
 
UCSRC |= (1 << URSEL) | (1<<USBS) | (1 << UCSZ0) | (1 << UCSZ1);
// Use 8-bit character sizes
 
UBRRL = BAUD_PRESCALE;
 
UBRRH = (BAUD_PRESCALE >> 8);
 
}
 
void BlueWrChar(unsigned char d)
{
while ((UCSRA & (1 << UDRE)) == 0); // wait till UDR is ready
 
UDR = d; // send data
}
 
unsigned int BlueRdChar()
{
while ((UCSRA & (1 << RXC)) == 0); // wait until data has been received
 
return(UDR); // return the byte
}
 
void BlueWrString(const char *msg)
{
 
 BlueWrChar('r');
 BlueWrChar('n');
 while(*msg!='')
 {
BlueWrChar(*msg);
msg++;
 }
 BlueWrChar('r');
 BlueWrChar('n');
}
 
 
 
int main()
{
unsigned char value;
 
DDRA=0x0F;
 
_delay_ms(50); // delay of 50 mili seconds
BlueInit(); // initialization of USART
while(1)
{
value=BlueRdChar(); // get data from serial port
 
BlueWrChar(value); // send the same data back to the PC
if (value=='w' || value=='W')
{
PORTA=0x09;
BlueWrString("ROBOT MOVING FORWARD");
}
else if (value=='s' || value=='S')
{
PORTA=0x06;
BlueWrString("ROBOT MOVING REVERSE");
}
else if (value=='d' || value=='D')
{
PORTA=0x01;
BlueWrString("ROBOT MOVING RIGHT");
}
else if (value=='a' || value=='A')
{
PORTA=0x08;
BlueWrString("ROBOT MOVING LEFT");
}
else if (value==' ')
{
PORTA=0x00;
BlueWrString("ROBOT HAS STOPPED");
}
else
{
BlueWrString("COMMAND NOT FOUND");
}
 
}
return 0;
}
 
 
 
 

###

 


Circuit Diagrams

CIRCUIT-DIAGRAM_1

Project Video


Filed Under: Electronic Projects
Tagged With: bluetooth, PC, robot, wireless
 

Next Article

← Previous Article
Next Article →

Questions related to this article?
👉Ask and discuss on Electro-Tech-Online.com and EDAboard.com forums.



Tell Us What You Think!! Cancel reply

You must be logged in to post a comment.

EE TECH TOOLBOX

“ee
Tech Toolbox: 5G Technology
This Tech Toolbox covers the basics of 5G technology plus a story about how engineers designed and built a prototype DSL router mostly from old cellphone parts. Download this first 5G/wired/wireless communications Tech Toolbox to learn more!

EE Learning Center

EE Learning Center
“engineers
EXPAND YOUR KNOWLEDGE AND STAY CONNECTED
Get the latest info on technologies, tools and strategies for EE professionals.

HAVE A QUESTION?

Have a technical question about an article or other engineering questions? Check out our engineering forums EDABoard.com and Electro-Tech-Online.com where you can get those questions asked and answered by your peers!


RSS EDABOARD.com Discussions

  • Diode recovery test Irrm timing.
  • How to make string LEDs?
  • The Analog Gods Hate Me
  • Battery Deep Discharge – IC Workarounds?
  • Safe Current and Power Density Limits in PCB Copper(in A/m² and W/m³) simulation

RSS Electro-Tech-Online.com Discussions

  • Raise your hand if your car had one of these:
  • Tektronix 2235 channel 1 trace unstable
  • How to make string LEDs?
  • Wideband matching an electrically short bowtie antenna; 50 ohm, 434 MHz
  • The Analog Gods Hate Me

Featured – LoRa/LoRaWan Series

  • What is the LoRaWAN network and how does it work?
  • Understanding LoRa architecture: nodes, gateways, and servers
  • Revolutionizing RF: LoRa applications and advantages
  • How to build a LoRa gateway using Raspberry Pi
  • How LoRa enables long-range communication
  • How communication works between two LoRa end-node devices

Recent Articles

  • Tria modules integrate edge AI processing with multi-core processors
  • pSemi introduces RF switch with 52 dBm PMAX,PEAK and 90-dBm IIP3 linearity
  • XP Power launches 1.3 kW power supply with 58.9 W/cm³ density
  • How to enable Wi-Fi provisioning in ESP32-based IoT products
  • Amphenol RF introduces FAKRA to SMA adapters with 4 GHz operating frequency

EE ENGINEERING TRAINING DAYS

engineering

Submit a Guest Post

submit a guest post
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • Battery Power Tips
  • DesignFast
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • EV Engineering
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • Subscribe to our newsletter
  • About Us
  • Contact Us
  • Advertise

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy

Search Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe