Smart Phone Controlled Arduino Mood Light with Alarm

Arduino

ByAswinth Raj 11

Smart Phone Controlled Arduino Mood Light with Alarm

I recently purchased the Neo Pixel LED strip and was quite impressed by the way it works. The tiny LED’s have an inbuilt driver IC which helps us to control each LED individually and can produce a wide spectrum of colors. Being a garish person who is obsessed with colours I really loved watching these tiny LED’s changing colors so I decided to build something on my own and leave it coloring my bedroom during night times.

 

 

I not only wanted these LED’s to change colors but should also have logic reasoning behind it. That is when I came across the article by Mr. Stephen Westland who is a professor of Color Science and Technology at University of Leeds. He claims that when humans are exposed to coloured lights they respond, both physiologically and psychologically based on the color. This concept is not new and has been widely practised in the name of Chromotherapy and the device used to do this is called a Mood Lamp.

 

So I finally settled to dig deep into chromotherapy and build a Mood Lamp which could change colors based on the time of the day and can also be controlled form the mobile phone. Apart from that I also added a LDR to turn it off automatically during day time and also an option to set a wake up alarm which will wake you up with a bright orange colour (sunshine) and another alarm that puts the LED’s in sleep mode with mild purple (night sky) color to doze you into sleep. Sounds interesting right? So let’s get building.

 

Chromotherapy – Mood Lamp

But there are lots of so called DIY mood lamps out there which just randomly change colour without any purpose behind it. After a bit of searching I found that a mood lamp should have a minimum of certain lumens brightness and should also change colours gradually with varying intensity. Each colour has a different impact on both mental and physical level. I have tabulated the impact against each colour in the below table.

 

 

Colour

Physiological impact 

Physical impact

Red

Gives more Energy, Boosts Sexual Desires

Kidney, Backbone, sense of smell

Yellow

Improves Digestion, Kills Depression

Stomach, Liver, Intestine

Blue

Lowers Blood Pressure, Calm Down People

Migraine headache, throat, ears and mouth

Green

Stimulates Growth and strengthens muscle

Bones, tissues, immune system

Purple

Sleep Inducer

Emotional and Mental Balance

Decreases Sexual desires

Nervous system, eyes

Orange

Stimulates creativity

Breathing, Brest feeding

Pink

Purifies Blood

Blood, arteries, veins

So based on this data I have designed the mood Lamp to change its colours based on what time of the day it is. Of course I have added some personal flavour, so feel free to edit the program accordingly.

 

Materials Required

Enough science we are supposed to be working with electronics, so let’s gather the required components.

  • Neo Pixel LEDs
  • Arduino
  • DS3231 RTC module
  • HC-05 Bluetooth Module
  • LDR
  • 100K resistor
  • 12V Power supply.

 

Circuit Diagram

The complete circuit diagram for this Bluetooth Controlled Arduino Mood Lamp Project is given below.

Arduino Mood Light Project Circuit Diagram

 

As you can see, we have used modules and hence the connections are pretty simply. For keeping track of the current time we have used the DS3231 Real Time Clock (RTC) module. This module works with the help of I2C communication and can be powered directly with 5V pin of the Arduino. The SDA and SCL pins are connected to the I2C pins A4 and A5 respectively.

 

Next we have used the HC-05 Bluetooth module. Through this Bluetooth connection we can set the required colour on the LED and also set a sleep time and wake up time for the LED. The Bluetooth module is powered with the 5V pin as well and the Tx and Rx pins are connected to Arduino through pins 11 and 10 respectively.

 

It is pointless to glow the LEDs when the room is very bright, hence we have used an LDR to detect brightness in the room and if it is very bright the LEDs turn off automatically and turns back on only when the room is dark is enough. We have formed a potential divider network with one resistor being the LDR itself and the other a 100K resistor and connect it to pin A0 of Arduino, this way a the resistance of LDR varies based on light the voltage read by the Arduino will also vary. Learn more about interfacing LDR with Arduino here.

 

Finally the neo pixel is connected to pin 6 of Arduino which is a PWM pin and is again powered by the 5V pin (vcc) of the Arduino. I have used an Arduino Pro-mini for my project since it is smaller and would be handy while packing it inside an enclosure. You can use any board of your choice. The complete set-up is powered by a 12V adapter which is connected to the RAW pin of the Arduino. The on board voltage regulator on Arduino converts this 12V to 5V which is then used to supply 5V to power all the modules through the vcc pin.

Smart Phone Controlled Arduino Mood Light Project

 

Neo Pixel LEDs and How They Work

The primary and cool component of this project is the neo Pixel LED. The idea for the Neo pixel LEDs were originally by the Adafruit industries in which they use an LED driver IC WS2812 inside an RBG LED. This driver IC can receive a control signal from a controller like Arduino and based on the control signal it can control the intensity of the RBG color thus helping us to achieve the required color.

 

You can connect as many as of these LED in series and the cool feature is that each of these LED can be addressed individually meaning each LED can be made to glow in different colors by tweaking the control signal accordingly. So remember that unlike an normal LED you can power a neo pixel using just a power supply, it has three pin namely the Vcc, ground and data. The Vcc and ground pin is used to power the Led which can range from 3.3V to 5V and the data pin is used to send the control signal which decide that which Led should glow in which color.

 

Using the Neo pixel LED is pretty simple because of the library provided by Adafruit itself.  Today there are many different types of Neo Pixel led available in the market from different vendors and they use different driver IC. But all of them can be controlled by this Adafruit library. We have previously interfaced NeoPixel with Arduino.

 

Programming Arduino for Mood Light

The complete program for this Neo-pixel mood light with Arduino project is given at the end of this page, which can be used as such after you have added the required libraries. In this section I will discuss few important snippets from the code which could help you modify the project as required. The program is quite big around 300 lines so if you feel grumpy trying to understand anything feels free to post your questions on the forums and as always complete Arduino program can be found at the end of this article.

 

As always we begin the program by adding the required libraries for the project in this case the following libraries are needed.

#include <SoftwareSerial.h> //Bluetooth module works with software serial
#include <Adafruit_NeoPixel.h> //Library for Neo Pixel (Download from Link in article)
#include <DS3231.h> //Library for RTC module (Download from Link in article)
#include <EEPROM.h> //Library for EEPROM (Pre-Loaded into Arduino)

 

The Bluetooth module works though serial communication; I do not prefer using the hardware serial pin (0 and 1) for that since I will be using the serial monitor to debug the program, so we include the software serial library into our program. This library will be present in your IDE by default.

 

Next we use the Adafruit Neo Pixel library from Adafruit that we discussed in previous heading. You can download the Adafruit Neo pixel library using the link, which will download the ZIP file from the GitHub. Then you can use the sketch -> Include Library -> Add .ZIP library option to add this ZIP file into your Arduino IDE.

 

Similarly you can also download the DS3231 library for the RTC module and add it the same way. Finally we have EEPROM library which are already pre-loaded into the Arduino library. We just have to add the library to store the wake up alarm and sleep alarm time in EEPROM so that when the Arduino re-boots after a power failure it remembers when to go to sleep and when to wake up.

 

The Neo Pixel LEDs can produce a wide range of colours, but we are not interested in all the colours for our mood light except for 8 of them which are Red, Orange, Yellow, Green, Cyan, Blue, Purple and Pink. To get each of these colours we have to pass the respective value of it. So we define the value of each colour using the macros as shown below.

#define Red 1
#define Orange 20
#define Yellow 30
#define Green 70
#define Cyan 100
#define Blue 130
#define Purple 200
#define Pink 240

 

Next we have to declare to which pins we have connected the neo Pixel and how many LEDs are present on the Neo Pixel strip. In my case I have connected the Neo pixel to pin 6 as shown in the circuit diagram above and I have a total of 5 LEDs on my strip so my code looks like

Adafruit_NeoPixel strip = Adafruit_NeoPixel(5, 6, NEO_GRB + NEO_KHZ800); //5 LEDs on PIN-6

 

There are a lot of global variables declared in the program in the next line, what you might be interested to play around is with the array declarations. There are two arrays namely the morning_rainbow and evening_rainbow each consisting of 4 colours. I have selected Red, Orange, Green and Pink to be the morning colours and Yellow, Cyan, Blue and Purple to be the evening colours based on the chromo therapy table that we discussed above you can change it as you wish

//array declarations
char current_rainbow[8] = {}; //the main array
char morning_rainbow[4] = {Red, Orange, Green, Pink}; //colours to show during day time
char evening_rainbow[4] = {Yellow, Cyan, Blue, Purple}; //colours to show during night time
char all_rainbow[8] = {Red, Orange, Yellow, Green, Cyan, Blue, Purple, Pink}; //colours that can be controlled thorugh Bluetooth

 

Inside the void setup function we initialise the Bluetooth module and Serial monitor at 9600 baud rate. The Bluetooth is used to communicate with our phone and the serial monitor is used for debugging. Simply launch the serial monitor and you can monitor all the vital variables in the program. Apart from that we also read the EEPROM values if the user has set them previously and store them in the respective variables

 void setup(){//Execute once during the launch of program
    Initialize_RTC();
    Bluetooth.begin(9600); 
    Serial.begin (9600); //for debugging
    strip.begin();
    strip.show(); // Initialize all pixels to 'off'
    Bluetooth.println("Mood Lamp Alarm -CircuitDigest");
    Serial.println("Mood Lamp Alarm -CircuitDigest");

//If anything was stored previously in EEPROM copy it to the alarm variables
    sleep_alarm_hour = EEPROM.read(0);
    sleep_alarm_minute = EEPROM.read(1);
    wake_alarm_hour =  EEPROM.read(2);
    wake_alarm_minute = EEPROM.read(3);
 }

 

Inside the main loop, we begin the program by reading the value from the LDR, if the room is very bright the program dims all the LEDs thus turning it off and then waits for the room to get bright again. The function Interactive_BT is also checked when the room is bright so that the user can still force the lights to turn on from the mobile phone. Here I have select 800 as the threshold value but if you want to lamp to work even in bright day light you can simply increase the value of 800. Then range is form 0-1024.

  while (lightvalue>800) //IF the room is very brigt (you can increase this values to make it glow even duringf day)
  {
       for (int i=0; i<=5; i++) //turn of all LED
        {
          strip.setBrightness(0); //by setting brightness to zero
          strip.show();
        }
   lightvalue = analogRead(A0); //kepp checking if the room is getting darker
    Serial.print("Too bright to glow: ");
    Serial.println(lightvalue); //for debugging
   Interactive_BT();  //Also check if the user is trying to access through bluetooth
   delay(100);
  }

 

The interactive_BT is the function inside which the user can set the alarm or control the Lamp from his phone. The code inside this function is self explanatory through comment section, so I am not going line by line. The speciality of the program is that it can use any Bluetooth application from android app store or Iphone store and still can interact with it.

 

Next we read the current time and update the time object “t”. From that we split the hour and minute value using the t.hour and t.min and store it in the variable current_time_hour and current_time_minute respectively.

  t = rtc.getTime(); //get the current time
  current_time_hour = t.hour; //get hour value
  current_time_minute = t.min; //get minute value

 

In this program I am changing the color of the Neo pixel for every 5 seconds, so  the next segment for code will be execute only once in every 5 seconds. Inside this segment we increase the value of count and call the function called glow_rainbow. This function glows the led based on the colors stored in the current_rainbow array. So before calling this glow rainbow we have to load current rainbow using a set of colors from either morning_rainbow or evening_rainbow based on the time of the day as shown below.

    if (sleeping == false) //If we are not sleeping
      glow_rainbow(colour_count); //dsplay the colours
    if (sleeping == true) //if we are sleeping
      night_lamp(); //display the night lamp effect

   if (t.hour>=17) //During evening time
  {
    for (int i=0; i<=3; i++)
     { current_rainbow[i] = evening_rainbow[i]; delay(100);} //copy evening raninbow into current_rainbow
  }
  else //During Morning
  {
    for (int i=0; i<=3; i++)
     { current_rainbow[i] = morning_rainbow[i]; delay(100);} //copy  mornign rainboe into current rainbow
  }

 

Inside the glow_rainbow function we use two for loops one to dim the LED and other to increase the brightness of the LED based on the required colour. This required colour is selected from the array current_rainboe[count] where count decides the current colour form the array. There are totally 5 LED in my strip so I have used variable i upto 5, the value of j can be fiddled around between 0-255 according to how much ever brightness you want to reduce

void glow_rainbow(int count)
{
    for (int j=150; j>=10; j--) //decrease the brightness to create dim effect
    {
      for (int i=0; i<=5; i++) //do it for all 5 leds
        {
          strip.setBrightness(j);
          strip.show();
        }
         1         delay(2);
    }

  for (int j=0; j<=255; j++) //increase the brightness
{
      for (int i=0; i<=5; i++) //do it for all 5 leds
        {
          strip.setPixelColor(i,Wheel(current_rainbow[count]));//select the colour based on count value
          strip.setBrightness(j);
          strip.show();
        }
                  delay(10);
}
}

 

The function wheel is directly taken from the Adafruit example program. It takes in a value from 0 to 255 and produces a colour based on the value. This value is what we defined initially in our program using the #define macros. The function is shown below.

// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
  WheelPos = 255 - WheelPos;
  if(WheelPos < 85) {
    return strip.Color( (255 - WheelPos * 3), 0, (WheelPos * 3) );
  }
  if(WheelPos < 170) {
    WheelPos -= 85;
    return strip.Color(0, (WheelPos * 3) , (255 - WheelPos * 3) );
  }
  WheelPos -= 170;
  return strip.Color((WheelPos * 3), (255 - WheelPos) * 3, 0);
}

 

This line strip.Color(x,y,z) is an important line which decides the colour of the LED. The variables x,y and z each take a value from 0-255 and based on the value it decides the amount of Red, Green and Blue light the LED should emit. So x,y ad z directly controls the Red, Green and Blue light intensity of the LED pixels.

 

Controlling and Setting Alarm through Smart Phone

Once you have made the connection as per the circuit diagram and have uploaded the code given below you can test the circuit. I would also recommend opening the serial monitor to check how the hardware is responding to the program. Once you are done with that you can open your Bluetooth application on the mobile phone.

I am using the Bluetooth terminal application from Play Store but you can use any Bluetooth application which helps you to read and write data through Bluetooth connection. Make sure you have paired the Bluetooth module with your phone using the password “1234” before launching the application. Once the application is launched connect to your Bluetooth device which should be normal named as “HC-05”.

 

To begin communications just send a random variable from the phone, in this case I have sent ‘g’. This will initiate Interactive Bluetooth communication mode in the program and you will get the following screen.

Bluetooth communication mode on Android Application

 

From here simply follow the on screen instruction to set alarm or for controlling the lamp for your required colour by simply send numbers. For example I have set the morning alarm here.

Set alarm or for controlling the lamp

 

Similarly you can also set the evening alarm and can also control the Lamp by sending the number for required colour as shown below. The complete working can also be understood form the video linked at the end of this project.

Control the Lamp by sending the number

 

3D Printing the Enclosure for Arduino Mood Light

As I said I made this project to be left working in my office or in my living room so it requires a good enclosure for housing all the electronics. Also it hurts our eyes to look at the pixel directly when they glow. So I decide to 3D print my enclosure using my Tevo tarantula printer and hence went on to design my enclosures.

 

The complete design files are available for download from thingiverse. You can also print your own if you have 3D printer or simply can use wood or acrylic to build an enclosure of our own. My print setting is show in the image below.

3D Printing the Enclosure for Arduino Mood Light

 

After printing you can push the LDR into the small hole provided and the LED strip can be slide into the top case. After assembling, my hardware looked something like this as shown below.

Arduino Mood Light Project Hardware Assembly in 3D Printed Case

 

All that is left to do is power the set-up using a 12V adapter and set the alarm using the Bluetooth option as discussed above and leave in illuminating your room. Hope you liked the project and enjoyed building it. If you have faced any problem in the build process you can post it in the comment section below or use the forums for quick help. 

Code

/*
 * Mood light using Arduino
 * Interactive Bluetooth Programming using Terminal
 * Alarm function for wake up and sleep.
 * Program by: B.Aswinth Raj https://circuitdigest.com/users/baswinth-raj
 * For: Circuitdigest.com
 * Dated: 24-9-2018
 */

 /*PIN CONNECTIONS
  * Bluetooth (HC-05)
  * #Tx -> 11
  * Rx ->10
  * #DS3231 (RTC)
  * SDA ->A4
  * SCL ->A5
  * #Neo Pixel 
  * Data -> pin 6
  */

#include <SoftwareSerial.h> //Bluetooth module works with software serial 
#include <Adafruit_NeoPixel.h> //Library for Neo Pixel (Download from Link in article)
#include <DS3231.h> //Library for RTC module (Download from Link in article)
#include <SPI.h> //Library for SPI communication (Pre-Loaded into Arduino)
#include <EEPROM.h> //Library for EEPROM (Pre-Loaded into Arduino)

//Define the value of colours 
#define Red 1
#define Orange 20
#define Yellow 30
#define Green 70
#define Cyan 100
#define Blue 130
#define Purple 200
#define Pink 240

Adafruit_NeoPixel strip = Adafruit_NeoPixel(5, 6, NEO_GRB + NEO_KHZ800); //5 LEDs on PIN-6

DS3231  rtc(SDA, SCL); //object for RTC module
Time t; //element t 

SoftwareSerial Bluetooth(11, 10); // TX, RX
 

 //GLOBAL variables
char incoming; //to store value form Bluetooth 
int lightvalue=0; //LDR output vale
int colour_count = 0; //to increment array 

//variable to store hour and minute values
int wake_alarm_hour; 
int sleep_alarm_hour;
int wake_alarm_minute;
int sleep_alarm_minute;
int current_time_hour;
int current_time_minute;

//flag variables 
boolean settings = false;
boolean sleeping = false;

//array declarations 
char current_rainbow[8] = {}; //the main array 
char morning_rainbow[4] = {Red, Orange, Green, Pink}; //colours to show during day time 
char evening_rainbow[4] = {Yellow, Cyan, Blue, Purple}; //colours to show during night time
char all_rainbow[8] = {Red, Orange, Yellow, Green, Cyan, Blue, Purple, Pink}; //colours that can be controlled thorugh bluetooth 

 

void wait_for_reply() //Function to wait for user to enter value for BT
{
  Bluetooth.flush(); while (!Bluetooth.available()); 
}

void Initialize_RTC()
{
  rtc.begin();   // Initialize the rtc object

//#### The following lines can be uncommented to set the date and time for the first time###  
//rtc.setDOW(TUESDAY);     // Set Day-of-Week to SUNDAY
//rtc.setTime(13, 01, 00);     // Set the time to 12:00:00 (24hr format)
//rtc.setDate(9, 25, 2018);   // Set the date to January 1st, 2014 
}

 int get_hour() //get the hour value for setting alarm 
 {
  char UD; char LD; //upper digit and lower digit 
  Bluetooth.println("Enter hours");
  wait_for_reply(); //wait for user to enter something
  UD = Bluetooth.read(); delay (100); //Read the first digit 
  wait_for_reply(); //wait for user to enter something
  LD = Bluetooth.read(); //Read the lower digit

  UD= int(UD)-48; LD= int(LD)-48; //convert the char to int by subtracting 48 from it

  return (UD*10)+ LD; // Comine the uper digit and lowe digit to form the number which is hours 
 }
 
 int get_minute() //get the minute value for setting alarm 
 {
  char UD; char LD; //upper digit and lower digit 
  Bluetooth.println("Enter minutes");
  wait_for_reply();//wait for user to enter something
  UD = Bluetooth.read(); delay (100); //Read the first digit 
  wait_for_reply();//wait for user to enter something
  LD = Bluetooth.read(); //Read the first digit 

  UD= int(UD)-48; LD= int(LD)-48; //convert the char to int by subtracting 48 from it

  return (UD*10)+ LD; // Comine the uper digit and lowe digit to form the number which is hours 
 }

 
 
 void setup(){//Execute once during the launch of program 
    Initialize_RTC();
    Bluetooth.begin(9600);  
    Serial.begin (9600); //for debugging 
    
    strip.begin();
    strip.show(); // Initialize all pixels to 'off'
    
    Bluetooth.println("Mood Lamp Alarm -CircuitDigest");
    Serial.println("Mood Lamp Alarm -CircuitDigest");

//If anything was stored previously in EEPROM copy it to the alarm variables 
    sleep_alarm_hour = EEPROM.read(0);
    sleep_alarm_minute = EEPROM.read(1);
    wake_alarm_hour =  EEPROM.read(2);
    wake_alarm_minute = EEPROM.read(3);

 }

 void loop(){

  lightvalue = analogRead(A0); //Read the value form LDR
  
  while (lightvalue>800) //IF the room is very brigt (you can increase this values to make it glow even duringf day)
  {
       for (int i=0; i<=5; i++) //turn of all LED
        {
          strip.setBrightness(0); //by setting brightness to zero
          strip.show();
        }
   lightvalue = analogRead(A0); //kepp checking if the room is getting darker
    Serial.print("Too bright to glow: ");
    Serial.println(lightvalue); //for debugging 
   Interactive_BT();  //Also check if the user is trying to access through bluetooth 
   delay(100);
  }
  
  
  settings=true; //if setting is true it means we have are ready to get into bluetooth control
  Interactive_BT(); //Also check if the user is trying to access through bluetooth 
  
    
  t = rtc.getTime(); //get the current time
  current_time_hour = t.hour; //get hour value
  current_time_minute = t.min; //get minute value 

    if (t.sec%5 == 0) //For every 5 seconds 
  {
    colour_count++; //change the colour 
    if (colour_count>=4) //if we exceed array count 
    colour_count = 0; //initialise the count 

    while(t.sec%5==0) //wait till the 5th secound is over
    t = rtc.getTime(); //update t.sec

    //For Debugging 
    Serial.print ("Glowing clour: ");Serial.println(colour_count);
    Serial.print("At time: "); Serial.print(t.hour); Serial.print (" : "); Serial.println (t.min);
    Serial.print("Enviroment Brightness: "); Serial.println(lightvalue);
    Serial.print("Wake up at :"); Serial.print(wake_alarm_hour); Serial.print (" : "); Serial.println (wake_alarm_minute);
    Serial.print("Sleep at :"); Serial.print(sleep_alarm_hour); Serial.print (" : "); Serial.println (sleep_alarm_minute);
    Serial.print ("Is Lamp sleeping? : "); Serial.println (sleeping);
    Serial.println("                   ******                ");  
    //End of debugging lines 

    if (sleeping == false) //If we are not sleeping 
      glow_rainbow(colour_count); //dsplay the colours
    if (sleeping == true) //if we are sleeping 
      night_lamp(); //display the night lamp effect 

   if (t.hour>=17) //During evening time
  {
    for (int i=0; i<=3; i++)
     { current_rainbow[i] = evening_rainbow[i]; delay(100);} //copy evening raninbow into current_rainbow 
  }
  else //During Morning
  {
    for (int i=0; i<=3; i++)
     { current_rainbow[i] = morning_rainbow[i]; delay(100);} //copy  mornign rainboe into current rainbow 
  }
      
  }
  
  

  if(t.hour == sleep_alarm_hour && t.min == sleep_alarm_minute) //If  the sleep time is meat 
  { sleeping = true; Serial.println("Lamp getting into Sleep Mode");}//get into sleeping mode

  if(t.hour == wake_alarm_hour && t.min == wake_alarm_minute)// If wake up time is meat
  { sleeping = false; Serial.println("Lamp is up and ready"); }// get out of sleeping mode.

 

 }

 

 void Interactive_BT() //using this funciton the user cna control LED colour and set alarm time.
 {
  
   if (Bluetooth.available() > 0 && settings == true) { //if the user has sent something 
    incoming = Bluetooth.read(); //read and clear the stack 
    Bluetooth.println("0-> Set Alarm "); Bluetooth.println("1 -> Control Lamp"); Bluetooth.println("x -> Exit Anytime"); //Display the options 
    wait_for_reply();
    incoming = Bluetooth.read(); //read what the user has sent 
//Based on user request 
    if (incoming == '0') //if user sent 0
    {
    Bluetooth.println("Setting Alarm"); Bluetooth.println("0-> Sleep alarm"); Bluetooth.println("1 -> Wake up Alarm"); //give alarm options
    wait_for_reply();
    incoming = Bluetooth.read();
    
       if (incoming == '0')
         {
            Bluetooth.println("Go to sleep at:"); sleep_alarm_hour = get_hour(); sleep_alarm_minute = get_minute(); 
            Bluetooth.print("Sleep alarm set at: "); Bluetooth.print(sleep_alarm_hour); Bluetooth.print(" : "); Bluetooth.println(sleep_alarm_minute);
            EEPROM.write(0, sleep_alarm_hour);  EEPROM.write(1, sleep_alarm_minute);
         }
      
        if (incoming == '1')
         {
            Bluetooth.println("Wake me at:"); wake_alarm_hour = get_hour(); wake_alarm_minute = get_minute(); 
            Bluetooth.print("Wake up alarm set at: "); Bluetooth.print(wake_alarm_hour); Bluetooth.print(" : "); Bluetooth.println(wake_alarm_minute);
            EEPROM.write(2, wake_alarm_hour);  EEPROM.write(3, wake_alarm_minute);
         }
         incoming = 'x';
    }

    if (incoming == '1')
    {
      Bluetooth.println("Select the colour you like");
      Bluetooth.println("0-> Red"); Bluetooth.println("1-> Orange"); Bluetooth.println("2-> Yellow"); Bluetooth.println("3-> Green"); Bluetooth.println("4-> Cyan");
      Bluetooth.println("5-> Blue"); Bluetooth.println("6-> Purple"); Bluetooth.println("7-> Pink");

      do{
      wait_for_reply();
      incoming = Bluetooth.read();

      memcpy(current_rainbow, all_rainbow, 8); 
      
      glow_rainbow(incoming-48);
      Serial.println(incoming-48);
      }while (incoming!='x');

      Bluetooth.println("Exiting control mode");
    }

    if (incoming == 'x') //exit from Bluetooth mode
    {
      Bluetooth.flush();
      incoming = Bluetooth.read();
      incoming = 0;
      settings= false;
      Bluetooth.println("Back to main");
    }

   }
 }
 

// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
  WheelPos = 255 - WheelPos;
  if(WheelPos < 85) {
    return strip.Color( (255 - WheelPos * 3), 0, (WheelPos * 3) );
  }
  if(WheelPos < 170) {
    WheelPos -= 85;
    return strip.Color(0, (WheelPos * 3) , (255 - WheelPos * 3) );
  }
  WheelPos -= 170;
  return strip.Color((WheelPos * 3), (255 - WheelPos) * 3, 0);
}
 
void glow_rainbow(int count)
{
    for (int j=150; j>=10; j--) //decrease the brightness to create dim effect
    {
      for (int i=0; i<=5; i++) //do it for all 5 leds
        {
          strip.setBrightness(j);
          strip.show();
        }
       delay(2);
    }
      
  
  for (int j=0; j<=255; j++) //increase the brightness 
{
      for (int i=0; i<=5; i++) //do it for all 5 leds
        {
          strip.setPixelColor(i,Wheel(current_rainbow[count]));//select the colour based on count value 
          strip.setBrightness(j);
          strip.show();
        }
                  delay(10);
}
}

void night_lamp()
{
for (int j=240; j<=254; j++) //decrease the brightness to create dim effect
{
  for (int i=0; i<=5; i++)//do it for all 5 leds
        {
          strip.setPixelColor(i, 255-j, 0, 255-j);
          strip.show();
        }
  delay(300);
}
for (int j=254; j>=240; j--)//decrease the brightness to create dim effect
{
{
  for (int i=0; i<=5; i++)//do it for all 5 leds
        {
          strip.setPixelColor(i, 255-j, 0, 255-j);
          strip.show();
        }
  delay(300);
}
}
}

Video

Get Our Weekly Newsletter!

Subscribe below to receive most popular news, articles and DIY projects from Circuit Digest

Comments

  • RogerK's picture
    RogerK
    Oct 04, 2018

    Hello,

    When downloading the DS3231 Library from the link provided in the article, it actually downloads the RTClib.h file and the zip file does not include the DS3231.h.

    The library that is referenced in the code "#include <DS3231.h> //Library for RTC module (Download from Link in article)" calls out the DS3231.h.  Should that be RTClib.h?

    Thanks,

    Roger

  • RogerK's picture
    RogerK
    Oct 28, 2018

    Thank you for the link.  I was able to downloaded and included into the code which was originally missing.

  • Semirgj's picture
    Semirgj
    Oct 26, 2018

    as I’m very new to electronics and Arduino I’m wondering how you split the ground wire in your schematic to run to multiple pin locations

  • RogerK's picture
    RogerK
    Oct 28, 2018

    One easy way is to to solder each ground wire to each board, then bring them all into one common node.  for example you may terminate all ground wires to the DC Barrel Jack ground terminal.

    Hope this helps.

  • RogerK's picture
    RogerK
    Nov 19, 2018

    If anyone took the time to seriously build this project, as I did, I have few comments/corrections to add:

    1.  The LDR circuit is wired for reverse operation.  The way it is currently wired, it will turn off the LEDs during night time and turn them on during day time.  The fix is to connect one lead of the LDR to Vcc and connect the resistor lead to ground.

    2.  The resistor value in this article is too large.  I used a 20K LDR, therefore the resistor value is set to 10K so that the voltage at A0 is approximately 1.7V.  The article does not mention what value of LDR is used.  You may want to tweak the resistor value according to what LDR value you use, as long as the Voltage at A0 is about 2V.  The LDR value is dependant on how soon you want to turn on the LEDs when it gets just dark enough or too dark.  It is light sensitive dependant.

    3.  If you use an Arduino Pro Mini it will not be able to drive the NeoPixel LEDs.  The maximum output current for the Arduino Pro Mini is 150 mA which is not sufficient to drive the NeoPixel.  It is highly recommended to use an LM7805 to separately power the NeoPixel. 

    Connect the input of the 7805 to the your main input supply (i.e 9V or 12V) and the ground pin to the ground pin of the input supply.  Then connect the output of the 7805 to the +5V of the NeoPixel LED stick.

    4. Be careful when supplying power to the RAW pin of the Arduino if using a 12V AC/DC wall adapter.  Be sure to use a "Regulated" 12V (recommend to use 9V) AC/DC wall adapter.  Otherwise sever damage will occur to the Arduino input voltage regulator.  Do not use an unregulated AC/DC wall adapter.

    Additionally, I was not able to find a 5 LED NeoPixel.  I used an 8 LED NeoPixel and modified the code accordingly for the 8 LED NeoPixel.  You can find a variety of 8 x 5050 RGB NeoPixel LED stick from Adafruit or Sparkfun.

    The 3D printed cover is very thin and will brake if not careful inserting it into the box.

    My project is finally completed and works just fine.  Still need to test the Blue Tooth Module with my smart phone.

    Good Luck and have fun with this project.  It is very educational and enjoyable to build.

     

  • Aswinth Raj's picture
    Aswinth Raj
    Nov 21, 2018

    Comments like this really encourage me to move forward :-)

    There are still a lot of things that can be built on top of it, creativity is the limit 

  • RogerK's picture
    RogerK
    Dec 06, 2018

    Hello,

    I am having difficulties understanding your statement about the morning and evening colours:

    "I have selected Red, Orange, Green and Pink to be the morning colours and Yellow, Cyan, Blue and Purple to be the evening colours..."

    I noticed that Neo Pixel is only displaying 4 colors:  Red, Orange, Green and Pink but not the rest.  The Neo Pixel will shut off during the day time.

    My Questions are:

    1. Can you please explain how can the Neo Pixel displays both morning and evening rainbow (or colours).

    2. what part of the code can I modify so that the NeoPixel can display all 8 colours.  I am assuming I can combine both lines of morning_raibow and evening_rainbow into one line. 

    Thanks for your help.

  • Jayant's picture
    Jayant
    Dec 06, 2018

       if (t.hour>=17) //During evening time
      {
        for (int i=0; i<=3; i++)
         { current_rainbow[i] = evening_rainbow[i]; delay(100);} //copy evening raninbow into current_rainbow 
      }
      else //During Morning
      {
        for (int i=0; i<=3; i++)
         { current_rainbow[i] = morning_rainbow[i]; delay(100);} //copy  mornign rainboe into current rainbow 
      }
          

    Here is the code that displays morning and evening colours. If you want all colours just run the for loop for all colours instead of only the 4 colors. You set the required colors and order using the morning_rainbow array.

    The device will not be of during morning, if there is not enough light n if the room is dark the morning colors will be displayed. 

  • RogerK's picture
    RogerK
    Dec 06, 2018

    I reviewed your comment and now it make sense.  Thank you for your explanation.

Log in or register to post Comment