IoT Traffic Light
Table of Contents
- Overview
- The Parts
- Schematics
- Sensor Assembly
- Traffic Light Assembly
- Programming
- Programming (Jenkins Status)
Overview
This project contains a tiny programmable traffic light and a remote sensor. Both driven by a Wemos D1mini powered via USB.
It has been successfully built during a hackathon by beginners to learn the basics of Arduino based IoT projects.
The Parts
To build the traffic light you will need
- Wemos D1 mini (ESP8266)
- a PCB: LED Board
- a case: thing:2463193
- a 5-LED-long segment from a 140/LEDs/m WS2812b LED strip
- pins & cables to connect everything
To build the sensor you will need
- Wemos D1 mini (ESP8266)
- a PCB: Sensor Board
- a case: thing:2463193
- pins to connect everything
Schematics
The schematics for this project are fairly simple. You do not necessarily need the connecting PCB, just add a few wires to make the connetions. If you plan on reusing your D1minis you are better off with the PCBs.
Sensor Assembly
Hint: I always orient the di1mini this way, so it does not wobble on the desk or in a case.
Traffic Light Assembly
Programming
Make sure you have the FastLED library installed.
In the menu you can select
Sketch -> Include Libraries -> Manage Libraries -> Search for “FastLED” and install.
Repeat this step for the BME280 library by “Tyler Glenn”.
In the menu you can select
Sketch -> Include Libraries -> Manage Libraries -> Search for “BME280” and install the library from Tyler Glenn.
To test the sensor, you can use the following Arduino source:
#include <BME280I2C.h>
#include <Wire.h>
BME280I2C bme;
void setup()
{
Serial.begin(9600);
while(!Serial) {}
Wire.begin();
while(!bme.begin())
{
Serial.println("Could not find BME280 sensor!");
delay(1000);
}
switch(bme.chipModel())
{
case BME280::ChipModel_BME280:
Serial.println("Found BME280 sensor! Success.");
break;
case BME280::ChipModel_BMP280:
Serial.println("Found BMP280 sensor! No Humidity available.");
break;
default:
Serial.println("Found UNKNOWN sensor! Error!");
}
}
void loop()
{
printBME280Data(&Serial);
delay(500);
}
void printBME280Data
(
Stream* client
)
{
float temp(NAN), hum(NAN), pres(NAN);
BME280::TempUnit tempUnit(BME280::TempUnit_Celsius);
BME280::PresUnit presUnit(BME280::PresUnit_Pa);
bme.read(pres, temp, hum, tempUnit, presUnit);
client->print("Temp: ");
client->print(temp);
client->print("°"+ String(tempUnit == BME280::TempUnit_Celsius ? 'C' :'F'));
client->print("\t\tHumidity: ");
client->print(hum);
client->print("% RH");
client->print("\t\tPressure: ");
client->print(pres);
client->println(" Pa");
delay(1000);
}
Open the serial monitor (Menu: Tools -> Serial Monitor), and verify the output:
Temp: 21.56°C Humidity: 33.30% RH Pressure: 99364.14 Pa
To test the traffic light, you can use the following Arduino source:
#include "FastLED.h" // Sketch -> Include Libraries -> Manage Libraries -> Search for "FastLED" and install.
#define NUM_LEDS 5
#define DATA_PIN D5
// Define the array of leds
CRGB leds[NUM_LEDS];
void setup() {
FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
}
uint8_t l = 0;
uint8_t c = 0;
void loop() {
uint8_t r = 255 * (c % 3 == 0);
uint8_t g = 255 * (c % 3 == 1);
uint8_t b = 255 * (c % 3 == 2);
for (int i = 0; i < NUM_LEDS; i++) {
leds[i] = CRGB(r * (l % NUM_LEDS == i), g * (l % NUM_LEDS == i), b * (l % NUM_LEDS == i));
}
if (l % NUM_LEDS == NUM_LEDS - 1) {
c++;
}
l++;
FastLED.show();
delay(250);
}
It will cycle through Red,Green,Blue and all single LEDs.
Programming (Jenkins Status)
See this post