AC diming



  • Any thoughts on this board? Looks interesting particularly the control of a large motor. It might make a good lamp or ceiling fan controller.

    Richard

    http://researchdesignlab.com/serial-3-channel-ac-230v-ssr-and-dimmer.html



  • @csa02221862 It can work with arduino mysensore?????



  • Yes, they show the diagram for the Arduino and the script on the site.





  • hi!

    after long searching and trying i managed to Build an 'MySensors' AC dimming node.
    I bought this:
    http://www.ebay.com/itm/4CH-AC-Dimmer-Module-Controller-Board-ARDUINO-RASPBERRY-Compatible-50-60Hz-/121752461158?ssPageName=ADME:X:RTQ:US:1123
    and i use it to control my lightning.

    regards, Thomas

    It was working for 1 dimmer but now im am updating the code for '4' dimmers but i am having trouble with understanding...
    this is the code so far:

    
    /*
    this is based on the sketch from Quocanhcgd 
    link: http://forum.mysensors.org/topic/1316/ac-dimmer-with-openhab
    
    Tested With Domoticz, working fine 220V 50Hz
    
    AC Light Control
    Uses up and down buttons to set levels
    makes use of a timer interrupt to set the level of dimming
    */
    #include <SPI.h>
    #include <MySensor.h>  
    #include <TimerOne.h>
    
    #define SN "AC Dimmer control"
    #define SV "1.0"
    #define NODE_ID 30  //change to a number to assign a specific ID
    #define FADE_DELAY 18  // Delay in ms for each percentage fade up/down (10ms = 1s full-range dim)
    #define FADE_PERCENTAGE 5 //The percentage the fade level will be changed when a button is pressed
    volatile int i=0;               // Variable to use as a counter of dimming steps. It is volatile since it is passed between interrupts
    volatile int j=0;  
    volatile int k=0;  
    volatile int l=0;  
    volatile boolean zero_cross=0;  // Flag to indicate we have crossed zero
    int AC_pin1 = 4;                 // Output to Opto Triac
    int AC_pin2 = 5;  
    int AC_pin3 = 6;  
    int AC_pin4 = 7;  
    
    int freqStep = 75;              // This is the delay-per-brightness step in microseconds. It allows for 128 steps
                                    // If using 60 Hz grid frequency set this to 65
    MySensor gw;
    //Tuy chinh lai
    static int currentLevel1 = 128;  // Current dim level...
    static int currentLevel2 = 128;  // Current dim level...
    static int currentLevel3 = 128;  // Current dim level...
    static int currentLevel4 = 128;  // Current dim level...
    
    uint8_t fadeLevel1 = 128; //used to store the fade level when using the buttons
    uint8_t fadeLevel2 = 128:
    uint8_t fadeLevel3 = 128;
    uint8_t fadeLevel4 = 128:
    
    MyMessage dimmer1Msg(AC_pin1, V_DIMMER);
    MyMessage light1Msg(AC_pin1, V_LIGHT);
    MyMessage dimmer2Msg(AC_pin2, V_DIMMER);
    MyMessage light2Msg(AC_pin2, V_LIGHT);
    MyMessage dimmer3Msg(AC_pin2, V_DIMMER);
    MyMessage light3Msg(AC_pin3, V_LIGHT);
    MyMessage dimmer4Msg(AC_pin4, V_DIMMER);
    MyMessage light4Msg(AC_pin4, V_LIGHT);
    
    void setup() {  // Begin setup
      Serial.begin(115200);
      /// - Setup Mysensors
      Serial.println( SN ); 
      gw.begin( incomingMessage,  NODE_ID, true);
      // Register the LED Dimmable Light with the gateway
        gw.present( AC_pin1, S_DIMMER );
        gw.present( AC_pin2, S_DIMMER );
        gw.present( AC_pin3, S_DIMMER );
        gw.present( AC_pin4, S_DIMMER );
         
      gw.sendSketchInfo(SN, SV);
      
      // Pull the gateway's current dim level - restore light level upon sendor node power-up
      gw.request( AC_pin1, V_DIMMER );
      gw.request( AC_pin2, V_DIMMER );
      gw.request( AC_pin3, V_DIMMER );
      gw.request( AC_pin4, V_DIMMER );
      
      //Setup AC PIN  // Set the Triac pin as output
       pinMode(AC_pin1, OUTPUT);  
       pinMode(AC_pin2, OUTPUT);
       pinMode(AC_pin3, OUTPUT);
       pinMode(AC_pin4, OUTPUT);
         
     // Set the Triac pin as output
     
      attachInterrupt(1, zero_cross_detect, RISING);    // Attach an Interupt to Pin 2 (interupt 0) for Zero Cross Detection
      Timer1.initialize(freqStep);                      // Initialize TimerOne library for the freq we need
      Timer1.attachInterrupt(dim_check, freqStep);      // Go to dim_check procedure every 75 uS (50Hz)  or 65 uS (60Hz)
      // Use the TimerOne Library to attach an interrupt
      
    }
    
    void zero_cross_detect() {    
      zero_cross = true;               // set flag for dim_check function that a zero cross has occured
      i=0;                             // stepcounter to 0.... as we start a new cycle
      digitalWrite(AC_pin1, LOW);
      digitalWrite(AC_pin2, LOW);
      digitalWrite(AC_pin3, LOW);
      digitalWrite(AC_pin4, LOW);
    }                                 
    
    // Turn on the TRIAC at the appropriate time
    // We arrive here every 75 (65) uS
    // First check if a flag has been set
    // Then check if the counter 'i' has reached the dimming level
    // if so.... switch on the TRIAC and reset the counter
    
    
    
    void dim_check1() {                   
      if(zero_cross == true) {              
        if(i>=fadeLevel1) {                     
          digitalWrite(AC_pin1, HIGH);  // turn on light       
          i=0;  // reset time step counter                         
          zero_cross=false;    // reset zero cross detection flag
        } 
        else {
          i++;  // increment time step counter                     
        }                                
      }    
    }
    
    void dim_check2() {                   
      if(zero_cross == true) {              
        if(j>=fadeLevel2) {                     
          digitalWrite(AC_pin2, HIGH);  // turn on light       
          j=0;  // reset time step counter                         
          zero_cross=false;    // reset zero cross detection flag
        } 
        else {
          j++;  // increment time step counter                     
        }                                
      }    
    }
    
    
    void dim_check3() {                   
      if(zero_cross == true) {              
        if(k>=fadeLevel3) {                     
          digitalWrite(AC_pin3, HIGH);  // turn on light       
          k=0;  // reset time step counter                         
          zero_cross=false;    // reset zero cross detection flag
        } 
        else {
          k++;  // increment time step counter                     
        }                                
      }    
    }
    
    void dim_check4() {                   
      if(zero_cross == true) {              
        if(l>=fadeLevel4) {                     
          digitalWrite(AC_pin4, HIGH);  // turn on light       
          l=0;  // reset time step counter                         
          zero_cross=false;    // reset zero cross detection flag
        } 
        else {
          l++;  // increment time step counter                     
        }                                
      }    
    }
    
                                
    
    void loop() {  
        gw.process();
    }
    
    void incomingMessage(const MyMessage &message) {
      if (message.type == V_LIGHT || message.type == V_DIMMER) {
        
        //  Retrieve the power or dim level from the incoming request message
        int requestedLevel = atoi( message.data );
        
        // Adjust incoming level if this is a V_LIGHT variable update [0 == off, 1 == on]
        requestedLevel *= ( message.type == V_LIGHT ? 100 : 1 );
        
        // Clip incoming level to valid range of 0 to 100
        requestedLevel = requestedLevel > 100 ? 100 : requestedLevel;
        requestedLevel = requestedLevel < 0   ? 0   : requestedLevel;
        
       
        float percent_level;
        percent_level = 128 - (requestedLevel * 1.28);
        fadeToLevel( percent_level );
         Serial.print( "Changing level to " );
        Serial.print( requestedLevel );
        Serial.print( ", from " ); 
        Serial.println( currentLevel );
        // Inform the gateway of the current DimmableLED's SwitchPower1 and LoadLevelStatus value...
       //  gw.send(lightMsg.set(currentLevel > 0 ? 1 : 0));
         // gw.send( dimmerMsg.set(currentLevel) );
          }
    }
    
    /***
     *  This method provides a graceful fade up/down effect
     */
    void fadeToLevel( int toLevel ) {
      Serial.print("toLevel Value: ");
     Serial.println(toLevel);
      
      int delta = ( currentLevel - toLevel ) < 0 ? 1 : -1;
      Serial.print("delta Value: ");
     Serial.println(delta);
      while ( currentLevel != toLevel ) {
        currentLevel += delta;
    
     fadeLevel= ((int)currentLevel);
        delay( FADE_DELAY );
    
      }
      
    }
    
    
    

    I have trouble understanding this part:
    void incomingMessage(const MyMessage &message) {
    if (message.type == V_LIGHT || message.type == V_DIMMER)

    all 4 dimmers are type V_LIGHT and V_DIMMER
    how do i get the right dimmer value from the controller from each different dimmer?

    someone who can help me with the rest of the code?

    thanks!


  • Hero Member

    @thomasdc , as simple as

     // Channel Number
      int i = message.sensor;


  • @rvendrame said:

    @thomasdc , as simple as

     // Channel Number
      int i = message.sensor;
    

    Thank you very much for the reply!
    can you expain it a litle more?

    so i have 4 dimmers:

    MyMessage dimmer1Msg(AC_pin1, V_DIMMER);
    MyMessage light1Msg(AC_pin1, V_LIGHT);
    MyMessage dimmer2Msg(AC_pin2, V_DIMMER);
    MyMessage light2Msg(AC_pin2, V_LIGHT);
    MyMessage dimmer3Msg(AC_pin2, V_DIMMER);
    MyMessage light3Msg(AC_pin3, V_LIGHT);
    MyMessage dimmer4Msg(AC_pin4, V_DIMMER);
    MyMessage light4Msg(AC_pin4, V_LIGHT);
    

    how do i get the vallue for each dimmer?
    so how do i get an 'int i' for channel one, an 'int j' for channel two, and so on ?
    where do i put the code? is it just behind the:

    void incomingMessage(const MyMessage &message) {
      if (message.type == V_LIGHT || message.type == V_DIMMER) {
    

    ? do i have to change something in the 'void incomming message' (see above)

    big thanks!


  • Hero Member



  • @korttoma said:

    My RGBW sketch is basically 4 dimmers also, take a look in this thread:

    http://forum.mysensors.org/topic/1939/scripting-scenes-for-rgb-strip-best-way-to-control-mysensors-rgbw-node-from-vera/6

    thanks for the reply!

    I dont really get your code... you receive a byte from the controller? / you use a 'mode' to set your dimmers? my dimmers are 4 induvidual dimmers and dont have to work together ..



  • Another way to go is to use something like this and just convert everything to 12/24v dc. You can upgrade your lighting as you go and much easier and safer than AC dimming. If coarse there is still the ceiling fan to deal with. I will probably do that with an IR blaster.





  • but anyway how to get the different dimmer value's from the controller stays the same 😉 and i am still troubling on that :s


  • Hero Member

    Just ignor the mode related code, you probably dont need that. I allso have 4 individual dimmers they just happen to be connected to a RGBW Led strip. Same same but different.


  • Hero Member

    Simplified the sketch code a bit. Here is an example how you can control 4 individual dimmers:

    // Example sketch showing how to control RGBW LED Strip.
    
    //IMPORTANTE NOTE!!! one of the "radio" pins has been moved from pin 9 to pin 4 because the White is connected to pin 9 because only 3,5,6 and 9 are PWM outputs!!!!
    
    // This code should generate 4 Dimmer devices in Vera so you can control the RED, GREEN, BLUE and WHITE individualy
    
    #define SN "RGBW"
    #define SV "1.2"
    
    #include <MySensor.h>
    #include <SPI.h>
    
    
    #define NODE_ID AUTO
    
    #define RED       3 // pin for red LED
    #define GREEN     5 // pin for green 
    #define BLUE      6 // pin for blue
    #define WHITE     9 // pin for white 
    
    #define RF24_CE_PIN		4	//<-- NOTE!!! (4,10) and NOT (9,10)
    #define RF24_CS_PIN		10
    #define RF24_PA_LEVEL	RF24_PA_MAX
    
    MyTransportNRF24 transport(RF24_CE_PIN, RF24_CS_PIN, RF24_PA_LEVEL);
    
    MySensor gw(transport);
    
    void setup()
    {
    	
    	gw.begin(setDimmerStatus, NODE_ID);
    	
    	// Send the Sketch Version Information to the Gateway
    	gw.sendSketchInfo(SN, SV);
    	// Register all sensors to gw (they will be created as child devices)
    	gw.present(RED, S_DIMMER);
    	gw.present(GREEN, S_DIMMER);
    	gw.present(BLUE, S_DIMMER);
    	gw.present(WHITE, S_DIMMER);
    
    
    	pinMode(RED, OUTPUT);
    	pinMode(GREEN, OUTPUT);
    	pinMode(BLUE, OUTPUT);
    	pinMode(WHITE, OUTPUT);
    	
    	
    
    	//Get values from RAM and write to outputs
    	analogWrite(RED, 255 * gw.loadState(RED) / 100);
    	analogWrite(GREEN, 255 * gw.loadState(GREEN) / 100);
    	analogWrite(BLUE, 255 * gw.loadState(BLUE) / 100);
    	analogWrite(WHITE, 255 * gw.loadState(WHITE) / 100);
    
    }
    
    void loop()
    {
    	gw.process();
    	
    	
    }
    
    void setDimmerStatus(const MyMessage &message)
    {
    		
    	if (message.type == V_DIMMER)
    	{
    		uint8_t incomingDimmerStatus = message.getByte();
    
    		analogWrite(message.sensor, 255 * incomingDimmerStatus / 100);
    		gw.saveState(message.sensor, message.getByte()); //Save value to RAM
    
    	}
    		
    }```

  • Hardware Contributor

    Today I played with my AC dimmer
    http://forum.mysensors.org/topic/1316/ac-dimmer-with-openhab/3

    It is very similar to the one reference above (but maybe a little bit cheaper 🙂 ).

    Good news: it is working fine with normal light bulbs and halogen tubes.

    Bad news: it doesn't work with the high voltage LED tubes I testetd.

    Has anybody a recommendation for a dimmable LED tube (E27/E17 230 V) working with the setup from this thread?


  • Hero Member

    @FotoFieber , I use some 230V dimmable leds that I bought from IKEA in Germany about 1 year ago and and they work good. Some are Philips and some are IKEA-branded.
    Most important is the 'dimmable' word on them. Most of current led drivers are not designed for AC dimming, as this increase the unit costs (usually the driver is more expensive than the leds itself)...


Log in to reply
 

Suggested Topics

  • 8
  • 90
  • 44
  • 1
  • 5
  • 7

0
Online

11.4k
Users

11.1k
Topics

112.7k
Posts