Project showcase
Bluetooth Controlled Vehicle

Bluetooth Controlled Vehicle

Wirelessly controlled vehicle; built on from last week's project.

  • 1,349 views
  • 0 comments
  • 2 respects

Components and supplies

About this project

**I was sick for the second week project, so I was actually behind in terms of adding on to make the Bluetooth work. I ended up doing the remote controlled + the bluetooth part together in one week. 

(Also, my cover image wouldn't load for some reason. That's why I have no photo for the cover.)

I found a very helpful detailed description of the H Bridge I was using here (along with sample code for running DC motors): H Bridge description

Equipment used: Laser cut Body (2 pieces); laser cut wheels, 2 dc motors, breadboard, arduino, H Bridge, 9V and 12V battery pack, bluetooth chip, phone that can download BLUE fruit, lots of wires, double sided tape, hot glue, super glue, rubber bands, and zip ties. 

For the wiring, I followed and combined tutorials from the nRF8001 Tutorial and the tutorial for wiring DC motors with the H Bridge. 

The final code I used was the callbackEchoModified file given in class. 

Difficulties:

  • Remembering to use the enA and enB output pins for the H Bridge ( needed for PWM on DC Motors)
  • Creating the final shaft and laser cut wheels for the back. Main problem was finding bearings and something that would fit snugly on the shaft. 
  • I forgot to switch the weight distribution so that most of it was over the motors. 
  • Also, had had minor issues with battery pack connectivity. 

Here's the final working video of the vehicle: 

Code

Final Code for Bluetooth VehicleC/C++
// This version uses call-backs on the event and RX so there's no data handling in the main loop!
// motor one
#include <SPI.h>
#include "Adafruit_BLE_UART.h"

#define ADAFRUITBLE_REQ 10
#define ADAFRUITBLE_RDY 2
#define ADAFRUITBLE_RST 9

//Do code below here
Adafruit_BLE_UART uart = Adafruit_BLE_UART(ADAFRUITBLE_REQ, ADAFRUITBLE_RDY, ADAFRUITBLE_RST);

boolean messageReceived = false;
uint8_t message[20];
  int enA = 7;
  int in1 = 3;
  int in2 = 4;
// motor two
  int enB = 8;
  int in3 = 5;
  int in4 = 6;
/**************************************************************************/
/*!
    This function is called whenever select ACI events happen
*/
/**************************************************************************/
void aciCallback(aci_evt_opcode_t event)
{
  switch(event)
  {
    case ACI_EVT_DEVICE_STARTED:
      Serial.println(F("Advertising started"));
      break;
    case ACI_EVT_CONNECTED:
      Serial.println(F("Connected!"));
      break;
    case ACI_EVT_DISCONNECTED:
      Serial.println(F("Disconnected or advertising timed out"));
      break;
    default:
      break;
  }
}

/**************************************************************************/
/*!
    This function is called whenever data arrives on the RX channel
*/
/**************************************************************************/
void rxCallback(uint8_t *buffer, uint8_t len)
{
  Serial.print(F("Received "));
  Serial.print(len);
  Serial.println(F(" bytes: "));
//  for(int i=0; i<len; i++)
//   Serial.print((char)buffer[i]); 
//
//  Serial.print(F(" ["));
//
//  for(int i=0; i<len; i++)
//  {
//    Serial.print(" 0x"); Serial.print((char)buffer[i], HEX); 
//  }
//  Serial.println(F(" ]"));

    switch(buffer[2]) {
      case 53:
        Serial.println ( "up");
        digitalWrite(7, HIGH);
        //Motor 1 forward- right wheel
        analogWrite(enA, 255);//Sets speed variable via PWM 
        digitalWrite(in1, LOW);
        digitalWrite(in2, HIGH);
        Serial.println("Motor 1 Forward"); // Prints out “Motor 1 Forward” on the serial monitor
        Serial.println("   ");
        //motor 2 forward- left wheel
        analogWrite(enB, 255);
        digitalWrite(in3, LOW);
        digitalWrite(in4, HIGH);
        Serial.println("Motor 2 Forward");
        Serial.println("   ");

        delay(1000);   
        //motor 1 stop
        analogWrite(enA, 0);
        digitalWrite(in1, LOW);
        digitalWrite(in2, HIGH);
        Serial.println("Motor 1 Stop");
        Serial.println("   ");
        //motor 2 stop
        analogWrite(enB, 0);
        digitalWrite(in3, LOW);
        digitalWrite(in4, HIGH);
        Serial.println("Motor 2 Stop");
        Serial.println("   ");
        break;
      case 54:
        Serial.println ( "down");
        digitalWrite(7, LOW);
        //motor 1 backwards
        analogWrite(enA, 255);
        digitalWrite(in1, HIGH);
        digitalWrite(in2, LOW);
        Serial.println("Motor 1 Reverse");
        Serial.println("   ");
        //motor 2 backwards
        analogWrite(enB, 255);
        digitalWrite(in3, HIGH);
        digitalWrite(in4, LOW);
        Serial.println("Motor 2 Reverse");
        Serial.println("   ");

        delay(1000);   
        //motor 1 stop
        analogWrite(enA, 0);
        digitalWrite(in1, LOW);
        digitalWrite(in2, HIGH);
        Serial.println("Motor 1 Stop");
        Serial.println("   ");
        //motor 2 stop
        analogWrite(enB, 0);
        digitalWrite(in3, LOW);
        digitalWrite(in4, HIGH);
        Serial.println("Motor 2 Stop");
        Serial.println("   ");
        break;
      case 55:
        Serial.println ( "left");
        // motor 1 forward- right wheel 
        analogWrite(enA, 255);//Sets speed variable via PWM 
        digitalWrite(in1, LOW);
        digitalWrite(in2, HIGH);
        Serial.println("Motor 1 Forward"); // Prints out “Motor 1 Forward” on the serial monitor
        Serial.println("   ");
        // motor 2 backwards- left wheel 
        analogWrite(enB, 255);
        digitalWrite(in3, HIGH);
        digitalWrite(in4, LOW);
        Serial.println("Motor 2 Reverse");
        Serial.println("   ");

        delay(1000);   
        //motor 1 stop
        analogWrite(enA, 0);
        digitalWrite(in1, LOW);
        digitalWrite(in2, HIGH);
        Serial.println("Motor 1 Stop");
        Serial.println("   ");
        //motor 2 stop
        analogWrite(enB, 0);
        digitalWrite(in3, LOW);
        digitalWrite(in4, HIGH);
        Serial.println("Motor 2 Stop");
        Serial.println("   ");
        break;
      case 56:
        Serial.println ( "right");
        //motor 1 backwards- left wheel
        analogWrite(enA, 255);
        digitalWrite(in1, HIGH);
        digitalWrite(in2, LOW);
        Serial.println("Motor 1 Reverse");
        Serial.println("   ");
        //motor 2 forwards- right wheel
        analogWrite(enB, 255);
        digitalWrite(in3, LOW);
        digitalWrite(in4, HIGH);
        Serial.println("Motor 2 Forward");
        Serial.println("   ");
        break;

        delay(1000);   
        //motor 1 stop
        analogWrite(enA, 0);
        digitalWrite(in1, LOW);
        digitalWrite(in2, HIGH);
        Serial.println("Motor 1 Stop");
        Serial.println("   ");
        //motor 2 stop
        analogWrite(enB, 0);
        digitalWrite(in3, LOW);
        digitalWrite(in4, HIGH);
        Serial.println("Motor 2 Stop");
        Serial.println("   ");
    }
  
  /* Echo the same data back! */
  uart.write(buffer, len);
}

/**************************************************************************/
/*!
    Configure the Arduino and start advertising with the radio
*/
/**************************************************************************/
 // connect motor controller pins to Arduino digital pins

void setup(void){ 
// set all the motor control pins to outputs
  pinMode(enA, OUTPUT);
  pinMode(enB, OUTPUT);
  pinMode(in1, OUTPUT);
  pinMode(in2, OUTPUT);
  pinMode(in3, OUTPUT);
  pinMode(in4, OUTPUT);
  Serial.begin(9600);
  while(!Serial); // Leonardo/Micro should wait for serial init
  Serial.println(F("Adafruit Bluefruit Low Energy nRF8001 Callback Echo demo"));

  uart.setRXcallback(rxCallback);
  uart.setACIcallback(aciCallback);
  uart.setDeviceName("AMY"); /* 7 characters max! */
  uart.begin();
  pinMode(7, OUTPUT);
}

/**************************************************************************/
/*!
    Constantly checks for new events on the nRF8001
*/
/**************************************************************************/


void loop()
{
  uart.pollACI();
  
}

Comments

Author

Prof pic  2
Amy Zou
  • 1 project
  • 3 followers

Published on

February 9, 2016

Members who respect this project

Default16939196 1265508460199979 970819631792798889 n
See similar projects
you might like

Similar projects you might like

Bluetooth Controlled Car

Project showcase by Ian St. Louis

  • 14,372 views
  • 4 comments
  • 17 respects

Robotic Car Controlled over Bluetooth by Andriod Phone

Project showcase by S.Ranjith Reddy

  • 7,158 views
  • 1 comment
  • 15 respects

Bluetooth Controlled Bot (Using Adafruit L293D Motor Driver)

Project showcase by Chandran N

  • 1,963 views
  • 0 comments
  • 13 respects

Bluetooth Controlled Light Switch

Project showcase by Team The Instrumentation Crustaceans

  • 27,050 views
  • 4 comments
  • 27 respects

Gesture Controlled Trainable Arduino Robot Arm via Bluetooth

Project tutorial by KureBas Robotics

  • 21,976 views
  • 53 comments
  • 149 respects

Gizmo, the App and Voice Controlled Robotic Vehicle

Project in progress by Michael Linsenmeier

  • 3,886 views
  • 1 comment
  • 24 respects
Add projectSign up / Login