# TIP120 LED strip dimming with flickering problem + questions delay

I need some help with my Arduino program.

Let me introduce the hardware and the goal.

• There is two white LED strip each one of them are controlled by TIP120 transistor.

• There is an potentiometer to set-up manually the full brightness value of the fade effect.

So, when The PIR sensor detect an human the first LED stip fade effect to the maximum brightness thanks to the potentiometer value read before. The second one has its fade-in effect just after the first LED strip.

The LED strips are on for 6 seconds after power on and each are extinguished with fadeout effect.

Problem:

When the first LED strip finish to fade-out it stays slightly on. How to fix this?

Video to show the problem:

https://imgur.com/a/Uf3pZbC

Moreover I noticed below the value 100 for fade-in/fade-out, the LED strips flickering slightly, how to fix that?

Delay question:

-As you can see there is an little delay for the second LED strip power. How to remove this delay and power it directly when the first LED strip have finish his fadein?

• I would like to know, how to start the second LED strip at the same time like the first one but with a difference of a second than the first.

If you have any suggestion to improve my code you are welcome!

The code:

int PIR = 4;              // the pin that the sensor is atteched to
int TR = 3;               // the pin that the TIP 120 Base is atteched to for the first led strip
int TRB = 5;              // the pin that the TIP 120 Base is atteched to for the second led strip
int ledDelay = 5000;          //time to wait untill light switch off
int pwm;

void setup() {
pinMode(PIR, INPUT);    // initialize sensor as an input
pinMode(TR, OUTPUT);    // initialize TIP 120 as an output
pinMode(TRB, OUTPUT);   // initialize TIP 120 as an output
Serial.begin(9600);     // initialize serial
}

void loop(){
pwm = map(pwm, 0, 1023, 0, 255);
Serial.println(pwm);
if (digitalRead(PIR) == HIGH) { // check if the sensor is HIGH
Serial.println("Motion detected!");

// sets the value (range from 0 to 255):
// wait for 60 milliseconds to see the dimming effect
delay(60);  // turn LED ON
}

delay(100);
///

// sets the value (range from 0 to 255):
// wait for 60 milliseconds to see the dimming effect
delay(60);
}
delay(100);

///
delay(ledDelay); //time to wait untill light switch off
// sets the value (range from 0 to 255):
// wait for 60 milliseconds to see the dimming effect
delay(60);
}
// sets the value (range from 0 to 255):
// wait for 60 milliseconds to see the dimming effect
delay(60);
}
}

else {
digitalWrite(TR, LOW);       // turn LED 1 OFF
digitalWrite(TRB, LOW);       // turn LED 2 OFF
Serial.println("Motion stopped!");
delay(100);                   // delay 100 milliseconds
}
}


Picture of schematic

Note :

• The led strip I used are 5V 3528 warm white not rgb
• Power supply of led strip is a step down converter on 12V battery(setting on 5V 2A).
• Please provide a schematic for you circuit – mike65535 Sep 17 '20 at 12:17
• Welcome to EE.SE! "introduce the hardware" This is where a schematic comes in. EE talks in schematics. If you click on edit and the schematic symbol, a competent schematics editor will open up. If you already have one from your e-CAD of choise, please post a picture of that. – winny Sep 17 '20 at 14:07
• Schematic added, please check :) – Cypf Sep 17 '20 at 14:56
• Tinkercad is not a schematic, and your tinkercad does not even match what you show in your video. I see issues in the tinkercad (e.g. resistors are shorted) that don't appear to be an issue in real life. – mbedded Sep 17 '20 at 15:28
• Do you understand your code? Your code sometimes doesn't fade out all the way to 0. The LEDs are just doing what you tell them. The flicker is probably unavoidable though. – user253751 Sep 17 '20 at 17:11