IT515 – Lab 3 – Telling stoplights what to do

Online Link

Source code can be found at: https://github.com/evade-ninja/it515-lab3

Objective

This lab is designed to take the Stoplight controller from Lab 2, and using a separate device, communicate with it to control its state. This will be implemented using the 3 color stoplight from lab 2, pairing it with another device utilizing an ultrasonic sensor, and having the two devices talk to each other using WiFi.

Materials

I used the following materials:

  • 2x Wemos D1 mini
  • Red, Yellow, and Green LEDs
  • 3x 220ohm resistors
  • 1 Ultrasonic Rangefinder model HCSR04
  • 2x breadboards
  • An assortment of jumper wires

References:

I used the following references in this lab:

Procedures:

  1. Modify the code from Lab 2 to implement a “blinking red” state and add an mDNS hostname. The blinking red light is to signify that the vehicle is too close, and the mDNS hostname makes it easy for the sensor device to locate the light device.
  2. Implement the ultrasonic rangefinder device. This was done in two phases.
    1. First, using the HCSR04 Arduino Library, I made sure that I could get measurements that seemed reasonable over the serial port. My initial attempts were not fruitful. I ended up with strange results. I was getting distances of -1, and 2. After some trial and error, I determined that my issue was that the ultrasonic sensor was being powered off of the 3v3, but it required 5v. Once I powered the sensor off of 5v, I started to get values for distance that seemed reasonable.
    2. Second, I used only the Wemos device to test connecting to the Stoplight device. As IP addresses can be inconsistent, I decided to use mDNS to locate the Stoplight device. Surprisingly, there are lots of mDNS responder (servers) for Arduino/ESP8266, but finding a resolver that worked was surprisingly difficult. After trying several differently libraries, I eventually came across Madpilot’s mDNSResolver library. Once I had the mDNSResolver working, I was able to communicate with the Stoplight device with ease.
  3. With the two halves ready, I united them. I defined distances for “too-close” (flashing red), “just right” (red), and “almost” (yellow). My code takes 5 readings from the sensor and averages them. In the event that the rangefinder returns negative results, these are treated as not far enough and result in a green light.

Thought Questions

  1. Think about the interaction between your devices. How well would this scale to multiple devices? Is it easy to add another sensor? Or actuator?
    Adding another sensor or actuator would require recoding of some degree. Each additional sensor or actuator would require additional coding. After 1 or 2, it gets unwieldly very quickly.
  1. What are the strengths and weaknesses of the tennis-ball-on-a-string system that Don had originally? What are strengths/weaknesses of the IoT system? What enhancements would you suggest?
    A low tech solution using a tennis ball on a string is simple. It is cheap. It doesn’t require batteries. It does however require someone to relocate it if the vehicle changes, or if someone tampers with it (like hitting it with a baseball bat). A high-tech solution does require power and some initial configuration, but vehicle changes would be fairly easy to implement. There are some concerns with over-complicating “things”. A wise engineer once said “the more they overthink the plumbing, the easier it is to stop up the drain.” Although more complicated, knowing if the vehicle is parked in the garage is nice, and being able to quickly adjust for new vehicles is nice if one frequently changes vehicles.
    As for enhancements, the ability to change the appropriate distance through a web interface or by pressing a button would be quite nice.
  2. What was your biggest challenge on this lab?
    The biggest challenge was the mDNS resolution. It took me a good hour to find a library that would work.
  3. How much time did you spend on this lab?
    I spent about 4.5 hours on the hardware/software portion and about an hour on the lab report.

Leave a Reply

Your email address will not be published. Required fields are marked *