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 :
and i found this on instructables to make it work :
and i use this code to programm the Arduino :
/*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.