Update serial.mdx

add arduino .ino code
tested with arduini mini pro with pir sensor connected to pin 2
This commit is contained in:
Delorean 2023-07-13 23:50:55 +02:00 committed by GitHub
parent 9ed7799ab8
commit d4bb6ef727
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -245,3 +245,30 @@ while True:
time.sleep(30)
time.sleep(0.5)
```
#### Circuit .ino Code
```
int LED = 13; // the pin that the LED is atteched to
int PIR = 2; // the pin that the sensor is atteched to
void setup() {
pinMode(LED, OUTPUT); // initalize LED as an output
pinMode(PIR, INPUT); // initialize sensor as an input
Serial.begin(9600); // initialize serial
}
void loop(){
if (digitalRead(PIR) == HIGH) { // check if the sensor is HIGH
digitalWrite(LED, HIGH); // turn LED ON
Serial.write(":Motion!:");
delay(10000); // delay 100 milliseconds
}
else {
digitalWrite(LED, LOW); // turn LED OFF
Serial.write("Motion stopped!");
delay(10000); // delay 100 milliseconds
}
}
```
```