How to creat PWM to control LED and stay still with brightest ?

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);
}
}

arduino.png

You need a resistor in series with that LED, without it you are damaging the Arduino pin.

You have the output of your sensor going into digital pin 8, yet your software reads analogue pin 0. Reading an analogue pin with nothing attached to it will give you random values as it is picking up interference signals from the mains and other radiation.

Thank you for your comment!
So sorry because i attached an old picture.
Could you please base on my code, and guide me somthing follow my homework requirement?

khoaptit:
Could you please base on my code, and guide me somthing follow my homework requirement?

Not until you have posted a schematic. Code means nothing without knowing what the hardware is.