LED strip connected to magic mirror

Sparkling LED strip is not just for your Magic Mirror

I felt like 5 years old boy looking at the Christmas tree(full of gifts, of course), when I managed to turn on LED strip from my Raspberry pi. I was cheering, clapping and felt excited. It’s extremely fun to see the physical result of your work. As developers, we sometimes work on very technical stuff like transactions, infrastructure or architecture, which is, yes, extremely interesting. Just the only visual result of them is a scheme on the paper. So, programming magic mirror with LEDs, gives you different effect.

I won’t get into too much details about physics here. I am going to tell how to attach LED strip to your Raspberry pi. Then you can use your LEDs for your magic mirror or… Christmas, disco lights or anything you can think of.


  • 3528 LED strip 12V. Or… you can buy LED 5050 instead – it provides more light. Or… you can buy multiple colours. Or multiple dimmable colours. Whatever your requirements are. I bought a cool white 3528 one
  • breadboard
  • male to male wires. Last two can be bough together on amazon here
  • male to female wires here
  • 12V 2A power supply with a power jack bought here
  • and of course, Raspberry Pi model B with GPIO.

LED recipe

  1. Connect MOSFET to the breadboard. Breadboard is our electric pitch and we are going to create the circuit to enable LED strip. MOSFET here works like a switch – enables and disables our LEDs. In order to do it’s job, MOSFET consists of three pins: drain, source and gate. Drain and source create a circuit when gate enables it. Deeper understanding about MOFSET you can find on wiki. So three pins:
    • gate. It determines conductivity of the device. Voltage at a gate makes it a very small resistor, which allows current to flow through. And other way around – when there is no voltage – it becomes a large resistor and current doesn’t flow. We connect Raspberry here.
    • Source – power supply. In our case we use ground bus of a breadboard.
    • Drain – LEDsMOSFET
  2. LED strip. The colour of LED strip is connected to the drain pin. Wire is connected to the ground bus of breadboard.To make LEDs fully light, the gate must have threshold voltage of maximum 3.3V. LED strip attached to breadboard
  3. Here comes the brain component – Raspberry Pi. All the GPIO pins of Raspberry PI have their own responsibility. GPIO layout I choose GPIO24 for my LEDs (you can use several pins if have multiple colours). Raspberry ground pin is connected to the ground bus of breadboard. And GPIO24 is connected to the gate PIN of MOSFET. raspberry attached to breadboard
  4. Connect power supply. Ground wire is connected to the ground bus of breadboard. The voltage cable is connected analogously to the voltage bus of the breadboard. Now you can plug your power supply cable into the socket. raspberry pi and LED connectionpower jack
  5. Control from Raspberry. You can use shell script to play around with GPIO. I use python script, which is pretty straightforward. RPi.GPIO module is installed in Raspbian by default. Only three lines of code required to enable lights:
  • GPIO.setmode(GPIO.BCM) # BCM is the type how we are referring the pins
  • GPIO.setup(24,GPIO.OUT) # set GPIO24 as an output
  • GPIO.output(24,100) # set a high output voltage. Which sets it for 3.3V supply

And disable them:

  • GPIO.setmode(GPIO.BCM) # BCM is the type how we are referring the pins
  • GPIO.setup(24,GPIO.OUT) # set GPIO24 as an output
  • GPIO.output(24,False) # just disable the output
  • GPIO.cleanup() # clean and close connection

All the GPIO ports get their power from the Raspberry Pi’s 3.3V (3V3) supply. The maximum recommended current draw from that supply is 51 mA. This is the total for all the 3V3 GPIO pins.

So… that’s it! Can you see your LED strip shining bright like a diamond? Coding is especially fun when you can phisically see your work fruits.

LED strip fully connected

Steps to build Magic Mirror

  1. Find out what are the features and motivation under the Magic Mirror here.
  2. Build hardware – the mirror and electrics here.
  3. Add LED lights here.
  4. Install software for mirror to become magical here.