22nd
JAN

WS2812b & DS1307 with Arduino

Posted by M. 4Gani under Electronic, Ring Clock Projecti:

Making a ring wall clock with 1-meter long WS2812B LED strip with 60 RGB LEDs.  (ماژول LED RGB WS2812)

 LED WS2812 حلقه یا RGB LED WS2812b پنج متری

 For clock I used a DS1307, which contains a real-time clock.

WS2812b & DS1307

Driver IC: I2C DS1307 Real Time Clock
SCL Analog 5 (clock line)
SDA: Analog 4 (data line)
Voltage: +3.3V to +5V
GND: GND of Arduino
I2C Address: 0x68

NeoPixel – WS2812B LED strip
Length of strip: 1-meter
Number of LEDS per meter: 60
DIN: Digital 3
VCC: +5V to +12V
GND: GND on Arduino

 

The WS2812B LED strip is an addressable RGB LED strip and each LED includes an IC built in. This gives LEDs the possibility to communicate through one-wire interface.

Each LED has a data in/out pin and requires 24 bits (for each color 8 bits) of data to work.
The data is shifted in an 8 bit for green, 8 bits for red and finally 8 bits for blue intensity. (Total 3 byte)
Once a LED receives 24 bits data at its data-in pin, it forwards the data through its data-out pin to the next LED’s data-in pin.

The LED strip should be powered by an external 5V-12V power source.
by setting LED to maximal brightness, the maximum current of  LED will be ca. 50mA  (0,05 A x 60 LED’s = 3,0 A).

To reduce noise on strip you need to  add a 220 or 470 Ohm resistor between the arduino digital output pin and the strip data input pin.

Arduino libraries:
Adafruit’s Neopixel and RTClib

Demo Code



// include the library code
#include <Adafruit_NeoPixel.h> 

#define PIN 3
#define NUM_LEDS 60

Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800);
RTC_DS1307 RTC;       // establish clock object

DateTime now;         // holds current clock time
byte hrs, mins, secs; 

int BLINK_PIN = 13;

void setup() {
  delay(1000);       // 1 second delay for recovery
  Serial.begin(9600);
  pinMode(BLINK_PIN, INPUT);
  if (!RTC.begin()) {
    Serial.println("Couldn't find RTC");
    while(1);
  }
  if (!RTC.isrunning()) {
    Serial.println("RTC is NOT running!");
    RTC.adjust(DateTime(F(__DATE__), F(__TIME__)));
  }
  Wire.begin();
  strip.begin();
  strip.show();       // Initialize all pixels to 'off'
  delay(500);
}

void loop() {
  DateTime now = RTC.now();
  secs = now.second();  // get seconds
  mins = now.minute();  // get minutes
  hrs = now.hour();     // get hours
  Serial.print("rtc:\t");
  Serial.print(now.year()); Serial.print("-");
  Serial.print(now.month()); Serial.print("-");
  Serial.print(now.day()); Serial.print(" ");
  Serial.print(hrs); Serial.print(":");
  Serial.print(mins); Serial.print(":");
  Serial.println(secs);  
  strip.setPixelColor(secs, 0x000055);
  strip.setPixelColor(mins, 0x550000);
  strip.setPixelColor(hrs, 0x005500);
  anyNr1(0, 0, 127); Serial.print("function: anyNr1\n");
  delay(200);
}

// fill
void anyNr1(byte red, byte green, byte blue) {
  int l;
  for(l=NUM_LEDS+1; l>secs; l--) {  
    LToRight(l, red, green, blue);
    for(int n=0; n<NUM_LEDS; n++) {
      if (n <= secs) {
        if (n != mins && n != hrs) strip.setPixelColor(n, 0x000055);
      } else {
        if (n != mins && n != hrs) strip.setPixelColor(n, strip.Color(0, 0, 0));
      }
    }
    strip.show();
  } 
}

void setPixel(int Pixel, byte red, byte green, byte blue) {
  strip.setPixelColor(Pixel, strip.Color(red, green, blue));
}

void LToRight(int i, byte red, byte green, byte blue) {
  if (i != secs && i != mins && i != hrs) 
    setPixel(i, red, green, blue);  
  if (i+1 != secs && i+1 != mins && i+1 != hrs) 
    setPixel(i+1, red/5, green/5, blue/5); 
  if (i+2 != secs && i+2 != mins && i+2 != hrs) 
    setPixel(i+2, red/10, green/10, blue/10);
  if (i+3 != secs && i+3 != mins && i+3 != hrs) 
    setPixel(i+3, red/20, green/20, blue/20);
  if (i+4 != secs && i+4 != mins && i+4 != hrs) 
    setPixel(i+4, red/30, green/30, blue/30);
  if (i+5 != secs && i+5 != mins && i+5 != hrs) 
    setPixel(i+5, red/90, green/90, blue/90);
  strip.setPixelColor(secs, 0x000055);
  strip.setPixelColor(mins, 0x550000);
  strip.setPixelColor(hrs, 0x005500);
  strip.show();
  delay(20);
}

 

Continue…

 

Post your comment

*

code