https://github.com/codeadamca/arduino-motion-sensor
A basic script to detect motion using an Arduino and a motion sensor.
https://github.com/codeadamca/arduino-motion-sensor
arduino cplusplus motion-sensor
Last synced: 3 months ago
JSON representation
A basic script to detect motion using an Arduino and a motion sensor.
- Host: GitHub
- URL: https://github.com/codeadamca/arduino-motion-sensor
- Owner: codeadamca
- Created: 2020-10-04T20:51:44.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2025-01-26T22:04:41.000Z (5 months ago)
- Last Synced: 2025-01-26T23:18:03.792Z (5 months ago)
- Topics: arduino, cplusplus, motion-sensor
- Language: C++
- Homepage:
- Size: 98.6 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Arduino and a Motion Sensor
A basic example of reacting to the status of a motion sensor using an Arduino and the built-in LED.
## Arduino Code
Open up [Arduino Create](https://create.arduino.cc/editor/) and add the following code:
```csharp
// Define a variable to store the pin number
int motionPin = 2;// The setup function runs once when you press reset or power the board
void setup(){Serial.begin(9600);
pinMode(motionPin, INPUT);pinMode(LED_BUILTIN, OUTPUT);
}
// The loop function runs over and over again forever
void loop (){// Add a delay between each loop
delay(1000);// Fetch the current motion sensor status
int motionResult = digitalRead(motionPin);// Output the current motion sensor result
Serial.println(motionResult);// Turn the bulit-in LED on or off based on the motino sensor status
if (motionResult == HIGH) {
digitalWrite(LED_BUILTIN, HIGH);
} else {
digitalWrite(LED_BUILTIN, LOW);
}}
```> [View the Arduino code on Arduino Create](https://create.arduino.cc/editor/professoradam/67d42c97-02ab-4f79-9f4b-fd4c3e68fd5c/preview)
You will need to setup the following circuit using your Arduino:

> [View the Circuit on Tinkercad](https://www.tinkercad.com/things/jDkGCF2jfv1)
> Full tutorial URL:
> https://codeadam.ca/learning/arduino-motion-sensor.html***
## Repo Resources
- [Arduino Create](https://create.arduino.cc/editor)