I got a broken old stag beetle toy with a wired remote control. I modified it so that it can be operated remotely from a smartphone with BLE!
Using BLE equipped microcomputer Adafruit Feather 32u4 Bluefruit LE and motor driver to control stag beetle from Blynk application of smartphone.
- [1] Cutting wire
There were four enameled wires in gold, green, red, and blue inside the wiring. There were two motors in the stag beetle toy.
Motor 1 (Gold - Blue) and Motor 2 (Red - Green) operate as follows:
- [2] Wiring / Connection of microcontroller and motor driver
The MODE pin of the motor driver is connected to GND.
- [3] Making scissors
I made scissors with plastic board because it got broken.
- Create a new project. Select the Arduino UNO in hardware, because there is no Adafruit Feather 32u4 BLE yet. AUTH TOKEN will make a note so you use at the time of Arduino code generation (send mail).
- Place the BLE widget and the button widgets.
- Button widgets setting. Set each of the four Button Widgets OUTPUT to Virtual Pins V0 - V3.
Latest library is located in the following: https://github.com/blynkkk/blynk-library. The Adafruit Feather 32u4 Bluefruit LE is used here, so the Arduino code is generated in reference to the following:
[Example] -> [Blynk] -> [Boards_BLE] -> [Adafruit_Feather_32u4_BLE]
#define BLYNK_USE_DIRECT_CONNECT
#define BLYNK_PRINT Serial
#include <BlynkSimpleSerialBLE.h>
#include <Adafruit_BLE.h>
#include <Adafruit_BluefruitLE_SPI.h>
#include <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);
void setup() {
Serial.begin(9600);
pinMode(6, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
pinMode(13, OUTPUT);
ble.begin(BLUEFRUIT_VERBOSE_MODE);
ble.factoryReset(); // Optional
ble.setMode(BLUEFRUIT_MODE_DATA);
Blynk.begin(auth, ble);
}
//Button Wedget V0
BLYNK_WRITE(V0) {
if(param.asInt()){
//motor2 Reverse rotation
digitalWrite(6, HIGH);
digitalWrite(11, LOW);
digitalWrite(12, HIGH);
digitalWrite(13, HIGH);
}else{
digitalWrite(6, HIGH);
digitalWrite(11, HIGH);
digitalWrite(12, HIGH);
digitalWrite(13, HIGH);
}
}
//Button Wedget V1
BLYNK_WRITE(V1) {
if(param.asInt()){
//motor1 Forward rotation
digitalWrite(6, HIGH);
digitalWrite(11, HIGH);
digitalWrite(12, LOW);
digitalWrite(13, HIGH);
}else{
digitalWrite(6, HIGH);
digitalWrite(11, HIGH);
digitalWrite(12, HIGH);
digitalWrite(13, HIGH);
}
}
//Button Wedget V2
BLYNK_WRITE(V2) {
if(param.asInt()){
//motor2 Forward rotation
digitalWrite(6, LOW);
digitalWrite(11, HIGH);
digitalWrite(12, HIGH);
digitalWrite(13, HIGH);
}else{
digitalWrite(6, HIGH);
digitalWrite(11, HIGH);
digitalWrite(12, HIGH);
digitalWrite(13, HIGH);
}
}
//Button Wedget V3
BLYNK_WRITE(V3) {
if(param.asInt()){
//motor1 Reverse rotation
digitalWrite(6, HIGH);
digitalWrite(11, HIGH);
digitalWrite(12, HIGH);
digitalWrite(13, LOW);
}else{
digitalWrite(6, HIGH);
digitalWrite(11, HIGH);
digitalWrite(12, HIGH);
digitalWrite(13, HIGH);
}
}
void loop() {
Blynk.run();
}
Blynk Connecting BLE- Click on the BLE widget of the project.
- Click on the "Connect BLE device".
- Then connect to "Adafruit Bluefruit LE" by clicking "OK".
Nice moves!
Comments
Please log in or sign up to comment.