Thursday, June 4, 2015

Creating your own Internet of Things

These instructions will help you setup your own Internet of Things.


What is the Internet of Things?  Moore's Law accurately predicted that computing density would roughly double every 18 months.  Today we have credit-card sized, fully-functional, general purpose computers that cost $35.  Eventually we will reach a point where embedded computing will be so small, cheap and low-power that many everyday objects (light switches, garage doors, thermostats, kitchen appliances, etc) will include an embedded processor/micro-controller.  These smart objects will be able to communicate, collaborate, coordinate with other objects and human interfaces to automate existing tasks, and enable new capabilities.

Some example ideas:

  • Set the room brightness with your smartwatch
  • Have your lights automatically turn on/off as you travel from room to room
  • See the remaining time on the clothes dryer
  • Track the internal temperature of the pot roast in the oven
  • lower your heating and cooling bills by reducing the climate control in unused rooms
  • unlock your door by simply grasping the handle

While there's many ways to go about it, I'll describe the approach I used.

Things you'll need for a basic setup:

  • Raspberry Pi 2 model B
    • 4GB+ SD card
    • power adapter
    • HDMI cable
    • Ethernet cable or compatible WiFi adapter
    • monitor, keyboard, mouse
  • Arduino
    • Ethernet shield + Ethernet cable
    • USB programming cable
    • PC for programming the Arduino

Step 1: Setup your Raspberry Pi

  1. Follow this guide to install Raspbian Wheezy onto your Raspberry Pi
  2. Install MQTT
    curl -O http://repo.mosquitto.org/debian/mosquitto-repo.gpg.key
    sudo apt-key add mosquitto-repo.gpg.key
    rm mosquitto-repo.gpg.key
    cd /etc/apt/sources.list.d/
    sudo wget http://repo.mosquitto.org/debian/mosquitto-wheezy.list
    sudo apt-get update
    sudo apt-get upgrade
    sudo apt-get install mosquitto mosquitto-clients
     
  3. Subscribe to a  MQTT topic
    mosquitto_sub -h YOUR_RPI_IP_ADDRESS -t hello/world
  4. Publish to a topic
    In another terminal window execute:
    mosquitto_pub -h YOUR_RPI_IP_ADDRESS -t hello/world -m "Hello World"

Step 2: Setup your Arduino


  1. Download the arduino pubsubclient from GitHub
    • Unzip the file and copy it into your Arduino/libraries directory
  2. Build the circuit
    • Connect an LED to pin 3 of the arduino through a 220 Ohm resistor
    • Connect an SPST (normally open momentary contact) switch between pin 2 and ground
  3. Program your Arduino
    • Grab this example Arduino sketch
    • change the server[] to your Rasberry Pi's IP address
    • load the code onto your Arduino
  4. Setup a subscriber to monitor the "led" topic
    • On your Raspberry Pi, open a terminal and subscribe the the "led" topic
      mosquitto_sub -h YOUR_RPI_IP_ADDRESS -t led
  5. Power up your Arduino 
    1. You should see "Hello World" published to the "led" topic
    2. When you press the switch you should see "on" or "off" on the "led" topic.
    3. When "on" appears, the LED should turn on and vice versa.
Here's a code example for the Spark Core:

Useful Links:


No comments:

Post a Comment