Powerbot connecting real world to twitter
via Raspberry Pi using GPIO pins
Intro
This post is long overdue. Recently, had a chance to present what I did with Raspberry Pi some years back. Powerbot is a fun experiment publishing the status of electricity availability in my home town back when we faced an electricity crisis.
Why and What
- Back in 2012, we were facing serious load shedding.
- Trying to figure out the time and duration of the load shedding.
- Heard about Raspberry Pi and was looking for an actual use case to buy it.
- That is when I imagined using Raspberry Pi to automatically collect electricity availability and publish it to the world via Twitter!
“Imagination is more important than knowledge.” - Albert Einstein.
System Layout
GPIO pins
GPIO - General Purpose Input Output pins. We can read/write state. State can be either 1 or 0, purely binary based on the voltage level.
Sensor Unit
- This is a simple circuit that changes the state of the GPIO_IN_4 using LDR. LDR - Light Dependent Resistor.
- LED light powered using mains line is placed in front of the LDR.
- 3 wires are connected to Pi.
- 2 for powering the circuit and one for detecting the state.
- 3.3 V line.
- Ground line.
- GPIO 4.
Software
- Built using Python. Simple Program would check the status of the electricity every second.
- If there is a change in status, it will trigger generating twitter message.
- Message will be buffered in local as well just in case internet connection goes down.
- I had used Twython client library to connect with Twitter. Even built a wrapper around this to overcome the unstable Internet connection.
- Additionally, the software would publish the stats of the electricity over last day, week, month, quarter etc.,
- Entire source code available at https://github.com/sakthipriyan/powerbot
Following code is used to set up and detect the status.
import RPi.GPIO as GPIO
def init_sensor():
GPIO.setmode(GPIO.BCM)
GPIO.setup(4, GPIO.IN)
def get_status():
return not GPIO.input(4)
Let’s revisit what happened on the Feb 26, 2013.
As summer is approaching, we can expect more load shedding ~ 05:49 OFF
— Powerbot (@powerbot_tn) February 26, 2013
Adding more green power plants, will certainly help us!! ~ 06:05 ON
— Powerbot (@powerbot_tn) February 26, 2013
It is new normal that current goes off with no fixed schedule ~ 12:01 OFF
— Powerbot (@powerbot_tn) February 26, 2013
It is new normal that current comes back with no fixed schedule ~ 13:57 ON
— Powerbot (@powerbot_tn) February 26, 2013
This electricity problem is affecting the SMEs. Increases operating cost ~ 16:14 OFF
— Powerbot (@powerbot_tn) February 26, 2013
Electricity is vital to development & betterment of live ~ 16:56 ON
— Powerbot (@powerbot_tn) February 26, 2013
Inefficieny & no long term planning & execution lead us to this situation ~ 17:03 OFF
— Powerbot (@powerbot_tn) February 26, 2013
With efficient planning & execution we could have avoid the situation ~ 18:03 ON
— Powerbot (@powerbot_tn) February 26, 2013
As long as we have government enterprises ruining the country, we have no options ~ 20:08 OFF
— Powerbot (@powerbot_tn) February 26, 2013
Open market, regulated private power plants would have met the demand way back ~ 20:51 ON
— Powerbot (@powerbot_tn) February 26, 2013
Daily Report:Feb 26, 2013. OFF TIME: 4:36:31. Availability: 80.80%. Change: +5.03%.
— Powerbot (@powerbot_tn) February 26, 2013
Apparently, latest tweets in the account has some issues probably due to hardware malfunctions.
In retrospect
- I truly enjoyed it!
- Doing electrical wiring, taking out the electrical wiring out of the switch box.
- Identifying the electronic components and soldering it to the board.
- Writing the software to read the GPIO pins.
- Tweet it out to the whole world the status of electricity in my hometown.
- I still missed the original goal of predicting the load shedding. :(
- It would have been real fun if powerbot tweeted the ON/OFF time before it happened.
- At least one of my friend from other part of the town started following this twitter handle to check if I had electricity in my home. :)
- I did powerbot, before the IoT became famous. It happened in early 2013. Loooooong time back.