ECE 4180 Final Project
IR Bot -IR Sensing Robot
Kartavya Agarwal, Christopher Hooper, Moongyu Kang, Eduard Shuvaev
The IR Bot project is to build an IR sensing robot to play a simple game with an IR remote or any other IR emitter, where one player targets the robot with an IR emitter and the other controls the robot and tries to prevent the robot from getting hit by the IR emitter.
The robot is built using a shadow robot kit and is able to be controlled through a Bluetooth connection using the Adafruit Bluefruit app. The Bluetooth module is placed on the Robot to receive the signal from a smartphone in order to control the Robot movements. The user can control the robot by using the arrow keys in the Adafruit Bluefruit app. The IR sensor (receiver) is placed towards one of the sides of the Robot and constantly searches for an IR signal. When the IR sensor detects an IR signal the mbed generates a PWM signal to play a tone on the speaker using a BJT. Also, the received IR signal immobilizes the robot and the user temporarily loses control on the robot.
Parts List

System Block Diagram

Wiring
| Mbed | H-Bridge | DC Motor(2x) | External Power(Battery Pack)-6V |
|---|---|---|---|
| GND | GND | - | GND |
| p26 | PWMA | - | - |
| p5 | AIN1 | - | - |
| p6 | AIN2 | - | - |
| p25 | PWMB | - | - |
| p8 | BIN1 | - | - |
| p7 | BIN2 | - | - |
| VU(5V) | STBY | - | - |
| - | VMOT | - | V+ |
| - | A01 | LEFT(RED) | - |
| - | A02 | LEFT(BLACK) | - |
| - | B01 | Right(RED) | - |
| - | B02 | Right(Black) | - |
| Mbed | Bluetooth Module | External Power(Battery Pack)-6V |
|---|---|---|
| - | VIN | V+ |
| GND | GND | GND |
| - | CTS | GND |
| p28 | RXI(Serial Rx) | - |
| p27 | TXD(Serial Tx) | - |
| nc | RTS | - |
| Mbed | Speaker | BJT |
|---|---|---|
| Vout or VU(5V) | V+ | - |
| - | V- | C |
| p21 | - | B |
| GND | - | E |
| Mbed | IR sensor |
|---|---|
| VU(5V) | VIN |
| GND | GND |
| p13 | - |
| p14 | IR_RX |
Source Code
Since there are multiple hardware units being controlled simultaneously, a multi-threading approach using RTOS was used. To implement RTOS, the Mbed RTOS libraries were used to make the implementation easier. The following code was developed for this project:
main.cpp
#include "mbed.h"
#include "Motor.h"
#include "rtos.h"
int count = 0;
int status = 0;
Serial blue(p28,p27);
Motor m1(p25, p7, p8); // pwm, fwd, rev
Motor m2(p26, p5, p6); // pwm, fwd, rev
// IR reciever connected to pin 14
RawSerial device(p13, p14);
//speaker
PwmOut speaker (p21);
// LED inctating and testing functionality
DigitalOut myled1(LED1);
DigitalOut myled2(LED2);
DigitalOut myled3(LED3);
DigitalOut myled4(LED4);
// RC control using Bluetooth and BlueFruit App
void bluetooth_thread(void const *args)
{
while(1) {
char bnum=0;
char bhit=0;
if(status == 0)
{ if (blue.getc()=='!') {
if (blue.getc()=='B') { //button data packet
bnum = blue.getc(); //button number
bhit = blue.getc(); //1=hit, 0=release
if (blue.getc()==char(~('!' + 'B' + bnum + bhit))) { //checksum OK?
// for case 1 - 4 (button 1 - 4) could be added additional functionality
switch (bnum) {
case '5': //button 5 (FORWARD)
if (bhit=='1') {
m1.speed(0.5);
m2.speed(0.55);
} else {
m1.speed(0.0);
m2.speed(0.0);
}
break;
case '6': //button 6 (REVERSE)
if (bhit=='1') {
m1.speed(-0.5);
m2.speed(-0.54);
} else {
m1.speed(0.0);
m2.speed(0.0);
}
break;
case '7': //button 7 (LEFT)
if (bhit=='1') {
m1.speed(-0.5);
m2.speed(0.5);
} else {
m1.speed(0.0);
m2.speed(0.0);
}
break;
case '8': //button 8 (RIGHT)
if (bhit=='1') {
m1.speed(0.5);
m2.speed(-0.54);
} else {
m1.speed(0.0);
m2.speed(0.0);
}
break;
default:
break;
}
}
}
}
}
// LED 4 blinking to indicate that robot is shot and could not move
else if (status == 1)
{
myled4 = !myled4;
m1.speed(0.0);
m2.speed(0.0);
}
Thread::wait(200);
}
}
// play sound and blinking
void blink_sound(void const *args) {
while (1){
if (status == 1)
{
myled1 = !myled1;
speaker =0.9; //90% duty cycle - max volume
Thread::wait(700);
speaker=0.0; // turn off audio
}
Thread::wait(500);
}
}
int main()
{
Thread thread1(bluetooth_thread);
Thread thread2(blink_sound);
device.baud(2400);
speaker.period(1.0/350.0); // 350hz period
while(1) {
if(device.readable())
{
device.getc();
myled2 = 1;
status = 1;
wait(1);
myled2 = 0;
device.putc(0);
}
// after few cycles the robot rebooting
if(device.readable() == 0)
{
status = 0;
}
Thread::wait(100);
}
}
Import programIRBot_ECE4180FinalProject
Final Project
Photos

Final Assembled Robot

Close-up of Motor Protoboard

Close-up of Bluetooth Protoboard
Videos
IR Bot Functionality
IR Bot Demo
Final Project Presentation Video
Please log in to post comments.
