A place users can post their projects. If you have a small project and would like your own dedicated place to post and have others chat about it then this is your spot.

User avatar
By Barnabybear
#32874 Hi, all I quite like nice Christmas lights & to get them you have to spend a fortune or make them yourself (more fun anyway).
So I give you the 30 LED snow fall effect. This sort of thing https://www.youtube.com/watch?v=UNlRhncDyh8 but only single LEDs lit (unless you want to code the fade & are sure your output will handle the load).
You need:
An ESP8266 with 6 useable GPIOs (not 0, 2, & 15), so an 07 or 12 variant.
30 white LEDs (Snow is white + coloured won’t work).
6 resistors – if you’re not happy running white LEDs directly on your outputs (1/2 the normal value you use – if you want 100 ohms use 50s – it works out as 50 ohms on the supply & 50 ohms on the ground).
Wire & time.

You’ll need to run wire from the 6 GPIOs to the LEDs (telephone or Cat5 is fine) then you need to attach the LEDs.
A couple of things before the diagram:

Code: Select all+ve   ->|-   -ve = LED lights.

-ve   ->|-   +ve = LED does not light.

+ve   ->|-   &   ->|-   -ve = LED does not light (if it is white, colours may @ 3.3V).

+ve   ->|-   GPIO as INPUT = LED does not light.

GPIO as INPUT   ->|-   -ve = LED does not light.


Image

On the left are the LED connections. Put the LED between the GPIO in the column and the GPIO in the row it appears in.
The first led goes between GPIO 1 & GPIO 2, the second GPIO 1 & GPIO 3, etc.
On the right is the GPIO state to make the LED light (blanks are GPIOs set as INPUT) the others are OP = OUTPUT & H = High or L =LOW.

How to code this:
I’ll use GPIO 1 to 6 for ease; these will not apply to your application – set variables.
This is not any actual code – just a method.

Code: Select all// setup
Set all GPIOs as INPUTs.     // disble all GPIO (NC)

// first 5 LEDs
Set GPIO 1 as an OUTPUT      // enable column GPIO
Set GPIO 1 as HIGH           // sets column GPIO (+ve)
For N = 2 to 6
Set GPIO N as an OUTPUT      // enable row GPIO
Set GPIO N as LOW            // sets row GPIO (-ve)
Delay
Set GPIO N as an INPUT       // disable row GPIO (NC)
Back to 'For' &  N+ 1
Set GPIO 1 as INPUT          // disable column GPIO (NC)
// end of first 5 LEDs

//next 4 LEDs
Set GPIO 2 as an OUTPUT
Set GPIO 2 as LOW
For N = 3 to 6
-------- you get the idea ---------

// with the diodes reversed
// first 5 LEDs
Set GPIO 1 as an OUTPUT
Set GPIO 1 as LOW
For N = 2 to 6
Set GPIO N as an OUTPUT
Set GPIO N as HIGH
Delay
Set GPIO N as an INPUT
Back to 'For' & N + 1
Set GPIO 2 as INPUT
// end of first 5 LEDs

//next 4 LEDs
Set GPIO 2 as an OUTPUT
Set GPIO 2 as LOW
For N = 3 to 6
-------- you get the idea ---------


You can loop the loops, but for this example it was easier to see whats happening with out lots of loops.

In the table above the LEDs should light, top line, second line, third line, etc.
So that’s it – be careful with the wiring – this is only supposed to light one led at a time!

TOP TIP: For the first time testing I would use a 1k resistor on all 6 of the GPIO’s – the LEDs will still light dimly & no matter how messed up your code or wiring is it won’t damage you GPIOs (does that sound like the words of advice from someone with dead GPIOs ?).

If you want to use resistors – as stated above put ½ the value on each GPIO:
GPIO (HIGH) -> resistor -> LED -> resistor -> GPIO (LOW).

If you find another GPIO (7 in total) you can run 42 leds. More here https://en.wikipedia.org/wiki/Charlieplexing.

I've only run LEDs as a proof of concept on an ESP8266. As I need 30 strings, I've opted for an Arduino clone for two reasons, it has 18 GPIOs (so 18 / 3 = 6, runs 3 strings for the same money) & an onboard regulator so I can feed it with 12V to negate volt drop on the long cable runs. I can just use an ESP at the end to switch all 30 on & off. It’s on test at the moment and working fine & have random seeds so they mix things up abit.
Just some thoughts.