octowide
Published © GPL3+

Arduino Digital Light - Octowide

A cool way to build an Arduino warm/ cool white lamp, based on the Octowide Digital Light.

IntermediateShowcase (no instructions)1,825
Arduino Digital Light - Octowide

Things used in this project

Hardware components

Arduino UNO & Genuino UNO
Arduino UNO & Genuino UNO
×1
12V Power Supply - to power the Octowide Light modules
×1
Keyes KY-022
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Octowide Digital Light - 2 Warm x 2 Cold

Circuit Diagram to build the 2x2 Octowide Light project

Code

Octowide Digital Light - 2 Warm x 2 Cold

C/C++
With this code you will be able to control 2 sets of octowide light with an infrared remote controller - tweaking the brightness, color temperature and fade speed.
/* octowide.com Example
 2 Warm White Octowide x 2 Cold White Octowide Light 3W modules Demo
 info@octowide.com
 Get Library at: https://github.com/shirriff/Arduino-IRremote
 Unzip folder into Libraries. RENAME folder IRremote
*/

/*-----( Import needed libraries )-----*/

/* Get Library at: https://github.com/shirriff/Arduino-IRremote
 Unzip folder into Libraries. RENAME folder IRremote
 NOTE!! If you have a late version of Arduino with a library IRRobotRemote, it may conflict and you may have to remove that library.
 Make sure to delete Arduino_Root/libraries/RobotIRremote.
 Where Arduino_Root refers to the install directory of Arduino. The library RobotIRremote has similar definitions to IRremote and causes errors.
 */
#include "IRremote.h"

/*-----( Declare Constants )-----*/
const int ir_receiver = 12;                   // pin 1 of IR receiver to Arduino digital pin 12

/*-----( Declare objects )-----*/
IRrecv irrecv(ir_receiver);                   // create instance of 'irrecv'
decode_results results;                       // create instance of 'decode_results'

/*-----( Declare Variables )-----*/
int Warm_White_Level = 0;                     // brightness level of Octowide Warm White (0 - 255)
int New_Warm_White_Level = 0;                 // new brightness level of Octowide Warm White (0 - 255)
int Cold_White_Level = 0;                     // brightness level of Octowide Cold White (0 - 255)
int New_Cold_White_Level = 0;                 // new brightness level of Octowide Cold White (0 - 255)
int Step = 1;                                 // brightness update step - 1 for the slowest transition to 255 for immediate transition
enum channel
{
  WARM_WHITE = 9,                             // Arduino Digital pin 9 connected to Octowide (Warm White) Signal pin
  COLD_WHITE = 10                             // Arduino Digital pin 10 connected to Octowide (Cold White) Signal pin
};
enum channel channel_selected = WARM_WHITE;   // Default Channel selected

void setup()   /*----( SETUP: RUNS ONCE )----*/
{
  analogWrite(WARM_WHITE, Warm_White_Level);  // Set initial Warm White Level
  analogWrite(COLD_WHITE, Cold_White_Level);  // Set initial Cold White Level
  Serial.begin(9600);
  Serial.println("Octowide 2 Warm x 2 Cold Demo");
  Serial.println("More Info: info@octowide.com");  
  irrecv.enableIRIn(); // Start the infrared receiver
}

void loop()   /*----( LOOP: RUNS CONSTANTLY )----*/
{
  static int cnt = 0;
  
  if (cnt++ == 5) // Check for a new IR once each 50ms
  {
    if (irrecv.decode(&results)) // have we received an IR signal?
    {
      translateIR(); 
      irrecv.resume(); // receive the next value
    }
    cnt = 0;
  }

  // Update Warm White Channel (if needed)
  if (Warm_White_Level != New_Warm_White_Level)
    update_level(WARM_WHITE, Warm_White_Level, New_Warm_White_Level);

  // Update Cold White Channel (if needed)
  if (Cold_White_Level != New_Cold_White_Level)
    update_level(COLD_WHITE, Cold_White_Level, New_Cold_White_Level);
 
  delay(10); // Wait a bit
}

/*-----( Declare User-written Functions )-----*/

/* Low level brightness update function */
void update_level(enum channel ch, int &level, int &new_level)
{
  if (level < new_level)
  {
    level += Step;
    if (level > new_level)
      level = new_level;
  } else {
    level -= Step;
    if (level < new_level)
      level = new_level;
  }
  analogWrite(ch, level);
}

/* Function stating what to do when receiving an IR code
 * 1   - Warm White channel selected
 * 2   - Cold White channel selected
 * UP  - increase brightness by aprox. 20% (on the channel selected)
 * DWN - decrease brightness by aprox. 20% (on the channel selected)
 * 0   - Fade down both channels
 * 4   - Max Brightness Warm White channel
 * 5   - Max Brightness Both channels
 * 6   - Max Brightness Cold White channel
 * 7   - Slow Fade (transition)
 * 8   - Fast Fade (transition)
 * 9   - No Fade
 * Code received / action taken sent by serial port
 */
void translateIR() // takes action based on IR code received

// describing KEYES Remote IR codes 
{
  int level;
  
  switch(results.value)
  {
    case 0xFF6897: Serial.println("WARM WHITE channel selected");
      channel_selected = WARM_WHITE;
      break;
    
    case 0xFF9867: Serial.println("COLD WHITE channel selected");
      channel_selected = COLD_WHITE;
      break;
    
    case 0xFF629D: Serial.println("UP 20%");
      if (channel_selected == WARM_WHITE)
        fade_channels(Warm_White_Level + 51, Cold_White_Level);
      else fade_channels(Warm_White_Level, Cold_White_Level + 51);
      break;
      
    case 0xFFA857: Serial.println("DOWN 20%");
      if (channel_selected == WARM_WHITE)
        fade_channels(Warm_White_Level - 51, Cold_White_Level);
      else fade_channels(Warm_White_Level, Cold_White_Level - 51);
      break;
      
    case 0xFF4AB5: Serial.println("Fade DOWN");
      fade_channels(0, 0);
      break;
      
    case 0xFF30CF: Serial.println("MAX Warm White");
         fade_channels(255, 0);
         break;
         
    case 0xFF18E7: Serial.println("MAX Both channels");
         fade_channels(255, 255);
         break;
    case 0xFF7A85: Serial.println("MAX Cold White");
         fade_channels(0,   255);
         break;

    case 0xFF10EF: Serial.println("SLOW fade");
         Step = 1;
         break;
         
    case 0xFF38C7: Serial.println("FAST fade");
         Step = 4;
         break;
         
    case 0xFF5AA5: Serial.println("NO fade");
         Step = 255;
         break;
  }
}

/* Update global new brightness values to start fading
 * Serial print of start and new brightness for each channel
 */
void fade_channels(int new_warm_level, int new_cold_level)
{
  char buf[32];

  // Sanitize both levels
  New_Warm_White_Level = sanitize_level(new_warm_level);
  New_Cold_White_Level = sanitize_level(new_cold_level);
    
  sprintf(buf, "WARM %3d > %3d | COLD %3d > %3d", Warm_White_Level, New_Warm_White_Level, Cold_White_Level, New_Cold_White_Level);
  Serial.println(buf);
}

/* Check the boundaries - max / min allowable brightness levels */
int sanitize_level(int level)
{
  if (level > 255)
    return 255;
  else if (level < 0)
    return 0;
  return level;
}
/* ( THE END ) */

Credits

octowide

octowide

1 project • 3 followers
Thanks to Pedro Júlio Pereira.

Comments