# Distance & movement sensors

Various sensors that can used with microcontrollers to track persons, objects, colours or other distance.

# Motion Tracking with Sensors for Microcontrollers

Research by Blackbox into various sensors that can used with microcontrollers to track persons, objects, colours or other motions. What kind of differents sensors are there to use and what are the pro’s and con’s of each sensor?

#### **Sensors of Interest:**

Sensing Distance and Proximity:

- **Ultrasonic Sensor**
- **Infrared Sensors / IR  
    [Infrared (IR) break-beam](https://bookstack.hku.nl/books/arduino-things/page/infrared-ir-break-beam-sensor)**
- **PIR Motion Sensor**
- **Microwave Doppler Radar Sensor**
- **Grove IR Disctance interrupter**

More advanced sensing:

- **LiDAR,<span class="Apple-converted-space"> </span>**
- **ToF, Time-of-flight sensors**
- **HuskyLens AI Vision**

Can also be used:

- **LDR Photocell sensors**
- **Capacitance sensors**
- **PhotoDiodes**

##### **Ultrasonic Sensor<span class="Apple-converted-space"> </span>**

[![grove-ultrasonic-distance-sensor-preview_1-1-1030x773.png](https://bookstack.hku.nl/uploads/images/gallery/2023-04/scaled-1680-/grove-ultrasonic-distance-sensor-preview-1-1-1030x773.png)](https://bookstack.hku.nl/uploads/images/gallery/2023-04/grove-ultrasonic-distance-sensor-preview-1-1-1030x773.png)

##### [**Example project**](https://bookstack.hku.nl/books/arduino-things/page/ultrasonic-of-pir-sensor-arduino-touchdesigner)

The Ultrasonic Sensor is arguably the most common distance measuring sensor, also known as the Sonar sensor. It detects the distance to objects by emitting high-frequency sound waves. The object needs to be in line with the sensors not so wide range. Used a lot in DIY distance measurement projects, robotics, smart cars, drones. Most common used sensor is the *HC-SR04.*

**+**

- not affected by colour object or transparency.
- Works well in dim places

**-<span class="Apple-converted-space"> </span>**

- limited detection range
- Not good in tracking fast objects
- Unable to measure objects with extreme textures or surfaces.

Detection is good for example; knowing if someone ‘entered’ the space and switch on video. Not so good for when you want one or multiple persons tracked.<span class="Apple-converted-space"> </span>


[![Screenshot 2023-04-25 at 15.54.47.png](https://bookstack.hku.nl/uploads/images/gallery/2023-04/scaled-1680-/screenshot-2023-04-25-at-15-54-47.png)](https://bookstack.hku.nl/uploads/images/gallery/2023-04/screenshot-2023-04-25-at-15-54-47.png)

#####   


##### **Infrared Sensor (IR) <span class="Apple-converted-space"> </span>**

##### **<span class="Apple-converted-space">[![Screenshot 2023-04-25 at 15.54.51.png](https://bookstack.hku.nl/uploads/images/gallery/2023-04/scaled-1680-/screenshot-2023-04-25-at-15-54-51.png)](https://bookstack.hku.nl/uploads/images/gallery/2023-04/screenshot-2023-04-25-at-15-54-51.png)  
  
[Example project](https://www.makerguides.com/sharp-gp2y0a21yk0f-ir-distance-sensor-arduino-tutorial/)  
</span>**

IR distance sensors work through the principle of triangulation; measuring distance based on the angle of the reflected beam. Used a lot in TV’s, computers and laptops, distance measurement projects, security systems, monitoring and control applications.

Recommended sensor: *80cm Infrared Proximity Sensor - GP2Y0A21YK*

**+**

- Small size
- Daytime and Nighttime usage
- Able to measure the distance of objects that have complex surfaces unlike ultrasonic sensors

**-**

- Limited measurement range
- Affected by environment conditions and hard objects

[![Screenshot 2023-04-25 at 15.55.03.png](https://bookstack.hku.nl/uploads/images/gallery/2023-04/scaled-1680-/screenshot-2023-04-25-at-15-55-03.png)](https://bookstack.hku.nl/uploads/images/gallery/2023-04/screenshot-2023-04-25-at-15-55-03.png)

#### **PIR Motion Sensor**

#### **<span class="Apple-converted-space">[![Screenshot 2023-04-25 at 15.54.55.png](https://bookstack.hku.nl/uploads/images/gallery/2023-04/scaled-1680-/screenshot-2023-04-25-at-15-54-55.png)](https://bookstack.hku.nl/uploads/images/gallery/2023-04/screenshot-2023-04-25-at-15-54-55.png)</span>**

#### **<span class="Apple-converted-space">[Example project](https://bookstack.hku.nl/books/arduino-things/page/ultrasonic-of-pir-sensor-arduino-touchdesigner) </span>**

Passive infrared (PIR) sensors are sensitive to infrared (IR) rays and are mostly used for motion detection where humans move in or out of the sensor range.

Used a lot in appliances and gadgets for home or business (room detection). Also in DIY projects.

All living objects, whose body temperature is more than 0°C, emit the heat in form of infrared radiation through their body, also called as thermal radiations. This Radiated energy is invisible to human eye. These Signals can be detected by using PIR sensor which is specially designed for such purpose.

<figure class="image" id="bkmrk-grid-eye-illusion">![Grid Eye Illusion](https://www.electronicwings.com/storage/PlatformSection/TopicContent/121/description/1_Grid_Eye_Illusion.PNG)<figcaption>Grid eye illusion</figcaption></figure>**PIR sensor i.e. Passive Infrared Sensor**, passive word indicates PIR Sensor does not generate or radiate any energy for detection purposes. PIR Sensors don't detect or measure "**HEAT**"; they detect the infrared radiation emitted or reflected from objects.They are small, inexpensive, low power and easy to use. They are commonly found at home, medical, factories etc. areas.

[Link to more info about PIR sensors](https://www.electronicwings.com/sensors-modules/pir-sensor)


##### **Microwave Doppler Radar Sensor**

**[![Screenshot 2023-04-25 at 16.00.00.png](https://bookstack.hku.nl/uploads/images/gallery/2023-04/scaled-1680-/screenshot-2023-04-25-at-16-00-00.png)](https://bookstack.hku.nl/uploads/images/gallery/2023-04/screenshot-2023-04-25-at-16-00-00.png)**

<span class="Apple-converted-space">For most of our Arduino projects that require knowing if someone has left or entered the area, the [PIR sensor](https://lastminuteengineers.com/pir-sensor-arduino-tutorial/) is an excellent choice. However, because they only detect movement from living things, they will generate fewer false alarms.</span>

<span class="Apple-converted-space">This is where a microwave sensor like the RCWL-0516 comes in handy. The RCWL-0516 microwave sensor detects any movement from any object and does not rely on heat signatures, making it more reliable in hot environments where a PIR sensor may not be as effective.</span>

[More about Doppler Microwave sensors here](https://lastminuteengineers.com/rcwl0516-microwave-radar-motion-sensor-arduino-tutorial/?utm_content=cmp-true)

**[![Screenshot 2023-04-25 at 16.01.44.png](https://bookstack.hku.nl/uploads/images/gallery/2023-04/scaled-1680-/screenshot-2023-04-25-at-16-01-44.png)](https://bookstack.hku.nl/uploads/images/gallery/2023-04/screenshot-2023-04-25-at-16-01-44.png)And a tutorial explaining the <span class="Apple-converted-space">RCWL-0516 Microwave Doppler Radar </span>sensor and running a beginner test can be found [here by CircuitDigest ](https://circuitdigest.com/microcontroller-projects/arduino-rcwl-0516-radar-sensor-interfacing).**


#### **Grove IR Disctance interrupter**

is used to detect any object blocking the path of light. The module consists of an IR LED and a photosensor (phototransistor) pair. The light emitted by the IR LED gets reflected by any object placed in front of the sensor and this reflection is detected by the photosensor(phototransistor). Any white (or lighter) colored surface reflects more than black (or darker) colored surface.

[![IR-dist-intr.png](https://bookstack.hku.nl/uploads/images/gallery/2026-03/scaled-1680-/tPpir-dist-intr.png)](https://bookstack.hku.nl/uploads/images/gallery/2026-03/tPpir-dist-intr.png)

When the reflected light is detected, it produces **Digital HIGH** (or Binary **1**) output on the **SIG** pin. The on-board LED indicator will also glow. If no reflection is detected or if the object is too far from the sensor, the output on the **SIG** pin stays at **Digital LOW** (Binary 0). The on-board LED indicator will be off as well. The detectable range of this sensor is 7.5–40 cm. The module incorporates a Rail-to-Rail Operational Amplifier to amplify the output of phototransistor. There is a potentiometer which can be used to adjust the gain of the amplifier, that is, sensitivity of detection.  
[More info &amp; sample project here](https://bookstack.hku.nl/books/arduino-things/page/grove-ir-distance-interrupter-v12)

####  **Lidar TF Luna  
  
[![TF-Luna_LiDAR_Range_Sensor.png](https://bookstack.hku.nl/uploads/images/gallery/2025-03/scaled-1680-/tf-luna-lidar-range-sensor.png)](https://bookstack.hku.nl/uploads/images/gallery/2025-03/tf-luna-lidar-range-sensor.png)**

TF-Luna is a single-point ranging Lidar based on the TOF principle. With its unique optical and electrical design, it adopts an 850nm infrared light source to achieve stable, accurate, and highly sensitive distance measurements.   
[More information here](https://www.waveshare.com/wiki/TF-Luna_LiDAR_Range_Sensor)

**[Lidar TF Luna Sensor](https://bookstack.hku.nl/books/arduino-things/page/lidar-with-arduino-tf-luna-sensor) example project**

# 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)

# LiDAR with Arduino - TF-Luna Sensor

Als je iets anders wilt dan Ultrasonic Sensor HC-SR04 kwa afstand namelijk meer afstand met minder ruis kun je kiezen voor de TF-Luna Sensor. Dit is een Lidar sensor die met behulp van een laser de afstand tot een object meet tussen 0,2 en 8 meter.  
&gt; De TF Luna LiDAR-afstandsmeter biedt een bereik van 0,2 m-8 m, een resolutie van 1 cm en een nauwkeurigheid van ±6 cm @ (0,2 m-3 m) &lt;

#### **Materiaal:**  
Arduino Nano + USB kabel  
TF-Luna Sensor  
Breadboard  
Jumper wires male/male  
kabel verbinders voor snel testen zonder solderen  


Ik heb om dit aan de praat te krijgen de volgende bron gebruikt:  
[https://www.diyengineers.com/2022/06/02/lidar-how-to-use-with-arduino/](https://www.diyengineers.com/2022/06/02/lidar-how-to-use-with-arduino/)  
  
Op deze site kun je belangrijke documenten downloaden zoals datasheet en user manual maar die heb ik amper nodig gehad.  
[https://en.benewake.com/TFLuna/index.html](https://en.benewake.com/TFLuna/index.html)

Shop:  
[https://eu.robotshop.com/nl/products/benewake-tf-luna-8m-lidar-afstandssensor](https://eu.robotshop.com/nl/products/benewake-tf-luna-8m-lidar-afstandssensor)

  
Wat ik lastig vond bij deze is dat er geen JST GH1.25 - 4P naar Dupont verloopjes bij zaten dus heb ik de kabel gestript en waco verbindingsklemmen gebruikt om te testen. Solderen kan natuurlijk ook maar ook dat was me even teveel werk.  
Kiwi Electronics verkoopt ze met de handige kabels maar niet op voorraad. [https://www.kiwi-electronics.com/nl/tf-mini-s-lidar-module-10359?search=lidar](https://www.kiwi-electronics.com/nl/tf-mini-s-lidar-module-10359?search=lidar)

[![IMG_4943.JPG](https://bookstack.hku.nl/uploads/images/gallery/2025-01/scaled-1680-/uLYimg-4943.JPG)](https://bookstack.hku.nl/uploads/images/gallery/2025-01/uLYimg-4943.JPG)[![pins-arduino-nano.png](https://bookstack.hku.nl/uploads/images/gallery/2025-01/scaled-1680-/pins-arduino-nano.png)](https://bookstack.hku.nl/uploads/images/gallery/2025-01/pins-arduino-nano.png)

Ik heb een Arduino Nano gebruikt. In de tutorial wordt de Arduino Uno gebruikt en voor data overdracht de poorten ICSP2. Volgens bovenstaand schema kan je daarvoor <span style="background-color: rgb(206, 212, 217);">IC2</span> pins <span style="background-color: rgb(251, 238, 184);">Analog A4 &amp; A5 </span>gebruiken.

De 6e kabel hoef je niet te gebruiken.

Installeer Arduino software  
[https://www.arduino.cc/en/software](https://www.arduino.cc/en/software)

Arduino Library:  
[https://github.com/budryerson/TFLuna-I2C](https://github.com/budryerson/TFLuna-I2C)   
Verbind de arduino met mini usb kabel aan je computer, kies links bovenin de Arduino software venster je type arduino board en de usb poort

[![Screenshot 2025-01-06 at 16.32.39.png](https://bookstack.hku.nl/uploads/images/gallery/2025-01/scaled-1680-/screenshot-2025-01-06-at-16-32-39.png)](https://bookstack.hku.nl/uploads/images/gallery/2025-01/screenshot-2025-01-06-at-16-32-39.png)

Volg de aanwijzingen in de tutorial via link bovenaan dit document om de library via Arduino software te installeren.  
Ga bovenin je menu balk in de arduino software naar Tools &gt; Serial Monitor.  
Zet rechts onderin 9600 Baud om naar 115200 Baud, anders krijg je rare resultaten.

Houd je hand boven de lidar sensor en zie de waardes veranderen.  
  
Als je nog info mist in deze uitleg of iets is niet duidelijk laat het me dan weten dan pas ik het aan.  
<Simone.vandordrecht@hku.nl>

### **Voorbeeld project: intensiteit licht LED pixel ring beïnvloeden door afstandmeting Lidar TF Luna sensor** 

**Materiaal:**  
[Neo pixel ring](https://www.kiwi-electronics.com/nl/neopixel-ring-16-x-ws2812-5050-rgb-led-met-drivers-1425) 12 of 16 pixels  
Arduino Nano + USB kabel  
TF-Luna Sensor  
Breadboard  
Jumper wires male/male  
Resistor 330 Ω tot 470 Ω  
Universal AC adapter 5V  
[Terminal block to 2.1mm DC barrel jack - Female](https://www.kiwi-electronics.com/en/terminal-block-to-2-1mm-dc-barrel-jack-female-747)

Bronnen voor testen:  
[https://www.diyengineers.com/2022/06/02/lidar-how-to-use-with-arduino/](https://www.diyengineers.com/2022/06/02/lidar-how-to-use-with-arduino/)  
[https://learn.adafruit.com/adafruit-neopixel-uberguide/arduino-library-installation](https://learn.adafruit.com/adafruit-neopixel-uberguide/arduino-library-installation)  
[https://medium.com/@elonskolnik/arduino-uno-tutorial-neopixel-ring-setup-9fafc099c89a](https://medium.com/@elonskolnik/arduino-uno-tutorial-neopixel-ring-setup-9fafc099c89a)  
[https://chatgpt.com/share/6787fc7b-e388-8006-98cc-3678b193ec44](https://chatgpt.com/share/6787fc7b-e388-8006-98cc-3678b193ec44)  
  
  
**Combineren:**

Soldeer de kabeltjes van de TF Luna aan jumper wires en gebruik krimpkousjes voor bescherming  
Power de Pixelring apart van de Arduino, zorg dat de ground wel doorlust naar de ground van arduino en TF Luna.  
  
[![Screenshot 2025-01-15 at 17.50.41.png](https://bookstack.hku.nl/uploads/images/gallery/2025-01/scaled-1680-/screenshot-2025-01-15-at-17-50-41.png)](https://bookstack.hku.nl/uploads/images/gallery/2025-01/screenshot-2025-01-15-at-17-50-41.png)  
(Duidelijk schema hiervan moet ik nog maken)  
  
Alternatief voor draadloos project: Gebruik een powerbank 5V voor stroom voor de arduino en een batterij pack bijvoorbeeld 4x AA voor de stroom voor pixelring. Foto hiervan volgt..  
Meer info kun je hier vinden:   
https://bookstack.hku.nl/books/arduino-things/page/controlling-ledstrips-with-arduino  
  
**Code:**

<div id="bkmrk-%23include-%3Cadafruit_n" 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: #c586c0;">\#include</span><span style="color: #dae3e3;"> </span><span style="color: #7fcbcd;">&lt;Adafruit\_NeoPixel.h&gt;</span><span style="color: #dae3e3;"> </span><span style="color: #7f8c8d;">//https://github.com/adafruit/Adafruit\_NeoPixel</span></div><div><span style="color: #c586c0;">\#include</span><span style="color: #dae3e3;"> </span><span style="color: #7fcbcd;">&lt;TFLI2C.h&gt;</span><span style="color: #dae3e3;"> </span><span style="color: #7f8c8d;">//https://github.com/budryerson/TFLuna-I2C</span></div><div><span style="color: #c586c0;">\#include</span><span style="color: #dae3e3;"> </span><span style="color: #7fcbcd;">&lt;Wire.h&gt;</span><span style="color: #dae3e3;"> </span><span style="color: #7f8c8d;">// Instantiate the Wire library</span></div>  
<div><span style="color: #c586c0;">\#define</span><span style="color: #dae3e3;"> </span><span style="color: #f39c12;">PIXEL\_PIN</span><span style="color: #dae3e3;"> </span><span style="color: #7fcbcd;">6</span><span style="color: #7f8c8d;"> // Pin verbonden met de NeoPixel-ring</span></div><div><span style="color: #c586c0;">\#define</span><span style="color: #dae3e3;"> </span><span style="color: #f39c12;">NUM\_PIXELS</span><span style="color: #dae3e3;"> </span><span style="color: #7fcbcd;">21</span><span style="color: #7f8c8d;"> // Aantal LEDs op de ring</span></div><div><span style="color: #c586c0;">\#define</span><span style="color: #dae3e3;"> </span><span style="color: #f39c12;">MAX\_BRIGHTNESS</span><span style="color: #dae3e3;"> </span><span style="color: #7fcbcd;">255</span><span style="color: #7f8c8d;"> // Maximale helderheid</span></div><div><span style="color: #c586c0;">\#define</span><span style="color: #dae3e3;"> </span><span style="color: #f39c12;">MIN\_BRIGHTNESS</span><span style="color: #dae3e3;"> </span><span style="color: #7fcbcd;">5</span><span style="color: #7f8c8d;"> // Minimale helderheid</span></div>  
<div><span style="color: #dae3e3;">Adafruit\_NeoPixel strip = </span><span style="color: #f39c12;">Adafruit\_NeoPixel</span><span style="color: #dae3e3;">(NUM\_PIXELS, PIXEL\_PIN, NEO\_RGBW + NEO\_KHZ800);</span><span style="color: #7f8c8d;"> //lees achterop de leds of in de specificaties online welk type het is en pas de informatie hier aan, oorspronkelijk stond GRB in de code maar de ledring is RGBW dus aangepast</span></div><div><span style="color: #dae3e3;">TFLI2C tfLuna;</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;">Wire</span><span style="color: #dae3e3;">.</span><span style="color: #f39c12;">begin</span><span style="color: #dae3e3;">();</span></div><div><span style="color: #dae3e3;"> </span><span style="color: #f39c12;">Wire</span><span style="color: #dae3e3;">.</span><span style="color: #f39c12;">setClock</span><span style="color: #dae3e3;">(</span><span style="color: #7fcbcd;">100000</span><span style="color: #dae3e3;">);</span><span style="color: #7f8c8d;"> // Stel I2C-snelheid in op 100 kHz</span></div>  
  
<div><span style="color: #dae3e3;"> </span><span style="color: #f39c12;">strip</span><span style="color: #dae3e3;">.</span><span style="color: #f39c12;">begin</span><span style="color: #dae3e3;">();</span></div><div><span style="color: #dae3e3;"> </span><span style="color: #f39c12;">strip</span><span style="color: #dae3e3;">.</span><span style="color: #f39c12;">show</span><span style="color: #dae3e3;">();</span><span style="color: #7f8c8d;"> // Zorgt ervoor dat alle pixels uit staan</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></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;">"Start setup"</span><span style="color: #dae3e3;">);</span></div><div><span style="color: #dae3e3;"> </span><span style="color: #f39c12;">delay</span><span style="color: #dae3e3;">(</span><span style="color: #7fcbcd;">1000</span><span style="color: #dae3e3;">);</span></div>  
<div><span style="color: #7f8c8d;"> // Probeer verbinding met de TF-Luna</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;">"Verbinding met TF-Luna..."</span><span style="color: #dae3e3;">);</span></div>  
<div><span style="color: #dae3e3;"> </span><span style="color: #0ca1a6;">uint16\_t</span><span style="color: #dae3e3;"> frameRate;</span></div><div><span style="color: #dae3e3;"> </span><span style="color: #c586c0;">if</span><span style="color: #dae3e3;"> (</span><span style="color: #f39c12;">tfLuna</span><span style="color: #dae3e3;">.</span><span style="color: #f39c12;">Get\_Frame\_Rate</span><span style="color: #dae3e3;">(frameRate, TFL\_DEF\_ADR)) {</span></div><div><span style="color: #dae3e3;"> </span><span style="color: #f39c12;">Serial</span><span style="color: #dae3e3;">.</span><span style="color: #f39c12;">print</span><span style="color: #dae3e3;">(</span><span style="color: #7fcbcd;">"Frame rate: "</span><span style="color: #dae3e3;">);</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;">(frameRate);</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;">Serial</span><span style="color: #dae3e3;">.</span><span style="color: #f39c12;">println</span><span style="color: #dae3e3;">(</span><span style="color: #7fcbcd;">"Kon frame rate niet ophalen. Controleer de verbinding."</span><span style="color: #dae3e3;">);</span></div><div><span style="color: #dae3e3;"> }</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;"> </span><span style="color: #0ca1a6;">int16\_t</span><span style="color: #dae3e3;"> distance = </span><span style="color: #7fcbcd;">0</span><span style="color: #dae3e3;">;</span></div>  
<div><span style="color: #7f8c8d;"> // Haal de afstand op van de TF-Luna</span></div><div><span style="color: #dae3e3;"> </span><span style="color: #c586c0;">if</span><span style="color: #dae3e3;"> (</span><span style="color: #f39c12;">tfLuna</span><span style="color: #dae3e3;">.</span><span style="color: #f39c12;">getData</span><span style="color: #dae3e3;">(distance, TFL\_DEF\_ADR)) {</span></div><div><span style="color: #7f8c8d;"> // Bepaal helderheid op basis van afstand</span></div><div><span style="color: #dae3e3;"> </span><span style="color: #0ca1a6;">int</span><span style="color: #dae3e3;"> brightness = </span><span style="color: #f39c12;">map</span><span style="color: #dae3e3;">(distance, </span><span style="color: #7fcbcd;">10</span><span style="color: #dae3e3;">, </span><span style="color: #7fcbcd;">100</span><span style="color: #dae3e3;">, MAX\_BRIGHTNESS, MIN\_BRIGHTNESS);</span><span style="color: #7f8c8d;"> // 10 staat voor minimale afstand, 100 staat voor maximale in cm, past dit aan als je meer of minder afstand nodig hebt</span></div><div><span style="color: #dae3e3;"> brightness = </span><span style="color: #f39c12;">constrain</span><span style="color: #dae3e3;">(brightness, MIN\_BRIGHTNESS, MAX\_BRIGHTNESS);</span></div>  
<div><span style="color: #7f8c8d;"> // Stel helderheid in en kleur de LEDs</span></div><div><span style="color: #dae3e3;"> </span><span style="color: #f39c12;">strip</span><span style="color: #dae3e3;">.</span><span style="color: #f39c12;">setBrightness</span><span style="color: #dae3e3;">(brightness);</span></div><div><span style="color: #dae3e3;"> </span><span style="color: #c586c0;">for</span><span style="color: #dae3e3;"> (</span><span style="color: #0ca1a6;">int</span><span style="color: #dae3e3;"> i = </span><span style="color: #7fcbcd;">0</span><span style="color: #dae3e3;">; i &lt; NUM\_PIXELS; i++) {</span></div><div><span style="color: #dae3e3;"> </span><span style="color: #f39c12;">strip</span><span style="color: #dae3e3;">.</span><span style="color: #f39c12;">setPixelColor</span><span style="color: #dae3e3;">(i, </span><span style="color: #f39c12;">strip</span><span style="color: #dae3e3;">.</span><span style="color: #f39c12;">Color</span><span style="color: #dae3e3;">(</span><span style="color: #7fcbcd;">0</span><span style="color: #dae3e3;">, </span><span style="color: #7fcbcd;">255</span><span style="color: #dae3e3;">, </span><span style="color: #7fcbcd;">255</span><span style="color: #dae3e3;">, </span><span style="color: #7fcbcd;">0</span><span style="color: #dae3e3;">));</span><span style="color: #7f8c8d;"> // Pas hier de kleur aan, volgorde = G, R, B, W (vreemd, klopt niet met de info van de ring maar het werkt)</span></div><div><span style="color: #dae3e3;"> }</span></div><div><span style="color: #dae3e3;"> </span><span style="color: #f39c12;">strip</span><span style="color: #dae3e3;">.</span><span style="color: #f39c12;">show</span><span style="color: #dae3e3;">();</span></div>  
<div><span style="color: #7f8c8d;"> // Print de afstand en helderheid naar de Serial Monitor</span></div><div><span style="color: #dae3e3;"> </span><span style="color: #f39c12;">Serial</span><span style="color: #dae3e3;">.</span><span style="color: #f39c12;">print</span><span style="color: #dae3e3;">(</span><span style="color: #7fcbcd;">"Afstand: "</span><span style="color: #dae3e3;">);</span></div><div><span style="color: #dae3e3;"> </span><span style="color: #f39c12;">Serial</span><span style="color: #dae3e3;">.</span><span style="color: #f39c12;">print</span><span style="color: #dae3e3;">(distance);</span></div><div><span style="color: #dae3e3;"> </span><span style="color: #f39c12;">Serial</span><span style="color: #dae3e3;">.</span><span style="color: #f39c12;">print</span><span style="color: #dae3e3;">(</span><span style="color: #7fcbcd;">" cm, Helderheid: "</span><span style="color: #dae3e3;">);</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;">(brightness);</span></div><div><span style="color: #dae3e3;"> } </span><span style="color: #c586c0;">else</span><span style="color: #dae3e3;"> {</span></div><div><span style="color: #7f8c8d;"> // Geef een foutmelding als de data niet kan worden opgehaald</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;">"Fout bij ophalen afstandsgegevens."</span><span style="color: #dae3e3;">);</span></div><div><span style="color: #dae3e3;"> </span><span style="color: #f39c12;">tfLuna</span><span style="color: #dae3e3;">.</span><span style="color: #f39c12;">printStatus</span><span style="color: #dae3e3;">();</span><span style="color: #7f8c8d;"> // Laat de foutstatus zien</span></div><div><span style="color: #dae3e3;"> }</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;"> // Kleine pauze voor de volgende meting</span></div><div><span style="color: #dae3e3;">}</span></div>  
</div>

# Grove - IR Distance Interrupter v1.2

[![IR-dist-intr.png](https://bookstack.hku.nl/uploads/images/gallery/2026-03/scaled-1680-/ir-dist-intr.png)](https://bookstack.hku.nl/uploads/images/gallery/2026-03/ir-dist-intr.png)

**Grove - IR Distance Interrupter** is used to detect any object blocking the path of light.  
The light emitted by the IR LED gets reflected by any object placed in front of the sensor and this reflection is detected by the photosensor(phototransistor). Any white (or lighter) colored surface reflects more than black (or darker) colored surface.  
  
You can borrow this sensor for testing from Blackbox workshop employe at location IBB: blackbox.ibb-pastoe@hku.nl

When the reflected light is detected, it produces **Digital HIGH** (or Binary **1**) output on the **SIG** pin. The on-board LED indicator will also glow. If no reflection is detected or if the object is too far from the sensor, the output on the **SIG** pin stays at **Digital LOW** (Binary 0). The on-board LED indicator will be off as well.

The detectable range of this sensor is **7.5–40 cm.**    
There is a potentiometer which can be used to adjust the gain of the amplifier, that is, sensitivity of detection. Use the best fitting scredriver for this and be **very sensitive!**!!

**Note**

This product is mildly **sensitive to non-IR radiations** also and hence any bright light on photosensor impairs or disturbs IR light detection.

#### Material required

- [Grove - IR Distance Interrupter v1.2 × 1](https://www.kiwi-electronics.com/nl/grove-ir-distance-interrupter-v1-2-1889?search=ir%20distance)
- [Arduino UNO](https://www.kiwi-electronics.com/nl/arduino-uno-rev3-atmega328-729?search=arduino%20uno) (other models also are fine) × 1 + [power cable](https://www.kiwi-electronics.com/nl/usb-a-naar-usb-b-kabel-05-meter-763) (sold seperately)
- [Grove cable ](https://www.kiwi-electronics.com/nl/grove-universal-4-pin-unbuckled-20cm-cable-5-pack-1888?search=Grove%20cable%20)× 1 (some sensors come wit cable, different lengths available)
- [Grove - Base Shield × 1](https://www.kiwi-electronics.com/nl/grove-base-shield-voor-arduino-v2-2100?search=base%20shield)

#### Connections

1.Connect Base shield to arduino board Grove, connect IR Distance Interrupter v1.2 to Arduino UNO with Grove cable. port D6

2.Place and hold the Reflective photosensor towards white(or light) colored surface. For adjusting sensitivity [read this](https://wiki.seeedstudio.com/Grove-IR_Distance_Interrupter_v1.2/)

3.Create an Arduino sketch and copy the below code into it.

```
void setup()  {
    Serial.begin(9600);
    pinMode(6,INPUT);
}
void loop()  {
    while(1)  {
        delay(500);
        if(digitalRead(6)==LOW)  {
            Serial.println("Somebody is here.");
        }
        else  {
            Serial.println("Nobody.");
        }
    }
}

```

<div class="language-text codeBlockContainer_ZGJx theme-code-block" id="bkmrk--1" style="--prism-color: #F8F8F2; --prism-background-color: #282A36;"><div class="codeBlockContent_kX1v"><div class="buttonGroup_dke2">  
</div></div></div>5.Connect Arduino to your comuter &amp; Upload the code.  
If you do not know how to upload a Arduino sketch, please visit [https://www.arduino.cc/en/Guide/Windows](https://www.arduino.cc/en/Guide/Windows) for Windows user or [https://www.arduino.cc/en/Guide/MacOSX](https://www.arduino.cc/en/Guide/MacOSX) for Mac user.

6.When the path of light is blocked by some object, you would see "Somebody is here." in Serial Terminal else you will see "Nobody."

##### For connecting with Isadora[ read this](https://bookstack.hku.nl/books/isadora/page/receive-data-from-arduino-in-isadora)  
  


#### Source:

 https://wiki.seeedstudio.com/Grove-IR\_Distance\_Interrupter\_v1.2/

# Infrared (IR) break-beam sensor

Infrared (IR) break-beam sensors are an easy way to detect movement. This sensor has a transmitter and receiver part. Point the transmitter at the receiver to create a light beam that will trigger the receiver if this bundle is interrupted.

[![KW-1516-1-1400x1050w.jpg](https://bookstack.hku.nl/uploads/images/gallery/2026-03/scaled-1680-/kw-1516-1-1400x1050w.jpg)](https://bookstack.hku.nl/uploads/images/gallery/2026-03/kw-1516-1-1400x1050w.jpg)

For this test i didn't use an LED as mentioned in the code and tutorial (see sources bottem of the page)   
You can leave it out of the setup if you don't need it and connect the data(yellow wire) directly to pin 5 (digital) on the arduino.  
Because it works with infrared light, use it indoors and close the curtains and maybe don't use halogen lights ;) I made that mistake.

#### Material  
  


- Arduino UNO (other models also are fine) × 1 + power cable (sold seperately)
- - Sensor: [https://www.kiwi-electronics.com/nl/infrarood-straal-detector-5mm-leds-1577?search=kw-1516](https://www.kiwi-electronics.com/nl/infrarood-straal-detector-5mm-leds-1577?search=kw-1516)

#### Assembly

**1.** If you buy this sensor new you will likely receive this without jumper wires. To make testing easy solder on some jumper wires.

**2.** Connect the sensors to the arduino, position them towards each other in a straight line. you can use a small box like in the tutorial in the source (below this text)  
Sice you have only one 5V output on your arduino you can split up the power for both sensors by using a breadboard.  
You can use this schematics:

[![schematic IR BreakB.jpg](https://bookstack.hku.nl/uploads/images/gallery/2026-03/scaled-1680-/schematic-ir-breakb.jpg)](https://bookstack.hku.nl/uploads/images/gallery/2026-03/schematic-ir-breakb.jpg)

##### with breadboard:  


[![Screenshot 2026-03-05 at 14.29.56.png](https://bookstack.hku.nl/uploads/images/gallery/2026-03/scaled-1680-/screenshot-2026-03-05-at-14-29-56.png)](https://bookstack.hku.nl/uploads/images/gallery/2026-03/screenshot-2026-03-05-at-14-29-56.png)

  
**3.** Create an Arduino sketch and copy this code into it:

void setup() {  
   
 Serial.begin(9600);  
 pinMode(5, INPUT\_PULLUP);  
 pinMode(13, OUTPUT);

}

void loop() {

 int val = digitalRead(5);

 if (val == 0) //Beam is broken  
 {  
 digitalWrite(13, LOW);  
 }  
 else  
 {  
 digitalWrite(13, HIGH);  
 }

 Serial.print(" ");  
 Serial.println(val);

 delay(100);

  
}

**4.** Connect Arduino to your comuter &amp; Upload the code.  
If you do not know how to upload a Arduino sketch, please visit [https://www.arduino.cc/en/Guide/Windows](https://www.arduino.cc/en/Guide/Windows) for Windows user or [https://www.arduino.cc/en/Guide/MacOSX](https://www.arduino.cc/en/Guide/MacOSX) for Mac user.

**5.** Open the serial monitor by clicking the Magnifying glass in the top right corner of the window.   
When the path of light is blocked by some object, you would see "0" in Serial Terminal else you will see "1"  
This is changed in the code from source github page (below text) so you can use the output in for instance Isadora.   
If you leave the text like in the original code  
 Serial.print("The value of pin 5 is: ");   
the actor output in Isadora will not give 1 or 0. Only - or X

##### For connecting with Isadora[ read this](https://bookstack.hku.nl/books/isadora/page/receive-data-from-arduino-in-isadora)

You can borrow this sensor for testing at the Blackbox location IBB. Contact: blackbox.ibb-pastoe@hku.nl

#### source: 

Sensor: [https://www.kiwi-electronics.com/nl/infrarood-straal-detector-5mm-leds-1577?search=kw-1516](https://www.kiwi-electronics.com/nl/infrarood-straal-detector-5mm-leds-1577?search=kw-1516)

Video: [https://www.youtube.com/watch?v=GWdDeB7Sltw](https://www.youtube.com/watch?v=GWdDeB7Sltw)

Code from video: [https://github.com/nickredsox/youtube/blob/master/Arduino/IR%20Beam/ir\_beam\_arduino/ir\_beam\_arduino.ino](https://github.com/nickredsox/youtube/blob/master/Arduino/IR%20Beam/ir_beam_arduino/ir_beam_arduino.ino)

# Time of Flight Distance Sensor VL53L4CD

The Adafruit VL53L4CD Time-of-Flight Distance Sensor is ideal for accurate distance measurements. The sensor delivers stable results from approximately 1.0 mm to 1300.0 mm with high repeatability. Thanks to its narrow measuring beam, it is ideal for robotics, obstacle detection, automatic measurements or interactive installations.

It has a STEMMA QT / Qwiic connector for easy plug-and-play connections without soldering.

<div class="block-body expand-block" id="bkmrk-measuring-range-from"><div class="block-wrapper"><div class="block-content ">- Measuring range from approximately 1.0 mm to 1300.0 mm
- Compatible with 3.3V and 5V
- Narrow beam (FoV approx. 18 degrees) for precise detection
- STEMMA QT / Qwiic connector for easy connection
- Fast measurements up to about 100 Hz

</div></div></div>#### 1 Material:

<div class="block-body expand-block" id="bkmrk-sensor%3A%C2%A0adafruit-vl5"><div class="block-wrapper"><div class="block-content ">- Sensor: [Adafruit VL53L4CD Time of Flight Distance Sensor](https://www.kiwi-electronics.com/nl/adafruit-vl53l4cd-time-of-flight-distance-sensor-1-to-1300mm-stemma-qt-qwiic-20520)
- Cable: [STEMMA QT / Qwiic JST SH 4-pin to Premium Male Headers Cable](https://www.kiwi-electronics.com/nl/stemma-qt-qwiic-jst-sh-4-pin-to-premium-male-headers-cable-150mm-long-10386?search=STEMMA%20QT%20%2F%20Qwiic%20JST%20SH%204-pin%20)
- [Arduino UNO](https://www.kiwi-electronics.com/nl/arduino-uno-rev3-atmega328-729?search=arduino%20uno) (other models also are fine) × 1 + [power cable ](https://www.kiwi-electronics.com/nl/usb-a-naar-usb-b-kabel-05-meter-763)(sold seperately)

</div></div></div>#### 2 Assembly

[![Screenshot 2026-03-09 at 13.58.23.png](https://bookstack.hku.nl/uploads/images/gallery/2026-03/scaled-1680-/screenshot-2026-03-09-at-13-58-23.png)](https://bookstack.hku.nl/uploads/images/gallery/2026-03/screenshot-2026-03-09-at-13-58-23.png)

Wire using the STEMMA QT connector.   
If you are using a **3V** board, like an Adafruit Feather, wire the board's 3V pin to the VL53L4CD VIN.

- **Board 5V** to **sensor VIN (red wire)**
- **Board GND** to **sensor** **GND (black wire)**
- **Board SCL** to **sensor** **SCL (yellow wire)**
- **Board SDA** to **sensor** **SDA (blue wire)**

#### 3 Software &amp; code  
  


<span class="s1">In the Arduino software Click the **Manage Libraries ...** menu item (under Tools), search for **VL53L4CD**, and select the **STM32duino VL53L4CD** library. Install it.</span>

The library comes with some example sketches, I used one of them and adjusted the code so the useless information like status, signal, tekst is removed. It now only outputs a stream of values.

Open a new arduino file ande replace the code with this:

<div id="bkmrk-%23include-%3Carduino.h%3E" 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: #c586c0;">\#include</span><span style="color: #dae3e3;"> </span><span style="color: #7fcbcd;">&lt;Arduino.h&gt;</span></div><div><span style="color: #c586c0;">\#include</span><span style="color: #dae3e3;"> </span><span style="color: #7fcbcd;">&lt;Wire.h&gt;</span></div><div><span style="color: #c586c0;">\#include</span><span style="color: #dae3e3;"> </span><span style="color: #7fcbcd;">&lt;vl53l4cd\_class.h&gt;</span></div>  
<div><span style="color: #c586c0;">\#define</span><span style="color: #dae3e3;"> </span><span style="color: #f39c12;">DEV\_I2C</span><span style="color: #dae3e3;"> Wire</span></div>  
<div><span style="color: #dae3e3;">VL53L4CD </span><span style="color: #f39c12;">sensor</span><span style="color: #dae3e3;">(&amp;DEV\_I2C, A1);</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: #f39c12;">Serial</span><span style="color: #dae3e3;">.</span><span style="color: #f39c12;">begin</span><span style="color: #dae3e3;">(</span><span style="color: #7fcbcd;">115200</span><span style="color: #dae3e3;">);</span></div><div><span style="color: #f39c12;">Wire</span><span style="color: #dae3e3;">.</span><span style="color: #f39c12;">begin</span><span style="color: #dae3e3;">();</span></div>  
<div><span style="color: #dae3e3;"> </span><span style="color: #f39c12;">sensor</span><span style="color: #dae3e3;">.</span><span style="color: #f39c12;">begin</span><span style="color: #dae3e3;">();</span></div><div><span style="color: #f39c12;">sensor</span><span style="color: #dae3e3;">.</span><span style="color: #f39c12;">VL53L4CD\_Off</span><span style="color: #dae3e3;">();</span></div><div><span style="color: #f39c12;">sensor</span><span style="color: #dae3e3;">.</span><span style="color: #f39c12;">InitSensor</span><span style="color: #dae3e3;">();</span></div>  
<div><span style="color: #7f8c8d;"> // Hoge nauwkeurigheid</span></div><div><span style="color: #f39c12;">sensor</span><span style="color: #dae3e3;">.</span><span style="color: #f39c12;">VL53L4CD\_SetRangeTiming</span><span style="color: #dae3e3;">(</span><span style="color: #7fcbcd;">200</span><span style="color: #dae3e3;">, </span><span style="color: #7fcbcd;">0</span><span style="color: #dae3e3;">);</span></div>  
<div><span style="color: #7f8c8d;"> // Start met meten</span></div><div><span style="color: #f39c12;">sensor</span><span style="color: #dae3e3;">.</span><span style="color: #f39c12;">VL53L4CD\_StartRanging</span><span style="color: #dae3e3;">();</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: #0ca1a6;">uint8\_t</span><span style="color: #dae3e3;"> dataReady = </span><span style="color: #7fcbcd;">0</span><span style="color: #dae3e3;">;</span></div><div><span style="color: #0ca1a6;">VL53L4CD\_Result\_t</span><span style="color: #dae3e3;"> results;</span></div>  
<div><span style="color: #7f8c8d;"> // Wacht tot er nieuwe data is</span></div><div><span style="color: #c586c0;">do</span><span style="color: #dae3e3;"> {</span></div><div><span style="color: #f39c12;">sensor</span><span style="color: #dae3e3;">.</span><span style="color: #f39c12;">VL53L4CD\_CheckForDataReady</span><span style="color: #dae3e3;">(&amp;dataReady);</span></div><div><span style="color: #dae3e3;"> } </span><span style="color: #c586c0;">while</span><span style="color: #dae3e3;"> (!dataReady);</span></div>  
<div><span style="color: #7f8c8d;"> // reset interrupt</span></div><div><span style="color: #f39c12;">sensor</span><span style="color: #dae3e3;">.</span><span style="color: #f39c12;">VL53L4CD\_ClearInterrupt</span><span style="color: #dae3e3;">();</span></div>  
<div><span style="color: #7f8c8d;"> // meetresultaat ophalen</span></div><div><span style="color: #f39c12;">sensor</span><span style="color: #dae3e3;">.</span><span style="color: #f39c12;">VL53L4CD\_GetResult</span><span style="color: #dae3e3;">(&amp;results);</span></div>  
<div><span style="color: #7f8c8d;"> // alleen afstand printen</span></div><div><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: #f39c12;">results</span><span style="color: #dae3e3;">.</span><span style="color: #f39c12;">distance\_mm</span><span style="color: #dae3e3;">);</span></div><div>  
</div><div><span style="color: #dae3e3;">}</span></div></div>
#### <span style="color: rgb(0, 0, 0);">5 Connect the arduino to your computer. </span>

<span style="color: rgb(0, 0, 0);">Connect Arduino to your computer &amp; Upload the code.  
If you do not know how to upload a Arduino sketch, please visit [https://www.arduino.cc/en/Guide/Windows](https://www.arduino.cc/en/Guide/Windows) for Windows user or [https://www.arduino.cc/en/Guide/MacOSX](https://www.arduino.cc/en/Guide/MacOSX) for Mac user.  
  
Open the serial monitor by clicking the Magnifying glass in the top right corner of the window.  
You might need to change the Baud rate to: 115200 before you get good results. Do this in the top right of the serial monitor field.  
You should now see a stream of data measuring the distance to the object in front of the sensor. Hold your hand in front of the sensor and move it.  
  
</span>

##### For connecting with Isadora[ read this](https://bookstack.hku.nl/books/isadora/page/receive-data-from-arduino-in-isadora)

You can borrow this sensor for testing at the Blackbox location IBB. Contact: blackbox.ibb-pastoe@hku.nl

<span style="color: rgb(0, 0, 0);">  
</span>

<div id="bkmrk-source-for-this-page"><span style="color: rgb(0, 0, 0); background-color: rgb(180, 247, 125);">Source for this page: [https://learn.adafruit.com/adafruit-vl53l4cd-time-of-flight-distance-sensor/arduino](https://learn.adafruit.com/adafruit-vl53l4cd-time-of-flight-distance-sensor/arduino)</span></div>

# IR Distance Sensor SHARP GP2Y0A02YK with Arduino

[![KW-1476-2-1400x1050h.jpg](https://bookstack.hku.nl/uploads/images/gallery/2026-03/scaled-1680-/kw-1476-2-1400x1050h.jpg)](https://bookstack.hku.nl/uploads/images/gallery/2026-03/kw-1476-2-1400x1050h.jpg)

The Sharp GP2Y0A02YK infrared ranger is able to continuously measure the distance to an object. The usable range is 20 cm to 150 cm. The device generates an analog voltage that is a function of range, and the output voltage can be measured by an analog-to-digital (ADC) input line. The voltage will range from approx. 0.4V at 150cm to 2.7V at 20cm.

#### 1 Material:

  
\- sensor: [Sharp GP2Y0A02YK ](https://www.kiwi-electronics.com/en/ir-distance-sensor-20cm-to-150cm-gp2y0a02yk-721?search=1476)  
[- Arduino UNO](https://www.kiwi-electronics.com/nl/arduino-uno-rev3-atmega328-729?search=arduino%20uno) (other models also are fine) × 1 + [power cable ](https://www.kiwi-electronics.com/nl/usb-a-naar-usb-b-kabel-05-meter-763)(sold seperately)  
\- [Dupont jumper wires Male - male](https://www.kiwi-electronics.com/en/jumperwires-10-wires-m-m-15cm-589?search=dupont%20jumper%20male)  
[- Capacitor(≥10 µF)](https://www.makerguides.com/sharp-gp2y0a21yk0f-ir-distance-sensor-arduino-tutorial/#Capacitor%E2%89%A510_%C2%B5F)  
\- [breadboard](https://www.kiwi-electronics.com/en/400pt-half-size-breadboard-white-283?search=breadboard)

Solder some male jumper wires on the cable that comes with the sensor for easy connection to arduino or breadboard.

#### 2 Assembly

Connect the parts according this schematic:

[![SHARP-GP2Y0A21YK0F_bb.png](https://bookstack.hku.nl/uploads/images/gallery/2026-03/scaled-1680-/sharp-gp2y0a21yk0f-bb.png)](https://bookstack.hku.nl/uploads/images/gallery/2026-03/sharp-gp2y0a21yk0f-bb.png)  
These type of distance sensors tend to be a bit noisy, so it is recommended to add a capacitor between Vcc and GND. The datasheet suggests a capacitor of 10 µF or more (I used 220 µF). Connect the positive lead of the capacitor to the Vcc wire connection and the negative lead to the GND wire connection (see picture). Capacitors are often marked with a stripe which indicates the negative lead. The positive lead is often longer then the negative lead.

#### 3 Software &amp; code

 Download the [**SharpIR** library written by Guillaume Rico and Thibaut Mauon here.](https://www.makerguides.com/wp-content/uploads/2019/02/SharpIR-master.zip)  
For more information check the[ github page here.](https://github.com/guillaume-rico/SharpIR)  
This library is not available through the library manager of Arduino. You have to manually instal it. For how to manually installing a library [check this page. Scroll down to: ](https://docs.arduino.cc/software/ide-v1/tutorials/installing-libraries/)"Importing a .zip Library"

I've edited the code from the source website a little so you only get values and no text as output. Works better with visual programming software like Isadora or touchdesigner.

Copy this code into a new empty file, connect with your arduino and uplaod the code.

<div id="bkmrk-%2F%2Asharp-gp2y0a21yk0f" 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;">/\*SHARP GP2Y0A21YK0F IR distance sensor with </span></div><div><span style="color: #7f8c8d;"> Arduino and SharpIR library example code. </span></div><div><span style="color: #7f8c8d;"> More info: https://www.makerguides.com \*/</span></div>  
<div><span style="color: #7f8c8d;">// Include the library:</span></div><div><span style="color: #c586c0;">\#include</span><span style="color: #dae3e3;"> </span><span style="color: #7fcbcd;">"SharpIR.h"</span></div>  
<div><span style="color: #7f8c8d;">// Define model and input pin:</span></div><div><span style="color: #c586c0;">\#define</span><span style="color: #dae3e3;"> </span><span style="color: #f39c12;">IRPin</span><span style="color: #dae3e3;"> A0</span></div><div><span style="color: #c586c0;">\#define</span><span style="color: #dae3e3;"> </span><span style="color: #f39c12;">model</span><span style="color: #dae3e3;"> </span><span style="color: #7fcbcd;">1080</span></div>  
<div><span style="color: #7f8c8d;">// Variable to store the distance</span></div><div><span style="color: #0ca1a6;">int</span><span style="color: #dae3e3;"> distance\_cm;</span></div>  
<div><span style="color: #7f8c8d;">/\* Model :</span></div><div><span style="color: #7f8c8d;"> GP2Y0A02YK0F --&gt; 20150</span></div><div><span style="color: #7f8c8d;"> GP2Y0A21YK0F --&gt; 1080</span></div><div><span style="color: #7f8c8d;"> GP2Y0A710K0F --&gt; 100500</span></div><div><span style="color: #7f8c8d;"> GP2YA41SK0F --&gt; 430</span></div><div><span style="color: #7f8c8d;">\*/</span></div>  
<div><span style="color: #7f8c8d;">// Create a new instance of the SharpIR class:</span></div><div><span style="color: #dae3e3;">SharpIR mySensor = </span><span style="color: #f39c12;">SharpIR</span><span style="color: #dae3e3;">(IRPin, model);</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: #7f8c8d;"> // Serial communication at a baudrate of 9600</span></div><div><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></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: #7f8c8d;"> // Get a distance measurement and store it as distance\_cm</span></div><div><span style="color: #dae3e3;"> distance\_cm = </span><span style="color: #f39c12;">mySensor</span><span style="color: #dae3e3;">.</span><span style="color: #f39c12;">distance</span><span style="color: #dae3e3;">();</span></div>  
<div><span style="color: #7f8c8d;"> // Print the measured distance to the serial monitor</span></div>  
<div><span style="color: #dae3e3;"> </span><span style="color: #f39c12;">Serial</span><span style="color: #dae3e3;">.</span><span style="color: #f39c12;">print</span><span style="color: #dae3e3;">(distance\_cm);</span></div><div><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;">" "</span><span style="color: #dae3e3;">);</span></div>  
<div><span style="color: #dae3e3;"> </span><span style="color: #f39c12;">delay</span><span style="color: #dae3e3;">(</span><span style="color: #7fcbcd;">1000</span><span style="color: #dae3e3;">);</span></div><div><span style="color: #dae3e3;">}</span></div></div><div id="bkmrk--1"></div>#### <span style="color: rgb(0, 0, 0);">4 Connect the arduino to your computer. </span>

<span style="color: rgb(0, 0, 0);">Connect Arduino to your computer &amp; Upload the code.  
If you do not know how to upload a Arduino sketch, please visit [https://www.arduino.cc/en/Guide/Windows](https://www.arduino.cc/en/Guide/Windows) for Windows user or [https://www.arduino.cc/en/Guide/MacOSX](https://www.arduino.cc/en/Guide/MacOSX) for Mac user.  
  
Open the serial monitor by clicking the Magnifying glass in the top right corner of the window.  
  
You should now see a stream of data measuring the distance to the object in front of the sensor. Hold your hand in front of the sensor and move it.  
  
</span>

##### For connecting with Isadora[ read this](https://bookstack.hku.nl/books/isadora/page/receive-data-from-arduino-in-isadora)

You can borrow this sensor for testing at the Blackbox location IBB. Contact: blackbox.ibb-pastoe@hku.nl

<span style="background-color: rgb(180, 247, 125);">source: </span>  
<span style="background-color: rgb(180, 247, 125);">https://www.makerguides.com/sharp-gp2y0a21yk0f-ir-distance-sensor-arduino-tutorial/</span>