Make a Twitter Bot App: Tweet at a Press of a Button - Arduino 101 BLE
by TechMartian in Circuits > Arduino
2825 Views, 13 Favorites, 0 Comments
Make a Twitter Bot App: Tweet at a Press of a Button - Arduino 101 BLE
![Screen Shot 2017-08-25 at 11.11.34 AM.png](/proxy/?url=https://content.instructables.com/FS0/9JX7/J6QQJ659/FS09JX7J6QQJ659.png&filename=Screen Shot 2017-08-25 at 11.11.34 AM.png)
This is a Twitter bot which post tweets at a press of a button. It uses the Bluetooth Low Energy connection of the Arduino 101 to connect to a phone and consequently the twitter app and the internet.
You can program as many buttons as you want, I chose three. Each button outputs a different tweet. For example the red one tweets a heart "<3". The blue one tweets "Good Night :)!". And the green one tweets "Good morning!"
BoM
![qnd4J4oBRo648SeGwyWqvQ_thumb_7cb.jpg](/proxy/?url=https://content.instructables.com/FGX/SLG4/J6QQHCED/FGXSLG4J6QQHCED.jpg&filename=qnd4J4oBRo648SeGwyWqvQ_thumb_7cb.jpg)
* Push Button Switches
* Arduino 101
* 10kΩ Resistor
* Breadboard Wires
* Jumper Wires
* Phone with BLE (Bluetooth 4.1) support
Connect All GND
![BmDQr1fdRQm871XgVH1PVQ_thumb_7cd.jpg](/proxy/?url=https://content.instructables.com/F5M/FI9R/J6QQHC89/F5MFI9RJ6QQHC89.jpg&filename=BmDQr1fdRQm871XgVH1PVQ_thumb_7cd.jpg)
Connect one of the pins of each of the switches to the common ground rail on the breadboard.
Connect All VCC
![ZqmjDBzfTj62SDzALRm4MA_thumb_7cc.jpg](/proxy/?url=https://content.instructables.com/FK7/XBYY/J6QQHCQI/FK7XBYYJ6QQHCQI.jpg&filename=ZqmjDBzfTj62SDzALRm4MA_thumb_7cc.jpg)
![od1S1Jt3QcK3OR5MpWgWdA_thumb_7cf.jpg](/proxy/?url=https://content.instructables.com/FI1/0JNH/J6QQHCCJ/FI10JNHJ6QQHCCJ.jpg&filename=od1S1Jt3QcK3OR5MpWgWdA_thumb_7cf.jpg)
Connect the remaining open pin (aka signal pin) of each of the switches to a 10kΩ resistor in series to the VCC (red) power rail on the breadboard.
Connect the common breadboard ground rail to the GND pin on the Arduino
Connect the common VCC power rail on the breadboard to the 3.3V pin on the Arduino.
Connect the Signal Pins
![yzEA0kcpQ+OzU%3J7tAtMg_thumb_7d1.jpg](/proxy/?url=https://content.instructables.com/F0S/61VG/J6QQHCOM/F0S61VGJ6QQHCOM.jpg&filename=yzEA0kcpQ+OzU%3J7tAtMg_thumb_7d1.jpg)
![b5XBCXw%R6mJAZgIN16F5Q_thumb_7d0.jpg](/proxy/?url=https://content.instructables.com/FWA/FULM/J6QQHC68/FWAFULMJ6QQHC68.jpg&filename=b5XBCXw%R6mJAZgIN16F5Q_thumb_7d0.jpg)
Connect each of the signal pins of the switches to pins 5, 6, and 7 on the Arduino.
Code
![Screenshot_20170820-232022.png](/proxy/?url=https://content.instructables.com/FOP/06Q8/J6QQHCGE/FOP06Q8J6QQHCGE.png&filename=Screenshot_20170820-232022.png)
Code and upload the following code to the Arduino. Change your auth token to the one you get from the Blank App.
#define BLYNK_PRINT Serial
#include <BlynkSimpleCurieBLE.h>
#include <CurieBLE.h>
// You should get Auth Token in the Blynk App. // Go to the Project Settings (nut icon). char auth[] = "c3f9335ebd0f4e48b82bbc5a8bb30d32";
BLEPeripheral blePeripheral;
BlynkTimer timer;
void tweetUptime() { long uptime = millis() / 60000L; Serial.println("Tweeting every 10 minutes ;)");
// Actually send the message. // Note: // We allow 1 tweet per 15 seconds for now. // Twitter doesn't allow identical subsequent messages. Blynk.tweet(String("Running for ") + uptime + " minutes."); }
void tweetOnButtonPress() { // Invert state, since button is "Active LOW" int isButtonPressed = !digitalRead(2); if (isButtonPressed) { Serial.println("Button is pressed.");
Blynk.tweet("Yaaay... button is pressed! :)\n #arduino #IoT #blynk @blynk_app"); } }
void setup() { // Debug console Serial.begin(9600);
delay(1000);
blePeripheral.setLocalName("Blynk"); blePeripheral.setDeviceName("Blynk"); blePeripheral.setAppearance(384);
Blynk.begin(blePeripheral, auth);
blePeripheral.begin();
Serial.println("Waiting for connections...");
// Tweet immediately on startup Blynk.tweet("My Arduino project is tweeting using @blynk_app and it’s awesome!\n #arduino #IoT #blynk");
// Setup a function to be called every 10 minutes timer.setInterval(10L * 60000L, tweetUptime);
// Setup twitter button on pin 2 pinMode(2, INPUT_PULLUP); // Attach pin 2 interrupt to our handler attachInterrupt(digitalPinToInterrupt(2), tweetOnButtonPress, CHANGE); }
void loop() { blePeripheral.poll(); Blynk.run(); timer.run(); }
Make the App
![Screenshot_20170820-233032.png](/proxy/?url=https://content.instructables.com/FS5/283G/J6QQHCMK/FS5283GJ6QQHCMK.png&filename=Screenshot_20170820-233032.png)
![Screenshot_20170820-233020.png](/proxy/?url=https://content.instructables.com/F3N/XMBC/J6QQHCMJ/F3NXMBCJ6QQHCMJ.png&filename=Screenshot_20170820-233020.png)
Download the Blynk App onto your phone.
Create a new project and add the following widgets inside the app:
- BLE
Pair the Bluetooth
![Screenshot_20170820-233004.png](/proxy/?url=https://content.instructables.com/FX3/BNFT/J6QQHCKH/FX3BNFTJ6QQHCKH.png&filename=Screenshot_20170820-233004.png)
![Screenshot_20170820-232132.png](/proxy/?url=https://content.instructables.com/FQO/K6EK/J6QQHCIF/FQOK6EKJ6QQHCIF.png&filename=Screenshot_20170820-232132.png)
![Screenshot_20170820-232956.png](/proxy/?url=https://content.instructables.com/FOR/GF1L/J6QQHCIG/FORGF1LJ6QQHCIG.png&filename=Screenshot_20170820-232956.png)
Click on the bluetooth widget on your app which is the name you specify in the code, I called it TechMartian. Select the name of your device. Click on the twitter widget and connect your twitter account to the app you created.
Run and Enjoy!
![0XSZiryhSPau6a%AFHeCoQ_thumb_7ce.jpg](/proxy/?url=https://content.instructables.com/FGC/GK48/J6QQHC67/FGCGK48J6QQHC67.jpg&filename=0XSZiryhSPau6a%AFHeCoQ_thumb_7ce.jpg)
Run the app by pressing the Play button (the small triangle in the upper right hand corner).
Press the buttons and watch it tweet for your automatically!