Raspberry Pi + electric current nerve stimulator + Twitter = Shock-bot
It was New Years Eve so I decided to wire up a T.E.N.S. (Transcutaneous electrical nerve stimulation) device through a relay to a raspberry pi and then run a python script that scans my twitter feed for the hashtag #happynewyear. Every time it sees #happynewyear, it shocks me! GREAT IDEA, RIGHT!?!?
Time to check out the parts list:
Step 1: Parts List
Step 2: Getting the Pi Ready
First, I assume you're familiar with using a Raspberry Pi through SSH so we'll start by updating the Pi
SSH into your Pi and run
sudo apt-get update
sudo apt-get upgrade
so we can start with an up to date Pi. Now we have to get a few packages to install.
Run these commands to download all the packages needed for this project:
sudo apt-get install python-pip sudo pip install twython
Step 3: Make You Twitter App
Now we'll head to Twitter
Visit apps.twitter.com and sign up or log in if you already have an account.
Once you have signed in, click on your user icon, and select “My Applications”.
Click on the “Create a new application” button, fill out the form about your application. Fill out the name and description fields. For “Website,” you can put anything that looks legitimate. At the bottom of the page, click the checkbox to agree to the terms, and click the “Create your Twitter application” button.
Now you need to create an access token by clicking the “Create my access token” button at the bottom of the screen. Copy down the “Consumer key,” “Consumer secret,” “Access token,” and “Access token secret.” You will need these for the shockbot.py script.
Step 4: Finish Up the Software
Back to the Pi to make the python script.
We'll make a directory for our project by typing:
sudo mkdir shockbot
Move into this new directory by typing
Now we'll make the Python script.
Use the command
to open the text editor.
Copy the Python script. Make sure you add in your access token info you got when creating the Twitter app.
import RPi.GPIO as GPIO from twython import TwythonStreamer
# Search terms TERMS = '#yourhashtag'
# GPIO pin number of LED LED = 22
# Twitter application authentication APP_KEY = 'YOUR_APP_KEY' APP_SECRET = 'YOUR_APP_SECRET' OAUTH_TOKEN = 'YOUR_TOKEN' OAUTH_TOKEN_SECRET = 'YOUR_TOKEN_SECRET'
# Setup callbacks from Twython Streamer class BlinkyStreamer(TwythonStreamer): def on_success(self, data): if 'text' in data: print data['text'].encode('utf-8') print GPIO.output(LED, GPIO.HIGH) time.sleep(1) GPIO.output(LED, GPIO.LOW)
# Setup GPIO as output GPIO.setmode(GPIO.BOARD) GPIO.setup(LED, GPIO.OUT) GPIO.output(LED, GPIO.LOW)
# Create streamer try: stream = BlinkyStreamer(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET) stream.statuses.filter(track=TERMS) except KeyboardInterrupt: GPIO.cleanup()
At this point, you want to set your Twitter keyword. Also set the time.sleep duration to the length of time you want to be shocked.
Save and exit
That finishes up the software part of this project
*This code was contributed to a Sparkfun tutorials project by ShawnHymel. We're repurposing it to trigger our device.
Step 5: Prep the T.E.N.S. Connector
Time to grab out T.E.N.S and relay and hack some hardware
The T.E.N.S. device has two pad inputs on the top, we're only going to need one. Take one set of pads and pull the wires apart down to about 4 or 5 inches from the plug.
Follow the wire with the red connector on top and cut it near the bottom where it plugs into the device. I soldered a header pin to the end of each wire.
Step 6: Wire Up Your Relay
Take your relay breakout and attach the plug side of the cut wire into the "Common" terminal of the relay.
Attach the pad side of the cut wire into the "Normally Open" terminal. You can use a multi meter to find this if your relay doesn't have any markings on it. On the low voltage side of the relay, connect wires to the Power, Ground, and Signal pins.
Step 7: Connect the Relay to the Pi
The Power and Ground pins will connect to power and Ground on the Pi and the Signals will connect to pin 22 of the Pi. Google search for the pinouts to match the model Pi you are using.
Pop the battery into your T.E.N.S. and that completes the hardware.
Turn on the T.E.N.S. and attach the pads to your forearm and get ready to start the python script
On your Pi in your shockbot directory run
sudo python shockbot.py
from the shockbot directory.
Now sit back and wait. You might want to start with the settings low and bump them up. You can also mess with the devices settings to get the desired result.
This projects is provided for education only. Only replicate this at your own risk. I am not responsible if you go to jail or die!