Go Down

Topic: BFM  (Read 301 times) previous topic - next topic

Bite_my_shiny_metal_ass

Hi!

my name's Gil, I'm quite new to this forum, I posted a topic a little more than a year ago, about an automatisation of Bender the robot from Futurama. I could never manage to put a picture on the forum, and for personal reasons (Moving out, getting a new workshop & a new job), ended up dropping the whole thing, mostly because i lacked the time to work on it. I remember people being very helpfull though.

maybe i'll get back to that sometime.

I work in a workshop with 5 other friends, we're all freelancers and we all have different skills. at the moment we're building a entrance room for a craftbeer company, and the room should look like a beer factory. so we made alll kind of decoration and stuff, and some part of it are gonna move, some ar gonna make sound, and everything's gonna be controlled thru an arduino.

we found a beautifull old school board that use to control different voltage (a free hug for anyone that can tell me the exact use of this thing)

here's the beast:





i will use this to control most of the action that will occur in the "beer factory".

i use rotary angle sensors from grove to get the position of every switch, that sends me a value that i get with the arduino and then map it to trigger an action.





no issues up to now with the mechanical parts, the system works fine.


now some of the switches (from now on what i call "switches" are the big handles on the board, there are 10 of em) are controlling a stepper motor that will move brushes (works fine), some other set the speed of a fan  (it already had 3 different speeds, so i just use relays to trigger the right ones), some define patterns on two led stripes (noo problems either up to now), and the last ones should dim several lamps in the room. here comes the problem.


i bought this :

https://www.aliexpress.com/item/AC-Light-Dimmer-Module-for-PWM-control-1-Channel-3-3V-5V-logic-AC-50-60hz/32802025086.html


and i found this on instructables to make it work : 

https://www.instructables.com/id/Arduino-controlled-light-dimmer-The-circuit/


and i use this code to programm the Arduino :
Code: [Select]
/*AC Light Control
 
 Updated by Robert Twomey
 
 Changed zero-crossing detection to look for RISING edge rather
 than falling.  (originally it was only chopping the negative half
 of the AC wave form).
 
 Also changed the dim_check() to turn on the Triac, leaving it on
 until the zero_cross_detect() turn's it off.
 
 Adapted from sketch by Ryan McLaughlin
 http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1230333861/30
 
 */

#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 = 3 ;                // Output to Opto Triac
int dim = 0;                    // Dimming level (0-128)  0 = on, 128 = 0ff
int inc=1;
const int SWITCHPIN =A0;
// counting up or down, 1=up, -1=down

int freqStep = 75;    // This is the delay-per-brightness step in microseconds.
                      // For 60 Hz it should be 65
// It is calculated based on the frequency of your voltage supply (50Hz or 60Hz)
// and the number of brightness steps you want.
//
// Realize that there are 2 zerocrossing per cycle. This means
// zero crossing happens at 120Hz for a 60Hz supply or 100Hz for a 50Hz supply.

// To calculate freqStep divide the length of one full half-wave of the power
// cycle (in microseconds) by the number of brightness steps.
//
// (120 Hz=8333uS) / 128 brightness steps = 65 uS / brightness step
// (100Hz=10000uS) / 128 steps = 75uS/step

void setup() {                                      // Begin setup
  pinMode(AC_pin, OUTPUT);                          // Set the Triac pin as output
  attachInterrupt(0, 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);     
  // Use the TimerOne Library to attach an interrupt
  // to the function we use to check to see if it is
  // the right time to fire the triac.  This function
  // will now run every freqStep in microseconds.                                           
Serial.begin(9600);
}

void zero_cross_detect() {   
  zero_cross = true;               // set the boolean to true to tell our dimming function that a zero cross has occured
  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>=dim) {                     
      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() {
int switchValue = analogRead(SWITCHPIN);
 delay(10);                     
 dim = map(switchValue, 0, 1023, 0, 128);
 Serial.print(dim);
 Serial.print("        ");
 Serial.println(switchValue);
 
}




Which is a slightly modified version of the code you'll find Under section 6 on the instructable webpage.

i basically just changed a couple of lines in the loop so i could use a potentiometer to chose the level of dimming instead of just having the lamp going on and off in a loop.

problem was the same with the original code so i guess its not the modifications.


Bite_my_shiny_metal_ass


i have three main issue with this:

first of all i cant really dimm the lamp (usual 230vac tungsten lightbulb) from 0 (fullon) to 128 (full off), but rather from 75 to 110. I put a voltmeter on the lamp and the voltage changes from 60V to 180V. when i go higher than 110 (dim Value) the voltage drops to 0V and under 75 it jumps to 230V. i sent the value of the potentiometer and the dimming via the serial monitor, and everything's fine there i have nmber from 0 to 1023 and from 0 to 123. so i gues its either the code, or the zerocross module that have a problem?


i havent had the time yet to try another lightbulb, or just test the voltage without any load (I'm kinda tired of the work and i just think of this now... but i will definitely try this tomorrow morning).

second thing is once the voltage reaches 180 volts, it jumps to 230V and once it's there, theres no way to regulate anything anymore, no matter if i turn the pot all the waydown... i mean maybe sometime things go back by themselves after a while but most of the time i have to turn the main off and on again to get things back to normal. its like the triac won't turn off anymore ?!?

there again i din't try to change the Zerocross module, i have several  other ones, and i will try this tomorrow anyway, but its brand new and it should work....


third and last issue is the potentiometer or "rotary angle sensor" as they label it. as i said it gives me values from 0 to 1023 no problem with this but when i read the value on the serial monitor i noticed that  the first say 80-90° of rotation it stays on 1023 and only after that starts to decrease all the way to 0 (and no problem on that side). i changed it and the problem stayed. is it supposed to be that way? i had never noticed that before.


if you girlz and guys have any idea that could be helpfull that would be great...

for info the whole project is gonna run on a mega, and with a lot more code and inputs/outputs, but for the moment i'm just using this piece of code on an arduino uno with just one pot as input (+the zero cross signal of course)and the Triac as an output, itself wired to the main and the lamp. the pot is not on one of the switch of the big board yet, its just on the table.  so it's as simple as it can be to test it (and hopefully get this dimn dammer to work).


i will tri to change the bulb and the module and test the voltage on without any load, and anything else i can think of during the night (...), and give feedback asap, eventhough i really doubt its one of these things.


i should try to run the rest of the code they give on instructables also to see if anything works, like the one with delay() and so on. there's a person in the comment that seems to have the same problem as i do, i will try to write them as well to see if they could solve the thing.


i spent a lot of hours scouting the net for "ac wave control" the last days and i couldn't solve this therefore i came here, maybe someone had the same problems?



ha and just one last thing cause i hear the warnings from here : i'm a certified electrician since 10 years, and i've been working with 230vac the last 14 years, i know what i'm doing with this and i take all the precautions needed. Actually its more the electronics i have to understand i guess ^^


thank you for any reply, sorry for the mistakes (I speak french), and i guess good night for some and good Morning for others…





(sorry i had to post in two parts..)
(and sorry i didnt finish the name of the post could some admin change it to "Craftbeer Factory decoration, trouble with 230 AC light dimming")

Go Up