HomeMadeGarbage
Published

Blynk Controlled Car using Accelerometer

I modified a Blynk-controlled car using Adafruit Feather 32u4 Bluefruit LE. I used the Accelerometer widget of Blynk.

IntermediateFull instructions provided2 hours1,828
Blynk Controlled Car using Accelerometer

Things used in this project

Hardware components

Adafruit Feather 32u4 Bluefruit LE
×1
DRV8835
×1
SparkFun Polymer Lithium Ion Battery - 400mAh
×1
Tamiya 70168 Double Gearbox Kit
×1
Tamiya 70157 Universal Plate Set
×1
Tamiya 70144 Ball Caster Kit
×1
Tamiya 70096 Off-Road Tires
×1

Software apps and online services

Arduino IDE
Arduino IDE
Blynk
Blynk

Story

Read more

Schematics

block diagram

Code

blynkCar03.ino

Arduino
//#define BLYNK_DEBUG
#define BLYNK_PRINT Serial

#define BLYNK_USE_DIRECT_CONNECT

#include <BlynkSimpleSerialBLE.h>
#include <SPI.h>
#include <Adafruit_BLE.h>
#include <Adafruit_BluefruitLE_SPI.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "YourAuthToken";

// SHARED SPI SETTINGS (see adafruit webpages for details)
#define BLUEFRUIT_SPI_CS               8
#define BLUEFRUIT_SPI_IRQ              7
#define BLUEFRUIT_SPI_RST              4    // Optional but recommended, set to -1 if unused
#define BLUEFRUIT_VERBOSE_MODE         true

// Create ble instance, see pinouts above
Adafruit_BluefruitLE_SPI ble(BLUEFRUIT_SPI_CS, BLUEFRUIT_SPI_IRQ, BLUEFRUIT_SPI_RST);

//pin name
const int  forwardL = 11;
const int  rearL = 10;
const int  forwardR = 5;
const int  rearR = 6;

long Speed;
long SpeedL, SpeedR;


BLYNK_WRITE(V0) {
  int x = param[0].asFloat();
  int y = param[1].asFloat();
  

  x = map(x, -10, 10, 255, -255);
  y = map(y, -10, 10, 255, -255);

  Serial.print("x: ");
  Serial.print(x);
  Serial.print("  y: ");
  Serial.print(y);

  Speed = sqrt(x*x+y*y);
  if(Speed > 255){
    Speed = 255;
  }
  Serial.print("  Speed: ");
  Serial.println(Speed);

  if(y >= 0){
    if(x >= 0){
      SpeedL = 0;
      SpeedR = abs(x);
    }else{
      SpeedL = abs(x);
      SpeedR = 0;
    }
    analogWrite(forwardL, Speed - SpeedL);
    analogWrite(rearL, 0);
    analogWrite(forwardR, Speed - SpeedR);
    analogWrite(rearR, 0);
  }else{
    if(x >= 0){
      SpeedL = 0;
      SpeedR = abs(x);
    }else{
      SpeedL = abs(x);
      SpeedR = 0;
    }
    analogWrite(forwardL, 0);
    analogWrite(rearL, Speed - SpeedL);
    analogWrite(forwardR, 0);
    analogWrite(rearR, Speed - SpeedR);
  }
}

void setup() {
  Serial.begin(9600);

  ble.begin(BLUEFRUIT_VERBOSE_MODE);
  ble.factoryReset(); // Optional
  ble.setMode(BLUEFRUIT_MODE_DATA);
  
  Blynk.begin(auth, ble);
}

void loop() {
  Blynk.run();
}

Credits

HomeMadeGarbage

HomeMadeGarbage

40 projects • 152 followers
We are family. hobby is D.I.Y!!

Comments

Add projectSign up / Login