PIR sensor example 2 Serial to Isadora
INSTRUCTIONS FOR:
PIR Motion sensor HW-416
DESCRIPTION:
A PIR (Passive Infrared) sensor like the HW-416 is typically used to detect motion by
sensing changes in infrared radiation in its surroundings. These sensors are widely used
in security systems, automatic lighting, and similar applications where detecting
human presence or movement is required
SOURCE:
https://bookstack.hku.nl/books/arduino-things/page/ultrasonic-of-pir-sensor-arduino-
touchdesigner-or-isadora
MATERIALS NEEDED:
- Arduino
- PIR Motion sensor HW-416
- Jumper wires (M/F)
Step 1: CONNECTING (as seen in photo):
- VCC (Red) -> 5V
- OUTPUT (Yellow) -> Digital Pin 2
- GND (Black) -> GND
Step 2: ARDUINO CODE:
1. Paste in the code (gray) below in the Arduino IDE, after selecting the right board and
port, and upload it (the end of the code is marked with the final "}" )
2. After you uploaded it, open up the Serial Monitor in the Arduino IDE to check if it is
working. (the icon all the way on the right of the green bar). Set the baud rate to 9600.
/*
Arduino with PIR motion sensor
For complete project details, visit: http://RandomNerdTutorials.com/pirsensor
Modified by Rui Santos based on PIR sensor by Limor Fried
*/
int sensor = 2; // the pin that the sensor is atteched to
int state = LOW; // by default, no motion detected
int val = 0; // variable to store the sensor status (value)
void setup() {
pinMode(sensor, INPUT); // initialize sensor as an input
Serial.begin(9600); // initialize serial
}
void loop(){
val = digitalRead(sensor); // read sensor value
if (val == HIGH) { // check if the sensor is HIGHif (state == LOW) {
Serial.println("1");
state = HIGH; // update variable state to HIGH
}
}
else {
if (state == HIGH){
Serial.println("0");
state = LOW; // update variable state to LOW
}
}
}
Step 3: ISADORA CODE:
1. In the Arduino IDE, close the Serial Monitor by clicking on the same icon again, after
you've confirmed that the code is working. If you don't shut down the Serial Monitor,
your Arduino won't be visible in Isadora.
Step 2: In Isadora, in the top bar, click on Communications -> Enable Serial Ports. Then
afterwards, again on Communication -> Serial Port Setup... Under Port 1, next to Device,
select the usbmodem11401 or similar, or on Windows select COM3 or similar. This is
your arduino.
Step 3: Create a Serial in watcher - Text. Edit 'eom char' to be 10. Double click the actor
and paste in the following code:
value:int=#
5. Finally, use the Limit-Scale value actor to translate the serial data into usable values