Summary

Arduino is a powerful microprocessor that can be programmed for I.O.T. purposes. In this report I’ll be showing you how I created a Stoplight using an Arduino that can be controlled over the internet.

Application

How could this technology be used? If Traffic Lights were controlled over the internet then light cycles could be adjusted for the time of day or for accidents and obstructions. In the world of COVID-19 an Internet Traffic Light could mean that workers don’t have to go out to the lights to program or maintain them which would reduce their chances of contracting the virus. Internet controlled Traffic Lights could be paired with machine learning so that they could time their cycles so that traffic flows at a smoother pace which in turn could result in less traveling time for you and me. All these possibilities start with Traffic Lights being controlled over the internet.

How does it work?

The Arduino is coded to connect to a WiFi network. Once connected the Arduino listens like a web server for certain requests to be made to it’s IP address. When the requests are made the Arduino will change the state of the Traffic Light. Once the change is made the Arduino sends an HTML page back to the requester showing what the state of the Stoplight is. Here’s a picture showing that interaction:

Materials Needed

  • Arduino D1 mini
  • Breadboard
  • wires
  • 3x Resistors
  • 3x LED Lights (Red, Yellow, Green)
  • Computer

Hardware Setup

  • To start let’s get the hardware setup:
    • Here’s what the end result will look like:
  • Grab all the materials listed in Materials except your computer
    • Choose a row on the bread board for each led
    • Place the led’s in the rows like shown in the diagram
      • Be sure the negative side of the LED is on the receiving end of power from the board
    • On the Arduino choose some of the pins that start with a “D” and write down which pins correlate to which light. (You’ll need this later in your code)
    • You can now connect a wire from the pin to the negative side of the LED
    • Now connect resistors from the positive side of each LED to what will be ground. In my example I choose to make a whole side row of the bread board to be used as ground.
    • Now connect the ground to the Arduino pin labeled with a “G”
    • Double check that everything is connected and in a closed circuit and you’re ready to start coding.

Code Setup

The code behind the Arduino Internet Traffic Light is fairly simple state machine illustrated by this state diagram:

To put this state diagram into English terms the Arduino will start by having the Traffic Light stay in the Off state. The off state means that all LED’s are off. From this state the Arduino can put the Traffic light into several states. There is one state per LED where only that LED is on and the Arduino can put the light into any of those states from the off state. The other state which I refer to as Auto which basically puts the Traffic Light into a loop that transitions from Red state to Green state to Yellow state.

Setting up Arduino IDE

  1. Grab your computer
    • (This setup tutorial comes from jonathanblack.org)
  2. Download and install Arduino IDE from https://www.arduino.cc/en/Main/Software
  3. Accept installation of USB drivers for Arduino.
  4. Add the Wemos D1 library to the Ardinuo IDE
    1. In the Arduino IDE select File -> Preferences
    2. In the Additional Boards Manager URLs field enter: http://arduino.esp8266.com/stable/package_esp8266com_index.json
    3. Click Tools -> Board: …. -> Board Manager
    4. Search for “Wemos D1” and install the “esp8266” board module
  5. Select the Lolin(Wemos) D1 R2 & mini . Click Tools -> Board … ->  Lolin(Wemos) D1 R2 & mini
  6. Download and install cQueue. Click Tools-> Manage Libraries. Search for cqueue and install it
  7. Plug Wemos D1 Mini into computer with USB cable.
  8. Open Device Manager. Look for a CH340 device under Ports. Note which COM port the device is assigned to
  9. In the Arduino IDE, select the proper COM port by clicking Tools -> Port
  10. Write Code. Upload it to the board by click Sketch -> Upload

Code

You can find the code I used on my Github

Certificate of Work

The work here represents my own and where I used others work I gave the credit it deserved.

References

  • https://www.jonathanblack.org/uncategorized/simple-arduino-traffic-light/
  • https://www.google.com/search?q=electricity+flows+from&oq=electricity+flows+&aqs=chrome.0.0l2j69i57j0l5.3042j0j7&sourceid=chrome&ie=UTF-8
  • https://www.youtube.com/watch?v=4dd9braoqb8
  • https://lmgtfy.app/?q=How+do+I+get+an+arduino+working

Thought Questions

  1. What are some key differences between developing this lab on a Raspberry Pi, and developing on Arduino?
    • For me the key difference was setting up the web server. The web server on RaspberryPi was much the same as the server I work with everyday at work but the Arduino required a different touch to get connected to the internet and listen for Requests.
  2. What are the strengths and trade-offs of each of these platforms?
    • The Arduino is smaller and single purpose which to me means it can be more ubiquitous and is less of a security threat. This is also a limitation because any update you need to do to the IOT device using an Arduino needs to be done connected to the computer where as the RaspberryPi can be setup like a webserver and be updated from where ever. The problem with the webserver attributes is that the RaspberryPi then becomes a security threat that can be manipulated.
  3. How familiar were you with the Arduino platform prior to this lab?
    • I once tried to help some engineering students get a 3D printer working that was made with Arduinos but I was not successful so I’d so little to none.
  4. What was the biggest challenge you overcame in this lab?
    • Connecting to WiFi. I followed a really great tutorial for this lab but when it came to connecting to WiFi the tutorial wasn’t very clear on how to make that happen so I had to do a lot of research just to figure out that I had misspelled the SSID of my WiFi and once I fixed that I was able to connect to the Arduino over the internet.
  5. Please estimate the total time you spent on this lab and report.
    • Like I said I found a really good tutorial for this lab and only spent around 2-3 hours on the actual lab. The report has been around the same amount.