Hi Blynkers,
I wanted to share with you this little project. This time I have been playing with a zero-crossing detector made several years ago and my ESP8266 Shield for Arduino Pro Micro.
I’m running the Local Server on a Raspberry Pi.
#include <ESP8266_HardSer.h>
#include <BlynkSimpleShieldEsp8266_HardSer.h>
#define EspSerial Serial1
#include <TimerOne.h> // Avaiable from http://www.arduino.cc/playground/Code/Timer1
volatile int i=0; // Variable to use as a counter volatile as it is in an interrupt
volatile boolean zero_cross=0; // Boolean to store a "switch" to tell us if we have crossed zero
int AC_pin = 10; // Output to Opto Triac
int brightness = 128; // Dimming level (0-128) 0 = on, 128 = 0ff
int freqStep = 75; // This is the delay-per-brightness step in microseconds.
ESP8266 wifi(EspSerial);
char auth[] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
void setup() {
pinMode(AC_pin, OUTPUT); // Set the Triac pin as output
attachInterrupt(0, zero_cross_detect, RISING); // Attach an Interupt to Pin 3 (interupt 0)
Timer1.initialize(freqStep); // Initialize TimerOne library
Timer1.attachInterrupt(dim_check, freqStep);
Serial.begin(9600);
delay(10);
EspSerial.begin(9600);
delay(10);
Blynk.begin(auth, wifi,"xxxxxx","xxxxxxxxxxxx","xxx.xxx.x.xx");
delay(10);
}
BLYNK_WRITE(V1)// slider brillo
{
int brillo = param.asInt();
brightness=brillo;
}
void zero_cross_detect() {
zero_cross = true;
i=0;
digitalWrite(AC_pin, LOW); // turn off TRIAC (and AC)
}
// Turn on the TRIAC at the appropriate time
void dim_check() {
if(zero_cross == true) {
if(i>=brightness) {
digitalWrite(AC_pin, HIGH); // turn on light
i=0; // reset time step counter
zero_cross = false; //reset zero cross detection
}
else {
i++; // increment time step counter
}
}
}
void loop() {
Blynk.run();
}
I like it very much! I’ve wanted tot learn more about dimming AC signals and detecting the zero-crossings for a long time now. So a big thanks for sharing this excellent project!!
I’m thinking it has to do with the intended audience of the Arduino. It’s mostly hobby stuff on low voltage. If you do screw up, it’s not really bad. When you mess around with 230v, it can lead to pretty devastating results. Since the Arduino platform is made to be easy to program and understand I can understand the lack of 230v applications and devices. The only thing I meddled with is some relays, which is not that exciting because they are isolated. Anyway, I’d love to see some 230v dimmers, but they are quite expensive, I have no idea why though.
Second that of course. But with the LED bulbs becoming more populair, it might not be the wisest choice. I only have one (1!) 230v bulb left in my living room and it’s an energy saver, so it can’t be dimmed anyway, haha.
All my other lights are LED, saves way more energy, but still, I’d like a 230v dimmer
It looks very nice. I think the hardware can be modified ie using ready made electronic dimmer, from the dimmer board if you remove the diac and attach MOC3020 pin 4 $ 6.It will be neat and avoiding soldering entire board.
Hi guys, nice to read your comments, @Lichtsignaal, you are right, LED bulbs are becoming more popular and this kind of dimmers for lights have less sense … but what about AC Motors? Don’t forget them!!
With this dimmer you can handle about 1000W if I’m not wrong (adding a heatsink just in case).
Anyway, be careful with 230v, it could be dangerous if you don’t pay attention.
Definitly could be dangerous yes, lol. I know all about that hahaha
The motor is indeed an option, but with the projects I have in my mind (a dragon on our h0 model track and an X-Wing in a swamp …) I have no use for it, for now anyway.
Maybe an automated vacuum cleaner at one point, or something like that. Garage door opener perhaps? Lawnmower? Lawnmower! I can see that happening
To improve the zero crossing accuracy and variations due to mains voltage, opto gain etc, you could use the following… www.dextrel.net/diyzerocrosser.htm
I have used this in a few circuits and it is very good.
Also best to have a snubber across the triac… O.047 x cap, 100R in series.(resistive loads) Plus best to use 600V triac drive opto’s… for 230 mains.
All good fun …
Thanks for sharing @Roffey. At the moment I’m just playing with this Dimmer, the idea is to use a LDR with other Arduino (outside) and adjust the light (inside) automatically using bridge function.
No problem … the main reason for using a slightly more complex zero cross circuit is that of phase accuracy within each half cycle. It’s not so critical with resistive loads, but any ‘offset’ when used with inductive type loads (transformers etc), will cause problems. Worst case being overheating and possible fire risks.
Have fun with your project:)
is there a way to keep the potetiometer of a standard dimmer and just add the possibility to controlle it with blynk??
if i change the value of my dimmer(pot) it change and if i change it on blynk it will change with the most recent value…
It would be nice to be able to use just a standard dimmer, but I’m afraid it would require too much modification. You would want two ‘master’ controls(blynk&pot) so logical sensing for a start. Then a mix of digital and external resistive phase control etc.
By the time you’ve done that, you would be better off designing from scratch.
Nice thought though… All you need is a pot that can be manually plus digitally controlled, takes high voltage, and knows what precedence by which is controlling it!
void dim_check() {
if(zero_cross == true) {
if(i>=brightness) {
digitalWrite(AC_pin, HIGH); // turn on light
i=0; // reset time step counter
zero_cross = false; //reset zero cross detection
}
else {
i++; // increment time step counter
}
}
}
You could basically use some hardware timers along with interrupts to do switching more precisely but it’s pretty minor thing you are not doing motor controll after all. Cool thx again I need to do this at my home:P
Hi @conkerkh,
I’m glad you like it! Definitely, there are other ways to achieve same result, in this case, I get this piece of code from someone time ago, I only did small changes to play with Blynk.
I don’t usually play with interrutps, it would be fine if you could develop your idea and share it with us.
The good ideas are always wellcome, and if I can learn a bit of them is even better!! Thanks!!