Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
RimaAditiHelen Wang
Published

Navibot

Navibot is a guidance system that helps visitors or patients navigate their way in any new building.

IntermediateShowcase (no instructions)24 hours3,117
Navibot

Things used in this project

Hardware components

Adafruit Bluefruit LE Shield
×1
Arduino UNO
Arduino UNO
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Top view of the robot

Top view of Bluetooth Module

Side view of Bluetooth Module

Code

Bluetooth LE Module

Arduino
#include <string.h>
#include <Arduino.h>
#include <SPI.h>
#include "Adafruit_BLE.h"
#include "Adafruit_BluefruitLE_SPI.h"
#include "Adafruit_BluefruitLE_UART.h"

#include "BluefruitConfig.h"

#if SOFTWARE_SERIAL_AVAILABLE
  #include <SoftwareSerial.h>
#endif

/*=========================================================================
    APPLICATION SETTINGS

    FACTORYRESET_ENABLE       Perform a factory reset when running this sketch
   
                              Enabling this will put your Bluefruit LE module
                              in a 'known good' state and clear any config
                              data set in previous sketches or projects, so
                              running this at least once is a good idea.
   
                              When deploying your project, however, you will
                              want to disable factory reset by setting this
                              value to 0.  If you are making changes to your
                              Bluefruit LE device via AT commands, and those
                              changes aren't persisting across resets, this
                              is the reason why.  Factory reset will erase
                              the non-volatile memory where config data is
                              stored, setting it back to factory default
                              values.
       
                              Some sketches that require you to bond to a
                              central device (HID mouse, keyboard, etc.)
                              won't work at all with this feature enabled
                              since the factory reset will clear all of the
                              bonding data stored on the chip, meaning the
                              central device won't be able to reconnect.
    MINIMUM_FIRMWARE_VERSION  Minimum firmware version to have some new features
    MODE_LED_BEHAVIOUR        LED activity, valid options are
                              "DISABLE" or "MODE" or "BLEUART" or
                              "HWUART"  or "SPI"  or "MANUAL"
    -----------------------------------------------------------------------*/
    #define FACTORYRESET_ENABLE         1
    #define MINIMUM_FIRMWARE_VERSION    "0.6.6"
    #define MODE_LED_BEHAVIOUR          "MODE"
/*=========================================================================*/

// Create the bluefruit object, either software serial...uncomment these lines
/*
SoftwareSerial bluefruitSS = SoftwareSerial(BLUEFRUIT_SWUART_TXD_PIN, BLUEFRUIT_SWUART_RXD_PIN);

Adafruit_BluefruitLE_UART ble(bluefruitSS, BLUEFRUIT_UART_MODE_PIN,
                      BLUEFRUIT_UART_CTS_PIN, BLUEFRUIT_UART_RTS_PIN);
*/

/* ...or hardware serial, which does not need the RTS/CTS pins. Uncomment this line */
// Adafruit_BluefruitLE_UART ble(BLUEFRUIT_HWSERIAL_NAME, BLUEFRUIT_UART_MODE_PIN);

/* ...hardware SPI, using SCK/MOSI/MISO hardware SPI pins and then user selected CS/IRQ/RST */
Adafruit_BluefruitLE_SPI ble(BLUEFRUIT_SPI_CS, BLUEFRUIT_SPI_IRQ, BLUEFRUIT_SPI_RST);

/* ...software SPI, using SCK/MOSI/MISO user-defined SPI pins and then user selected CS/IRQ/RST */
//Adafruit_BluefruitLE_SPI ble(BLUEFRUIT_SPI_SCK, BLUEFRUIT_SPI_MISO,
//                             BLUEFRUIT_SPI_MOSI, BLUEFRUIT_SPI_CS,
//                             BLUEFRUIT_SPI_IRQ, BLUEFRUIT_SPI_RST);


// A small helper
void error(const __FlashStringHelper*err) {
  Serial.println(err);
  while (1);
}

// function prototypes over in packetparser.cpp
uint8_t readPacket(Adafruit_BLE *ble, uint16_t timeout);
float parsefloat(uint8_t *buffer);
void printHex(const uint8_t * data, const uint32_t numBytes);

// the packet buffer
extern uint8_t packetbuffer[];


/**************************************************************************/
/*!
    @brief  Sets up the HW an the BLE module (this function is called
            automatically on startup)
*/
/**************************************************************************/

char rx_byte = 0;
String rx_str = "";
int bp = 0;
bool b = false;


void setup(void)
{
  while (!Serial);  // required for Flora & Micro
  delay(500);

  Serial.begin(115200);
  Serial.println(F("Adafruit Bluefruit App Controller Example"));
  Serial.println(F("-----------------------------------------"));

  /* Initialise the module */
  Serial.print(F("Initialising the Bluefruit LE module: "));

  if ( !ble.begin(VERBOSE_MODE) )
  {
    error(F("Couldn't find Bluefruit, make sure it's in CoMmanD mode & check wiring?"));
  }
  Serial.println( F("OK!") );

  if ( FACTORYRESET_ENABLE )
  {
    /* Perform a factory reset to make sure everything is in a known state */
    Serial.println(F("Performing a factory reset: "));
    if ( ! ble.factoryReset() ){
      error(F("Couldn't factory reset"));
    }
  }


  /* Disable command echo from Bluefruit */
  ble.echo(false);

  Serial.println("Requesting Bluefruit info:");
  /* Print Bluefruit information */
  ble.info();

  Serial.println(F("Please use Adafruit Bluefruit LE app to connect in Controller mode"));
  Serial.println(F("Then activate/use the sensors, color picker, game controller, etc!"));
  Serial.println();

  ble.verbose(false);  // debug info is a little annoying after this point!

  /* Wait for connection */
  while (! ble.isConnected()) {
      delay(500);
  }

  Serial.println(F("****************************"));

  // LED Activity command is only supported from 0.6.6
  if ( ble.isVersionAtLeast(MINIMUM_FIRMWARE_VERSION) )
  {
    // Change Mode LED Activity
    Serial.println(F("Change LED activity to " MODE_LED_BEHAVIOUR));
    ble.sendCommandCheckOK("AT+HWModeLED=" MODE_LED_BEHAVIOUR);
  }

  // Set Bluefruit to DATA mode
  Serial.println( F("Switching to DATA mode!") );
  ble.setMode(BLUEFRUIT_MODE_DATA);

  Serial.println(F("****************************"));

}

/**************************************************************************/
/*!
    @brief  Constantly poll for new command or response data
*/
/**************************************************************************/
void loop(void)
{
  /* Wait for new data to arrive */
  uint8_t len = readPacket(&ble, BLE_READPACKET_TIMEOUT);
  if (len == 0) return;

  /* Got a packet! */
  // printHex(packetbuffer, len);

//  // Color
//  if (packetbuffer[1] == 'C') {
//    uint8_t red = packetbuffer[2];
//    uint8_t green = packetbuffer[3];
//    uint8_t blue = packetbuffer[4];
//    Serial.print ("RGB #");
//    if (red < 0x10) Serial.print("0");
//    Serial.print(red, HEX);
//    if (green < 0x10) Serial.print("0");
//    Serial.print(green, HEX);
//    if (blue < 0x10) Serial.print("0");
//    Serial.println(blue, HEX);
//  }

  // Buttons
  if (packetbuffer[1] == 'B') {
    uint8_t buttnum = packetbuffer[2] - '0';
    boolean pressed = packetbuffer[3] - '0';
    Serial.print ("Button "); Serial.print(buttnum);
    if (pressed) {
      Serial.println(" pressed");
    } else {
      Serial.println(" released");
      b = true;
      bp = buttnum;
    }
  }

  if(b = true){
    Serial.print ("Button "); Serial.print(bp); Serial.println(" released haha!");
    b = false;
  }
  
  

//  // GPS Location
//  if (packetbuffer[1] == 'L') {
//    float lat, lon, alt;
//    lat = parsefloat(packetbuffer+2);
//    lon = parsefloat(packetbuffer+6);
//    alt = parsefloat(packetbuffer+10);
//    Serial.print("GPS Location\t");
//    Serial.print("Lat: "); Serial.print(lat, 4); // 4 digits of precision!
//    Serial.print('\t');
//    Serial.print("Lon: "); Serial.print(lon, 4); // 4 digits of precision!
//    Serial.print('\t');
//    Serial.print(alt, 4); Serial.println(" meters");
//  }
//
//  // Accelerometer
//  if (packetbuffer[1] == 'A') {
//    float x, y, z;
//    x = parsefloat(packetbuffer+2);
//    y = parsefloat(packetbuffer+6);
//    z = parsefloat(packetbuffer+10);
//    Serial.print("Accel\t");
//    Serial.print(x); Serial.print('\t');
//    Serial.print(y); Serial.print('\t');
//    Serial.print(z); Serial.println();
//  }
//
//  // Magnetometer
//  if (packetbuffer[1] == 'M') {
//    float x, y, z;
//    x = parsefloat(packetbuffer+2);
//    y = parsefloat(packetbuffer+6);
//    z = parsefloat(packetbuffer+10);
//    Serial.print("Mag\t");
//    Serial.print(x); Serial.print('\t');
//    Serial.print(y); Serial.print('\t');
//    Serial.print(z); Serial.println();
//  }
//
//  // Gyroscope
//  if (packetbuffer[1] == 'G') {
//    float x, y, z;
//    x = parsefloat(packetbuffer+2);
//    y = parsefloat(packetbuffer+6);
//    z = parsefloat(packetbuffer+10);
//    Serial.print("Gyro\t");
//    Serial.print(x); Serial.print('\t');
//    Serial.print(y); Serial.print('\t');
//    Serial.print(z); Serial.println();
//  }
//
//  // Quaternions
//  if (packetbuffer[1] == 'Q') {
//    float x, y, z, w;
//    x = parsefloat(packetbuffer+2);
//    y = parsefloat(packetbuffer+6);
//    z = parsefloat(packetbuffer+10);
//    w = parsefloat(packetbuffer+14);
//    Serial.print("Quat\t");
//    Serial.print(x); Serial.print('\t');
//    Serial.print(y); Serial.print('\t');
//    Serial.print(z); Serial.print('\t');
//    Serial.print(w); Serial.println();
//  }
}

Motor Control

Arduino
#include "AlphaBot.h"

AlphaBot Car1 = AlphaBot();
#define IN1 A0
#define IN2 A1
#define IN3 A2
#define IN4 A3

#define CLK 13
#define ADDR 12
#define DOUT 11
#define CS 10

#define ENA 5
#define ENB 6

#define NUM_SENSORS 5
#define NUM_SAMPLES_PER_SENSOR  4  // average 4 analog samples per sensor reading
#define EMITTER_PIN 2  // emitter is controlled by digital pin 2
#define QTR_NO_EMITTER_PIN 255
QTRSensorsAnalog qtra((unsigned char[]) {0, 1, 2, 3, 4},
  NUM_SENSORS, NUM_SAMPLES_PER_SENSOR, EMITTER_PIN);
unsigned int sensorValues[NUM_SENSORS];

int proportional;

#include <string.h>
#include <Arduino.h>
#include <SPI.h>
#include "Adafruit_BLE.h"
#include "Adafruit_BluefruitLE_SPI.h"
#include "Adafruit_BluefruitLE_UART.h"

#include "BluefruitConfig.h"

#if SOFTWARE_SERIAL_AVAILABLE
  #include <SoftwareSerial.h>
#endif

    #define FACTORYRESET_ENABLE         1
    #define MINIMUM_FIRMWARE_VERSION    "0.6.6"
    #define MODE_LED_BEHAVIOUR          "MODE"
Adafruit_BluefruitLE_SPI ble(BLUEFRUIT_SPI_CS, BLUEFRUIT_SPI_IRQ, BLUEFRUIT_SPI_RST);


// A small helper
void error(const __FlashStringHelper*err) {
  Serial.println(err);
  while (1);
}

// function prototypes over in packetparser.cpp
uint8_t readPacket(Adafruit_BLE *ble, uint16_t timeout);
float parsefloat(uint8_t *buffer);
void printHex(const uint8_t * data, const uint32_t numBytes);

// the packet buffer
extern uint8_t packetbuffer[];


/**************************************************************************/
/*!
    @brief  Sets up the HW an the BLE module (this function is called
            automatically on startup)
*/
/**************************************************************************/

char rx_byte = 0;
String rx_str = "";
int bp = 0;
bool b = false;



void setup()
{
  Car1.SetSpeed(50);       //Speed:0 - 255
  Serial.begin( 9600 );
pinMode( IN1,OUTPUT );
pinMode( IN2,OUTPUT );
pinMode( IN3,OUTPUT );
pinMode( IN4,OUTPUT );
pinMode( ENA,OUTPUT );
pinMode( ENB,OUTPUT );
digitalWrite( IN1,0 );
digitalWrite( IN2,0 );
digitalWrite( IN3,0 );
digitalWrite( IN4,0 );
analogWrite( ENA,0 );
analogWrite( ENB,0 );
//Serial.println( “Setup Scuccessfully” );



while (!Serial);  // required for Flora & Micro
  delay(500);

  Serial.begin(115200);
  Serial.println(F("Adafruit Bluefruit App Controller Example"));
  Serial.println(F("-----------------------------------------"));

  /* Initialise the module */
  Serial.print(F("Initialising the Bluefruit LE module: "));
 
  if ( !ble.begin(VERBOSE_MODE) )
  {
    error(F("Couldn't find Bluefruit, make sure it's in CoMmanD mode & check wiring?"));
  }
  Serial.println( F("OK!") );

  if ( FACTORYRESET_ENABLE )
  {
    /* Perform a factory reset to make sure everything is in a known state */
    Serial.println(F("Performing a factory reset: "));
    if ( ! ble.factoryReset() ){
      error(F("Couldn't factory reset"));
    }
  }


  /* Disable command echo from Bluefruit */
  ble.echo(false);

  Serial.println("Requesting Bluefruit info:");
  /* Print Bluefruit information */
  ble.info();

  Serial.println(F("Please use Adafruit Bluefruit LE app to connect in Controller mode"));
  Serial.println(F("Then activate/use the sensors, color picker, game controller, etc!"));
  Serial.println();

  ble.verbose(false);  // debug info is a little annoying after this point!

  /* Wait for connection */
  while (! ble.isConnected()) {
      delay(500);
  }

  Serial.println(F("**************************"));

  // LED Activity command is only supported from 0.6.6
  if ( ble.isVersionAtLeast(MINIMUM_FIRMWARE_VERSION) )
  {
    // Change Mode LED Activity
    Serial.println(F("Change LED activity to " MODE_LED_BEHAVIOUR));
    ble.sendCommandCheckOK("AT+HWModeLED=" MODE_LED_BEHAVIOUR);
  }

  // Set Bluefruit to DATA mode
  Serial.println( F("Switching to DATA mode!") );
  ble.setMode(BLUEFRUIT_MODE_DATA);

  Serial.println(F("**************************"));



}

void loop()
{  
  delay(1000);
  Car1.Forward(1000);     //Car run forward for 1s
  Car1.Brake();

/* Wait for new data to arrive */
  uint8_t len = readPacket(&ble, BLE_READPACKET_TIMEOUT);
  if (len == 0) return;

  /* Got a packet! */
  // printHex(packetbuffer, len);

//  // Color
//  if (packetbuffer[1] == 'C') {
//    uint8_t red = packetbuffer[2];
//    uint8_t green = packetbuffer[3];
//    uint8_t blue = packetbuffer[4];
//    Serial.print ("RGB #");
//    if (red < 0x10) Serial.print("0");
//    Serial.print(red, HEX);
//    if (green < 0x10) Serial.print("0");
//    Serial.print(green, HEX);
//    if (blue < 0x10) Serial.print("0");
//    Serial.println(blue, HEX);
//  }

  // Buttons
  if (packetbuffer[1] == 'B') {
    uint8_t buttnum = packetbuffer[2] - '0';
    boolean pressed = packetbuffer[3] - '0';
    Serial.print ("Button "); Serial.print(buttnum);
    if (pressed) {
      Serial.println(" pressed");
    } else {
      Serial.println(" released");
      b = true;
      bp = buttnum;
    }
  }

  if(b = true){
    Serial.print ("Button "); Serial.print(bp); Serial.println(" released haha!");
    b = false;
  }
  
  

//  // GPS Location
//  if (packetbuffer[1] == 'L') {
//    float lat, lon, alt;
//    lat = parsefloat(packetbuffer+2);
//    lon = parsefloat(packetbuffer+6);
//    alt = parsefloat(packetbuffer+10);
//    Serial.print("GPS Location\t");
//    Serial.print("Lat: "); Serial.print(lat, 4); // 4 digits of precision!
//    Serial.print('\t');
//    Serial.print("Lon: "); Serial.print(lon, 4); // 4 digits of precision!
//    Serial.print('\t');
//    Serial.print(alt, 4); Serial.println(" meters");
//  }
//
//  // Accelerometer
//  if (packetbuffer[1] == 'A') {
//    float x, y, z;
//    x = parsefloat(packetbuffer+2);
//    y = parsefloat(packetbuffer+6);
//    z = parsefloat(packetbuffer+10);
//    Serial.print("Accel\t");
//    Serial.print(x); Serial.print('\t');
//    Serial.print(y); Serial.print('\t');
//    Serial.print(z); Serial.println();
//  }
//
//  // Magnetometer
//  if (packetbuffer[1] == 'M') {
//    float x, y, z;
//    x = parsefloat(packetbuffer+2);
//    y = parsefloat(packetbuffer+6);
//    z = parsefloat(packetbuffer+10);
//    Serial.print("Mag\t");
//    Serial.print(x); Serial.print('\t');
//    Serial.print(y); Serial.print('\t');
//    Serial.print(z); Serial.println();
//  }
//
//  // Gyroscope
//  if (packetbuffer[1] == 'G') {
//    float x, y, z;
//    x = parsefloat(packetbuffer+2);
//    y = parsefloat(packetbuffer+6);
//    z = parsefloat(packetbuffer+10);
//    Serial.print("Gyro\t");
//    Serial.print(x); Serial.print('\t');
//    Serial.print(y); Serial.print('\t');
//    Serial.print(z); Serial.println();
//  }
//
//  // Quaternions
//  if (packetbuffer[1] == 'Q') {
//    float x, y, z, w;
//    x = parsefloat(packetbuffer+2);
//    y = parsefloat(packetbuffer+6);
//    z = parsefloat(packetbuffer+10);
//    w = parsefloat(packetbuffer+14);
//    Serial.print("Quat\t");
//    Serial.print(x); Serial.print('\t');
//    Serial.print(y); Serial.print('\t');
//    Serial.print(z); Serial.print('\t');
//    Serial.print(w); Serial.println();
//  }




  digitalWrite( IN1,1 );
  digitalWrite( IN2,0 );
  digitalWrite( IN3,0 );
  digitalWrite( IN4,1 );
  analogWrite( ENA,100 );
  analogWrite( ENB,100 );


  // read raw sensor values
 // unsigned int position = qtra.read(sensorValues);

  // The "proportional" term should be 0 when we are on the line.
  proportional = qtra.readLine(sensorValues) - 2000;
  //int proportional = (int)position - 2000;
  // improve performance.
  int power_difference = proportional/10; //+derivative;  

  // Compute the actual motor settings.  We never set either motor
  // to a negative value.
  const int maximum =100;

  if (power_difference > maximum)
    power_difference = maximum;
  if (power_difference < - maximum)
    power_difference = - maximum;
//    Serial.println(power_difference);
  if (power_difference < 0)
  {
    analogWrite(ENB,maximum + power_difference);
    analogWrite(ENA,maximum);
  }
  else
  {
    analogWrite(ENB,maximum);
    analogWrite(ENA,maximum - power_difference);
  }    





}  



#include <QTRSensors.h>

// This example is designed for use with six QTR-1A sensors or the first six sensors of a
// QTR-8A module.  These reflectance sensors should be connected to analog inputs 0 to 5.
// The QTR-8A's emitter control pin (LEDON) can optionally be connected to digital pin 2,
// or you can leave it disconnected and change the EMITTER_PIN #define below from 2 to
// QTR_NO_EMITTER_PIN.

// The main loop of the example reads the raw sensor values (uncalibrated).
// You can test this by taping a piece of 3/4" black electrical tape to a piece of white
// paper and sliding the sensor across it.  It prints the sensor values to the serial
// monitor as numbers from 0 (maximum reflectance) to 1023 (minimum reflectance).





//  delay(1000);
//  Car1.Backward(1000);  //Car run backward for 1s
//  Car1.Brake();

//  delay(1000);
//  Car1.Left(1000);      //Car turn left for 1s
//  Car1.Brake();

//  delay(1000);
//  Car1.Right(1000);     //Car turn right for 1s
//  Car1.Brake();

//  delay(1000);
//  Car1.LeftCircle(1000);  //Car left circle for 1s
//  Car1.Brake();

//  delay(1000);
//  Car1.RightCircle(1000);  //Car right circle for 1s
//  Car1.Brake();
  
//  delay(1000);  
//  Car1.MotorRun(250,250);  //Car run forward for 1s; left motor speed:250,right motor speed:250
//  delay(1000);
//  Car1.Brake();

//  delay(1000);  
//  Car1.MotorRun(-250,-250);  //Car run backward for 1s; left motor speed:250,right motor speed:250
//  delay(1000);
//  Car1.Brake();
  
//  delay(1000);  
//  Car1.MotorRun(0,250);       //Car left circle for 1s; left motor speed:0,right motor speed:250
//  delay(1000);
//  Car1.Brake();

//  delay(1000);  
//  Car1.MotorRun(250,0);       //Car turn right for 1s; left motor speed:250,right motor speed:0
//  delay(1000);
//  Car1.Brake();

Credits

Rima
1 project • 0 followers
Contact
Aditi
0 projects • 0 followers
Contact
Helen Wang
0 projects • 0 followers
Contact

Comments

Please log in or sign up to comment.