Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
Matthew Chiang
Published

BE∆ST: Bluetooth Vehicle Final Designed Chassis

Adding an aesthetic aspect to the working functionality of my bluetooth vehicle.

BeginnerShowcase (no instructions)5,432
BE∆ST: Bluetooth Vehicle Final Designed Chassis

Things used in this project

Hardware components

3mm Blue Water Ultra Bright LEDs
×2
Arduino UNO
Arduino UNO
×1
Arduino L298N Dual H-Bridge Motor Controller
×1
DC motor (generic)
×2
DC motor gear box
For the DC motors to decrease speed and increase torque to turn the car wheels
×2
RC car tires
Generic tires were used to fit the custom made wheels
×2
4xAA battery holder
4xAA battery holder
×1
AA Battery
×4
9V Battery Holder with On/Off Switch
×1
9V battery (generic)
9V battery (generic)
×1
Breadboard (generic)
Breadboard (generic)
×1
Resistor 160 ohm
×2
Jumper wires (generic)
Jumper wires (generic)
×24
Arduino Proto Shield
Arduino Proto Shield
×1
Adafruit nRF8001 Bluetooth LE Breakout
×1

Software apps and online services

Tinkercad
Autodesk Tinkercad

Hand tools and fabrication machines

Laser cutter (generic)
Laser cutter (generic)
3D Printer (generic)
3D Printer (generic)
Wire stripper
Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Custom parts and enclosures

Origami AI File

Shaft STL

Load it into Cura for the wheel's shaft component

Wheel STL

Load it into Cura for the wheel

Schematics

Full circuit diagram

Diagrams how the switches and LEDs are connected

Full circuit diagram

Diagrams how the switches and LEDs are connected

Code

callbackEchoModified.ino

Java
/*********************************************************************
This is an example for our nRF8001 Bluetooth Low Energy Breakout

  Pick one up today in the adafruit shop!
  ------> http://www.adafruit.com/products/1697

Adafruit invests time and resources providing this open source code, 
please support Adafruit and open-source hardware by purchasing 
products from Adafruit!

Written by Kevin Townsend/KTOWN  for Adafruit Industries.
MIT license, check LICENSE for more information
All text above, and the splash screen below must be included in any redistribution
*********************************************************************/

// This version uses call-backs on the event and RX so there's no data handling in the main loop!

#include <SPI.h>
#include "Adafruit_BLE_UART.h"

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

Adafruit_BLE_UART uart = Adafruit_BLE_UART(ADAFRUITBLE_REQ, ADAFRUITBLE_RDY, ADAFRUITBLE_RST);

boolean messageReceived = false;
uint8_t message[20];

// Added by Matt Chiang

// Motor 1
int IN1 = 7; // IN1 on the L298 is linked to digital pin 7
int IN2 = 6; // pwm

// Motor 2
int IN3 = 8;
int IN4 = 5; // pwm

// button input
char button = '0';

int ledPins[] = {3,4};

/**************************************************************************/
/*!
    Motor control functions
*/
/**************************************************************************/

void forward() {
  digitalWrite (IN1, HIGH);
  digitalWrite (IN2, LOW);
  digitalWrite (IN3, HIGH);
  digitalWrite (IN4, LOW);
}

void turnRight() {
  digitalWrite (IN1, HIGH); // LOW for stopping
  digitalWrite (IN2, LOW);
  digitalWrite (IN3, LOW);
  digitalWrite (IN4, LOW);
}

void turnLeft() {
  digitalWrite (IN1, LOW);
  digitalWrite (IN2, LOW); 
  digitalWrite (IN3, HIGH);
  digitalWrite (IN4, LOW);
}

void reverse() {
  digitalWrite (IN1, LOW);
  digitalWrite (IN2, HIGH);
  digitalWrite (IN3, LOW);
  digitalWrite (IN4, HIGH);
}

void reverseLeft() {
  digitalWrite (IN1, LOW);
  digitalWrite (IN2, LOW);
  digitalWrite (IN3, HIGH);
  digitalWrite (IN4, LOW);
}

void reverseRight() {
  digitalWrite (IN1, LOW);
  digitalWrite (IN2, HIGH);
  digitalWrite (IN3, LOW);
  digitalWrite (IN4, LOW);
}

void brake() {
  digitalWrite (IN1, LOW);
  digitalWrite (IN2, LOW);
  digitalWrite (IN3, LOW);
  digitalWrite (IN4, LOW);
}

/**************************************************************************/
/*!
    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(" ]"));


  // RC controls basic

   if ((char)buffer[1] == 'B') {
    if((char)buffer[3] == '0') {
      button = '0';    //turn off motors if button is released
    } else {
      button = (char)buffer[2];     //select proper direction, which corresponds to motor output below
    }
  }

  if (button == '0') {
    brake();
  } else if (button == '5') { // up button pressed
    forward();
  } else if (button == '6') { // down button pressed
    reverse();
  } else if (button == '7') { // left button pressed
    turnLeft();
  } else if (button == '8') { // right button pressed
    turnRight();
  }



  
  /* Echo the same data back! */
  uart.write(buffer, len);
}

/**************************************************************************/
/*!
    Configure the Arduino and start advertising with the radio
*/
/**************************************************************************/
void setup(void)
{ 
  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("PHATTY"); /* 7 characters max! */
  uart.begin();

  pinMode(IN1, OUTPUT); // Set the pin IN# to behave as an output
  pinMode(IN2, OUTPUT);
  pinMode(IN3, OUTPUT);
  pinMode(IN4, OUTPUT);

  pinMode(3, OUTPUT); // LED output
  digitalWrite(3, OUTPUT); // Turn LED on when power is on
  pinMode(4, OUTPUT); // LED output
  digitalWrite(4, OUTPUT); // Turn LED on when power is on
}

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


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

Credits

Matthew Chiang

Matthew Chiang

16 projects • 9 followers

Comments