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

https://os.mbed.com/media/uploads/johnnykang0905/partslist_7mwOj5D.png


System Block Diagram

https://os.mbed.com/media/uploads/johnnykang0905/diagram.png


Wiring
MbedH-BridgeDC Motor(2x)External Power(Battery Pack)-6V
GNDGND-GND
p26PWMA--
p5AIN1--
p6AIN2--
p25PWMB--
p8BIN1--
p7BIN2--
VU(5V)STBY--
-VMOT-V+
-A01LEFT(RED)-
-A02LEFT(BLACK)-
-B01Right(RED)-
-B02Right(Black)-
MbedBluetooth ModuleExternal Power(Battery Pack)-6V
-VINV+
GNDGNDGND
-CTSGND
p28RXI(Serial Rx)-
p27TXD(Serial Tx)-
ncRTS-
MbedSpeakerBJT
Vout or VU(5V)V+-
-V-C
p21-B
GND-E
MbedIR sensor
VU(5V)VIN
GNDGND
p13-
p14IR_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

https://os.mbed.com/media/uploads/johnnykang0905/final_assembled_robot.jpg
Final Assembled Robot


https://os.mbed.com/media/uploads/johnnykang0905/close-up_of_motor_protoboard.jpg
Close-up of Motor Protoboard


https://os.mbed.com/media/uploads/johnnykang0905/close-up_of_bluetooth_protoboard.jpg
Close-up of Bluetooth Protoboard


Videos


IR Bot Functionality



IR Bot Demo


Final Project Presentation Video


Please log in to post comments.