Introduction: Big, Auto Dim, Room Clock (using Arduino and WS2811)
First Hello instructables.
This is my first contact with :
- Instructables
- Arduino
- Programmable LED's
So please don't trow rocks at me for noobish mistakes.
Keeping that in mind I'm waiting to read your comments with grate interest and I'm open to any suggestion
Features :
- big digits ( each digit is approximately the size of a A4 paper).
- slim in order to fit in a photo frame (a big one).
- auto dim the light depending on the light in the room.
- dedicated DST button.
Step 1: Prerequisites
Things I used for this project :
Electronics :
- Arduino nano V3.0 (sadly since I can't afford an original arduino I used a chinese clone, for showing my support I donated 2.9 $ to arduino) - 2.9$ on ebay
Digital Light Intensity Sensor Module Photo Resistor for Arduino - 0.99$ on ebay
DS3231 AT24C32 IIC Module Precision Real Time Clock Quare Memory for Arduino - 0.99$ on ebay
DC-DC Buck Converter Step Down Module LM2596 Power Output 1.23V-30V - 0.90$ on ebay
4m WS2811 led strip 30 leds/m - 12 $ on aliexpress (1 WS2811 IC control 3 LED Chip)
Total cost of electronics : 17.78 $ (without arduino donation)
Miscellaneous :
Heat Shrink Tubing - 7.99$ ebay (assortment, it total 33m)
20 pcs 5 x 7 cm prototype pcb - 3$ ebay
3 pcs Micro Switch - 1$ locally bought
Solder - 1$ locally bought
- Flux - 1$ locally bought
- UTP cable (individual wires used for various connections)
- LCD font (http://www.dafont.com/lcd-lcd-mono.font) - free
- Cardboard - free loacal supermarket
Polystyrene board - 1.50$ locally bought
Various tools.
Step 2: Preparing - Digit Template
- download and install LCD font (http://www.dafont.com/lcd-lcd-mono.font
- open word or similar editor and make a template similar to the image (first img)
- font size ~800,
- white font color black outline,
- gray boxes where led strip fits
- Print and cut the gray strips with a exacto knife (second img)
Step 3: Preparing - Cut Cardboard and Led Strip
Using the digit template cut the cardboard to size (don't forget to leave space for the dots between hours and minutes)
If your LED strips came with connectors at each end (like mine did) desolder the connector and cut them in sets of 3.
Step 4: Stick the LED Strips
Using the template stick the LED strip on the cardboard.
It's not mandatory but I used a pencil to mark where the LED strips should be placed, this way I got to see the final form before attaching the LED's. It was a good thing since this is how I noticed I left two much space for those dots in the middle, as a result I had stuck the LED strips a little closer.
Step 5: Solder LED Strips
Now starts a long soldering session.
Solder the LED strips in order to form a continues strip.
Notice the order in which to solder the strips in the picture.
For the middle dots I used a single LED strip and covered the middle LED with duct tape.
I used the following color code
- Blue for ground
- Green for data
- Red for Vcc (12v)
Step 6: Wire Arduino on Breadbord
I tried doing a sketch in fritzing but I can't find all the parts :( , Sorry
So here is a list with all the connections and another picture with the setup on a breadboard
Step 7: Test LED's
Before loading this sketch (for which I assume no credit) don't forget to add FastLED library.
If everything went OK the LED's should cycle trough colors. If you have any problems first check your soldered points.
Attachments
Step 8: Program the Clock
After struggling a little I managed to get a working clock that covers all my needs. I'm sure there is room for improvement.
The code is very commented, if you have any questions please feel free to ask. Also if you have any suggestions, please do tell.
All debugging messages are commented as well.
In order to change the color used you must modify the variable at line 22 ( int ledColor = 0x0000FF; // Color used (in hex)). You can find a list of colors at the bottom of this page: https://github.com/FastLED/FastLED/wiki/Pixel-refe...
If you have problems downloading the code file from instructables here is a mirror : http://bit.ly/1Qjtgg0
Step 9: Make Digits Form Using Polystyrene
Cut each segment in the template printed at the beginning.
Form each digit in the polystyrene using a exacto knife (very hard) or a Hot Wire Cutter.
You can see how I made mine in the pictures.
If you don't have a guitar string you can use just about any thin STEEL wire.
In order to power the Hot Wire Cutter I used the 12v LED power supply.
Also there is a picture with a cut digit. (sorry I forgot to take pictures in the process).
Step 10: Glue Digits and Adding Diffuser
After cutting all 4 digits and the dots glue all of them on the cardboard with the LED strips. (for this process I used
double sided adhesive tape).
In order to diffuse the LED light I used 2 paper sheets on top of the polystyrene. For convenience and aesthetics I used a single A2 size paper folded in two.
Also for finishing touches I've put the entire assembly in a large picture frame.

Second Prize in the
Time Contest
26 People Made This Project!
- Beaker99 made it!
- jmlocci made it!
- Peck76_2000 made it!
- wreksakarya made it!
- aneta8 made it!
- ehsiung made it!
- Martin T made it!
- hajnelkoch made it!
- adrianfeticu made it!
See 17 More
245 Comments
9 months ago
I would like to use this idea to use for a speed sign, using only 2 digits and a radar module for the arduino. Has anyone done this or have any tips or tricks?
1 year ago on Step 1
Well done my friend. Your genius idea has solved a longtime problem for me. I've been looking for a huge clock like this. I didn't want it to look hokey though and thanks to your brilliance, I no longer have to worry abut that. Really great job!!! And because of your solution I do not have to worry about what color display I want. Brilliant!!! Thank You and best of luck!
Tip 1 year ago on Step 10
Quite cool idea... My is made around a NodeMCU 12F to grab the time over Internet (pool.ntp.org), so it's always accurate and you don't need an RTC module and/or adjustment buttons. I also removed the temperature function because I made a LED thermometer on the side. I kept the luminosity adjustment, which is indispensable in my view. I fitted that into a wood/metal photo frame from the shelf of a DIY store.
Reply 1 year ago
Hello
I want to do this project with four LEDs with your code but I can't find the library "bh1750.h".
Please could you provide it to me.
thanks greetings!!
Reply 1 year ago
You will find the library (bh1750.h) I used here: https://github.com/itechnofrance/Arduino/blob/mas...It is actually slightly modified from the English version (BH1750.h)
Reply 1 year ago
Hi. I am away from home and my PC, but is is very easy to find it on GitHub : https://github.com/claws/BH1750
Reply 1 year ago
Could you please share your code? I found code for an NTP clock for NodeMCU but I'm struggling to convert this project's code for NTP
Reply 1 year ago
// ====== Carte ESP8266 / NodeMCU 1.0 (ESP12E module)
#define FASTLED_ESP8266_NODEMCU_PIN_ORDER
#include <ESP8266WiFi.h> // librairie pour gérér la connexion WiFi "pool.ntp.org"
#include <TimeLib.h> // manipultaion et formattage des dates ("epoch" en hh:mm:ss dd:mm:yy)
#include <FastLED.h> // librairie ruban LED
#include <bh1750.h> // librairie capteur de luminosité "custom" en français
const char* ssid = "SSID";
const char* password = "Password";
// serveur epoch time (Network Time Protocole)
const char* ntpServer = "pool.ntp.org";
const long gmtOffset_sec = +1 * 3600; // fuseau horaire France = +1h (3600s)
const int daylightOffset_sec = 3600; // 3600s en été
unsigned long epochTime;
#define NUM_LEDS 114 // 7 segments * 4 pixel par segment * 4 chiffres + 2 pour le dot (2 points clignotants)
#define COLOR_ORDER GRB // cartographie couleur du ruban LED
#define DATA_PIN 6 // broche LED
#define BRI_PIN 3 // capteur luminosité
int sda = D2; // GPIO4 - broche SDA pour le capteur de lumière
int scl = D1; // GPIO5 - broche SCL pour le capteur de lumière
long int brightnessLow = 5; // brillance mini
long int brightnessHigh = 48; // brillance maxi
CRGB leds[NUM_LEDS]; // déclare instance ruban LEDs
bh1750 mesure_lumiere; // déclare instance mesure luminosité
bool Dot = true; // dot state
int last_digit = 0;
long ledColor = CRGB::DarkOrchid; // couleur initiale des LED (puis qui change chaque minute)
// palettes choisies au hasard chaque minute
long ColorTable[14] = {
//CRGB::Red,
//CRGB::Blue,
CRGB::Amethyst,
CRGB::Aqua,
CRGB::Chartreuse,
CRGB::DarkGreen,
CRGB::DarkMagenta,
CRGB::DarkOrange,
CRGB::DeepPink,
CRGB::Fuchsia,
CRGB::Gold,
CRGB::GreenYellow,
CRGB::LightCoral,
CRGB::Tomato,
CRGB::Salmon,
CRGB::Orchid
};
// les 7 segments des nombres en 2D Array
byte digits[10][28] = {
{0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, // Digit 0
{0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1}, // Digit 1
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0}, // Digit 2
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1}, // Digit 3
{1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1}, // Digit 4
{1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1}, // Digit 5
{1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, // Digit 6
{0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1}, // Digit 7
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, // Digit 8
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1} // Digit 9
};
void setup()
{
// Serial.begin(9600);
// Serial.setDebugOutput(false);
FastLED.addLeds<WS2812B, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS);
mesure_lumiere.begin(0x23, sda, scl); // initialise la librairie BH1750 sur le bus I2C
initWiFi(); // initialise le WiFi
configTime(gmtOffset_sec, daylightOffset_sec, ntpServer);
}
void loop()
{
BrightnessCheck(); // luminosité
TimeToArray(); // affiche l'heure
FastLED.show();
delay (1000);
}
// ------ ajustement de la brillance en fonction de la luminosité ------
void BrightnessCheck()
{
uint16_t luxValue = mesure_lumiere.lecture_lumiere(0x23, MODE_CONTINU_HAUTE_RESOLUTION); // effectue une mesure
int brightNess = min(map(luxValue, 0, 1000, brightnessLow, brightnessHigh), brightnessHigh);
LEDS.setBrightness(brightNess);
// Serial.print(luxValue);
// Serial.print(" ");
// Serial.println(brightNess);
}
//------ transforme le temps en affichage ------
void TimeToArray()
{
int epochTime = getTime() + gmtOffset_sec + daylightOffset_sec;
int heureVraie = hour(epochTime);
int minuteVraie = minute(epochTime);
int secondPar = second(epochTime);
if (secondPar % 2 == 0) {
Dot = false;
}
else {
Dot = true;
}
int Now = heureVraie * 100 + minuteVraie;
// Serial.println(Now);
int cursor = NUM_LEDS; // positionnement sur la dernière LED
if (Dot)
{
leds[56] = ledColor; // LED 1 du "deux-points"
leds[57] = ledColor; // LED 2 du "deux-points"
}
else
{
leds[56] = 0x000000;
leds[57] = 0x000000;
}
for (int i = 1; i <= 4; i++) {
int digit = Now % 10;
// contrôle chiffre 4
if (i == 1) {
cursor = 86; // positionnement sur la LED du début du chiffre 4
for (int k = 0; k <= 27; k++) {
if (digits[digit][k] == 1) {
leds[cursor] = ledColor;
}
else if (digits[digit][k] == 0) {
leds[cursor] = 0x000000;
};
cursor ++;
};
if (digit != last_digit)
{
cylon();
ledColor = ColorTable[random(14)];
}
last_digit = digit;
delay(10);
}
// contrôle chiffre 3
else if (i == 2) {
cursor = 58; // positionnement sur la LED du début du chiffre 3
for (int k = 0; k <= 27; k++) {
if (digits[digit][k] == 1) {
leds[cursor] = ledColor;
}
else if (digits[digit][k] == 0) {
leds[cursor] = 0x000000;
};
cursor ++;
};
}
// contrôle chiffre 2
else if (i == 3) {
cursor = 28; // positionnement sur la LED du début du chiffre 2
for (int k = 0; k <= 27; k++) {
if (digits[digit][k] == 1) {
leds[cursor] = ledColor;
}
else if (digits[digit][k] == 0) {
leds[cursor] = 0x000000;
};
cursor ++;
};
}
// contrôle chiffre 1
else if (i == 4) {
cursor = 0; // positionnement sur la LED du début du chiffre 1 (début du ruban)
for (int k = 0; k <= 27; k++) {
// Serial.print(digits[digit][k]);
if (digits[digit][k] == 1) {
if (digit == 0) {
leds[cursor] = CRGB::Black;
}
else {
leds[cursor] = ledColor;
}
}
else if (digits[digit][k] == 0) {
leds[cursor] = 0x000000;
};
cursor ++;
};
}
Now /= 10;
};
};
void cylon()
{
static uint8_t hue = 0;
// First slide the led in one direction
for (int i = 0; i < NUM_LEDS; i++) {
// Set the i'th led to red
leds[i] = CHSV(hue++, 255, 255);
FastLED.show();
// Wait a little bit before we loop around and do it again
delay(10);
}
// Now go in the other direction.
for (int i = (NUM_LEDS) - 1; i >= 0; i--) {
// Set the i'th led to red
leds[i] = CHSV(hue++, 255, 255);
// Show the leds
FastLED.show();
delay(10);
}
}
void initWiFi()
{
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
}
unsigned long getTime()
{
time_t tempsVrai;
struct tm timeinfo;
time(&tempsVrai);
return tempsVrai;
delay(10);
}
2 years ago
Everything works fine, but after a month, I realized that the clock is late to display about 10 minutes, I used 1 Led/segment, uno clone and ds3231 rtc, is any one have same problem? Thanks and sorry for my terrible language ,,,,,,,,
Reply 1 year ago
But ten months later, I realized that the clock is late to display about 40 minutes,It's unknown for what reason。
1 year ago on Introduction
Awesome project! I thought I'd share one I ran across a few months ago and built. I used 5 ws2812b leds per segment. Super cool.
https://m.youtube.com/watch?v=w1XMInQThNI
Question 1 year ago on Introduction
Hi everyone,
Is there anyone who can help me with a complete library with all associated files of this Big Clock?
Thanks in advance.
boby
Question 1 year ago on Step 10
What is the purpose of the Buck Converter in this project? Is it only there to power the Arduino so that a separate USB power adapter isn't necessary?
Question 2 years ago on Step 6
Podrías adaptar el sensor ds28b10 para que marque el temperamento
Question 2 years ago
I have added 24/12hr mode , and hr and mins adjustment
I'd be thankful if anyone can help me :)
/*Leds used here are WS2812B, 3 leds by segment
total = (3*7)* 4numbers + 2 dots = 86 leds
Led controlled with FastLeds Lib on Pin 5
Brightness sensor on A0
RTC Modul on A4 A5
I'm using 5V 2A Power supply
*/
#include
#include
#include
#include
#include
#define NUM_LEDS 58 //3*7*4 +2 Number of LED controles (remember I have 3 leds / controler
#define LED_TYPE WS2812B
#define COLOR_ORDER GRB // Define color order for your strip
#define BRIGHTNESS_DEFAULT 180
#define LED_PIN 6 // Data pin for led comunication
char incoming_command = 'H';
int brightness = 0;
int auto_brightness = 1;
//brightness
int photocellPin = 0; // the cell and 10K pulldown are connected to a0
int photocellReading; // the analog reading from the analog resis
int led_on = 1;
//LEDS COLORS
volatile boolean animate = true;
volatile long animation_change_timeout;
unsigned long previousMillis = 0; // will store last time LED was updated
const long interval = 5000; // interval for printing Temp and date
bool ClkHr_Change = false;
CRGB leds[NUM_LEDS]; // Define LEDs strip
// 10 digit :0...10, each digit is composed of 7 segments of 3 leds
byte digits[12][14] = {{0,0,1,1,1,1,1,1,1,1,1,1,1,1}, // Digit 0
{0,0,1,1,0,0,0,0,0,0,0,0,1,1}, // Digit 1
{1,1,1,1,1,1,0,0,1,1,1,1,0,0}, // Digit 2
{1,1,1,1,1,1,0,0,0,0,1,1,1,1}, // Digit 3
{1,1,1,1,0,0,1,1,0,0,0,0,1,1}, // Digit 4
{1,1,0,0,1,1,1,1,0,0,1,1,1,1}, // Digit 5
{1,1,0,0,1,1,1,1,1,1,1,1,1,1}, // Digit 6
{0,0,1,1,1,1,0,0,0,0,0,0,1,1}, // Digit 7
{1,1,1,1,1,1,1,1,1,1,1,1,1,1}, // Digit 8
{1,1,1,1,1,1,1,1,0,0,1,1,1,1}, // Digit 9 | 2D Array for numbers on 7 segment
{1,1,1,1,1,1,1,1,0,0,0,0,0,0}, // Digit *0
{0,0,0,0,1,1,1,1,1,1,1,1,0,0}};
// Digit 1 first number | 2D Array for numbers on 7 segment
bool DotState = true;
bool Dot = true; //Dot state
bool HrFormat = false;
bool Min_Change = false;
bool DST = false; //DST state
int last_digit = 0;
//long ledColor = CRGB::DarkOrchid; // Color used (in hex)
long ledColor = CRGB::MediumVioletRed;
//Random colors i picked up
long ColorTable[28] = {
CRGB::Amethyst,
CRGB::Aqua,
CRGB::Blue,
CRGB::Chartreuse,
CRGB::DarkGreen,
CRGB::DarkMagenta,
CRGB::DarkOrange,
CRGB::DeepPink,
CRGB::Fuchsia,
CRGB::Gold,
CRGB::GreenYellow,
CRGB::LightCoral,
CRGB::Tomato,
CRGB::Salmon,
CRGB::Red,
CRGB::Orchid,
CRGB::Violet,
CRGB::Cyan,
CRGB::HotPink,
CRGB::Teal,
CRGB::Purple,
CRGB::Maroon,
CRGB::DarkBlue,
CRGB::Navy,
CRGB::Turquoise,
CRGB::Lime,
CRGB::Pink,
CRGB::White
};
void setup() {
Serial.begin(9600);
Wire.begin();
FastLED.addLeds(leds, NUM_LEDS);
// FastLED.addLeds(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
FastLED.setBrightness( BRIGHTNESS_DEFAULT );
}
// Check Light sensor and set brightness accordingly
void BrightnessCheck() {
photocellReading = analogRead(photocellPin);
const byte brightnessLow = 30; // Low brightness value
const byte brightnessHigh = 100; // High brightness value
//you can choose between auto or manual brightness
if (auto_brightness ) {
if (photocellReading > 100) {
FastLED.setBrightness( brightnessHigh );
}
else if (photocellReading < 100) {
FastLED.setBrightness( brightnessLow);
}
}
};
// Get time in a single number
int GetTime() {
tmElements_t Now;
RTC.read(Now);
//time_t Now = RTC.Now();// Getting the current Time and storing it into a DateTime object
int hour = Now.Hour;
if(!HrFormat){
/* if(hour==24)
{
hour =1;
}
else
{
hour +=1;
}
*/
}
else {
if(hour>12){
hour -=12;
}}
int minutes = Now.Minute;
int second = Now.Second;
//use this to blink your dots every second
if (second % 2 == 0) {
Dot = false;
}
else {
Dot = true;
};
//it is easy to manipulate 2150 rather than hours = 10 minutes = 50
return (hour * 100 + minutes);
};
//function to print day and month
int DayMonth() {
tmElements_t Now;
RTC.read(Now);
int day = Now.Day;
int month = Now.Month;
return (day * 100 + month);
}
// not used yet
void DSTcheck() {
int buttonDST = digitalRead(2);
Serial.print("DST is: ");
Serial.println(DST);
if (buttonDST == LOW) {
if (DST) {
DST = false;
Serial.print("Switching DST to: ");
Serial.println(DST);
}
else if (!DST) {
DST = true;
Serial.print("Switching DST to: ");
Serial.println(DST);
};
delay(500);
};
}
// Convert time to array needet for display
void TimeToArray() {
int Now = GetTime(); // Get time
int cursor = 58; //
//Serial.print("Time is: ");
//Serial.println(Now);
if (Dot) {
long colorrandom = ColorTable[random (28)];
for(int i = 250; i>0 ; i--)
{
if(DotState)
{
leds[28] = ledColor;
leds[29] = ledColor;
}
else if(!DotState)
{
leds[28] = colorrandom;
leds[29] = colorrandom;
}
leds[29].fadeLightBy(i-1);
leds[28].fadeLightBy(i-1);
FastLED.show();
delay(3);
}
}
else {
leds[28].nscale8(250);
delay(1);
leds[29].nscale8(250);
};
for (int i = 1; i <= 4; i++) {
int digit = Now % 10; // get last digit in time
if (i == 1) {
cursor = 44;
//Serial.print("Digit 4 is : ");
//Serial.print(digit);
//Serial.print(", the array is : ");
for (int k = 0; k <= 13; k++) {
//Serial.print(digits[digit][k]);
if (digits[digit][k] == 1) {
leds[cursor] = ledColor;
}
else if (digits[digit][k] == 0) {
leds[cursor] = 0x000000;
};
cursor ++;
}; // fin for
// Serial.println();
if (digit != last_digit)
{
fadefonction();
ledColor = ColorTable[random(16)];
}
last_digit = digit;
}// fin if
else if (i == 2) {
cursor = 30;
//Serial.print("Digit 3 is : ");
//Serial.print(digit);
//Serial.print(", the array is : ");
for (int k = 0; k <= 13; k++) {
//Serial.print(digits[digit][k]);
if (digits[digit][k] == 1) {
leds[cursor] = ledColor;
}
else if (digits[digit][k] == 0) {
leds[cursor] = 0x000000;
};
cursor ++;
};
// Serial.println();
}
else if (i == 3) {
cursor = 14;
//Serial.print("Digit 2 is : ");
//Serial.print(digit);
//Serial.print(", the array is : ");
for (int k = 0; k <= 13; k++) {
//Serial.print(digits[digit][k]);
if (digits[digit][k] == 1) {
leds[cursor] = ledColor;
}
else if (digits[digit][k] == 0) {
leds[cursor] = 0x000000;
};
cursor ++;
};
//Serial.println();
}
else if (i == 4) {
cursor = 0;
//Serial.print("Digit 1 is : ");
//Serial.print(digit);
//Serial.print(", the array is : ");
for (int k = 0; k <= 13; k++) {
//Serial.print(digits[digit][k]);
if (digits[digit][k] == 1) {
leds[cursor] = ledColor;
}
else if (digits[digit][k] == 0) {
leds[cursor] = 0x000000;
};
cursor ++;
};
// Serial.println();
};
Now /= 10;
};
};
// Convert date to array needet for display
void DateToArray() {
FastLED.clear();
unsigned long currentMillis = millis();
while (millis() - currentMillis < interval) {
FastLED.show();
int Now = DayMonth(); // Get time
int cursor = 58; //116
//Serial.print("Time is: ");
//Serial.println(Now);
for (int i = 1; i <= 4; i++) {
int digit = Now % 10; // get last digit in time
if (i == 1) {
cursor = 44; //82
//Serial.print("Digit 4 is : ");
//Serial.print(digit);
//Serial.print(", the array is : ");
for (int k = 0; k <= 13; k++) {
//Serial.print(digits[digit][k]);
if (digits[digit][k] == 1) {
leds[cursor] = ledColor;
}
else if (digits[digit][k] == 0) {
leds[cursor] = 0x000000;
};
cursor ++;
}; // fin for
// Serial.println();
}// fin if
else if (i == 2) {
cursor = 30;
//Serial.print("Digit 3 is : ");
//Serial.print(digit);
//Serial.print(", the array is : ");
for (int k = 0; k <= 13; k++) {
//Serial.print(digits[digit][k]);
if (digits[digit][k] == 1) {
leds[cursor] = ledColor;
}
else if (digits[digit][k] == 0) {
leds[cursor] = 0x000000;
};
cursor ++;
};
// Serial.println();
}
else if (i == 3) {
cursor = 14;
//Serial.print("Digit 2 is : ");
//Serial.print(digit);
//Serial.print(", the array is : ");
for (int k = 0; k <= 13; k++) {
//Serial.print(digits[digit][k]);
if (digits[digit][k] == 1) {
leds[cursor] = ledColor;
}
else if (digits[digit][k] == 0) {
leds[cursor] = 0x000000;
};
cursor ++;
};
//Serial.println();
}
else if (i == 4) {
cursor = 0;
//Serial.print("Digit 1 is : ");
//Serial.print(digit);
//Serial.print(", the array is : ");
for (int k = 0; k <= 13; k++) {
//Serial.print(digits[digit][k]);
if (digits[digit][k] == 1) {
leds[cursor] = ledColor;
}
else if (digits[digit][k] == 0) {
leds[cursor] = 0x000000;
};
cursor ++;
};
// Serial.println();
};
Now /= 10;
};
}
};
//not used yet
void MinAdjust(){
delay(200);
tmElements_t Now;
RTC.read(Now);
int minutes = Now.Minute;
if(Min_Change)
{
if (Now.Minute == 59) {
Now.Minute = 0;
}
else {
Now.Minute += 1;
}
}
if(!Min_Change)
{
if (Now.Minute == 0) {
Now.Minute = 59;
}
else {
Now.Minute -= 1;
}
}
RTC.write(Now);
}
/* coool effect function*/
void fadeall() {
for (int m = 0; m < NUM_LEDS; m++) {
leds[m].nscale8(250);
}
}
void fadefonction () {
static uint8_t hue = 0;
// First slide the led in one direction
for (int i = 0; i < NUM_LEDS; i++) {
// Set the i'th led to red
leds[i] = CHSV(hue++, 255, 255);
// Show the leds
FastLED.show();
// now that we've shown the leds, reset the i'th led to black
// leds[i] = CRGB::Black;
fadeall();
// Wait a little bit before we loop around and do it again
delay(10);
}
// Now go in the other direction.
for (int i = (NUM_LEDS) - 1; i >= 0; i--) {
// Set the i'th led to red
leds[i] = CHSV(hue++, 255, 255);
// Show the leds
FastLED.show();
// now that we've shown the leds, reset the i'th led to black
// leds[i] = CRGB::Black;
fadeall();
// Wait a little bit before we loop around and do it again
delay(10);
}
}
/******IR check****
Check the command on the serial port sent by
the other arduino depending on the button pressed
*/
void IR_Check() {
if (Serial.available() > 0) {
// read the incoming byte:
incoming_command = Serial.read();
switch (incoming_command) {
//colors
case 'R' :
//Serial.println("RED");
ledColor = CRGB::Red;
break;
case 'B' :
ledColor = CRGB::Blue;
break;
case 'G' :
ledColor = CRGB::Green;
break;
case 'W' :
ledColor = CRGB::White;
break;
case 'I' :
ledColor = CRGB::OrangeRed;
break;
case 'J' :
ledColor = CRGB::GreenYellow;
break;
case 'K' :
ledColor = CRGB::MediumSlateBlue;
break;
case 'L' :
ledColor = CRGB::Pink;
break;
case 'M' :
ledColor = CRGB::DarkOrange;
break;
case 'N' :
ledColor = CRGB::Aqua;
break;
case 'P' :
ledColor = CRGB::DarkSlateBlue;
break;
case 'Q' :
ledColor = CRGB::LightPink;
break;
case 'S' :
ledColor = CRGB::LightSalmon;
break;
case 'U' :
ledColor = CRGB::LightSeaGreen;
break;
case 'V' :
ledColor = CRGB::Purple;
break;
case 'X' :
ledColor = CRGB::Yellow;
break;
case 'Y' :
ledColor = CRGB::Teal;
break;
case 'Z' :
ledColor = CRGB::PaleVioletRed;
break;
case '*' :
ledColor = CRGB::PaleTurquoise;
break;
case 'b' :
if(HrFormat)
{
HrFormat = false;
}
else
{
HrFormat = true;
}
break;
case 'i' :
ClkHr_Change = true;
ClkHrAdjust();
break;
case 'j' :
ClkHr_Change = false;
ClkHrAdjust();
break;
case 'x' :
Min_Change = true;
MinAdjust();
break;
case 'y' :
Min_Change = false;
MinAdjust();
break;
case 'z' :
if(DotState)
{
DotState = false;
}
else
{
DotState = true;
}
break;
case 'F' :
//pick a random color but not working yet
ledColor = ColorTable[random(28)];
break;
case '+' : //brighter
brightness += 10;
if (brightness > 255) brightness = 255;
FastLED.setBrightness( brightness );
auto_brightness = 0;
break;
case '-' :
brightness -= 10;
if (brightness < 10) brightness = 10;
FastLED.setBrightness( brightness );
auto_brightness = 0;
break;
case 'O' : //Turn ON/OFF Leds
if (led_on)
{
brightness = 0;
led_on = 0;
}
else
{
brightness = BRIGHTNESS_DEFAULT ;
led_on = 1;
}
FastLED.setBrightness( brightness );
break;
case 'T' : //Temp
Temp();
break;
case 'a' : //Date
DateToArray();
break;
case 'A' :
auto_brightness = 1;
break;
default:
break;
//Serial.println("error");
}//switch
// say what you got:
//Serial.print("I received: ");
//Serial.println(incoming_command);
}
/* if (irrecv.decode(&results)) {
Serial.println(results.value, HEX);
switch(results.value) {
case 0xFF1AE5 :
Serial.println("RED");
ledColor = CRGB::Red;
break;
default:
Serial.println("error");
}
irrecv.resume(); // Receive the next value
}
*/
};
//print the internal temperature
void Temp()
{
FastLED.clear();
int cursor = 14; //65
float t = RTC.temperature();
int celsius = t / 4.0;
Serial.print(celsius);
unsigned long currentMillis = millis();
while (millis() - currentMillis < interval) {
FastLED.show();
int cursor = 14; //65
float t = RTC.temperature();
int celsius = t / 4.0;
for (int i = 1; i <= 2; i++) {
int digit = celsius % 10; // get last digit in time
Serial.print("digit");
Serial.println(digit);
if (i == 1) {
//Serial.print("Digit 4 is : ");
//Serial.print(digit);
//Serial.print(", the array is : ");
for (int k = 0; k <= 13; k++) {
//Serial.print(digits[digit][k]);
if (digits[digit][k] == 1) {
leds[cursor] = ledColor;
}
else if (digits[digit][k] == 0) {
leds[cursor] = 0x000000;
};
cursor ++;
}; // fin for
FastLED.show();
}// fin if
else if (i == 2) {
cursor = 0;
//Serial.print("Digit 3 is : ");
//Serial.print(digit);
//Serial.print(", the array is : ");
for (int k = 0; k <= 13; k++) {
//Serial.print(digits[digit][k]);
if (digits[digit][k] == 1) {
leds[cursor] = ledColor;
}
else if (digits[digit][k] == 0) {
leds[cursor] = 0x000000;
};
cursor ++;
};
// Serial.println();
}
celsius /= 10;
FastLED.show();
}
for (int m = 30; m < 38; m++) {
leds[m] = ledColor;
}
for (int m = 49; m < 56; m++) {
leds[m] = ledColor;
}
FastLED.show();
//check_for_input();
}//fin while animate
};
void ClkHrAdjust() {
delay(30);
tmElements_t Now;
RTC.read(Now);
int hour = Now.Hour;
if (ClkHr_Change) {
if (Now.Hour == 24) {
Now.Hour = 1;
RTC.write(Now);
}
else {
Now.Hour += 1;
};
RTC.write(Now);
}
if(!ClkHr_Change)
{
if (Now.Hour == 1) {
Now.Hour = 24;
RTC.write(Now);
}
else {
Now.Hour -= 1;
};
RTC.write(Now);
}
};
//not used yet
void check_for_input() {
if (animation_change_timeout > 100) {
if (Serial.available() > 0) {
// read the incoming byte:
incoming_command = Serial.read();
// say what you got:
Serial.print("I received: ");
Serial.println(incoming_command);
animate = false;
}
}
}
void loop() // Main loop
{
BrightnessCheck(); // Check brightness
TimeToArray(); // Get leds array with required configuration
IR_Check();
FastLED.show(); // Display leds array
}
2 years ago
I made three of these clocks years ago. I now added a brightness dimmer that is dimming the leds as the light gets lower and brighting the leds as the light gets higher. You'll need an LDR and a resistor. Google 'LDR and Arduino' and you'll get lots of hits on how to wire it. I use A0 pin.
// Check Light sensor and set brightness accordingly
void BrightnessCheck(){
const byte sensorPin = 0; // Analog light sensor pin
int sensorValue = analogRead(sensorPin); // Read sensor
sensorValue = 1023 - sensorValue; //LED gets brighter the darker it is at the sensor that means we have to -invert- the reading from 0-1023 back to 1023-0
const byte LEDbrightness = map(sensorValue, 0, 1023, 20, 255);
LEDS.setBrightness(LEDbrightness);
};
Just replace the above code with your void BrightnessCheck(){.
If the leds are too bright or too dim when the light is low change the '20' in (sensorValue, 0, 1023, 20, 255) to 15 or 10 or 25 or whatever will suit you.
2 years ago
Hi,
I have created the following code
But the problem is
TEMPERATURE IS SHOWING ( 00.C) ALL THE TIME
please help me
regards
julee11
code
#include <DS3232RTC.h>
#include <Time.h>
#include <DHT.h>
#include <Wire.h>
#include "FastLED.h"
#define NUM_LEDS 29// Number of LED controles (remember I have 3 leds / controler
#define COLOR_ORDER BRG // Define color order for your strip
#define DATA_PIN 6 // Data pin for led comunication
#define DHTPIN 7
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
CRGB leds[NUM_LEDS]; // Define LEDs strip
byte digits[12][7] = {{0,1,1,1,1,1,1}, // Digit 0
{0,1,0,0,0,0,1}, // Digit 1
{1,1,1,0,1,1,0}, // Digit 2
{1,1,1,0,0,1,1}, // Digit 3
{1,1,0,1,0,0,1}, // Digit 4
{1,0,1,1,0,1,1}, // Digit 5
{1,0,1,1,1,1,1}, // Digit 6
{0,1,1,0,0,0,1}, // Digit 7
{1,1,1,1,1,1,1}, // Digit 8
{1,1,1,1,0,1,1}, // Digit 9
{1,1,1,1,0,0,0}, // Digit *0
{0,0,1,1,1,1,0}}; // Digit C I 2D Array for numbers on 7 segment
bool TempShow = true;
bool Dot = true; //Dot state
bool DST = true; //DST state
int last_digit = 0;
//long ledColor = CRGB::DarkOrchid; // Color used (in hex)
long ledColor = CRGB::MediumVioletRed;
long ColorTable[16] = {
CRGB::Amethyst,
CRGB::Aqua,
CRGB::Blue,
CRGB::Chartreuse,
CRGB::DarkGreen,
CRGB::DarkMagenta,
CRGB::DarkOrange,
CRGB::DeepPink,
CRGB::Fuchsia,
CRGB::Gold,
CRGB::GreenYellow,
CRGB::LightCoral,
CRGB::Tomato,
CRGB::Salmon,
CRGB::Red,
CRGB::Orchid
};
void setup() {
// Serial.begin(9600);
// Wire.begin();
LEDS.addLeds<WS2811, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS); // Set LED strip type
LEDS.setBrightness(255); // Set initial brightness
pinMode(2, INPUT_PULLUP); // Define DST adjust button pin
pinMode(4, INPUT_PULLUP); // Define Minutes adjust button pin
pinMode(5, INPUT_PULLUP); // Define Hours adjust button pin
}
// Get time in a single number, if hours will be a single digit then time will be displayed 155 instead of 0155
int GetTime(){
tmElements_t Now;
RTC.read(Now);
//time_t Now = RTC.Now();// Getting the current Time and storing it into a DateTime object
int hour=Now.Hour;
int minutes=Now.Minute;
int second =Now.Second;
if (second % 2==0) {Dot = false;}
else {Dot = true;};
return (hour*100+minutes);
};
// Check Light sensor and set brightness accordingly
void BrightnessCheck(){
const byte sensorPin = 3; // light sensor pin
const byte brightnessLow = 5; // Low brightness value
const byte brightnessHigh =225 ; // High brightness value
int sensorValue = digitalRead(sensorPin); // Read sensor
if (sensorValue == 0) {LEDS.setBrightness(brightnessHigh);}
else {LEDS.setBrightness(brightnessLow);}
};
void TempToArray(){
tmElements_t tm;
RTC.read(tm);
if (tm.Second != 47) {
TempShow =false;
return;
}
TempShow = true;
int t = dht.readTemperature();
//int celsius = (t / 4.0) * 100;
int celsius =(t);
Serial.print("Temp is: ");
int cursor = 29; // last led number
leds[14]=0x000000;
leds[14]=0x000000;
for(int i=0;i<=13;i++){
int digit = celsius % 10; // get last digit in time
if (i==4){
Serial.print("Digit 4 is : ");
Serial.print(digit);
Serial.print(" ");
cursor = 22;
for(int k=0; k<=13;k++){
Serial.print(digits[11][k]);
if (digits[11][k]== 1){leds[cursor]=ledColor;}
else if (digits[11][k]==0){leds[cursor]=0x000000;};
cursor ++;
};
Serial.println();
}
else if (i==3){
Serial.print("Digit 3 is : ");Serial.print(digit);Serial.print(" ");
cursor =15;
for(int k=0; k<=13 ;k++){
Serial.print(digits[10][k]);
if (digits[10][k]== 1){leds[cursor]=ledColor;}
else if (digits[10][k]==0){leds[cursor]=0x000000;};
cursor ++;
};
Serial.println();
}
else if (i==2){
Serial.print("Digit 2 is : ");Serial.print(digit);Serial.print(" ");
cursor =7;
for(int k=0; k<=13;k++){
Serial.print(digits[digit][k]);
if (digits[digit][k]== 1){leds[cursor]=ledColor;}
else if (digits[digit][k]==0){leds[cursor]=0x000000;};
cursor ++;
};
Serial.println();
}
else if (i==1){
Serial.print("Digit is : ");Serial.print(digit);Serial.print(" ");
cursor =0;
for(int k=0; k<=13;k++){
Serial.print(digits[digit][k]);
if (digits[digit][k]== 1){leds[cursor]=ledColor;}
else if (digits[digit][k]==0){leds[cursor]=0x000000;};
cursor ++;
};
Serial.println();
}
celsius /= 10;
};
};
// Convert time to array needet for display
void TimeToArray(){
int Now = GetTime(); // Get time
int cursor = 29; //116
Serial.print("Time is: ");Serial.println(Now);
if (Dot){leds[15]=ledColor;}
else {leds[15]=0x000000;
};
for(int i=1;i<=4;i++){
int digit = Now % 10; // get last digit in time
if (i==1){
//Serial.print("Digit 4 is : ");Serial.print(digit);
Serial.print(", the array is : ");
cursor =22;
for(int k=0; k<=6;k++){
//Serial.print(digits[digit][k]);
if (digits[digit][k]== 1){leds[cursor]=ledColor;}
else if (digits[digit][k]==0){leds[cursor]=0x000000;};
cursor ++;
}; // fin for
Serial.println();
if (digit != last_digit)
{ fadefonction();
ledColor = ColorTable[random(16)];
}
last_digit = digit;
}// fin if
else if (i==2){
Serial.print("Digit 3 is : ");Serial.print(digit);Serial.print(", the array is : ");
cursor =15;
for(int k=0; k<=6;k++){
Serial.print(digits[digit][k]);
if (digits[digit][k]== 1){leds[cursor]=ledColor;}
else if (digits[digit][k]==0){leds[cursor]=0x000000;};
cursor ++;
};
Serial.println();
}
else if (i==3){
Serial.print("Digit 2 is : ");Serial.print(digit);Serial.print(", the array is : ");
cursor =7;
for(int k=0; k<=6;k++){
Serial.print(digits[digit][k]);
if (digits[digit][k]== 1){leds[cursor]=ledColor;}
else if (digits[digit][k]==0){leds[cursor]=0x000000;};
cursor ++;
};
Serial.println();
}
else if (i==4){
Serial.print("Digit 1 is : ");Serial.print(digit);Serial.print(", the array is : ");
cursor =0;
for(int k=0; k<=6;k++){
Serial.print(digits[digit][k]);
if (digits[digit][k]== 1){leds[cursor]=ledColor;}
else if (digits[digit][k]==0){leds[cursor]=0x000000;};
cursor ++;
};
// Serial.println();
};
Now /= 10;
};
};
void DSTcheck(){
int buttonDST = digitalRead(2);
// Serial.print("DST is: ");Serial.println(DST);
if (buttonDST == LOW){
if (DST){
DST=false;
// Serial.print("Switching DST to: ");Serial.println(DST);
}
else if (!DST){
DST=true;
// Serial.print("Switching DST to: ");Serial.println(DST);
};
delay(500);
};
}
void TimeAdjust(){
int buttonH = digitalRead(5);
int buttonM = digitalRead(4);
if (buttonH == LOW || buttonM == LOW){
delay(100);
tmElements_t Now;
RTC.read(Now);
int hour=Now.Hour;
int minutes=Now.Minute;
int second =Now.Second;
if (buttonH == LOW){
if (Now.Hour== 23){Now.Hour=0;}
else {Now.Hour += 1;};
}else {
if (Now.Minute== 59){Now.Minute=0;}
else {Now.Minute += 1;};
};
RTC.write(Now); }}
void fadeall() {
for(int m = 0; m < NUM_LEDS; m++) {
leds[m].nscale8(250);}}
void fadefonction () {
static uint8_t hue = 0;
// First slide the led in one direction
for(int i = 0; i < NUM_LEDS; i++) {
// Set the i'th led to red
leds[i] = CHSV(hue++, 255, 255);
// Show the leds
FastLED.show();
// now that we've shown the leds, reset the i'th led to black
// leds[i] = CRGB::Black;
fadeall();
// Wait a little bit before we loop around and do it again
delay(10);
}
// Now go in the other direction.
for(int i = (NUM_LEDS)-1; i >= 0; i--) {
// Set the i'th led to red
leds[i] = CHSV(hue++, 255, 255);
// Show the leds
FastLED.show();
// now that we've shown the leds, reset the i'th led to black
// leds[i] = CRGB::Black;
fadeall();
// Wait a little bit before we loop around and do it again
delay(10);
}
}
void loop() // Main loop
{
int t = dht.readTemperature();
Serial.print("Temperatura: ");
Serial.print(t);
BrightnessCheck(); // Check brightness
DSTcheck(); // Check DST
TimeAdjust(); // Check to se if time is geting modified
TimeToArray(); // Get leds array with required configuration
TempToArray();
FastLED.show(); // Display leds array
if (TempShow == true) delay (7000);
}
Question 2 years ago on Step 5
Hi OnlyNoise.
Your clock is brilliant. The use of the serially adressable LEDS is inspired.
Three Questions
1) Is it going to be difficult to change from an RTC to a GPS module? I imagine it would just be a little tweaking of the code, and using a different included file. (I have a tiny little GPS Arduino clock here which I made)
2) Is it an issue to add seconds digits? Do you know of anyone with code to do that?
3) If I wanted to use the 60 LEDS/m strip and use 6 LEDs (2 segments) per segment, how much work is that to change the coding? Again can you point me at anyone who has done that?
Many thanks for the inspiration.
3 years ago
Great work! I used it to do my first project with led strips. However, I made some changes:
1 - I used 3 leds per segment totaling 21 led per digit and 86 total leds including the two points.
2 - the 4 adjustment buttons: 1 - to display the temperature; 2 - to change the color; 3- set the time, 4- set the minutes.
3 - I deleted the control via bluethooh
4 - I simplified the code to suit my need:
https://drive.google.com/open?id=1PxSQj4_Bb9bNBLVQ...
Reply 2 years ago
Bonjour je suis très novices dans le domaine j ai utiliser le G-Code cependant j ai un petit soucis c est que mon afficheur est plus grand du coup il faudrait que je rajoute 3 led pour les points fi milieux est ce possible merci d avance