write code for arduino, i want it to have a PIR sensor in PWM3,that sensor shoudl…
- User
write code for arduino, i want it to have a PIR sensor in PWM3,that sensor shoudl trigger PWM 13 if motion is detected
Assistant
Here's Arduino code for a PIR motion sensor that triggers pin 13 when motion is detected:
// PIR Motion Sensor Code const int pirPin = 3; // PIR sensor connected to digital pin 3 const int outputPin = 13; // Output pin (built-in LED on most Arduinos) void setup() { // Initialize pins pinMode(pirPin, INPUT); pinMode(outputPin, OUTPUT); // Initialize serial communication for debugging Serial.begin(9600); Serial.println("PIR Motion Sensor Ready"); // Give the sensor time to calibrate delay(2000); } void loop() { // Read the PIR sensor int motionDetected = digitalRead(pirPin); if (motionDetected == HIGH) { // Motion detected digitalWrite(outputPin, HIGH); // Turn on pin 13 Serial.println("Motion detected! Pin 13 activated"); } else { // No motion digitalWrite(outputPin, LOW); // Turn off pin 13 } // Small delay to avoid excessive readings delay(100); }
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.