Introduction: Real-Time IoT Poll Tracking Display

Picture of Real-Time IoT Poll Tracking Display

To distract myself from the anxiety of this interminable election season I decided to channel my angst into a project that displays the results from an aggregated election polling site in real-time. This IoT connected project retrieves the latest polling data from the polling aggegator site FiveThirtyEight.com (which correctly predicted the election outcome of 49/50 states in 2012), and displays the current net liklihood of winning for the two major political parties on a 4-digit 7-segment numerical display.

Step 1: Hardware

Picture of Hardware

The hardware components for this project are:

I chose the Adafruit Huzzah board to control this project because it combines simple WiFi access using the ESP8266 with Arduino IDE compatibility and enough I/O pins to run the LEDs, switch and 7-segment display. Additionally, it's inexpensive and Adafruit provides some nice libraries and code examples to show how to use various protocols to access data over the Internet.

The logic level converter was necessary because the Huzzah operates at 3.3V and the 7-Segment display operates at 5V. Sometimes, you can trigger 5V logic with a lower voltage input, but I found the display wouldn't work without the converter.

The slide switch allows the user to toggle the view between the Democratic and Republican parties, as desired.

Step 2: Wiring

Picture of Wiring

The wiring is shown on the diagram above. The 5mm LEDs connect to the Huzzah via 220 ohm resistors. In case you can't read the pin numbers on the diagram, the connections are: Power is connected to the board from the 6V wall adapter which plugs into a barrel-jack to breadboard adapter on the breadboard.

  • Huzzah Pin 2 -> LED Up (indicates odds of winning have gone up)
  • Huzzah Pin 15 -> LED Down (indicates odds of winning have gone down)
  • Huzzah Pin 4 -> LED Dem (indicates display is showing odds of a Democratic win)
  • Huzzah Pin 5 ->LED Rep (indicates display is showing odds of a Republican win)
  • Huzzah Pin 13 -> Logic Converter -> 7-Segment LED RX (Displays the percent chance of winning)

Step 3: 3D Printed Case

Picture of 3D Printed Case

The case doesn't fully enclose the electronics, but holds the LEDs in place and shields the electronics from the front view. I designed it in Sketchup and printed it without support. 3D printer design files for the case are at GitHub: https://github.com/geekmomprojects/apocalyptometer

To make the display more visually interesting, I glued on pictures of the symbols for the Democratic and Republican parties over their indicator LEDs (blue for Democrat and red for Republican, of course).

Step 4: Assembly

Picture of Assembly

Assembly is very straightforward. Wire up the electronics on the breadboard as shown in step 2. The image above shows that actual wiring usually looks a lot messier than the diagram.

I soldered the 220 Ω resistors directly to the positive legs of the LEDs to keep wiring simpler. Then stick the breadboard to the back platform of the stand, and push the LED holders through the holes in the front panel. Then push the LEDs into the holders. The 7-segment LED display fits inside the rectangular hole in the front. I didn’t even have to glue it into place. A rubber band helped secure a barrel-jack connector to the breadboard to transmit power from the 6V wall adapter.

Step 5: Software - Raspberry Pi

Picture of Software - Raspberry Pi

The combination of mosquitto and Node-RED running on a Raspberry Pi makes it easy to get information from the web to an IoT connected device. Mosquitto is an open-source MQTT message broker which receives and sends out lightweight messages on a publish/subscribe model. Node-RED is a Javascript-based tool which allows drag-and-drop interfacing of APIs, online services and hardware.

Here are instructions to install mosquitto on a Raspberry Pi:

https://www.instructables.com/id/Installing-MQTT-BrokerMosquitto-on-Raspberry-Pi/

and here are instructions to install Node-RED on a Raspberry Pi:

http://nodered.org/docs/hardware/raspberrypi

In Node-RED, a flow is a sequence of nodes that operate on data and pass the results onto the next node. The Node-RED flow I used is shown in the picture above. The flow is triggered by the receipt of an MQTT message from the Adafruit Huzzah. The first node subscribes to an MQTT topic (‘polls/get’) and waits for a message to trigger the subsequent nodes in the flow. The second node runs a system command on the Raspberry pi to get the FiveThirtyEight.com data using Lynx, a text-based web browser. I tried using Node-RED’s HTTP node in the flow to grab the data from the website, but it didn’t work well with the FiveThirtyEight’s complex formatting. The FiveThirtyEight text data from Lynx then runs through the third node – a Javascript function to parse the text and extract the percentage chance of winning assigned to each party. The final node sends the output data in an MQTT message by publishing to the topic ‘polls/current’. The code running on the Huzzah subscribes to the same topic and receives each message as it is published. You can find the code for the Node-RED flow in the source files at: https://github.com/geekmomprojects/apocalyptometer

If you want to use this flow directly, here is a link on how to import a flow from a file into Node-Red:

http://developers.sensetecnic.com/article/how-to-import-a-node-red-flow/

If you use it, you will have to make sure Lynx is installed on your system, and you will need to substitute your own values for the username/password combination to access the mosquitto server.

Step 6: Software - Huzzah

The Arduino IDE code that runs on the Adafruit Huzzah board is available at https://github.com/geekmomprojects/apocalyptometer and uses the Adafruit MQTT library to connect to the MQTT server, publish to the ‘polls/get’ topic to trigger a request for data and subscribe to the ‘polls/current’ topic to receive the latest polling data. I based this code off of one of the examples that comes with the Adafruit MQTT library.

I also used some code from the Sparkfun examples for setting values on the 4-digit 7-segment display available here: https://learn.sparkfun.com/tutorials/using-opensegment?_ga=1.92394845.1939965206.1463025221

The code also responds if the user moves the slide switch to toggle the display between the percentage chance of winning for the Republicans and Democrats. Additionally it lights up the appropriate LEDs to indicate whether the percentage chance of winning has most recently gone up or down.

Step 7: Future Improvements

I’ve contemplated adding an alarm (loud, klaxon-type) to indicate when my preferred party’s support drops below a certain level, or visual cues on how the race is going (e.g. panic/don’t panic display). I'm also joking about adding a Xanax dispenser.

Whatever the outcome of the election this November, I'll at least be able to look proudly at this project to say something positive came out of it!

Comments

About This Instructable

356views

8favorites

License:

Bio: Mom, maker, tinkerer, technophile.
More by GeekMomProjects:Baseball Cap with Pussycat EarsDr. Honeydew and Beaker Halloween Gourds with 3D PrintingReal-Time IoT Poll Tracking Display
Add instructable to: