The Keyestudio Motion Sensor is an electronic device that detects motion within its vicinity. It is commonly used in security systems, lighting control, and automation projects. The sensor is often employed in hobbyist projects, particularly those involving Arduino microcontrollers, due to its ease of use and integration capabilities.
Pin Number | Name | Description |
---|---|---|
1 | VCC | Power supply input (4.5V to 20V) |
2 | OUT | Digital output signal (High/Low) |
3 | GND | Ground connection |
// Define the motion sensor pin
const int motionSensorPin = 2; // Connect the OUT pin of the sensor to digital pin 2
// Variable to hold the motion sensor status
int motionStatus = 0;
void setup() {
// Set the motion sensor pin as an input
pinMode(motionSensorPin, INPUT);
// Begin serial communication at a baud rate of 9600
Serial.begin(9600);
}
void loop() {
// Read the status of the motion sensor
motionStatus = digitalRead(motionSensorPin);
// Check if motion was detected
if (motionStatus == HIGH) {
// Motion detected
Serial.println("Motion detected!");
// Add your code here to handle the motion detection event
} else {
// No motion detected
Serial.println("No motion detected.");
}
// Delay for a short period to avoid spamming the serial output
delay(100);
}
Q: Can the sensor be used outdoors? A: The sensor can be used outdoors but should be protected from direct sunlight and water.
Q: How can I adjust the range and delay of the sensor? A: The sensor typically has two potentiometers to adjust the sensitivity (range) and the time delay.
Q: What is the output voltage of the OUT pin when motion is detected? A: The output voltage is typically equal to the VCC supply voltage when motion is detected.
Remember to always follow safety guidelines when working with electronic components and consult the sensor's datasheet for more detailed information.