Arduino “having11” Guy
Published © GPL3+

What to Wear? Twitter Button

Push a button to receive a message on Twitter for what to wear that day.

EasyShowcase (no instructions)2 hours2,453
What to Wear? Twitter Button

Things used in this project

Hardware components

Arduino UNO & Genuino UNO
Arduino UNO & Genuino UNO
×1
Pushbutton switch 12mm
SparkFun Pushbutton switch 12mm
×1
Jumper wires (generic)
Jumper wires (generic)
×1
LED (generic)
LED (generic)
×1
Resistor 10k ohm
Resistor 10k ohm
×1
Resistor 221 ohm
Resistor 221 ohm
×1

Software apps and online services

Arduino IDE
Arduino IDE
Enthought Canopy Python IDE

Hand tools and fabrication machines

3D Printer (generic)
3D Printer (generic)
Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Custom parts and enclosures

Button Housing

Button Top

Schematics

Schematic

Just connect. The 220 ohm resistor can go between the LED and GND.
Schematic twitter to wear jqdaa2t76k

Code

Python Code

Python
from twython import Twython
import os
import random
import serial

pathToImages = "images/"
app_key = "secret"
app_secret = "secret"
oauth_token = "secret"
oauth_token_secret = "secret"
twitter = Twython(app_key,app_secret,oauth_token,oauth_token_secret)
ser = serial.Serial("COM8",baudrate=9600)

def getImage():
        #Takes the folder where your images are as the input
    images = os.listdir(pathToImages)
    image_open = open(pathToImages + str(images[random.randint(1,(len(images)) -1)]), 'rb')
    print "I chose: " + str(image_open)
    image_ids = twitter.upload_media(media=image_open)
    twitter.update_status(status='You should wear this today: ',media_ids=image_ids['media_id'])

while 1:
    if ser.read() == "h":
        getImage()

Arduino Code

C/C++
const int buttonPin = 5;     // the number of the pushbutton pin
const int ledPin =  13;      // the number of the LED pin

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status

void setup() {
  Serial.begin(9600);
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);
}

void loop() {
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == HIGH) {
    //tell Python it went high
    Serial.print("h");
    // turn LED on:
    digitalWrite(ledPin, HIGH);
    delay(500);
    digitalWrite(ledPin,LOW);
    //5 min delay
    delay(60*1000*5);
  } else {
    // turn LED off:
    digitalWrite(ledPin, LOW);
    //debounce
    delay(50);
  }
}

Credits

Arduino “having11” Guy

Arduino “having11” Guy

26 projects • 181 followers
IoT, Arduino, and Raspberry Pi. I can create design, code, and build projects for only $22/hr. Just message me with your project request.
Contact

Comments