Led´s String Lights For Christmas

Just because it's Christmas, I decided to do a small project with multi-colored LEDs to put at the entrance of my house, in the hallway.

It will use 5 LEDs of different colors and an ultrasonic sensor.

The goal is that every time someone passes in front of the sensor, a specific sequence of LEDs will light up.

The distance between the ultrasonic sensor and the wall is approximately 130cm.

I set it so that every time a person passes in front of the sensor and the distance is equal to or less than 90 cm, the LEDs are activated.

This circuit consists of 4 different sequences of flashing LEDs.

Three sequences are activated by the ultrasonic sensor, when a person passes in front of it. Pressing a push button allows switching from one sequence to another.

There's a second button that we can switch to sequence 4.

The sequence of 4 flashing LEDs does not use a sensor, it's for when we want the LEDs to flash without needing someone to walk in front of them. It's a typical Christmas light effect.

It's a very simple project made with an Arduino Uno and 5 LEDs of different colors. Blue, yellow, red, green, and white.

Calculating the resistance is crucial, as the voltage drops vary significantly between colors. Blue and green LEDs require more voltage than red and yellow, which affects the resistance calculation. Let's calculate the resistance value for each LED color.

The formula to be used is Ohm's Law adapted for LEDs:

\[ R = \frac{V_{out} - V_F}{I_F} \]
1. Red, Orange and Yellow

These LEDs have lower operating voltages (\(V_F\)).

Red / Orange (\(V_F \approx 2.0\text{V}\)):

\[ R = \frac{5.0\text{V} - 2.0\text{V}}{0.020\text{A}} = \frac{3.0\text{V}}{0.020\text{A}} = 150\ \Omega \]

Yellow (\(V_F \approx 2.1\text{V}\)):

\[ R = \frac{5.0\text{V} - 2.1\text{V}}{0.020\text{A}} = \frac{2.9\text{V}}{0.020\text{A}} = 145\ \Omega \rightarrow \text{Use } 150\ \Omega \]
2. Blue, Green and White

High brightness LEDs that require more voltage to operate properly.

Blue (\(V_F \approx 3.5\text{V}\)):

\[ R = \frac{5.0\text{V} - 3.5\text{V}}{0.020\text{A}} = \frac{1.5\text{V}}{0.020\text{A}} = 75\ \Omega \rightarrow \text{Use } 68\ \Omega \text{ or } 82\ \Omega \]

Green / White (\(V_F \approx 3.3\text{V}\)):

\[ R = \frac{5.0\text{V} - 3.3\text{V}}{0.020\text{A}} = \frac{1.7\text{V}}{0.020\text{A}} = 85\ \Omega \rightarrow \text{Use } 100\ \Omega \text{ or } 82\ \Omega \]
General table:
Color of the LED Tension (\(V_F\)) Ideal Resistor
Red / Orange 2.0V 150 \(\Omega\)
Yellow 2.1V 145 \(\Omega\)
Green / White 3.3V 85 \(\Omega\)
Blue 3.5V 75 \(\Omega\)

Note: For Blue and Green LEDs, using slightly lower resistors (such as 68 \(\Omega\)) ensures maximum brightness in fast sequences.

Here is the schematic of the circuit:

Fig.1 - Schematic of the Christmas effect circuit.

Here's the Arduino code that you can use:

// Leds pisca NATAL 2025 - Joel Bonifácio --> 22/12/2025 const int pinoTrig = 7; // Disparo ultrassónico const int pinoEcho = 8; // Receção ultrassónico const int pinoBotao1 = 2; // Alterna modos const int pinoBotao2 = 11; // Sequência fixa const int pinosLEDs[] = {3, 5, 6, 9, 10}; const int NUM_LEDS_TOTAL = 5; // Total de LEDs void setup() { Serial.begin(9600); // Monitorização pinMode(pinoTrig, OUTPUT); pinMode(pinoEcho, INPUT); pinMode(pinoBotao1, INPUT_PULLUP); for (int i = 0; i < NUM_LEDS_TOTAL; i++) { pinMode(pinosLEDs[i], OUTPUT); digitalWrite(pinosLEDs[i], HIGH); // Iniciam desligados } } void loop() { int dist = lerDistanciaInstantanea(); bool estadoBotao1 = digitalRead(pinoBotao1); if (estadoBotao1 == LOW) { delay(50); // Debounce modoSequenciaFixa = false; modo++; // Muda modo sensor if (modo > 3) modo = 1; } if (modoSequenciaFixa) { piscarLEDInterrupcao(0, 2); // Sequência fixa - botao 2 } else if (dist > 1 && dist < DISTANCIA_GATILHO) { [cite_start]if (modo == 1) { // Efeito Fade for (int i = 0; i < 5; i++) fazerFade(pinosLEDs[i]); } } delay(30); } int lerDistanciaInstantanea() { digitalWrite(pinoTrig, LOW); delayMicroseconds(2); digitalWrite(pinoTrig, HIGH); delayMicroseconds(10); digitalWrite(pinoTrig, LOW); long tempo = pulseIn(pinoEcho, HIGH, 20000); return tempo / 58; // Converte para cm }

Fig.2 - Full Arduino code.

Here's a short video of all the LED flashing sequences, using my hand to simulate a person walking by.

Fig.3 - General video of the christmas circuit.

Leave A Comment