Site icon AranaCorp

Using an AC Dimmer with ESP8266

4.4
(13)

The AC voltage variator is a module that allows to vary the power of an alternating current. It has the same use as a transistor in direct current. It can be used to vary the brightness of a lamp supplied with 220V or to vary the speed of a fan, for example. We will see how to manage the AC voltage dimmer with a NodeMCU ESP8266.

Material

Principle of operation

The AC dimmer consists of a triac (equivalent to a DC transistor) and a phase zero crossing detector to synchronize the voltage variation and the phase of the AC current.

Scheme

As far as the wiring diagram is concerned, the module is connected to the mains via the AC-IN terminal block and the bulb is connected to the LOAD terminal block. On the electronic side, the pins are connected as follows:

If you use several drives, the Z-C pins are all connected to the same microcontroller pin (in our case D1). The RBDdimmer library uses some pins in particular, depending on the microcontroller used. Please check the documentation of the library to see which pins you can use.

Caution: When using a NodeMCU, there are different versions of these cards with different pinouts and labels that can sometimes have errors. Ask your supplier and check the documentation of your card.

Code

Before programming your NodeMCU ESP8266, make sure that the board manager is installed on the Arduino IDE. To configure the IDE, you can follow this tutorial.

To use the AC Light Dimmer module, we use the RBDdimmer.h. library. The library will manage the synchronization between the PWM signal, which sets the power, and the phase of the AC current. Once the library has been imported and the module initialized, we only have to choose the power level between 0 and 100%.

Before uploading the code, you need to install the RBDdimmer library.

//Libraries
#include <RBDdimmer.h>//https://github.com/RobotDynOfficial/RBDDimmer

//Parameters
const int zeroCrossPin  = D1;
const int acdPin  = D2;
int MIN_POWER  = 0;
int MAX_POWER  = 80;
int POWER_STEP  = 2;

//Variables
int power  = 0;

//Objects
dimmerLamp acd(acdPin,zeroCrossPin);

void setup(){
//Init Serial USB
Serial.begin(115200);
Serial.println(F("ESP8266 System"));
acd.begin(NORMAL_MODE, ON);
}

void loop(){
  testDimmer();
}

void testDimmer(){/* function testDimmer */ 
////Sweep light power to test dimmer
  for(power=MIN_POWER;power<=MAX_POWER;power+=POWER_STEP){
    acd.setPower(power); // setPower(0-100%);
      Serial.print("lampValue -> ");
      Serial.print(acd.getPower());
      Serial.println("%");
    delay(100);
  }

  for(power=MAX_POWER;power>=MIN_POWER;power-=POWER_STEP){
    acd.setPower(power); // setPower(0-100%);
      Serial.print("lampValue -> ");
      Serial.print(acd.getPower());
      Serial.println("%");
    delay(100);
  }
}

Result

The brightness of the bulb varies according to the ‘power’ value sent to the module. It is good to note that this module works with dimmable loads and works best with incandescent bulbs. I use an LED bulb and the dimming works well between 6 and 40. Below 6, the lamp goes out, above that, I don’t see any change in brightness and the bulb goes out above 85.

Applications

Sources

How useful was this post?

Click on a star to rate it!

Average rating 4.4 / 5. Vote count: 13

No votes so far! Be the first to rate this post.

Exit mobile version