Die Augen des Kürbisses - Halloween kommt ganz plötzlich

Halloween always comes so suddenly. We have not yet bought and "sculpured" a pumpkin, but I wanted to make some preparations. After last year's Project by Andreas Wolter, with my eyes moving, I wanted to design and program a cheaper and weatherproof solution for the eyes this year.

DIY Mikroelektronik Halloween Projekt LED & ToF Sensor & D1 Mini Kürbis basteln

The idea is to put sparkling eyes with RGBLEDs in the eye cavities, which can adopt different colors depending on the distance to the nearest people. For this we need:


Microcontroller Board ATmega328


D1 Mini NodeMcu with ESP8266-12F WLAN module (in today's deal)

Power supply for MCU




Resistance (220 to 680 Ohm)


VL53L0X Time-of-Flight (ToF) Laser distance sensor


HC-SR04 Ultrasound Module Remote Sensor

Shrinking hose assortment


On the following photo track I will show you how I have equipped the RGBLED with resistors and made it all weather-friendly with heat-shrinking tubes. But first I want to remember the most important about RGBLEDs.

RGBLEDs are, so to say, three LEDs in one housing. If you look at them from close up, you can see the individual colors: RGB stands for red, green and blue. The component has four "legs", one per color and one common. And here comes the first hurdle: Is the common leg the anode (the plus pole) or the cathode (the minus pole) At the length of the legs you can only see the common connection: it is the longest of the four wires. The single one next to it is the connection for red, on the other side are then two wires for green and blue. In the question whether the common connection is the cathode or the anode only helps a little test. My RGBLEDs have a common cathode, i.e. here is the connection to ground. The other three legs are connected via resistors to PWM-suitable pins, often marked with Tilde ~.

In the test setup I found that the green part is clearly brighter than red and blue, so I use a higher resistor here and also take this into account in the sketch (see below). Then it is time to solder.


Here the material used: The longest leg of the RGBLED is the common connection, in my case the cathode. For the red and blue anode I use 330 Ohm resistors, for the green connection 680 Ohm.

Green anode center

I start with the green anode in the middle. The leg is wrapped and soldered.

Salted anode

Then I'll weld a green jumper cable with the resistance.

Note: Due to the size of the Dupont connector, I had to pull the green heat-shrink tube over the cable before soldering.


For the common leg  i did not need a resistor. Therefore, I did not shorten the jumper cable, but only removed the insulation and soldered the leg of the RGBLED. Oh yes, also here, if necessary, pull the heat-shrink tube over the cable before.

Cathode soldered and isolated

Then I shrunk the black and green tube. In the absence of a hot air nozzle, I took a gas lighter and a candle.

All connections soldered and isolated

Then I soldered the two outer connectors (red and blue) in the same way and shrunk the remaining tubes. One can still suspect the resistors within the colored shrink tubes.

complete isolation

In the end, I pulled a bigger shrinking tube over all four connecting cables and resistors. This ensures not only protection against moisture (rain or pumpkin), but also traction relief and mechanical stability.

ready RGB LED

My favorite distance sensor is the VL53L0X Time of Flight that measures the distance with infrared light pulses and transmits the value via the I2C interface to the Micro Controller.

VL53L0X Pinout

Of the six connections we use only the top four for this project, whereby VCC can be connected to either 3,3V or 5V.

Now to my sketch for the structure with the bright eyes, which you can of course customize to your own ideas. As mentioned above, we need PWM-capable outputs for the RGBLEDs. I have connected both RGBLEDs in parallel, so I only use three pins: red to pin ~3, green to pin ~5 and blue to pin ~6. The respective colour components are sent to the respectives pins with analogWrite() and values between 0 and 255.

I have personally waived a blue portion (but taken care of your possible wishes), the green portion is high at a great distance and gets lower, the red part gets bigger with decreasing distance. In order to simulate the blinking of the eyes, the LEDs are dimmed for 250 ms after a few seconds.

For distances over 255 cm the value is limited to 255. The PWM value for green corresponds to the distance (because of the bright green part of my RGBLED I have divided the value by 2), the value for the red part is calculated with (255 minus distance). At medium distances, the red and green LEDs are equally bright and this results in yellow. With the self-defined function twinkle() I'll simulate the winking.

As usual, install the library for the distance sensor under /Tools/Libraries... I have chosen the library of Polulu, which also provides two sample sketches.

Library Manager Screenshot

Here the sketchdownload):

   Eyes of the pumpkin
   RGBLED and distance sensor VL53L0X
   based on example for library VL53L0X
   by Bernd Albrecht for AZ-Delivery
 #include <Wire.h>
 #include <VL53L0X.h>
 VL53L0X sensor;
 const int redPin =  3;    // the number of the red pin
 const int greenPin =  5;  // the number of the green pin
 const int bluePin =  6;   // the number of the blue pin
 int red = 128;            // initial value for red
 int green = 128;          // initial value for green
 int blue = 0;             // initial value for blue
 long interval;            // interval at which to blink (milliseconds)
 unsigned long previousMillis = 0;        // will store last time LED was updated
 void setup() {
 // set the digital pin as output:
   pinMode(redPin, OUTPUT);
   pinMode(greenPin, OUTPUT);
   pinMode(bluePin, OUTPUT);
   if (!sensor.init())
     Serial.println("Failed to detect and initialize sensor!");
     while (1) {}
   // Argument is the desired inter-measurement period in ms
 void twinkle() {
   interval = random(3000,6000);  
 void loop() {
   unsigned long currentMillis = millis();
   int distance =  int(sensor.readRangeContinuousMillimeters()/10);
   if (sensor.timeoutOccurred()) { Serial.print(" TIMEOUT"); }
   if (distance > 255)  distance=255;
   red = 255-distance;
   green = int(distance/2);
   Serial.print("red = ");
   Serial.print(" green = ");
   Serial.print(" Interval = ");  
   if (currentMillis - previousMillis >= interval) {
     // save the last time you blinked the LED
     previousMillis = currentMillis;
     // set the LED with the ledState of the variable:

Instead of the distance sensor VL53L0X, you can of course also use the ultrasound distance sensor HC-SR04 . Here we need two digital pins; the trigger connector controls the ultrasonic transmitter; this requires 5 V. The echo is evaluated over the second pin.

The algorithm for controlling RGBLEDs remains the same, but another library for the HC-SR04 is needed. Here the deviating lines in the sketch (download):

#include <HCSR04.h>
 byte triggerPin = 8;
 byte echoPin = 9;
in void setup()
 HCSR04.start(triggerPin, echoPine);

in void loop()

 double* distances = HCSR04.measureDistanceCm();
 int distance =  int (distances[0]);

Have fun with the reconstruction. Feel free to write me your ideas for more gimmicks.

Esp-8266For arduinoSensorsSpecials


Andreas Wolter

Andreas Wolter

Für die anderen Probleme mit dem VL53L0X:
Stellen Sie bitte sicher, dass Sie den Quellcode aus dem Download entnehmen, statt aus dem Text im Beitrag. Eventuell werden falsche Formatierungen übernommen.
Ansonsten wurde der Quellcode noch einmal getestet und funktioniert.
Bibliothek ist von Pololu. VCC an +5V, GND an GND, SDA an A4 und SCL an A5. Dort die Kontakte prüfen. Eventuell direkt verbinden, also ohne Breadboard testen. Dann einmal den Beispielsketch “Continuous” testen. Wenn das nicht funktioniert, eventuell einen anderen MC probieren.

Bernd Albrecht

Bernd Albrecht

Danke für Ihr Interesse an diesem Projekt.
Für die Nutzer des HC-SR04: Wie Karsten Dee schreibt, konnten wir sein Problem durch Löschen der nicht benötigten „Konkurrenz“-Bibliotheken lösen. Die von mir benutzte Bibliothek stammt von Dirk Sarodnick, im Unterverzeichnis libraries erkennbar durch den Bindestrich HC-SR04.
Für die Nutzer des VL53L0X: Hier habe ich die Bibliothek von Polulu verwendet.

Andreas Kühn

Andreas Kühn

Habe dasselbe Problem wie Martin und Peter: die mit der Bibliothek veröffentlichten Beispielsketches bringen ein paar Ausgaben 65535, dann 65535 TIMEOUT. Vom I2C-Scanner wird die Adresse 0×29 erkannt.



ich habe einen Arduino Uno und den VL53L0X verwendet.
Ich bekomme aber immer ein Timeout. Anscheint bekomme ich keine Daten von diesen. Der I²C Scanner findet diesen aber unter der Adresse 0×29.
Was kann ich nun machen?
MfG Martin

Rolf-Dieter Gerke

Rolf-Dieter Gerke

ich habe dasselbe Problem wie Karsten Dee. Welche Library für den HCSR04 wird verwendet?
Viele Grüße



Hallo Herr Albrecht, ein interessantes Projekt. Funktioniert leider mit dem Ultraschallsensor nicht (siehe Fehlerbeschreibung von Herrn Karsten Dee). Könnten sie vielleicht einmal die verwendete Bibliothek vom
HCSR04 angeben (gibt mindestens 6 mit unterschiedlichen Versionsständen). Danke !
Mit freundlichen Grüßen



Hallo Herr Albrecht,
die von mir bei Az-Delivery erworbenen Sensoren vl53LOX (3Stck.) reagieren auf keine Entfernungsänderung.
Das Programm und das Testprogramm gibt als gemessene Entfernung stets 65535 an.
Programmfehler oder Sensoren defekt ?
Viele Grüße

Karsten  Dee

Karsten Dee

Projekt läuft jetzt ohne Probleme,
Ich hatte mehrere Bibliotheken installiert und dadurch wurde die falsche eingebunden.

Andreas Wolter

Andreas Wolter

Circuit diagram has now been added

Karsten  Dee

Karsten Dee

Hallo Herr Albrecht,
Schönes Projekt. Möchte es nachbauen mit einen Ultraschallsensor. Aber ich bekomme immer die Fehlermeldung :
Bibliothek HCSR04 in Version 2.0.0 im Ordner: C:\Users\User\Documents\Arduino\libraries\HCSR04 wird verwendet

exit status 1

‘HCSR04’ was not declared in this scope
in Zeile 34. Was übersehe ich?
Schöne Grüsse, Karsten

sean turner

sean turner

do you have a circuit diagram of this as new to Arduino thanks

Leave a comment

All comments are moderated before being published

Recommended blog posts

  1. Install ESP32 now from the board manager
  2. Lüftersteuerung Raspberry Pi
  3. Arduino IDE - Programmieren für Einsteiger - Teil 1
  4. ESP32 - das Multitalent
  5. OTA - Over the Air - ESP programming via WLAN