How to dim the lights using ESP8266, a Light intensity sensor and a micro-dimmer

Hey guys,
this is my first post and I am kind of new in the concept of Arduino.

I would like to create a very simple system,
in order to be able to dim the light of my room according to a light intensity sensor.

I am having some trouble with the electronic and electrical components needed.

  1. The sensor will be measuring the light intensity of the room in defined time intervals
  2. The signal from the sensor will be processed by the ESP8266 (accessible via WiFi)
  3. The controller then, gives a signal to a dimmer and sets the power output accordingly.

For e.g.,
If the max. achieved light intensity is at Avalue, then don't give electrical power in the lamp (0Watt).
If the min. achieved intensity is Bvalue, then give max. electrical power to the lamp (60Watt).
iF the intesity achieved is equal to Cvalue and C is, B<C<A, then give (40Watt) etc etc
NOTE!
I want more than 2-3 thresholds (above ValueA, ValueB, ValueC).

IS THAT TECHNICALLY POSSIBLE?

What hardware do I need to do this project?
Any links or comments are helpful.

Thanks for the support!

60 Watt? What are you trying to light up? My living room is doing fine with just 2x 11W.
Or is it an old-fashioned incandescent lamp?
The type of bulb is very important here. Also the voltage it operates on. Is it 12V DC, or 240V AC, or something else?

Then: what exact light sensor are you using? Can you make sure that your lamp does not affect the light sensor's reading?

It is quite easy to set an output based on an input in code. Read the light intensity, set output value accordingly. By using PWM output (to switch low voltage DC) you can set it to 256 different levels. By using a TRIAC (to switch high voltage AC) it's going to depend on the accuracy of your timing.

One important thing to beware of here: one of the very few weaknesses of the ESP8266 vs Arduino is this kind of timing. They're known to experience glitches in PWM and other timing, due to the handling of the http stack. I've even had timing issues with interrupts myself - timing the discharge of a capacitor, normally about four microseconds (to 1-2 clock pulses the same time over dozens of measurements) and then suddenly a single measurement in the 7-8 microsecond range, and back to normal. That while using an interrupt. You may experience this in the form of flicker of your lights.

If that's an issue for you, the cheapest/easiest solution for PWM would be to use an external PWM chip. For the TRIAC solution there may also be external chips that can handle the timing for you, I don't know about this.

Hi @wvmarle,
thank you for your comment first of all.
I will answer to your comment in the same paragraph fashion as your post so that we can both follow the discussion easilly.

As for the 60 Watt, let me be clear here. My goal is to be able to control the intensity of Incandescent and/or Halogen lamps. Those can be easily dimmed and are widely used.
As for your comment regarding wether it operates on DC or AC, I am still figuring out (thanks for the heads up-totally forgot it).

When it comes to the light sensor, I made some research and realised that there are plenty with very nice properties and hence, I don't think that this may be a problem, right?

Moreover, regarding your comment in the third paragraph and If I understood correctly, I can ONLY use a TRIAC for AC and a PWM fro DC, right? This is exaclty the part which is the most unclear to me at the moment. Any extra comments would be great.

Finally, as for the timing, I am still checking on the most efficient way to program it and thus, maybe I will use Arduino directly. Other than this, I assume that now I will just need to find a replacement for an direct Arduino compatible Wi-Fi chip. (any cheap suggestion here?)

Looking forward to any recommendations or comments,
I will start working on it in 12 hours again and I will be able to share more if that is OK with you.

Many thanks,
greetings from Germany!

woksalonica:
My goal is to be able to control the intensity of Incandescent and/or Halogen lamps. Those can be easily dimmed and are widely used.

Halogen lights shouldn't be dimmed. That shortens their life.
Leo..

Then we stick to Incadescent lamps @wvmarle.
Short Notice here,
this is pretty much my list for light intensity senors
https://www.intorobotics.com/common-budgeted-arduino-light-sensors/
I will select one from this list. (any comments are very welcome).

Many thanks for the great remark @Leo!
Really useful.

woksalonica:
As for the 60 Watt, let me be clear here. My goal is to be able to control the intensity of Incandescent and/or Halogen lamps. Those can be easily dimmed and are widely used.

How about LEDs?
Easy to dim (with the correct driver hardware - and no need to deal with line voltages so safer - they use a low voltage DC), very energy efficient, little to no heat to deal with.

When it comes to the light sensor, I made some research and realised that there are plenty with very nice properties and hence, I don't think that this may be a problem, right?

No problem to have "a light sensor". The importance is "which sensor" as they are handled in different ways. For example a cheap LDR works very well in a great range of light, it's the cheapest and simplest.
The TEMT6000 is another I have played with myself, I have on or two of them still in my toolkit, not using them because they can't handle sunlight, they are very quickly saturated. Using the TSL2591 now (successor of the TSL2561). For your indoor application the TEMT6000 would work well.

Moreover, regarding your comment in the third paragraph and If I understood correctly, I can ONLY use a TRIAC for AC and a PWM fro DC, right?

For sake of keeping it simple: yes, that's right.
There are of course other ways to dim, but this are the most common and most efficient ways for either.

I will just need to find a replacement for an direct Arduino compatible Wi-Fi chip. (any cheap suggestion here?)

That would be the ESP8266 based boards, like NodeMCU or WeMOS D1.

AC dimmers use phase angle control. You can't just connect a triac to an Arduino output and PWM its gate. You need zero crossing detection to know when to turn on or off the triac.

+1 for DC LED lighting.

Pieter

HI guys,
thank you all for the great comments. I am currently researching everything that we have discussed yesterday.

@wvmarle, as for the LEDs, I am a bit sceptical regarding LEDs, although they are very easy to use and maintain, I would still like to focus on controlling my living room lights remotely and thus Incandescent lamps are more widely spread.
Also, thanks for the sensor and ESP8266 base board suggestion. I will stick to your advice.

@PieterP, thank you for your comment, I will check out what I can do for yero crossing detection.
As I said above I would really love to work with Incandescent lamps since 60% of the households use them (at least in EU). Is there something similar to TRIAC (Arduino IC) that I could use for such an application? (any suggestions are very welcome here)

Many thanks to all of you again for the great support!!

woksalonica:
As I said above I would really love to work with Incandescent lamps since 60% of the households use them (at least in EU).

That's not correct. You can no longer buy 'normal' incandescent bulbs in the EU. All general purpose incandescent bulbs on the market today are halogen bulbs. And these halogen bulbs should be phased out by September of next year as well.

Pieter

@PieterP
thank you for your comment,
any literature or statistics would be great.
I am on it as well.

However, if that's the case, my problem is simplified to a big extend.

LEDs for the glory!!

Press corner | European Commission
From September 2009, lamps equivalent in light output to 100W transparent conventional incandescent bulbs and above will have to be at least class C (improved incandescent bulbs with halogen technology instead of conventional incandescent bulbs).
By the end of 2012, the other wattage levels will follow and will also have to reach at least class C. The most commonly used bulbs, the 60W will remain available until September 2011 and 40 and 25W bulbs until September 2012.

@PieterP

this is very hlpful. I guess I will stick to LED lamps then.
I will define the product properties soon and come back!

Using incandescents is a broad statement, and I'm surprised it's only 60%.

In my home we use incandescents - they're so rarely used that they haven't broken down yet, most of those are 10-15 years old or older. We also have some CFLs left, again because they still work, all a few years old. Everything that breaks we try to replace with LEDs, even though in my locality incandescents and CFLs are still available. It's just so much cheaper in the long run.

LED lighting is the future. I consider incandescent lighting obsolete, and for most applications fluorescent as well. Even high power floodlights are LED nowadays.

You have to be careful when dimming those AC powered LEDs, not all types are dimmable. This has to do with the driver electronics, which apparently can't stand PWM or phase cutting. I don't know the details of this. DC powered LEDs should be much easier to dim.

AC powered LED bulbs can't be dimmed because they have a build-in switching power supply. It doesn't care if the input voltage is 60 or 250 V AC. It just takes the 12 V DC for the LED.

Dimmable LEDs have a driver to regulate the output based on input reference. They are made for compatibility with classic dimmers in existing installations and old fixtures.

Dimming a LED bulb on the AC side with microcontroller would be weird.

woksalonica:
@PieterP

this is very hlpful. I guess I will stick to LED lamps then.
I will define the product properties soon and come back!

Hi,

What are you doing about ESP8266 Timer interrupt ? ..... I believe you would need that if you are applying phase angle firing of the Triac for dimming incandescent lamp.

I am stuck with ESP8266 Timer interrupt. I need a good working code for that.

If anybody can help please ......... Thanks