logo
 

For this DIY project, we will be creating a dance sensor that can be hooked to a computer. If you have a rasberry pi rasberry pi icon or an android phone android logo, you could connect this sensor to it and carry it with you.

The project is basically a sensor that is hooked to a shoe, when you dance, it will twitter a status update stating that you're dancing and play a short sound.

 
STEP 1 - Get your shit together
  • Arduino Diecimila
  • Wires
  • 1K Ω resistor
  • 250 Ω resistor
  • Push button
  • Shoes
  • Computer running GNU/Linux
 
STEP 2 - Connect
Hook up a circuit according to this schematic, PIN 13 and its LED is not mandatory. Both the VCC, GND and PIN 2 are from the Arduino.
schematic

when hooked up and done, it should look as such

 
STEP 3 - get a twitter account
You not only need a twitter account, you also need to go to the developer section and request API access. this is done by first singing up with twitter.com then going to http://dev.twitter.com and creating a new application. See the pictures below.

Retrieve from the application settings, the following API codes:

  • consumer_key
  • consumer_secret
  • access_token
  • access_token_secret
  •  
    STEP 4 - Programming

    Replace your API codes with the ones in this Python code and save this code to a text file named "instadance.py"

     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
    import datetime
    import serial
    import twitter
    import os
    
    ser = serial.Serial('/dev/ttyUSB0', 9600)
    
    api = twitter.Api("consumer_key", 
    		"consumer_seccret", 
    		"access_token", 
    		"access_token_secret")
    
    counter=0
    t0 = datetime.datetime.now()
    msg = "I'm Dancing :D"
    
    while 1:
    	p = ser.readline()
    	counter=counter+1	
    	print (datetime.datetime.now()-t0)
    	if ((datetime.datetime.now()-t0).seconds) > 30:
    		t0 = datetime.datetime.now()
    		counter=0
    	else:
    		counter=counter+1
    		if counter==50:
    			os.system("aplay bell.wav")
    			print "Loading please wait..."
    			hour=str(datetime.datetime.now().hour)
    			minute=str(datetime.datetime.now().minute)
    			api.PostUpdate(msg+" ("+hour+":"+minute+")")
    			print msg
    
     
    STEP 5 - Getting a sound
    You need an unformatted wav file, download the following bell.wav (14K) and place it in the same folder as "instadance.py".

     
    STEP 6 - Install Libraries

    For the code to work, you need to install two libraries, one for the twitter API and one for the serial port.

    The twitter API library installation guide

    Download python-twitter-0.8.2.tar.gz (62.2 Kb)

    or use this QR-code to scan and download the file

    Extract the content of the file to a folder, direct a terminal to it and type in the following command:

    you@computer:~$ python setup.py install

    For the twitter API itself to work, you have three other dependencies. Visist and install the following three libraries.

  • http://cheeseshop.python.org/pypi/simplejson
  • http://code.google.com/p/httplib2/
  • http://github.com/simplegeo/python-oauth2
  • The serial port library installation guide

    Download pyserial-2.6.tar.gz (113 Kb)

    Extract the content of the file to a folder, direct a terminal to it and type in the following command:

    you@computer:~$ python setup.py install

     
    STEP 7 - Arduino
    Connect your Arduino to your laptop or pc running GNU/Linux and upload the following code to the device
     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
    // set pin numbers:
    const int buttonPin = 2;
    const int ledPin =  13;
    
    // variables will change:
    int buttonState = 0; 
    
    void setup() {
      // 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) {     
        // turn LED on:    
        digitalWrite(ledPin, HIGH);  
      } 
      else {
        // turn LED off:
        digitalWrite(ledPin, LOW); 
    
      }
    }
    
     
    STEP 8 - The Shoe
    Attach the push button to a shoe, this can be done differently depending the type of push button you are using and the amount of love you have for your shoes.
     
    STEP 9 - Try it out

    To understand what the pattern for dancing is you need to try it out. Make sure to have the arduino connected to your computer with the USB cord. Run the "instadance.py" code by directing your terminal to the file and typing the following

    you@computer:~$ python instadance.py

    Here are the following test-data we recieved
     
    6.98184
    7.173643
    8.15385
    8.241606
    9.165586
    9.23362
    10.205625
    10.276241
    11.249569
    11.317582
    12.229567
    12.297611
    13.169597
    13.249615
    14.141594
    14.209798
    15.1536
    15.213615
    16.085618
    16.153569
    17.033597
    17.105527
    17.997402
    18.057402
    18.977585
     
    1.008517
    1.068062
    1.340072
    1.400025
    1.680034
    1.740081
    1.980035
    2.032051
    2.323795
    2.36135
    2.632031
    2.683898
    2.952042
    3.004751
    3.283833
    3.333152
    3.604032
    3.644022
    3.924005
    3.964415
    4.253245
    4.304062
    4.584036
    4.624146
    4.909567
     
    0.258927
    0.326955
    0.710992
    0.772081
    1.44266
    1.490909
    1.818936
    1.872711
    2.270864
    2.331092
    3.043039
    3.08289
    3.414647
    3.442887
    3.794751
    3.834866
    4.543797
    4.586889
    4.903928
    4.946783
    5.288098
    5.335065
    5.966894
    5.995035
    6.327148
     
    STEP 10 - Choose a dance
    The python code provided is just 50 steps / 30s, you need to choose a dance-style and modify the code with an algorithm that recognizes the pattern. When that is done you're good to go.
     
    HERE'S OUR DANCE UPDATER