Iemand gezocht om LED verlichting dimmend te maken

Projecten die niet passen in bovenstaande onderwerpen
Berichten: 1
Geregistreerd: 04 Dec 2018, 12:26

Iemand gezocht om LED verlichting dimmend te maken

Berichtdoor El Pollo Diablo » 04 Dec 2018, 12:29

Beste Arduino liefhebbers,

Mijn naam is Stephan, 33 jaar oud en woonachtend in Dordrecht. Ik ben op zoek naar iemand om deze klus voor mij te realiseren, uiteraard tegen betaling. Ik heb namelijk totaal geen kaas gegeten van Arduino, maar mij is gezegd dat mijn wens te realiseren is met Arduino. Het gaat om het volgende:

Ik heb onlangs mijn trap laten renoveren met LED verlichting, dat aanspringt met een bewegingssensor. Ik zou echter dit licht dimmend (fade in fade out) willen laten aan- en uitgaan. De trapboer had hier geen oplossing voor. Op dit moment zit het als volgt in elkaar: stopcontact -> voeding -> sensor -> LED verlichting geschakeld. Dit idee zou ik dus willen (alleen dan niet 1-voor-1, alles tegelijk dimmend aan/uit is voldoende): https://youtu.be/TmF0eJc6IO0?t=6

Alvast enorm bedankt voor de hulp! Ik hoor het graag.

Groeten,
Stephan

Advertisement

Berichten: 25
Geregistreerd: 09 Jun 2018, 06:54
Woonplaats: Roodepoort, Zuid Afrika

Re: Iemand gezocht om LED verlichting dimmend te maken

Berichtdoor sterretje » 05 Dec 2018, 06:20

Voordat iemand hierin stapt zul je moeten aangeven wat je precies hebt geinstalleerd. Linkjes naar de sensor, the led verlichting enzovoorts.

PS
Dit is misschien allemaal te vinden in je video maar ik kijk geen youtubes.

Berichten: 21
Geregistreerd: 27 Feb 2017, 14:36
Woonplaats: Hoensbroek

Re: Iemand gezocht om LED verlichting dimmend te maken

Berichtdoor GTIBert » 24 Jan 2019, 11:44

cpp code
/*
*
* LED STRIPS control for stairways, by DJT88.
* Modify definitions/variables below to match pin-schematic for your project.
* This code was used on an Arduino MEGA 2560. Other boards may work, as long as you have sufficient PWM outputs and Analog/Digital pins available.
* This code was made using specific PIR sensors (HC-SR505) and custom LDR setup and switches. It will not work 'AS IS' for your project. Customize code to fit your needs
*
*/
#define step0 44 // output pins PWM to LED strips (via MosFET 2n7000)
#define step1 45
#define step2 2
#define step3 3
#define step4 46
#define step5 5
#define step6 6
#define step7 7
#define step8 8
#define step9 9
#define step10 10
#define step11 11
#define step12 12
#define step13 13

#define ON 255 // max pwm value
#define OFF 0 // min pwm value (OFF)

#define PIR_UP 24 // input pin number for PIR sensor upstairs
#define PIR_DOWN 22 // input pin number for PIR sensor downstairs

#define PIN_MODE1 30 // input pin number for Multi-position-switch Mode 1
#define PIN_MODE2 32 // input pin number for Multi-position-switch Mode 2
#define PIN_MODE3 26 // input pin number for Multi-position-switch Mode 3
#define PIN_MODE4 28 // input pin number for Multi-position-switch Mode 4


#define M1LoopSpeed 10 // Tetris Speed (lower value is higher speed)

const int VarioPin = A1; // input pin for the potentiometer (analog IN)
const int LuxPin = A0; // input for Lux level from LDR (analog IN)
const int Max = 13; // max step starting from 0, so 14 led strips in my case.
const int StartNext = 15; // this value holds the value a step must have before the next one starts (Mode 0)

//--------------------------------------------
/*
* FUNCTION DEFINITIONS
*/
bool CLS_Tetris(int Check[Max+1]); // Returns a bool; Check Loose Step ( checks if tetris loop was halfway down the stairs...)
float Check_Illumination(bool NonLineair); // Returns a float; 0.0 - 1.0 of the illumination level from the LDR sensor input.

//--------------------------------------------

int Mode = 0; // used for switch cases for operating different modes.
bool Mode1 = 1;
bool Mode2 = 1;
bool Mode3 = 1;
bool Mode4 = 1;

float Brightness = 1; // Dimvalue. (0.xx tot 1.0) Calculated from LuxVal.
float VarioVal = 0; // Stores input value from POT meter. For brightness adjusting in Mode 2.
float BrightSteady = 1; // stabelized Dimvalue for Mode 2 (0.xx tot 1.0)

int LoopDelay = 0; // for tuning speed of the loop. (stock 5 ms)

bool stoploop = false; // tetris mode Control value.
bool StartTop = false; // tetris mode Control value.
int F = 0; // used for FullOn check.
int ModeLoop = 0;

int MaxBright = 255; // maximum brightness. (only tested for 255)
int timeout = 2000; // for delay in turning lights off.

int trede[14] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0}; // step values for output to LED strips (PWM)
int tredeA[14] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0}; // step values for mode 1
int tredeB[14] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0}; // step values for mode 2
int tredeC[14] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0}; // step values for mode 3
int tredeD[14] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0}; // step values for mode 4
int test = 0;
int DirOFF = 1; // Keeps track of last trigered sensor, to control proper direction for turning lights OFF.

int SensUp = 0; // current value sensor Upstairs
int SensDown = 0; // current value sensor Downstairs
int OldSensUp = 0; // old value for sensor UP, for checking for flank.
int OldSensDown = 0; // old value for sensor DOWN, for checking for flank.

bool StartDownUp = false; // Active program start Down to Up
bool StartUpDown = false; // Active program start Up to Down
bool StopDownUp = false; // Active program stop Down to Up
bool StopUpDown = false; // Active program stop Up to Down
bool FullOn = false; // FullOn is true when lights are fully on.

/*
* SETUP
*/

void setup() {
//Serial.begin(9600); // for debugging (serial monitor in IDE)
pinMode(PIR_DOWN, INPUT_PULLUP); // SensorDown, for motionsensor down
pinMode(PIR_UP, INPUT_PULLUP); // SensorUp, for motionsensor up
// mode0 : when no input given.
pinMode(PIN_MODE1, INPUT_PULLUP); // mode1 ( Tetris )
pinMode(PIN_MODE2, INPUT_PULLUP); // mode2 (
pinMode(PIN_MODE3, INPUT_PULLUP); // mode3
pinMode(PIN_MODE4, INPUT_PULLUP); // mode4

tredeC[5] = ON; // start position for demo mode (mode 3)

}

/*
* MAIN LOOP
*/

void loop() {

SensUp = digitalRead(PIR_UP); // read the value from the sensors and settings:
SensDown = digitalRead(PIR_DOWN);

if (SensUp && !SensDown){ // Keeps track of which sensor was last to trigger. DirOFF used for turning of in correct direction.
DirOFF = 1 ; // last sensor UP
}
if (!SensUp && SensDown){
DirOFF = 2 ; // last sensor DOWN
}

Mode1 = digitalRead(PIN_MODE1); // read pins for mode detection.
Mode2 = digitalRead(PIN_MODE2);
Mode3 = digitalRead(PIN_MODE3);
Mode4 = digitalRead(PIN_MODE4);

Mode = 0; // standard smooth fading

if(Mode1 == 0){ // inverted inputs ("0" is high)
Mode = 1; // Tetris falling steps
}
if(Mode2 == 0){
Mode = 2; // Continuously ON, control brightness
}
if(Mode3 == 0){
Mode = 3; // Continuous motion (demo mode)
}
if(Mode4 == 0){ // reserve mode
Mode = 4;
}

//ModeSTATE tracker
switch (Mode){
case 0: // some unfinished business...
break;
case 1:
break;
case 2:
break;
case 3: // demo mode triggers.
ModeLoop++;
if (ModeLoop > 20){
ModeLoop = 0;
Brightness = Check_Illumination(false); // check lux (linear)
if(Brightness < 0.008){ // minimal visible value.
Brightness = 0.008;
}
if(DirOFF == 1){
for (int i=0; i<=13; i++){
if (i<13){
tredeC[i] = tredeC[i+1];
}
else{
tredeC[i] = tredeC[0];
}
}
}
else{
for (int i=13; i>=0; i--){
if (i>0){
tredeC[i] = tredeC[i-1];
}
else{
tredeC[i] = tredeC[13];
}
}
}
}
break;
case 4:

break;
}


LoopDelay = 5; // minimal delay = 5 for now...

VarioVal = (analogRead(VarioPin)/4);
if (((VarioVal/255) > (BrightSteady+0,1))||((VarioVal/255) < (BrightSteady - 0,1))){
BrightSteady = (VarioVal/255);
}

/*
* Start or Stop procedure triggering.
*/
if(SensDown && (SensDown != OldSensDown)){ // Up-Flank DOWN sensor
if(FullOn == false){ // only do stuff if stairs are not yet FULLY ON!

// first, check brightness;
Brightness = Check_Illumination(true); // returns 0.000 to 1.000
if(Brightness < 0.008){ // minimal visible value.
Brightness = 0.008;
}

// start procedure for DOWN > UP lighting
StartDownUp = true; // Start DownUp if stairs are not FullOn. somebody wants UP

if (Mode == 1){ // If Mode 1 is active, no simultanious turning ON from up and down.
if (StopDownUp){ // if we were turning OFF in the Down > UP movement, Turn back ON in 'wrong' direction for this sensor.
StartUpDown = true;
if(!CLS_Tetris(tredeB)){
StartTop = true;
}
}
if (StartUpDown){
StartDownUp = false;
}
else{
if(!CLS_Tetris(tredeB)){
StartTop = true;
}
}
}
StopDownUp = false; // if lights were going off (stop procedure), stop doing that. We need lights!
StopUpDown = false;

// RESET timeout, somebody is still near the stairs.
timeout = 2000;
}
}

if(SensUp && (SensUp != OldSensUp)){ // Up-Flank UP sensor
if(FullOn == false){

// first, check brightness;
Brightness = Check_Illumination(true); // returns 0.000 to 1.000
if(Brightness < 0.008){
Brightness = 0.008;
}

// start procedure for UP > DOWN lighting
StartUpDown = true; // Start UpDown if stairs are not FullOn. somebody wants DOWN

if (Mode == 1){ // If Mode 1 is active, no simultanious turning ON from up and down.
if (StopUpDown){ // if we were turning OFF in the UP > DOWN movement, Turn back ON in 'wrong' direction for this sensor.
StartDownUp = true;
if(!CLS_Tetris(tredeB)){
StartTop = true;
}
}
if (StartDownUp){
StartUpDown = false;
}
else{
if(!CLS_Tetris(tredeB)){
StartTop = true;
}
}
}

StopDownUp = false; // if lights were going off (stop procedure), stop doing that. We need lights!
StopUpDown = false;

// RESET timeout, somebody is still near the stairs.
timeout = 2000;
}
}

// -----------------------------------------
/*
* TIMEOUT procedure
*/
if (timeout > 0){
timeout--;
}
if ((timeout <= 0) && (!SensUp && !SensDown)){ // When all Sensors are off & timeout is 0 -> Turn stuff off. Using correct direction (DirOFF)
switch (DirOFF){
case 1: // OFF from Down to Up
StopDownUp = true;
StartDownUp = false; // in case off bug.. turn ON > OFF (timeout overrules everything)
StartUpDown = false; // in case off bug.. turn ON > OFF
timeout = 2000; // reset timeout
break;
case 2: // OFF from Up to Down
StopUpDown = true;
StartDownUp = false; // in case off bug.. turn ON > OFF
StartUpDown = false; // in case off bug.. turn ON > OFF
timeout = 2000; // reset timeout
break;
}
}


/* -----------------------------------------
*
* ON and OFF procedures
*
/ -----------------------------------------
*/

if (StartDownUp){
switch (Mode){
case 0: // Mode standard (puts value in tredeA)
if (tredeA[0] < MaxBright){tredeA[0]++;} // starting step
for(int l=1; l<=Max; l++){ // next steps to Max.
if (tredeA[l]<MaxBright && tredeA[l-1] > StartNext){tredeA[l]++;}
}
break;
case 1: // Mode 1 (tetris) (puts value in tredeB)
// Mode A (tetris)
ModeLoop++;
if (ModeLoop > M1LoopSpeed){
ModeLoop = 0;
for(int i=(Max); i >= 1; i--){
if((!stoploop)&&(tredeB[i] > 0)){
if(tredeB[i-1] > 0){
StartTop = true;
}
else{
tredeB[i-1] = ON;
tredeB[i] = 0;
}
stoploop = true;
if(i==1){
StartTop = true;
}
}
}
if(StartTop){
tredeB[Max] = ON;
StartTop = false;
}
stoploop = false;
}
break;
}
}

if (StartUpDown){
switch(Mode){
case 0: // Mode Standaard
if (tredeA[Max]<MaxBright){tredeA[Max]++;} // begintrede (van boven naar beneden)
for(int m=(Max-1); m>=0; m--){ // opvolgende tredes tot 0.
if (tredeA[m]<MaxBright && tredeA[m+1] > StartNext){tredeA[m]++;}
}
break;
case 1: // Tetris
ModeLoop++;
if (ModeLoop > M1LoopSpeed){ // do this every XX loops, to control speed.
ModeLoop = 0;
for(int i=0; i < Max; i++){
if((!stoploop)&&(tredeB[i] > 0)){
if(tredeB[i+1] > 0){
StartTop = true; // Either start a new 'falling trede', because the last one is in position.
}
else{
tredeB[i+1] = ON; // OR, continue 'falling'.
tredeB[i] = OFF;
}
stoploop = true; // only do one of the actions above with the 'lit' step, then 'exit' the loop.
if(i==(Max-1)){
StartTop = true;
}
}
}
if(StartTop){
tredeB[0] = ON; // Start the 'falling' proces from the start. (array tredeB is filling up)
StartTop = false;
}
stoploop = false;
}
break;
}
}

if (StopDownUp){
switch(Mode){
case 0: // Std. Mode
if (tredeA[0] > 0){tredeA[0]--;}
for(int o=1; o<=Max; o++){
if ((tredeA[o] > 0) && (tredeA[o-1] < (MaxBright-StartNext))){tredeA[o]--;}
}
if (tredeA[Max] == 0){
StopDownUp = false;
}
break;
case 1: // tetris Mode
ModeLoop++;
if (ModeLoop > M1LoopSpeed){
ModeLoop = 0;
if(tredeB[0] > 0){
tredeB[0] = OFF;
}
else{
for(int i=1; i <=Max; i++){
if((!stoploop)&&(tredeB[i] > 0)){
tredeB[i-1] = ON;
tredeB[i] = OFF;
stoploop = true;
}
}
stoploop = false;
}
}
break;
}
}

if (StopUpDown){
switch(Mode){
case 0:
if (tredeA[Max] > 0){tredeA[Max]--;}

for(int n=(Max-1); n>=0; n--){
if(tredeA[n] > 0 && tredeA[n+1] < (MaxBright-StartNext)) {tredeA[n]--;}
}
if (tredeA[0] == 0){
StopUpDown = false;
}
break;
case 1:
ModeLoop++;
if (ModeLoop > M1LoopSpeed){
ModeLoop = 0;
if(tredeB[Max] == ON){
tredeB[Max] = OFF;
}
else{
for(int i=(Max-1); i >=0; i--){
if((!stoploop)&&(tredeB[i] > 0)){
tredeB[i+1] = ON;
tredeB[i] = OFF;
stoploop = true;
}
}
stoploop = false;
}
}
break;
}
}


/*
* when step != tredeA/B/C/D, increase or reduce step value.
*/
switch(Mode){
case 0: // Make steps follow the pattern in tredeA.
for(int i = 0; i <= Max; i++){
if (trede[i] < tredeA[i]){
trede[i]++;
}
else{
if (trede[i] > tredeA[i]){
trede[i]--;
}
}
}
break;
case 1: // Make steps (trede[x]) follow the tetris pattern in tredeB, but more smoothly.
for(int i = 0; i <= Max; i++){
if (trede[i] < tredeB[i]){
trede[i]= trede[i]+15;
if (trede[i] > 255){ // max is 255 for PWM.
trede[i] = 255;
}
}
else{
if (trede[i] > tredeB[i]){
trede[i] = trede[i]-5;
if (trede[i] < 0){ // minimum is 0 for PWM.
trede[i] = 0;
}
}
}
}
break;
case 2: // Always ON mode, brightness is adjustable with Potentio-meter knob.
for(int i = 0; i <= Max; i++){
if (trede[i] < (255*BrightSteady)){
trede[i]++;
}
else{
if (trede[i] > (255*BrightSteady)){
trede[i]--;
}
}
}
break;
case 3: // FLOW/SHOW mode, Creating trail effect here...
for(int i = 0; i <= Max; i++){
if (trede[i] < tredeC[i]){
trede[i]= trede[i]+7;
if (trede[i] > 255){
trede[i] = 255;
}
}
else{
if (trede[i] > tredeC[i]){
trede[i] = trede[i]-2;
if (trede[i] < 0){
trede[i] = 0;
}
}
}
}
break;

}
/*
* OUTPUT TO LEDSTRIPS ( Multiplied by Brighness).
*/
if (Mode == 2){ // Mode 2 is MANUAL mode controlling brightness. No auto Brightness for this.
analogWrite(step0,trede[0]);
analogWrite(step1,trede[1]);
analogWrite(step2,trede[2]);
analogWrite(step3,trede[3]);
analogWrite(step4,trede[4]);
analogWrite(step5,trede[5]);
analogWrite(step6,trede[6]);
analogWrite(step7,trede[7]);
analogWrite(step8,trede[8]);
analogWrite(step9,trede[9]);
analogWrite(step10,trede[10]);
analogWrite(step11,trede[11]);
analogWrite(step12,trede[12]);
analogWrite(step13,trede[13]);
// extend or reduce this code for number of steps on your stairs.
}
else{
analogWrite(step0,((int)(trede[0]*Brightness)));
analogWrite(step1,((int)(trede[1]*Brightness)));
analogWrite(step2,((int)(trede[2]*Brightness)));
analogWrite(step3,((int)(trede[3]*Brightness)));
analogWrite(step4,((int)(trede[4]*Brightness)));
analogWrite(step5,((int)(trede[5]*Brightness)));
analogWrite(step6,((int)(trede[6]*Brightness)));
analogWrite(step7,((int)(trede[7]*Brightness)));
analogWrite(step8,((int)(trede[8]*Brightness)));
analogWrite(step9,((int)(trede[9]*Brightness)));
analogWrite(step10,((int)(trede[10]*Brightness)));
analogWrite(step11,((int)(trede[11]*Brightness)));
analogWrite(step12,((int)(trede[12]*Brightness)));
analogWrite(step13,((int)(trede[13]*Brightness)));
// extend or reduce this code for number of steps on your stairs.
}


//Check if stairs is FullOn...
FullOn = true;
switch(Mode){
case 0: // FULL ON check for mode 0
for(F = 0; F <= Max; F++){
if (tredeA[F] < 255){
FullOn = false;
}
if ((F == Max)&&(FullOn)){
// Serial.println("Full ON!");
StartUpDown = false;
StartDownUp = false;
}
}
break;
case 1: // FULL ON check for mode 1
for(F = 0; F <= Max; F++){
if (tredeB[F] < 255){
FullOn = false;
}
if ((F==Max)&&(FullOn)){
// Serial.println("Full ON!");
StartUpDown = false;
StartDownUp = false;
}
}
break;
}

delay(LoopDelay);
OldSensUp = SensUp;
OldSensDown = SensDown;




/* (debug info. Used when debugging to understand code functionality.
if (test > 200){

Serial.println("LuxVal:");
Serial.println(LuxVal);
Serial.println("Brightness:");
Serial.println(Brightness);
Serial.println("VarioVal:");
Serial.println(VarioVal);
Serial.println("BrightSteady:");
Serial.println(BrightSteady);

Serial.println("StartDU:");
Serial.println(StartDownUp);
Serial.println("StartUD:");
Serial.println(StartUpDown);
Serial.println("StopDU:");
Serial.println(StopDownUp);
Serial.println("StopUD:");
Serial.println(StopUpDown);
Serial.println("FullOn:");
Serial.println(FullOn);
test = 0;
}
test++;
*/

// END OF MAIN LOOP
}

/*
* function checking if a Step is ON halfway the tetris 'fall'.
*/
bool CLS_Tetris(int Check[Max]){
bool result = false;
int temp = Max;

for(int i= 0; i <= Max; i++){
if ((Check[i] == ON)&&(i < Max)){ // "< max" is to stop checking after 12, because Max is Top step; if that is ON, result is
if((i - temp) > 1){ // gap between 2 ON steps. = loose step.
return true;
}
else{
temp = i;
}
}
else{
result = false;
}
if ((i == Max) && (temp != Max) && (temp != 0)){ // if only 1 step is ON, also return true when step is not 0 or Max (end points)
return true;
}
}
return result;
}

/*
* Check the Illumination in the room using LDR input.
* for values above 100 return value will increase faster.
* Return the value in float format 0.0 - 1.0
*/
float Check_Illumination(bool NonLinear){
float result = 1.0;
float Lumi = 0;
int Lcalc = 0;

Lumi = (analogRead(LuxPin)/4); // read LDR /4 because value can be 0 - 1023

if((Lumi > 100)&&(NonLinear)){
Lcalc = (Lumi - 100);
Lumi = (Lumi + (Lcalc*5));
if(Lumi > 255)
Lumi = 255;
}
result = (Lumi/255);
return result;
}

Berichten: 4064
Geregistreerd: 16 Okt 2013, 14:31
Woonplaats: s hertogenbosch

Re: Iemand gezocht om LED verlichting dimmend te maken

Berichtdoor shooter » 24 Jan 2019, 16:30

maak een foto, van de bekabeling en een schema.
paul deelen
shooter@home.nl

Terug naar Overige projecten

Wie is er online?

Gebruikers in dit forum: Geen geregistreerde gebruikers en 15 gasten