Arduino PIR Dimmer Upgrade

Job ID: 39918931

Budget: ₹750 – ₹1,250 INR

I have a basic sketch that switches a light on for five seconds whenever my PIR sensor spots movement. It works, but I now want smoother control over the lamp’s brightness instead of the simple on/off you see below.

```cpp
int pirPin = 2;
int relayPin = 3;
int pirState = LOW;

void setup() {
pinMode(pirPin, INPUT);
pinMode(relayPin, OUTPUT);
Serial.begin(9600);
}

void loop() {
int val = digitalRead(pirPin);
if (val == HIGH) {
digitalWrite(relayPin, HIGH);
Serial.println("Motion detected! Light ON");
delay(5000); // keep light on for 5 seconds
} else {
digitalWrite(relayPin, LOW);
Serial.println("No motion. Light OFF");
}
}
```

Hardware in use
• Arduino (Uno form-factor)
• PIR sensor for motion detection

What I need
• Add light intensity control. Ideally the lamp should fade in to full brightness when motion is detected and fade out when the timer lapses. PWM on a free pin is fine, or a simple MOSFET dimming stage if that’s safer than the current relay.
• Keep the five-second ON period unchanged for now; no additional delay adjustment is necessary.
• Update the sketch, comment the new sections clearly, and include a brief wiring diagram (Fritzing, hand-drawn, or similar) so I can replicate the setup on a breadboard.

Deliverables
1. Revised, fully-commented Arduino sketch (.ino) that compiles without errors in Arduino IDE.
2. Diagram or photo that shows the added dimming hardware.
3. Short note explaining any parts list changes (e.g., MOSFET or transistor model, resistor value).

If you have a neat idea for ramp timing or a safer solid-state approach, let me know—otherwise the job is as described above.