Completed Arduino based IR Module and lightbulb

Completed Arduino based IR Module and lightbulb

Here at Jaycon we are always trying to be more efficient, organized and better overall. We came up with a system that will require us to constantly keep track of time. To make life easier for everyone in the office, we came up with  a device that will display different colors that will represent different time slots for us here at Jaycon.

We have an RGB light bulb that would normally receive a signal from an Infra Red (IR) remote control. We will be using the Arduino to send a specific color signal depending on the time. We are going to plug this somewhere in the office away from computers, this is we have to keep track of time without using their clock.

For this tutorial, we are going to be doing some cool stuff with IR, LED, RTC and some other things. Are you ready ?

The idea behind this is for the LED bulb to display 3 different colors (Red, Green,Yellow). These colors will indicate different designated times for Jaycon’s team inside the office.  

 Jaycon’s 3 different color states

Jaycon’s 3 different color states

There are two essential components of this project, the RTC (Real Time Clock) and the IR Led.

Real time clock with battery and IR LED

Real time clock with battery and IR LED

We want the device to be placed somewhere where everyone can see it. That is why we cannot depend on a computer's clock to retrieve time. The benefit of using a Real Time Clock module is that it includes an independent battery that will run even if the Arduino is not powered on. This clock will indicate the times in which the color has to change. The color changing  is done by the IR LED.

IR LED and Remote

IR LED and Remote

If you have looked closely at some remote controls, like the one for your tv or sound system, you would probably have noticed a small LED bulb at the front of it. This is an Infra Red LED that will send a specific signal at a special frequency that the device will recognize. We are doing exactly that just that we are using an Arduino to be able to manipulate which signal to send.

Ok let’s get started, now we’ll see what we need to build this and how exactly we are going to do it. Excited?

Materials for project

Materials for project

Hardware  

1 x Arduino or any microcontroller you prefer

1 x RTC Module

1 x 220 Ohm resistor

1 x Piezo buzzer

1 x IR LED

1 x Breadboard

Wires and cables

OPTIONAL

1 x Proto Shield

1 x transceiver module

1 x RGB Light Bulb

Wiring and connections

Testing circuit

Testing circuit

First, we created a prototype that was used to test the IR LED and the RTC time. To send a signal we just need a LED, a transceiver module is not required. However, If you wanted to also receive a signal with an Arduino you would have to implement a transceiver. I used a transceiver to be able to map the buttons on my remote control so that I can send the same signal with the Arduino.

The following diagram will show the connections to only send signals, without the transceiver. It also includes a buzzer and the RTC.

Circuit Diagram

Circuit Diagram

The Arduino will be connected to the RTC using SDA & SCL serial communication. Two digital pins will be connected to the resistor, led and to the piezo buzzer. That is basically all the wiring we need. Remember you can use any pin in your microcontroller as long as it is an appropriate digital/serial pin.  Not that complicated right? Here is also a breadboard view of the connections just in case you are having some trouble with the diagram.

Circuit Illustration

Circuit Illustration

With the wires done properly and the code uploaded, you should be ready to go. With the programming I’ve done the board will send a signal that will turn on the device at 8:00 am. At 8:05 a signal will be sent that will turn the LED to yellow. At 9:00 the LED will be changing the color to GREEN and at 9:30 RED. We followed a pre-established schedule for the color changing.

Everything was working properly, but we wanted to have it all compact and organized without any wires exposed. We used one of the proto shields available at Jaycon to create a custom shield for our Arduino.

Proto Shield

Proto Shield

This shield now includes everything needed for our project. To be able to do this you might need some soldering skills and a soldering iron. This is why we have included this step as optional. Building the shield really improves the size, appearance, and reliability of the overall project.

Proto Shield in Arduino

Proto Shield in Arduino

Programming (ง°ل͜°)ง

Connect the Arduino to the computer, using the A to B USB cable and open the Arduino IDE software.

Go to Tools > Serial Port and make sure you have selected the proper serial port.  (Ex. COM3)

Go to Tools > Board and make sure you have selected the Arduino UNO or any Arduino board you are using.

Now it's time to enter the code: You can copy the code I've developed below (feel free to play with and edit this code). If you prefer, go ahead and enter your own code. We acknowledge that there are several ways to achieve results with this project. If you have any suggestions or ideas please let us know in the comment section below. 

 

//www.jayconsystems.com  
//www.jayconsystems.com
//We need to include these libraries to be able to use the RTC and the IR functions
#include 
#include 
#include "RTClib.h"
IRsend irsend;
//define the pin for the Piezo Buzzer, you can use any pin as long as it's a Digital Pin  
int speakerPin =4;
//RTC_Millis RTC;
RTC_MCP79401 RTC;                                // Instantiate the RTC module as a MCP79401
void setup () {
//    Wire.begin();                                  // Starts the I2C bus   
//    Serial.begin(57600);
//    // following line sets the RTC to the date & time this sketch was compiled
//    RTC.begin(DateTime(__DATE__, __TIME__));
pinMode(speakerPin, OUTPUT); // declare the motor Pin as an OUTPUT:
Wire.begin();                                  // Starts the I2C bus   
Serial.begin(9600);                            // Starts the Serial module
  RTC.begin();    
  RTC.calibrate(0b00000000);                     // Reset calibration (refer to the MCP79401 datasheet for more info)
  //RTC.adjust(DateTime(__DATE__, __TIME__, 6));   // Initializes RTC time with computer time and day of the week (1-7)
  // the previous line should be uncommented then loaded -> then commented and loaded
  //this to set the proper time and date for RTC to work properly
    RTC.batteryEnable();                           // Enables the RTC to run on battery if VCC is disconnected
}
void loop() {
//we will start the loop to send the signals to the LED and print the date in the serial monitor
        DateTime now = RTC.now();
 //For monitoring purposes we will be printing the date and the time that the RTC clock is reading
    Serial.print(now.year(), DEC);
    Serial.print('/');
    Serial.print(now.month(), DEC);
    Serial.print('/');
    Serial.print(now.day(), DEC);
    Serial.print(' ');
    Serial.print(now.hour(), DEC);
    Serial.print(':');
    Serial.print(now.minute(), DEC);
    Serial.print(':');
    Serial.print(now.second(), DEC);
    Serial.println();


 //we sill start here our if statements for the comparison between the date and the times we want the alarm to be set 


 //we realize that this is not the most efficient way to write the comparison statements but with this way the user can see better the progress of the time and why the alarms 
 //At this point the LED is off so we will send a singal to turn it ON
 if (now.hour() == 8 && now.minute()== 0){    
    irsend.sendNEC(0xFFE01F,32); //ON
  //when 5 seconds have passed we are outputting a sound trough the buffer so we can also hear the change
   if (now.second() == 5){ beepsound();}
  Serial.println("ON");          
        }
   else if (now.hour() ==8 && now.minute()==5){
      irsend.sendNEC(0xFF8877,32); //Yellow
      Serial.print("YELLOW");  
        } 
        //If it's 9 we will turn it green
     else if (now.hour() == 9 && now.minute()== 0){
      if (now.second() == 5){ beepsound();}
      irsend.sendNEC(0xFF10EF,32); //GREEN
      Serial.print("GREEN");  
        }
        //If it's 9:30 then we will send a RED signal
        //the pattern repeats but we are changing the hours
      else if (now.hour() == 9 && now.minute()== 30){
        if (now.second() == 5){ beepsound();}
        irsend.sendNEC(0xFF906F,32); //RED    
        }
        else if (now.hour() == 10 && now.minute()== 30){
          if (now.second() == 5){ beepsound();}  
          irsend.sendNEC(0xFF10EF,32); //GREEN
          Serial.print("GREEN");    
          }
          else if (now.hour() == 11 && now.minute()== 0){
            if (now.second() == 5){ beepsound();}
            irsend.sendNEC(0xFF906F,32); //RED     
            }
            else if (now.hour() == 12 && now.minute()== 0){
              if (now.second() == 5){ beepsound();}
              irsend.sendNEC(0xFF10EF,32); //GREEN    
              }
              else if (now.hour() == 12 && now.minute()== 30){
                if (now.second() == 5){ beepsound();}
                irsend.sendNEC(0xFF906F,32); //RED    
                }
                else if (now.hour() == 13 && now.minute()== 30){
                  if (now.second() == 5){ beepsound();}
                  irsend.sendNEC(0xFF10EF,32); //GREEN     
                  }
                  else if (now.hour() == 14 && now.minute()== 0){
                    if (now.second() == 5){ beepsound();}
                    irsend.sendNEC(0xFF906F,32); //RED    
                    }
                    else if (now.hour() == 15 && now.minute()== 0){
                      if (now.second() == 5){ beepsound();}
                      Serial.println("Sending GREEN");
                      irsend.sendNEC(0xFF10EF,32); //GREEN    
                      }
                      else if (now.hour() == 15 && now.minute()== 30){
                        if (now.second() == 5){ beepsound();}
                        Serial.println("Sending RED");
                        irsend.sendNEC(0xFF906F,32); //RED     
                        }
                        else if (now.hour() == 16 && now.minute()== 30){
                          if (now.second() == 5){ beepsound();}
                          irsend.sendNEC(0xFF10EF,32); //GREEN    
                          }
                          else if (now.hour() == 17 && now.minute()== 0){
                            if (now.second() == 5){ beepsound();}
                            irsend.sendNEC(0xFF8877,32); //yellow
                            }
                              else if (now.hour() == 17 && now.minute()== 30){
                                if (now.second() == 5){ beepsound();}
                              irsend.sendNEC(0xFF609F,32); //OFF     
                              }
}
//SOME OTHER COLORS & FUNCTIONS
//0xFF18E7 lightblue
//0xFFD827 violet
//0xFF8877 yellow 
//0xFFD827 fade between colors
//0xFFE01F ON
//0xFF609F OFF
//0xFF906F RED
//0xFF10EF GREEN
//www.jayconsystems.com

 

Notes about the project

When sending signals you always have to be aware of noise and interference. If you are sending two different signals you have to wait at least a couple of seconds before sending the second one. This is the reason why I have waited 5 minutes to send a color signal after turning it ON. This means that there has to be a gap in between 2 different signals where there is no signal sent.