Introduction: RGB 7 Segment Clock Using ESP8266

This clock also has automatic brightness control and temperature sensor to display the readings. RGB Neo-pixel clock.

Supplies

1) Costom PCB from JLCPCB

2) ESP8266 or Nodemcu

3) Jumper wires

4) Soldering tools

Step 1: Story:

Hi guys, today we are going to discuss, interfacing of neo pixel led through NodeMCU (ESP8266-12E). Neopixel is addressable led, we can program to display any number/name in any color using microcontroller. Neo pixel came in different smd packages, here we are using Ws2812b-5050 mini RGB.

This mini led has voltage ratings: 3.0v to 5.5volts @16mA (for each Led). Our NodeMCU has 3.3-volt regulator, to drive all the LED’s properly.

Step 2: Making 7 Segment Display Using Neo Pixel Led:

Here, I do all the power connections in parallel and all the Data connection in series. Using the 7-segment display method, and connect all the LED’s in proper format (As in diagram)

Each of the segment has 2 LED’s and One whole panel has 14 LED’s in total. We need 4 panels to display time (2 for Hours, 2 for minutes). Two more panels can be connected to display seconds/any other values like Temperature.

Always connect Dout of first panel to Din of second.

Step 3: Dash Connections:

To connect the hours and minutes panel, A small PCB is there in between named as Dash, contains 2 LED’s as binary digits. These 2 LED’s glow after each second.

Step 4: Need of NodeMCU/ESP8266:

ESP8266 is integrated with a 32-bit Tensilica processor, standard digital peripheral interfaces.

Our Esp8266 has on board Wi-Fi support, through this we can adjust the time over internet without any RTC(real time clock) module. This will reduce the connections and make this project simple.

Step 5: Supported Features in Code:

If you are using my code, then there are 2 extra features you may add in this 7-segment clock.

1) Temperature and humidity using tactile switch.

Add a DHT11 sensor on pin number 13 and a tactile button on pin number 12 to get the temperature values on screen in Celcius or Farenheit.

Connect the button pin 12 to 5volt using a 10k resistor and the other end to GND. Means when the button pin is pull down to GND, Display will show temperature readings. The code will also work without this Temperature sensor, so if you want to keep it simple there is no need of these connections.

Step 6: 2) Brightness Control Using LDR Sensor at Pin A0.

Add a LDR sensor with 10k resistor by making a resistor divider network on A0 pin, this will change the brightness accordingly. High brightness in day time, low in night. The code will also work without these sensors if you don't want adjustable brightness, it will locked on default settings.

Step 7: Video: Steps Involved in Making This Clock.

Step 8: 7- Segment Clock:

Now, we have 4 panels and one dash. Connect 2 panels in series in pair.Now connect dash in between and connect NodeMCU using schematics given above

Step 9: Code:

1) First initialize the code using libraries

#include <ESP8266WiFi.h>
#include <Adafruit_NeoPixel.h>
#include <WiFiUdp.h>
#include <NTPClient.h>
#include <TimeLib.h>
#include <DHT.h>
#include <Adafruit_Sensor.h>

2) Define all pixels, I/O pins, sensor pins:

#define PIXEL_PER_SEGMENT 2 // Number of LEDs in each Segment
#define PIXEL_DIGITS 4 // Number of connected Digits
#define PIXEL_PIN 2 // GPIO Pin
#define PIXEL_DASH 1 // Binary segment
#define LDR_PIN A0 // LDR pin
#define DHT_PIN 13 // DHT Sensor pin
#define BUTTON_PIN 12 // Button pin

3) For time format connect Internet using Wi-Fi to ESP8266

WiFi.begin(ssid, password);
Serial.print("Connecting.");
while ( WiFi.status() != WL_CONNECTED )

4) Time settings on Pixel

void disp_Time() {
clearDisplay();
writeDigit(0, Hour / 10);
writeDigit(1, Hour % 10);
writeDigit(2, Minute / 10);
writeDigit(3, Minute % 10);
writeDigit(4, Second / 10);
writeDigit(5, Second % 10);
disp_Dash();

5) Color setting on panels:

if (index == 0 || index == 1 ) color = strip.Color(0, Brightness, 0);
if (index == 2 || index == 3 ) color = strip.Color(0, Brightness, 0);
if (index == 4 || index == 5 ) color = strip.Color(Brightness, 0, 0);

This is a brief about code, also the code has temperature and auto time options. Temperature mode can be selected using tactile switch on Digital pin 12.

Step 10: Working Code:

#include <ESP8266WiFi.h>
#include <Adafruit_NeoPixel.h>
#include <WiFiUdp.h>
#include <NTPClient.h>
#include <TimeLib.h>
#include <DHT.h>
#include <Adafruit_Sensor.h>

#define PIXEL_PER_SEGMENT  2     // Number of LEDs in each Segment
#define PIXEL_DIGITS       4     // Number of connected Digits 
#define PIXEL_PIN          2     // GPIO Pin
#define PIXEL_DASH         1    // Binary segment

#define LDR_PIN       A0    // LDR pin
#define DHT_PIN       13    // DHT Sensor pin
#define BUTTON_PIN    12    // Button pin

// Uncomment the type of sensor in use
#define DHT_TYPE    DHT11     // DHT 11
//#define DHT_TYPE    DHT22     // DHT 22 (AM2302)
//#define DHT_TYPE    DHT21     // DHT 21 (AM2301)

#define TIME_FORMAT        12    // 12 = 12 hours format || 24 = 24 hours format 

Adafruit_NeoPixel strip = Adafruit_NeoPixel((PIXEL_PER_SEGMENT * 7 * PIXEL_DIGITS) + (PIXEL_DASH * 2), PIXEL_PIN, NEO_GRB + NEO_KHZ800);
DHT dht(DHT_PIN, DHT_TYPE);

// set Wi-Fi SSID and password
const char *ssid     = "Hackster";
const char *password = "Sainisagar7294";

WiFiUDP ntpUDP;
// 'time.nist.gov' is used (default server) with +1 hour offset (3600 seconds) 60 seconds (60000 milliseconds) update interval
NTPClient timeClient(ntpUDP, "time.nist.gov", 19800, 60000); //GMT+5:30 : 5*3600+30*60=19800

int period = 2000;   //Update frequency
unsigned long time_now = 0;
int Second, Minute, Hour;

// set default brightness
int Brightness = 40;
// current temperature, updated in loop()
int Temperature;

bool Show_Temp = false;

//Digits array
byte digits[12] = {
  //abcdefg
  0b1111110,     // 0
  0b0110000,     // 1
  0b1101101,     // 2
  0b1111001,     // 3
  0b0110011,     // 4
  0b1011011,     // 5
  0b1011111,     // 6
  0b1110000,     // 7
  0b1111111,     // 8
  0b1110011,      // 9
  0b1001110,     // C
  0b1000111,     // F
};

//Clear all the Pixels
void clearDisplay() {
  for (int i = 0; i < strip.numPixels(); i++) {
    strip.setPixelColor(i, strip.Color(0, 0, 0));
  }
  strip.show();
}

void setup() {
  Serial.begin(115200);
  strip.begin();
  strip.show();

  dht.begin();
  pinMode(BUTTON_PIN, INPUT);

  WiFi.begin(ssid, password);
  Serial.print("Connecting.");
  while ( WiFi.status() != WL_CONNECTED ) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("connected");
  timeClient.begin();
  delay(10);
}

void loop() {
  if (WiFi.status() == WL_CONNECTED) { // check WiFi connection status
    int sensor_val = analogRead(LDR_PIN);
    Brightness =40;
    timeClient.update();
    int Hours;
    unsigned long unix_epoch = timeClient.getEpochTime();   // get UNIX Epoch time
    Second = second(unix_epoch);                            // get seconds
    Minute = minute(unix_epoch);                            // get minutes
    Hours  = hour(unix_epoch);                              // get hours

    if (TIME_FORMAT == 12) {
      if (Hours > 12) {
        Hour = Hours - 12;
      }
      else
        Hour = Hours;
    }
    else
      Hour = Hours;
  }

  if (digitalRead(BUTTON_PIN) == LOW) {
    Show_Temp = true;
  }
  else
    Show_Temp = false;

  if (Show_Temp) {
    Temperature = dht.readTemperature();
    Serial.println(Temperature);
    clearDisplay();
    writeDigit(0, Temperature / 10);
    writeDigit(1, Temperature % 10);
    writeDigit(2, 10);
    strip.setPixelColor(28, strip.Color(Brightness, Brightness,  Brightness));
    strip.show();
    delay(3000);
    clearDisplay();
    Show_Temp = false;
  }
  while (millis() > time_now + period) {
    time_now = millis();
    disp_Time();     // Show Time
  }
}

void disp_Time() {
  clearDisplay();
  writeDigit(0, Hour / 10);
  writeDigit(1, Hour % 10);
  writeDigit(2, Minute / 10);
  writeDigit(3, Minute % 10);
  writeDigit(4, Second / 10);
  writeDigit(5, Second % 10);
  disp_Dash();
  strip.show();
}

void disp_Dash() {
  int dot, dash;
  for (int i = 0; i < 2; i++) {
    dot = 2 * (PIXEL_PER_SEGMENT * 7) + i;
    for (int j = 0; j < PIXEL_DASH; j++) {
      dash = dot + j * (2 * (PIXEL_PER_SEGMENT * 7) + 2);
      Second % 2 == 0 ? strip.setPixelColor(dash, strip.Color(0,Brightness ,0)) : strip.setPixelColor(dash, strip.Color(0, Brightness,0));
    }
  }
}

void writeDigit(int index, int val) {
  byte digit = digits[val];
  int margin;
  if (index == 0 || index == 1 ) margin = 0;
  if (index == 2 || index == 3 ) margin = 1;
  if (index == 4 || index == 5 ) margin = 2;
  for (int i = 6; i >= 0; i--) {
    int offset = index * (PIXEL_PER_SEGMENT * 7) + i * PIXEL_PER_SEGMENT + margin * 2;
    uint32_t color;
    if (digit & 0x01 != 0) {
      if (index == 0 || index == 1 ) color = strip.Color(Brightness, 0,  Brightness);
      if (index == 2 || index == 3 ) color = strip.Color(Brightness, 0,Brightness);
      if (index == 4 || index == 5 ) color = strip.Color(Brightness, 0,  0);
    }
    else
      color = strip.Color(0, 0, 0);

    for (int j = offset; j < offset + PIXEL_PER_SEGMENT; j++) {
      strip.setPixelColor(j, color);
    }
    digit = digit >> 1;
  }
}

Step 11: Fully Functional Circuit Diagram:

Step 12: PCB Design:

This is the main PCB design which is used to display the digits and other letters. Download all the Required files regarding this project from here.

Step 13: This Is the Design to 2nd Pcb Named As Dash.

Step 14: Troubleshooting:

1) Din is always connected to Dout in series with on e another, if connected in opposite or disconnected from anywhere whole setup stops working.

2) Connect the Dash as shown in figure above.

3) Make sure all the connections are properly soldered, dry soldering will cause change in data value and color.

4) Don't heat the PCB too much, while Soldering and keep the temperature on 300*c.

Step 15: My Clock:

Step 16: JLCPCB:

I have my own Arduino boards because of JLCPCB to program them/troubleshoot them and learn from them. If you want to make your own board, the JLCPCB SMT service can be the solution.

JLCPCB is the one of the most popular PCB makers. Price is just $2 for 2, 4 and 6 layer PCB. They just launched new purple solder mask, aluminum Pcb and 3d printing service in very low cost. Pcb quality is not compromised at any cost. Check them out right now from Here.

JLCPCB Is also providing new user coupons and sign-up rewards of up to $30. So, check them out from here. Register using this link to get Free PCB assembly service coupons. Get your 2 layer to 6-layer PCB’s just in $2, stencil and PCB assembly service in just $7.

For PC: https://jlcpcb.com/SSRFor mobile phone: http://m.jlcpcb.com/ssi

Step 17: Here Are Some Exciting Projects, Which You May Like:

1) How to make Arduino Uno clone board.

2) How to program Arduino Using Smart Phone.

3) Arduino Nano clone board problems and solutions.

4) How to make Inductance Meter Using Arduino.

5) Raspberry Pi- PICO Oscilloscope.

Think you enjoyed my work, stay tuned. Follow us on Instagram (sagar_saini_7294) and hackaday.

please support us- No donations, just follow and leave a comment.

Make it Glow Contest

Participated in the
Make it Glow Contest