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.

Share

Great!! You read till this point, just go ahead and share this post to your followers, collegues and friends. Thanks!

About Author

Sakthi Priyan H
Passionate Programmer

  • I am passionate about building excellent teams, processes and systems.
  • Primarily I use Java, Scala and Python for building various systems and tools.
  • Building API services, Big data processing and Machine Learning systems in Crayon Data.
  • Also, interested in Golang and building web apps using Javascript ecosystem.
  • I wrote my first program in BASIC in 1998, Passionate about computers since then.