IR Switch for Luminara Candle Automation (repost with video, photos and final sketch)
-
@korttoma - sorry you missed the video ;) I have it on my to-do list to draw a proper schematic for the IR blaster board and the actuator but I just haven't had time yet. I would like to post one in this thread to make it easier for people to build their own IR actuator. Maybe you will get there first ;)
-
Hello @blacey , I got a question... If I'm going to add another IR into the sketch, how do I go about doing this? So two independent sensors into one. This is what I have done so far. Correct me if I'm wrong. Should I be changing something in IRsend irsend ....?
And is your IR LED connected to Pin 1 or Pin3?
/*** * Binary IR Switch sketch that controls Luminara Candles * * Sketch inspired by, and a derivative work of, Hek's IR Sensor example sketch */ #include <MySensor.h> #include <SPI.h> #include <IRLib.h> int RECV_PIN = 8; #define CHILD1 3 // Arduino Pin 3 #define CHILD2 4 // Arduino Pin 4 MySensor gw; MyMessage switchMsg1(CHILD1, V_VAR1); MyMessage switchMsg2(CHILD2, V_VAR1); // IR LED must be connexted to Arduino PWM pin 3 IRsend irsend; #define switchOnIRcode 0x00ff629d // Luminara On IR code #define switchOffIRcode 0x00ffa857 // Luminara Off IR code void setup() { gw.begin(incomingMessage); // Send the sketch version information to the gateway and Controller gw.sendSketchInfo("IR Switch", "1.0"); // Register a sensors to gw. Use binary light for test purposes. gw.present(CHILD1, S_LIGHT); gw.present(CHILD2, S_LIGHT); // Sync switch state to gateway state upon reset / power-up gw.request(CHILD1, V_LIGHT); gw.request(CHILD2, V_LIGHT); } void loop() { gw.process(); } void incomingMessage(const MyMessage &message) { // We only expect one type of message from controller. But we better check anyway. if (message.type==V_LIGHT) { int incomingRelayStatus = message.getInt(); // Emit the IR ON/OFF code irsend.send(NEC, (incomingRelayStatus == 1 ? switchOnIRcode : switchOffIRcode), 32); // Sync gateway of the light switch state gw.send(switchMsg1.set(incomingRelayStatus)); gw.send(switchMsg2.set(incomingRelayStatus)); } } -
Hello @blacey , I got a question... If I'm going to add another IR into the sketch, how do I go about doing this? So two independent sensors into one. This is what I have done so far. Correct me if I'm wrong. Should I be changing something in IRsend irsend ....?
And is your IR LED connected to Pin 1 or Pin3?
/*** * Binary IR Switch sketch that controls Luminara Candles * * Sketch inspired by, and a derivative work of, Hek's IR Sensor example sketch */ #include <MySensor.h> #include <SPI.h> #include <IRLib.h> int RECV_PIN = 8; #define CHILD1 3 // Arduino Pin 3 #define CHILD2 4 // Arduino Pin 4 MySensor gw; MyMessage switchMsg1(CHILD1, V_VAR1); MyMessage switchMsg2(CHILD2, V_VAR1); // IR LED must be connexted to Arduino PWM pin 3 IRsend irsend; #define switchOnIRcode 0x00ff629d // Luminara On IR code #define switchOffIRcode 0x00ffa857 // Luminara Off IR code void setup() { gw.begin(incomingMessage); // Send the sketch version information to the gateway and Controller gw.sendSketchInfo("IR Switch", "1.0"); // Register a sensors to gw. Use binary light for test purposes. gw.present(CHILD1, S_LIGHT); gw.present(CHILD2, S_LIGHT); // Sync switch state to gateway state upon reset / power-up gw.request(CHILD1, V_LIGHT); gw.request(CHILD2, V_LIGHT); } void loop() { gw.process(); } void incomingMessage(const MyMessage &message) { // We only expect one type of message from controller. But we better check anyway. if (message.type==V_LIGHT) { int incomingRelayStatus = message.getInt(); // Emit the IR ON/OFF code irsend.send(NEC, (incomingRelayStatus == 1 ? switchOnIRcode : switchOffIRcode), 32); // Sync gateway of the light switch state gw.send(switchMsg1.set(incomingRelayStatus)); gw.send(switchMsg2.set(incomingRelayStatus)); } }@jeylites My IR LEDs are connected to Pin 3 because that is what IR Lib requires. Your sketch looks close but you will need to define separate switchOnIRcode and switchOffIRcode codes for your respective lights. Then in the incomingMessage loop, send the appropriate code based upon the child ID. If you plan to have a large number of child IDs, I would create an array indexed by child ID to hold the on/off IR codes and then simply invoke ir.send() passing the onOffCode[childID] to it. Does that make sense?
Also, I just started another thread for an official IR Blaster board that you might want to review. I plan to provide multiple device support out of the box...
-
-
@blacey I think I get what you're saying on #define but don't know how to associate child id with ir code. Do you have a sample or something ?
IR blaster - you working on looks great. Next project is to use that to control my AV system.
Thank you!
@jeylites Here is a quick and dirty example for two switch IR devices... Hope this helps you get started. I will give multi-device more thoughts/elegance for the final IR Blaster.
#include <MySensor.h> #include <SPI.h> #include <IRLib.h> #define NumChildDevices 2 typedef struct IRCode { IRTYPES brand; unsigned long on; unsigned long off; unsigned int bits; } ir; ir childIR[NumChildDevices]; IRsend iremitter; MySensor gw; MyMessage child1Msg(1, V_VAR1); MyMessage child2Msg(2, V_VAR2); void setup() { gw.begin(); gw.sendSketchInfo("Multi IR", "0.1"); // Initialize children devices // 1. Candles (Switch) gw.present(1, S_LIGHT); childIR[1] = {NEC, 0x00ff629d, 0x00ffa857, 32}; // 2. TV gw.present(2, S_LIGHT); childIR[2] = {SONY, 0x0062ff8d, 0x00aff578, 32}; } void loop() { gw.process(); } void incomingMessage(const MyMessage &message) { //Determine the child device uint8_t child = message.sensor; //Get the relay status for the child device int incomingRelayStatus = message.getInt(); //Emit the appropriate IR code to the child device iremitter.send( childIR[child].brand, incomingRelayStatus == 1 ? childIR[child].on : childIR[child].off, childIR[child].bits); } -
I just wanted to confirm that the cheep ebay Luminara "style" candles does work with blaceys sketch "out of the box".
-
@tbowmo said:
Hmm by cheap, I thought it was below 15$ :)
They are cheep compared to the Genuine Luminara products + I could not find a good suppler for the real thing sending to Europe
Maybe the once @betonishard mentioned earlier in the thread would be something more in your prize range? Would be nice to know if they also work with blaceys sketch though.
-
@korttoma, didn't had time to make the ir blaster yet. So quite frankly I don't know. I am using the remote delivered in the package. It still works by the way, which was surprising for that price. The flicker of the candles is kind of fast, like there is a firm wind in my livingroom.
-
Wow this is an old topic!
But... I was working on a project and thought that anyone who was looking for a NeoPixel candle example that isn't blocking, well this would be the place. It flickers and flutters like a real candle. The only thing is that the flame isn't illuminated like these nice Luminaras, but I'm too cheap to buy them!
Keep in mind that my example here uses GRB LEDs, but you merely need to reorder the variables in order to get this working for RGB. Plus the Time Library is not Arduino, so you will have to play with that too for a good
randomSeed().It looks pretty realistic with even a single neoPixel in a sheet of A4 paper rolled into a cylinder. I'll post a video when I can.
Have fun with it:
#include "neopixel.h" enum CandleStates{ BURN_CANDLE, FLICKER_CANDLE, FLUTTER_CANDLE, MODES_MAX_CANDLE }; enum PixelSelect{ EVERY_PIXEL, SINGLE_PIXEL, }; class Candle : public Adafruit_NeoPixel { public: Candle(uint16_t count, uint8_t pin, uint8_t type); Candle(uint16_t count, uint8_t pin, uint8_t type, PixelSelect pixel, uint32_t pixNum = 0); ~Candle(){}; void update(); private: bool fire(uint8_t greenDropValue, uint32_t cycleTime); PixelSelect _pixelMode = EVERY_PIXEL; uint32_t _pixNum = 0; CandleStates _mode; uint32_t _lastModeChange; uint32_t _modeDuration; uint8_t _redPx = 255; uint8_t _bluePx = 10; //10 for 5v, 15 for 3.3v uint8_t _grnHigh = 100; //110-120 for 5v, 135 for 3.3v uint8_t _grnPx = 100; uint32_t _lastBurnUpdate = 0; int _direction = 1; }; Candle::Candle(uint16_t count, uint8_t pin, uint8_t type) : Adafruit_NeoPixel(count, pin, type) { randomSeed(Time.now() + micros()); _mode = BURN_CANDLE; } Candle::Candle(uint16_t count, uint8_t pin, uint8_t type, PixelSelect pixel, uint32_t pixNum) : Adafruit_NeoPixel(count, pin, type) { _pixelMode = pixel; _pixNum = pixNum; } void Candle::update() { if(millis() - _lastModeChange > _modeDuration) { _mode = static_cast<CandleStates>(random(MODES_MAX_CANDLE)); _modeDuration = random(1000, 8000); _lastModeChange = millis(); //Serial.printlnf("New state: %d\tTime: %d", static_cast<int>(_mode), _modeDuration); } switch(_mode) { case BURN_CANDLE: this->fire(10, 120); break; case FLICKER_CANDLE: this->fire(15, 120); break; case FLUTTER_CANDLE: this->fire(30, 120); break; }; } bool Candle::fire(uint8_t greenDropValue, uint32_t cycleTime) { int currentMillis = millis(); if(currentMillis - _lastBurnUpdate > (cycleTime / greenDropValue / 2)) { _grnPx = constrain(_grnPx += _direction, _grnHigh - greenDropValue, _grnHigh); if(_grnPx == _grnHigh - greenDropValue or _grnPx == _grnHigh) { _direction *= -1; } switch (_pixelMode) { case EVERY_PIXEL: for(int i = 0; i < this->numPixels(); i++) { this->setPixelColor(i, _grnPx, _redPx, _bluePx); } break; case SINGLE_PIXEL: this->setPixelColor(_pixNum, _grnPx, _redPx, _bluePx); break; } this->show(); _lastBurnUpdate = currentMillis; } } #define PIXEL_COUNT 2 #define PIXEL_PIN D2 #define PIXEL_TYPE WS2812B // I'M USING GRB WS2821B's here Candle candle = Candle(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE, SINGLE_PIXEL); void setup(void) { Serial.begin(115200); pinMode(13, OUTPUT); candle.begin(); candle.show(); Serial.println("Started program"); } void loop(void) { candle.update(); static uint32_t lastFlashMillis = 0; if(millis() - lastFlashMillis > 250) { digitalWrite(13, !digitalRead(13)); lastFlashMillis = millis(); } }