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)

Twitter

Let’s revisit what happened on the Feb 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.
hardware iot python code circuit raspberry pi twitter

Recent blogs

Creating Base64 UUID in Java
Alphanumeric unique id using base64 charset

uuid java code base64

Documenting Play Framework using Swagger
Setting up live documentation for API

api swagger play framework documentation design

Creating REST API Specification
using Swagger Specification

api swagger documentation design cricscore api

Set up G-WAN web server
to serve static website

web server g wan setup

Scala code to access documents in AWS S3 bucket
via http get and put requests

scala aws s3 http code dispatch

Auto refresh Chrome when files modified
Using python pyinotify and chrome debugging

chrome python webgen code