Table of Contents

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

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.

To connect the sensor, just match the follwing pins:
  • VCC/3V3
  • GND/GND
  • SCL/D1
  • SDA/D2
To connect the light strip, match the following pins:
  • 3V3/3V3
  • GND/GND
  • DATA/D5

Sensor Assembly

This is an overview on what we are going to build.
Make sure you have all the modules and PCB, as well as the pins
First, put the female pins into the D1mini with the metal shield facing down. Solder the pin headers.

Hint: I always orient the di1mini this way, so it does not wobble on the desk or in a case.
Next, insert the pins into the female connectors...
And add the Sensor PCB, label facing up, and solder the pins
Insert the pins for the BME280 and solder them.
Add the BEM280 and solder it too. Make sure it is aligned properly.
Print the case and add the hardware.
The usb connector is connected through the hole on the bottom of the case.

Traffic Light Assembly

This is an overview on what we are going to build.
Make sure you have all the parts, and three wires connected to the back of the LED strip segment.
First, put the female pins into the D1mini with the metal shield facing down. Solder the pin headers.
Next, insert the pins into the female connectors...
And add the Sensor PCB, label facing up, and solder the pins
Print the traffic light, then insert the LEDs into the light, and thread the cables through the pole
Solder the cables to the PCB. Make sure you got the correct wiring.

Programming

These are my usual settings.

The port might be different depending on your OS.

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.