Hi guys , I'm new here and just got a problem
My homework is to control brightness of a LED, use RCWL-0516 Doppler Radar Sensor module
- when detect movement, Arduino will control a LED by PWM, the LED will Fade ON.
- the LED will keep light up with brightest condition until no movement detected => LED turn off.
My problem here is that can't keep the LED brightest, it loop again and again.
Here is my schematic and code.
int led=11;
int brightness=0;
int fade=5;
const int motionpin=A0;
int motionsensvalue;
void setup()
{
pinMode(led, OUTPUT);
pinMode(motionpin, INPUT);}
void loop()
{
motionsensvalue=analogRead(motionpin);
if((motionsensvalue>=200)&& brightness<255)
{
analogWrite(led,brightness);
brightness=brightness+fade;
if(brightness>=255)
{
fade=0;
}delay(100);
}
else
{
analogWrite(led, 0);
}
}