Bonjour à tous,
On est avec un ami à travailler sur une installation lumineuse avec capteur ultra son dont l'intensité doit varier selon la distance de l'obstacle. Pour faire simple, en dehors de la zone de captation, l'installation est éteinte, arrivé à 450cm elle s'allume faiblement, et plus on se rapproche plus l'intensité augmente également.
Pour le moment, on travaille avec un capteur Velleman HC-SR05 + un Arduino Uno + un dimmer module pour PWM Control 1 Channel 3.3 V/5 V. Pour ce qui est du code, on a ce ceci:
/*
AC Voltage dimmer with Zero cross detection
Author: Charith Fernanado Adapted by DIY_bloke
License: Creative Commons Attribution Share-Alike 3.0 License.
Attach the Zero cross pin of the module to Arduino External Interrupt pin
Select the correct Interrupt # from the below table
(the Pin numbers are digital pins, NOT physical pins:
digital pin 2 [INT0]=physical pin 4 and digital pin 3 [INT1]= physical pin 5)
check: interruptsPin | Interrrupt # | Arduino Platform
2 | 0 | All -But it is INT1 on the Leonardo
In the program pin 2 is chosen
*/int AC_LOAD = 3; // Output to Opto Triac pin
int AC_INTERRUPT = 2; // pin interruptionint dimming = 128; // Dimming level (0-128) 0 = ON, 128 = OFF
const unsigned int TRIG_PIN = 8;
const unsigned int ECHO_PIN = 9;const unsigned long MEASURE_TIMEOUT = 250000UL; // 25ms = ~8m à 340m/s
void setup()
{
pinMode(TRIG_PIN, OUTPUT);
pinMode(ECHO_PIN, INPUT);
pinMode(AC_LOAD, OUTPUT);// Set AC Load pin as outputattachInterrupt(0, zero_crosss_int, RISING); // Choose the zero cross interrupt # from the table above
Serial.begin(9600); // Starts the serial communication
}//the interrupt function must take no parameters and return nothing
void zero_crosss_int() //function to be fired at the zero crossing to dim the light
{
// Firing angle calculation : 1 full 50Hz wave =1/50=20ms
// Every zerocrossing thus: (50Hz)-> 10ms (1/2 Cycle)
// For 60Hz => 8.33ms (10.000/120)
// 10ms=10000us
// (10000us - 10us) / 128 = 75 (Approx) For 60Hz =>65int dimtime = (75 * dimming); // For 60Hz =>65
delayMicroseconds(dimtime); // Wait till firing the TRIAC
digitalWrite(AC_LOAD, HIGH); // Fire the TRIAC
delayMicroseconds(20); // triac On propogation delay
// (for 60Hz use 8.33) Some Triacs need a longer period
digitalWrite(AC_LOAD, LOW); // No longer trigger the TRIAC (the next zero crossing will swith it off) TRIAC
}int mesure()
{
digitalWrite(TRIG_PIN, LOW);
delayMicroseconds(10);
digitalWrite(TRIG_PIN, HIGH);
delayMicroseconds(20);
digitalWrite(TRIG_PIN, LOW);unsigned long duration = pulseIn(ECHO_PIN, HIGH, MEASURE_TIMEOUT);
unsigned long distance = duration / 29 / 2;if (distance > 250){
distance = 250;
}return distance;
}void loop() {
long distance = mesure();
Serial.print("distance : ");
Serial.println(distance);if (distance > 0)
{dimming = map(distance, 1, 250, 0, 128);
Serial.print("dimmer : ");
Serial.println(dimming);
}delay(500);
}
Cependant on est face à deux problèmes majeurs qu'on n'arrive pas à résoudre :
-
- Le capteur n'arrive pas à capter à plus de 200cm alors qu'il devrait pouvoir aller jusqu'à 450, et on en a essayé 2 différents.
-
- La variation lumineuse n'est pas du tout fluide. Elle est même quasi inexistante. La lampe est en mode stromboscopique constamment et se stabilise des fois quand on est très proche du capteur (à environ 50cm).
Si bien qu'on aimerait savoir si les problèmes ne viendraient pas du matériel qui serait alors inadapté, et si notamment, l'arduino n'arriverait pas à gérer la fréquence du signal du capteur et de celle du dimmer.
Un tout grand merci pour vos éclairages ![]()