Intro: Incoming Subway Lamp
Tired of rushing to the subway only to see tail lights as it pulls away from the station?
Me too. So I have created a little Arduino powered lamp that changes colors based on when the next train is coming. This one was built using the BART API but many systems have public access to their GTFS Feed(this is what gives you the time until the next train/bus), but check your system's website before starting to build!
Step 1: Gather Materials
- Arduino UNO board + Ethernet Shield (though any board with ethernet would work)
- Adafruit's Neo Pixels (preferably the breadboard friendly version)
- Blank PCB Board
- Soldering Iron
- Ethernet cable
- Power cable
- Web server access (for processing the API data)
- Ikea Lamp shade (Ikea Website) OR
- 3D Printer and Laser Cutter and materials for that
Step 2: Find Transit Live Feed
Step 3: Set Up Simple PHP Document for Parsing
So the Arduino has a hard time extracting the time for the full feed, so in order to expedite this process it is worthwhile to set up a .php document on your website to get just that information. For example, what it looks like for the BART API to get the next train departing Hayward, CA going North:
<p>$xml=simplexml_load_file("http://api.bart.gov/api/etd.aspx?cmd=etd&orig=HAYW&key=MW9S-E7SL-26DU-VV8V&dir=n");<br> echo '<'.$xml->station->etd->estimate->minutes.'>';</p>
This will then put the time between '<' and '>' so we can tell the Arduino to just grab that number and use it.
Make sure to add the opening and closing PHP tags!
Step 4: Upload the Arduino With the Code
Please download the attached file and change lines 16 and 21 (the ones shown below) to the location of your PHP script we just set up.
Make sure to leave in the HTTP/1.0 so the Arduino knows what type of party it is going to!
<p>char server = "www.fosterport.co";</p><p>String location = "/arduinoTesting/ardi.php HTTP/1.0"; </p>
Step 5: Solder Neo Pixels Together and to PCB Board
The number depends on how many you want to use and how bright you need the lamp to be, also the PCB is optional but it is a lot easier to use than just soldering them together in the air and they stay together better.
Step 6: Wire the Arduino and NeoPixels Together
The code uses Pin 6 for the data, and 3.3V for the Power and Ground for Ground.
The Adafruit Best Practices(available here) suggests using a capacitor and possibly an additional resistor, I would go with that if you have them around but I have run these for a few months without them and I have not had any problems.
Step 7: Create Device Inclosure
On the simpler side, you can just buy an Ikea lamp and use that or if you want to get fancy you can 3D print almost anything to put it in. I personally made a little BART car and the 3D model is attached and I laser cut the additional inclosure you see.