Blynk-controlled Stag Beetle
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!
目次
Constitution
Using BLE equipped microcomputer Adafruit Feather 32u4 Bluefruit LE and motor driver to control stag beetle from Blynk application of smartphone.
Parts
- BLE-equipped microcomputer Adafruit Feather 32u4 bluefruit LE
- Motor driver drv8835
- Li-ion polymer battery 400mAh
Assembly
- 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:
Forward rotation Reversed Motor 1 Turning AdvanceMotors 2 Scissors Head Swing - Wiring / Connection of microcontroller and motor driver
The mode pin of the motor driver is connected to GND.
http://akizukidenshi.com/download/ds/akizuki/AE-DRV8835-Ss.pdf - Making scissors
I made scissors with plastic board because it got broken.
Blynk settings
- Install the Blynk app on your smartphone
- 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.
Arduino Program
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]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
#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 ble connection
Click to set the BLE Wejit for the Blynk project.
Click “Connect BLE Device” and click OK to connect when “Adafruit bluefruit LE” is displayed.
Operating
Remote Stag #blynk Pic.twitter.com/JIMmqSqMey
— Homemadegarbage (@H0meMadeGarbage) May 23, 2017
The movement is quite real!