# UltraSonic of PIR sensor Arduino & Touchdesigner or Isadora

Deze manual werkt voor PIR (passive infrared) bewegings sensor en ook voor de Ultrasonic sensor

Beschrijving PIR sensor (Duits)  
[https://www.reichelt.nl/nl/nl/raspberry-pi-infrarood-bewegingsmelder-hc-sr501-rpi-hc-sr501-p224216.html?PROVID=2809&amp;gclid=CjwKCAjwzJmlBhBBEiwAEJyLu7b6GP911-3vaEA33hXK1vssSrwNGtU83omn4zjNUqw3wLPmZsHYzRoCQnEQAvD\_BwE](https://www.reichelt.nl/nl/nl/raspberry-pi-infrarood-bewegingsmelder-hc-sr501-rpi-hc-sr501-p224216.html?PROVID=2809&gclid=CjwKCAjwzJmlBhBBEiwAEJyLu7b6GP911-3vaEA33hXK1vssSrwNGtU83omn4zjNUqw3wLPmZsHYzRoCQnEQAvD_BwE)   
Detectieafstand: 3-7m

[![PIR-schema(1).jpg](https://bookstack.hku.nl/uploads/images/gallery/2026-02/scaled-1680-/pir-schema1.jpg)](https://bookstack.hku.nl/uploads/images/gallery/2026-02/pir-schema1.jpg)

Code voor PIR sensor:

<div id="bkmrk-%2F%2A-arduino-with-pir-" style="color: #dae3e3; background-color: #1f272a; font-family: Menlo, Monaco, 'Courier New', monospace; font-weight: normal; font-size: 12px; line-height: 18px; white-space: pre;"><div><span style="color: #7f8c8d;">/\* </span></div><div><span style="color: #7f8c8d;"> Arduino with PIR motion sensor</span></div><div><span style="color: #7f8c8d;"> For complete project details, visit: http://RandomNerdTutorials.com/pirsensor</span></div><div><span style="color: #7f8c8d;"> Modified by Rui Santos based on PIR sensor by Limor Fried</span></div><div><span style="color: #7f8c8d;">\*/</span></div><div><span style="color: #dae3e3;"> </span></div><div><span style="color: #0ca1a6;">int</span><span style="color: #dae3e3;"> led = </span><span style="color: #7fcbcd;">13</span><span style="color: #dae3e3;">;</span><span style="color: #7f8c8d;"> // the pin that the LED is atteched to</span></div><div><span style="color: #0ca1a6;">int</span><span style="color: #dae3e3;"> sensor = </span><span style="color: #7fcbcd;">2</span><span style="color: #dae3e3;">;</span><span style="color: #7f8c8d;"> // the pin that the sensor is atteched to</span></div><div><span style="color: #0ca1a6;">int</span><span style="color: #dae3e3;"> state = LOW;</span><span style="color: #7f8c8d;"> // by default, no motion detected</span></div><div><span style="color: #0ca1a6;">int</span><span style="color: #dae3e3;"> val = </span><span style="color: #7fcbcd;">0</span><span style="color: #dae3e3;">;</span><span style="color: #7f8c8d;"> // variable to store the sensor status (value)</span></div>  
<div><span style="color: #0ca1a6;">void</span><span style="color: #dae3e3;"> </span><span style="color: #f39c12;">setup</span><span style="color: #dae3e3;">() {</span></div><div><span style="color: #dae3e3;"> </span><span style="color: #f39c12;">pinMode</span><span style="color: #dae3e3;">(led, OUTPUT);</span><span style="color: #7f8c8d;"> // initalize LED as an output</span></div><div><span style="color: #dae3e3;"> </span><span style="color: #f39c12;">pinMode</span><span style="color: #dae3e3;">(sensor, INPUT);</span><span style="color: #7f8c8d;"> // initialize sensor as an input</span></div><div><span style="color: #dae3e3;"> </span><span style="color: #f39c12;">Serial</span><span style="color: #dae3e3;">.</span><span style="color: #f39c12;">begin</span><span style="color: #dae3e3;">(</span><span style="color: #7fcbcd;">9600</span><span style="color: #dae3e3;">);</span><span style="color: #7f8c8d;"> // initialize serial</span></div><div><span style="color: #dae3e3;">}</span></div>  
<div><span style="color: #0ca1a6;">void</span><span style="color: #dae3e3;"> </span><span style="color: #f39c12;">loop</span><span style="color: #dae3e3;">(){</span></div><div><span style="color: #dae3e3;"> val = </span><span style="color: #f39c12;">digitalRead</span><span style="color: #dae3e3;">(sensor);</span><span style="color: #7f8c8d;"> // read sensor value</span></div><div><span style="color: #dae3e3;"> </span><span style="color: #c586c0;">if</span><span style="color: #dae3e3;"> (val == HIGH) {</span><span style="color: #7f8c8d;"> // check if the sensor is HIGH</span></div><div><span style="color: #dae3e3;"> </span><span style="color: #f39c12;">digitalWrite</span><span style="color: #dae3e3;">(led, HIGH);</span><span style="color: #7f8c8d;"> // turn LED ON</span></div><div><span style="color: #dae3e3;"> </span><span style="color: #f39c12;">delay</span><span style="color: #dae3e3;">(</span><span style="color: #7fcbcd;">100</span><span style="color: #dae3e3;">);</span><span style="color: #7f8c8d;"> // delay 100 milliseconds </span></div><div><span style="color: #dae3e3;"> </span></div><div><span style="color: #dae3e3;"> </span><span style="color: #c586c0;">if</span><span style="color: #dae3e3;"> (state == LOW) {</span></div><div><span style="color: #dae3e3;"> </span><span style="color: #f39c12;">Serial</span><span style="color: #dae3e3;">.</span><span style="color: #f39c12;">println</span><span style="color: #dae3e3;">(</span><span style="color: #7fcbcd;">"1"</span><span style="color: #dae3e3;">); </span></div><div><span style="color: #dae3e3;"> state = HIGH;</span><span style="color: #7f8c8d;"> // update variable state to HIGH</span></div><div><span style="color: #dae3e3;"> }</span></div><div><span style="color: #dae3e3;"> } </span></div><div><span style="color: #dae3e3;"> </span><span style="color: #c586c0;">else</span><span style="color: #dae3e3;"> {</span></div><div><span style="color: #dae3e3;"> </span><span style="color: #f39c12;">digitalWrite</span><span style="color: #dae3e3;">(led, LOW);</span><span style="color: #7f8c8d;"> // turn LED OFF</span></div><div><span style="color: #dae3e3;"> </span><span style="color: #f39c12;">delay</span><span style="color: #dae3e3;">(</span><span style="color: #7fcbcd;">200</span><span style="color: #dae3e3;">);</span><span style="color: #7f8c8d;"> // delay 200 milliseconds </span></div><div><span style="color: #dae3e3;"> </span></div><div><span style="color: #dae3e3;"> </span><span style="color: #c586c0;">if</span><span style="color: #dae3e3;"> (state == HIGH){</span></div><div><span style="color: #dae3e3;"> </span><span style="color: #f39c12;">Serial</span><span style="color: #dae3e3;">.</span><span style="color: #f39c12;">println</span><span style="color: #dae3e3;">(</span><span style="color: #7fcbcd;">"0"</span><span style="color: #dae3e3;">);</span></div><div><span style="color: #dae3e3;"> state = LOW;</span><span style="color: #7f8c8d;"> // update variable state to LOW</span></div><div><span style="color: #dae3e3;"> }</span></div><div><span style="color: #dae3e3;"> }</span></div><div><span style="color: #dae3e3;">}</span></div></div>  
Test of het werkt:

maak in Arduino verbinding met de Arduino door de juiste board en poort te kiezen, Board: Arduino Uno &amp; poort Mac: /dev/cu.usbmodem1301 Serial Port (USB), Poort PC: COM3

installeer de code op de Arduino door links bovenin op het pijltje te drukken.  
test de code en setup door rechts boveninn op het vergrootglaasje te drukken.  
werkt het niet neem contact op met Blackbox medewerker voor een check van je setup.

Data ontvangen in Isadora:  
Zet serial monitor in Arduino uit  
gebruik de actor: serial in watcher text

verander de instelling van de serial in watcher actor:  
open de actor by double klikking it and fill in this code : **value:int=eol**  
in actor put **eom** **char** on **10**

[![Screenshot 2025-01-14 at 10.48.07.png](https://bookstack.hku.nl/uploads/images/gallery/2025-01/scaled-1680-/screenshot-2025-01-14-at-10-48-07.png)](https://bookstack.hku.nl/uploads/images/gallery/2025-01/screenshot-2025-01-14-at-10-48-07.png)

  
Zet verbinding met Arduino aan:   
1 menu &gt; communications &gt; serial port setup   
2 Port 1 &gt; Device &gt; Select &gt; kies USB poort  
Als Isadora de poort niet laat zien of zegt dat hij Busy is kies dan None en daarna weer de USB poort. &gt; OK  
Menu &gt; communications &gt; Enable serial ports

[![Screenshot 2025-01-14 at 10.52.26.png](https://bookstack.hku.nl/uploads/images/gallery/2025-01/scaled-1680-/screenshot-2025-01-14-at-10-52-26.png)](https://bookstack.hku.nl/uploads/images/gallery/2025-01/screenshot-2025-01-14-at-10-52-26.png) [![Screenshot 2025-01-14 at 10.51.58.png](https://bookstack.hku.nl/uploads/images/gallery/2025-01/scaled-1680-/screenshot-2025-01-14-at-10-51-58.png)](https://bookstack.hku.nl/uploads/images/gallery/2025-01/screenshot-2025-01-14-at-10-51-58.png)  
  
Aan de rechterkant van de serial in watcher actor zou de waarde in msg rcv moeten veranderen van - naar X   
En value moet veranderen van 0 naar 1  
  
Voorbeeld Isadora met een video:

[![Screenshot 2026-02-26 at 12.33.32.png](https://bookstack.hku.nl/uploads/images/gallery/2026-02/scaled-1680-/screenshot-2026-02-26-at-12-33-32.png)](https://bookstack.hku.nl/uploads/images/gallery/2026-02/screenshot-2026-02-26-at-12-33-32.png)

\--------------------------------

Beschrijving ultrasonic sensor:  
[https://randomnerdtutorials.com/complete-guide-for-ultrasonic-sensor-hc-sr04/](https://randomnerdtutorials.com/complete-guide-for-ultrasonic-sensor-hc-sr04/)  
Detectieafstand: 2cm tot 400cm  
Werkt goed op solid surface, stoffen zoals kleding is minder accuraat.

Installatie Ultrasonic sensor check volgende tutorial &gt;&gt;&gt;

Data &gt; touchdesigner:  
[https://www.youtube.com/watch?v=lkudxFrwPXU](https://www.youtube.com/watch?v=lkudxFrwPXU)

Let op als je in Touchdesigner of Isadora de input wilt testen dan moet je in Arduino je Serial Monitor uitzetten.  
Anders kan de software niet communiceren met de Arduino .

<div id="bkmrk--3" style="color: #dae3e3; background-color: #1f272a; font-family: Menlo, Monaco, 'Courier New', monospace; font-weight: normal; font-size: 12px; line-height: 18px; white-space: pre;"><div>  
</div></div>Deze tutorial is getest door Simone van Dordrecht (Blackbox medewerker IBB)