
Read articles from the magazine right here on Make:. Don’t have a subscription yet? Get one today.
This project displays live traffic conditions between two locations on a physical map, using an Arduino device that gathers data from the Google Maps API and then sets the color of a string of NeoPixels — green for good traffic, yellow for slower traffic, and red for bad traffic conditions, just like online maps. It refreshes every minute to adjust the color of the LEDs as the traffic changes.
The project runs on an AdaFruit Feather HUZZAH ESP8266 programmed via the Arduino IDE, but the code should run on any ESP8266 board. Its configuration is persistent across resets, as it uses SPIFFS, which is internal flash memory on the ESP8266.
1. Build the circuit
On your breadboard:
- Place a 220uF capacitor between 3V and GND
- Connect the positive power lead of your first NeoPixel to 3V, and then wire the positive leads of your remaining NeoPixels in parallel
- Repeat this same step for GND and the negative power leads
- Place a 330 Ohm resistor between the output pin of your board and the data-in of your first NeoPixel
- Connect the data-out of the NeoPixel to the data-in of the next, and repeat. The data-out of the last NeoPixel should be left disconnected

2. Get the Google Maps API Key
In order to get the traffic data from the Google Maps API you need use an API key, these are free and very easy to get.
- Open https://developers.google.com/maps/documentation/distance-matrix in your browser
- Scroll down to Quick start steps and click the Get a Key option
- Type in the name of your project and click the checkbox to agree to the terms and conditions
- You will then be given your key that you need to use later in the sketch
I recommend trying out your key using the following URL to make sure it’s working correctly (Make sure to change the key at the end!)
If everything appears to be working, you’ll paste your API key into line 89 of the code, which you’ll download from the project’s Github page.
3. Set The Code For Your Map
You now have everything you need to program you board with the example sketch.
- Open the traffic-notifier sketch in the Arduino IDE
- There is a list of libraries up the top of the sketch, they will all need to be installed if you do not have them already (All are available on the Arduino Library Manager)
- If you scroll down a small bit, you will see a commented section where you can adjust the code for your specific use. It is here that you can set your output pin, number of NeoPixels, brightness, traffic thresholds, and refresh rate
You should now be able to program your board with the sketch.
4. Run the Device
First, connect board to wifi:
- Power board on and find its WiFi network. Connect computer to the board’s WiFi and configure it to join your network. Now it can load traffic condition data.
- Find your starting longitude and latitude:
- Navigate to your starting point in Google Maps, then copy the longitude and latitude from the end of the URL
- Input it into line 96 of the code
- Repeat for destination (line 97)
- Upload code to the board
- Unplug your computer and connect supply power to the board if not already done.
- Wait a few seconds as the map downloads the traffic data and changes the map’s lights to the appropriate color.
5. Mount it
This part is up to you — we used a vintage map of San Francisco that we downloaded and printed to track traffic over the Bay Bridge, placing four LEDs along the bridge’s path. We mounted the map and circuitry to a foamcore board for rigidity. This can be placed inside a nice picture frame and hung on the wall.
NOTE: If you use more than five LEDs, you may need to add a logic level converter to supply adequate power to all. Wire it up as such:
Conclusion

The rare “daytime all green”.
Your traffic map is done! Now you simply have to plug it in using any standard 5V power source with a MicroUSB plug on it. The board will connect to the internet and run the code; a few moments later, the LEDs will light up to show you the traffic between the locations you’ve specified.
I think the Google Maps API paired with an ESP8266 has the potential to create some really interesting projects that represent the information available on google maps in a physical way. It can be used to compare the travel times of several different routes home to or from work (as shown here https://www.instructables.com/id/Arduino-Commute-Checker/) or even could be used to compare travel times between different modes of transport (driving / walking / public transport etc) so it could even be used as a device to try encourage people to try alternative ways of getting to work if driving is significantly slower.
Dumb question (I’m not an EE)… but why the capacitor?
It’s best practice when working neopixels to use a capacitor because there can be such large differences in current draw between different modes. For a project like this where there is a only a few neopixels and they are not at full brightness I think there would be no issues without, but for the sake of a couple of cents for a capacitor I think its a good idea to include it.
This is a really good guide on how to connect up Neopixels:
https://learn.sparkfun.com/tutorials/ws2812-breakout-hookup-guide
In Step 1 Build the Circuit the description says, “Connect the positive power lead of your first NeoPixel to 3V, and then wire the positive leads of your remaining NeoPixels in parallel”, however the picture of the soldered neopixels appears to be done in series for the +red wires, daisy chaining from one to the next. The drawing , however, looks to be done in parallel. Please correct me if I am seeing a contradiction where none exists or tell me if I am right to go with the series connection which I believe was also done in the live video. Thank you in advance.
Hi Jason,
When the Red + wires are looped like that it is connecting them in parallel, the VCC of all the LEDs share a common connection .
Think of one continuous stripped wire connected to 3V, all along that wire be 3V.
If you cut the wire in half, then soldered it back together it would still be 3V all along.
Now solder the VCC pin of your LED to your solder joint, its still 3v all along the wire.
You could repeat the above as many times as you like and 3v would still be connected along the wire.
Does that make sense?
If you were connecting something in series from a power perspective you would be connecting VCC of the second one to GND of the first.
I just love how the EPS8266 started out as a way to ad wi-fi to you projects and it becomes it’s own SBC
Yeah @billfusionjazz:disqus , what this board can do is absolutely amazing to me, it is what me got into “making”. I even showed a project similar to this (the one linked at the bottom of the post) on Adafruit’s show and Tell and even Lady Ada was surprised the ESP8266 could do this!
I ended up spending more time than I would’ve expected trying to figure out how to get this working with a NodeMCU ESP8266 board as the pinouts in the code weren’t making any sense to me….until I realized that the link here to the project GitHub page points to an older project that uses a standard RGB LED (and thus three pins). For anyone else trying to do this per the instructions with neopixels, look here instead: https://github.com/witnessmenow/Bridge-Traffic-Display
Hi Erik
You are right, looks like it’s the wrong version of code linked to in this, thanks for pointing that out!
I’ll email make to see if they can updated the link.
Brian
Hi Brian,
This project seems to be working for me, however when I open the serial monitor I get
“Getting traffic for…”
“Setting colour to…”
“Changing LED”
It does not actually show the duration in traffic value. I’m not good enough to understand how to fix it, but I tried to set the duration int variable into a global variable but it still doesn’t display the travel time.
Hi Ducky,
Great that it’s working that much for you!
Good question! There are two endpoints of the maps API available in the Arduino Library, distance matrix and directions.
Distance matrix does not support waypoints, but the directions one does. You can get the same traffic information out of the directions API. Distance Matrix has a much smaller response so its a little faster, so for something like the bridge project where it could never re-route it’s probably makes sense to use that.
Here is an example of the directions API from the library (I set a waypoint in the example):
https://github.com/witnessmenow/arduino-google-maps-api/blob/master/examples/ESP8266/Directions/Directions.ino
You can also set multiple waypoints if required, format for that is :
via:waypoint1%7Cvia:waypoint2
note the “via” before each waypoint and there is a %7C inbetween each waypoint (%7C is the html encoding for |)
I have a project that uses the directions API, It compares the travel time of several routes and lights up which is the current fastest
http://www.instructables.com/id/Arduino-Commute-Checker/
If you go to step 11 and 12 there should be useful information on how to get the waypoints and how to use them
Hope this helps!
Brian
I think I may have this project working now…I am a beginner and this was probably an ambitious step. But I am not getting the traffic times right. I had to edit the moderate and heavy values to 50 and 60 respectively for a 35-40 min drive.
Also, I need to edit the time for Pacific time, you mention it in a comment, but not what/how to change it.
Can you help?
Just playing around with the color recipies a bit till I get it figured out.
Dave
ConfigureACCEPT
Privacy Overview
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.