Replace Fluorescent Tubes in a Light with LED Bulbs

A few months ago I helped my brother rewire some lights for his shop to use LED bulbs instead of flourescent tubes. I decided to do the same thing for my kitchen light, which had been flickering and didn’t always light up every tube.

Years ago, a friend rhetorically asked me, “Are you an electrician?” after I screwed up some wiring, which left us without heat on the coldest night of the winter. I’d say I’m the perfect man for this job. ūüėČ

Jokes aside, it is an extremely easy wiring task. Electrical stuff can be scary for a lot of people, so I figured I’d document my process. Fair warning… I¬†am not a professional and I’m not telling you how to do this. This is just an explanation of what I did. I’m also not a lawyer.

I did this at night, guided by some battery-powered LED lights, so the lighting in the photos isn’t very good.

First I TURN OFF THE BREAKER connected to my light. Absolutely no shortcuts here. Then I took the tubes out and removed the fixture covers.

img_0808.jpg

Those black boxes are the ballasts, which limit the current in a circuit. To use LED bulbs those need to be bypassed. I cut all of the wires and removed them.

img_0809.jpg

img_0810.jpg

Then I stripped the ends of every wire I had cut.

img_0811.jpg

In these particular fixtures, one side used 2 blue and 2 red wires and the other side used 2 yellow wires. The yellow side did use some short white wires to connect one tube to the other, but those white wires were not directly connected to the ballast.

This is the key step. All of the wires on one side of the fixture needed to be connected and then connected to either the black (hot) or white (neutral). It doesn’t matter which side goes to white and which goes to black, but it’s very important that everything on one side of the fixture goes together.

As you can see here I grouped by dark (blue and red to black) and light (yellow to white) colors. I screwed a wire nut on each bundle of wires. When I have 3 or more wires connected like this I gently pull on each wire to make sure nothing will come loose.

img_0812.jpg

Before I closed everything up, I flipped the breaker and made sure the light switch was on. Then I took one LED bulb and tested it in each spot to make sure everything worked. There’s nothing worse than having to take something apart after it’s been closed up. Everything worked great, so I wrapped each wire nut with electrical tape.

img_0813.jpg

For the final step I put the covers back on over the wiring and slipped in the LEDs.

img_0814.jpg

It made a huge difference in my kitchen. Here are some unedited before and after shots.

img_0818.jpg
The camera really shows how green the light was from the flourescent tubes.
img_0819.jpg
You can see how much more natural the wood looks.

What happened with that wiring mistake I made years ago? We got drunk and¬†survived¬†a cold night. I woke up early the next morning determined to figure out what I had done wrong. I fixed the mistake and learned not to assume that speaker wire running through a basement ceiling was useless. I’m probably lucky the wires I cut were only used for thermostats instead of something with a higher voltage.

I didn’t let my friend’s joke discourage me from trying. To this day I continue to learn.

3-way Switch Wiring

I get confused every time I work on a 3-way switch. After I remember to make a diagram to lay out all of the wires I have it makes sense. This was for a Wi-Fi connected switch and “remote” pairing I installed yesterday.

Creative Wiring

On Saturday I went to help my brother move a thermostat and fix a bit of wiring. You’ll never guess where this cord leads…

The cord (hidden behind the dish washer) takes electricity up to a switch by the kitchen sink, which feeds down to wires under the sink. The wires were laying there with wire nuts. Obviously this was meant for controlling the garbage disposal, so we installed a GFCI outlet and now they can turn it on like you’re supposed to.

I’m come across some weird shit in my old 1979 house, but never anything quite like this. What’s the weirdest wiring configuration you’ve seen?

Wire Loop Game

Kennedy and I made a wire loop game, using some basic cheap electronics.

  • 9v Battery
  • Buzzer
  • Old light switch
  • LED
  • Various wires
  • Nuts and bolts
  • Electrical tape
  • Wire screw caps
  • Cardboard box

The initial wiring and cutting of the box took more time than I figured and she started to lose interest until we got around to the top. We did this all on-the-fly, but there are plenty of tutorials (like one on Instructables) you can follow.

‚Äč

‚Äč‚Äč ‚Äč

‚Äč

A Raspberry Pi HAT

I successfully built the second piece to a large project I’m working on. I’ve essentially built my own XL¬†Raspberry Pi HAT¬†(Hardware Attached on Top). Since I’m not following the specs, I shouldn’t really call it a HAT.

I’m not sure how, but once again I correctly connected everything on the first try. Either I’m extremely lucky, my attention to detail is paying off, or a combination of the two. I’m just waiting for some catastrophic failure to happen soon when I solder things the wrong way one of these days. Every one of my solder bridges¬†worked. I did run continuity tests¬†on all of the early bridges, which I’m sure was a big factor to my success.

Any guesses on what this board does? Leave your best guess in the comments. It’ll be at least a month before I share more details because I need to finish the entire project first.

Multiplexing 7 Segment Common Cathode Displays on a Raspberry Pi

7-segment-displays
I picked up a 10 pack of these 7 segment red LED displays for less than $5. Since each display requires connecting to a minimum of 8 of the 10 pins (9 if using the decimal point), they aren’t exactly easy to work with. Sure, you can buy these where 2 or 4 displays are already connected in a nice package, controlled with the help of an integrated circuit, but where is the fun in that?

If you need to use more than 1 or 2 displays (at 8-9 pins per display), you’ll quickly run out of pins on your microcontroller or Raspberry Pi. The most common way to work with several of these displays is called multiplexing. It’s a method where you briefly turn on one display, turn it off, turn on the next one, and turn it off. You repeat this through all of your displays and then start over. If you do this fast enough, the human eye thinks all of the displays are on at once. It’s pretty slick!

The advantages of multiplexing are:

  • Fewer wires/pins needed to drive the displays.
  • Lower power consumption since the LEDs on only one display are lit.

common-cathode-7-segment-LED-display-pinout.png
Image source: learningaboutelectronics.com
Let’s get our hands dirty, shall we?

Seven of the pins on one of these displays match up to the 7 segments (labeled a through g), one pin is for the decimal point (DP), and the two remaining pins can be used for the common cathode (cc), though you only need to connect one or the other. Over to the right you can see how all of the pins and LED segments are arranged. Pretty straight forward.

I’m using 6 of these displays in a project, so I needed a lot of wires. It got complex and tangled in a hurry, but amazingly, I connected all the wires without a single mistake on my first try. ūüôā For the most part, I based my circuit design off of this schematic…

multiplexing-7-segement-display-schematic.png
Image source: circuitstoday.com
The end result is something like the Fritzing screenshot below. With so many wires overlapping, it’s not easy to see what’s really going on here. I suggest grabbing wiring.fzz from my GitHub repo and playing around with it in the Fritzing app.

multiplexing-fritzing.png

When I went to write my proof of concept code, I decided to use the Gpiozero Python library to simplify working with the LEDs. The library allowed me to set up a couple of arrays for the LED segments and the 6 digits (displays)…

segment_leds = []
for i in range( len( segment_pins ) ) :
segment_leds.append( LED( segment_pins[i] ) )

digits = []
for i in range( len( digit_pins ) ) :
digits.append( LED( digit_pins[i] ) )

Then I could easily loop through and toggle the LEDs in a display as necessary…

for i in range( len( digits ) ) :
for j in range( 7 ) :
if ( numbers[ digit_values[i] ][j] ) :
segment_leds[j].on()
else :
segment_leds[j].off()

To make sure things worked I count up from 999000 and then start back at 000000 after hitting 999999. You can see the full code on GitHub.

Now for some visual proof that I actually got it all working! Here it is running when I keep one digit lit for 5/10,000th of a second before turning it off and lighting the next digit.

You’d never know that only one digit is turned on at a time, would you?

If I change from 0.0005 to 0.05 of a second you can start to see that only one display is on at any point in time.

You may also notice it’s counting up a low slower due to the way this code increments the counter. Don’t worry about that.

When I keep each digit turned on for half of a second you can really see how this works.

An issue I’m running into on a Pi Zero is when the processor gets busy doing other tasks, there is a bit of flicker across the displays. You can see this a couple of seconds in to the first video. I’m guessing the code would perform much better on a Raspberry Pi 3B. For my project it’s not a concern, but I want to mention it in case you follow this for your own project. You may also pick up what looks like random flickering of a single digit here and there but that’s due to video timing; the human eye doesn’t see any of that when it’s in front of you.

If necessary, you can take multiplexing a step further and only light up an individual LED on each display at a time, with a method called charlieplexing. It will use even less power, but due to the speed at which you need to switch from one LED to the next, especially across an array of multiple displays, you lose brightness to the human eye.

Phone Keypad Hacking: Part 4

So when part 3 of this series turned out to be a bit uneventful, I wasn’t expecting a grand finale with fireworks. I was right about it being more difficult though.

Through numerous failed attempts I was running into trouble isolating the signals between the rows and columns. Everything was getting connected in one big circuit. Then I realized it was a perfect place to use diodes! Each button needed 2 though; one for its connection to the row and one to the column. I have a bunch of 1N4148 signal diodes so I wired everything up.


Although the Fritzing is using a different board than in the implementation pictured above, it’s much easier to follow the wiring…

2x3-custom-keypad-wiring.png

This obviously is a lot more complicated circuit¬†than the examples in part 3 of this series. It was a success at what I set out to do though¬†and it works great with my custom keypad code. I’ve also added the actual Fritzing file for this circuit¬†to the repo.

I’m glad I continued down this path with keypad experimentation. I learned a lot. In the beginning I was wondering why the keypads you can buy these days work the way they do and not how I had wired up the old phone keypad to function. Turns out what ended up being a simple solution for me was due to how the old phone keypad made its connections mechanically inside the device. The keypad solutions I showed in part 3 are much easier to create as I’ve now proven by recreating the circuit above.

I’m still curious if I could wire up the old phone keypad to work with the Arduino Keypad library. I guess if I ever get my hands on another old phone, I’ll have to continue with a part 5 of this series.

Phone Keypad Hacking: Part 3

In parts 1 and 2, I walked through my journey of repurposing the keypad out of a phone from 1980. I learned that a more modern keypad matrix doesn’t exactly function (behind the scenes) in a way I’d expect. I wanted to understand it better so I set out to recreate a 2×2 keypad (kept it simple to make wiring easier) that would function the same way as something you can buy today. It would be a success if it worked with the Arduino Keypad Library.

adafruit-3x4-keypad

From my earlier looks through the code I knew it pulsed power out to a column pin and then read in each row’s key from that column before switching to the next column and repeating the process. I figured that should be enough for me to wire this up and try example programs without going back to look at the library’s code again.

I don’t know why I was thinking this would be more complicated and at least a little more exciting, but it was unbelievably easy. I guess I should be celebrating I understood how it worked. Literally all you do is connect one side of every button in a column to a pin and one side of every button in a row to a pin. No need for connections to power, or ground. No pull up/down resistors.

2x2-keypad-matrix-wiring.png

It immediately worked with the Arduino Keypad library examples, even the MultiKey one. I guess being able to detect multiple key presses at once is where the advantage to this implementation comes in. It worked flawlessly when pressing 2 of the 4 buttons, but when you get to 3/4 there are too many connections to distinguish the keys.

Just to be sure I had it figured out, I added a 3rd column to make it a 2×3 grid and it was just as easy.

2x3-keypad-matrix-wiring.png

I love the beauty of how simple this is. I’ve added Fritzing for both of these to my phone-keypad GitHub repo (2×2 & 2×3). If you check this PDF, in the How it Works section it has a really good explanation and shows the row and column connections exactly like I came up with.

Naturally now I need to do a part 4 and attempt to recreate the keypad implementation I ended up with from the old phone. Due to how it mechanically makes the electrical connections I think it’s going to be a bit more complicated than this was. We shall see…

Update: Read part 4.

Phone Keypad Hacking: Part 2

Go back and read Part 1¬†if you want to the full story on this little project. I did decide to get rid of the PCB on the old phone keypad. Good thing I’ve been getting a lot of desoldering practice. In order to remove the PCB, I first had to remove the wires I had added to the column and row contact points. That was easy and getting the PCB off was a pretty smooth process as well.

PCB and new look of the back side of the keypad.
Other side of the PCB. The white rectangle is the back of the 557D IC.

Now that I didn’t have the PCB to carry power and ground around everywhere, I had to solder in my own wires. I also had to solder back in all of my connection points to provide the outputs I’d feed into a microcontroller (I used an¬†Adafruit Feather 32u4 Basic Proto).

Once all of the wires were in place¬†and then connected to my microcontroller I wasn’t getting expected results from a simple little program I wrote to display¬†the values. Took far too long for me to remember I needed to use pull down resistors to prevent floating values. I put¬†10k ő© resistors in each of the circuits…

img_8994
Prototyping with pull down resistors.

Output from the pins couldn’t get any better…

phone-keypad-row-col-values.png

I loaded an example from the¬†Arduino KeyPad library, which gave me¬†very weird behavior. After looking¬†at the underlying code, I realized it wanted the outputs of the keypad to be HIGH when a key¬†was not pressed and LOW when it was. Well, my circuit¬†was doing the opposite, so I had¬†to have to invert everything. I didn’t have any inverter ICs, so I used NPN transistors to create an inverter circuit on each output.

img_8993
Prototyping by inverting the output of the keypad column and row values.

Progress. Now I was able to get the library to correctly recognize some key presses. 95% of the time it seemed to think everything was coming from column 1 (1, 4, 7, *) though. The library comes with a MultiKey example. When I ran that, it was reporting every key on the row as being pressed. WTF?!

For the life of me I could not figure out what caused this. I checked wires, measured voltages, did continuity tests, resoldered connections, changed boards, used¬†different GPIO pins, and countless other things. Nothing made a difference.¬†My own¬†code was working beautifully though. Eventually I gave up on the library. It wasn’t worth the effort and I was out of ideas.

Update: Later on I went back and read the KeyPad library code again because it was bugging me. Turns out these keypads don’t actively read the column pins like they do the row pins. My assumptions about how they worked was very wrong because I hadn’t read far enough into the code before. When checking for key presses, typical keypads¬†iterate through the columns to¬†send a pulse which feeds over in to the rows, which are¬†then read¬†in.¬†How a Key Matrix Works¬†has a pretty good explanation with visuals. If I get my hands on another similar keypad maybe I’ll try to recreate¬†this functionality.

I rewired everything to use the pull down resistors again (video of soldering). A huge benefit of the decision was it drastically simplified my circuitry. This would save me 49 solder points! I probably would have needed to use a half-size perma-proto board instead of the 1/4 size I ended up using.

I decided to put in a piezo buzzer to add sounds. I also used a tiny LED, which I had salvaged from some old computer speakers, to show when power is switched on to the backlight.

The finished board. Isn’t it a thing of beauty?

 

Side view before bending the output wires off to the sides.

I tried a couple of different methods of producing touch tones (DTMF)¬†to match up with each key, but with the microcontroller I’m using and the small piezo buzzer, the sound was terrible. I would need something a little more capable I think.

Here’s a demo video.

Hard to see the OLED screen in the video, but I was only using it to output each key press. Something like this…

phone-keypad-oled-output.jpg

All of the code and Fritzing wiring are available in my phone-keypad repo on GitHub.

I even went out of my comfort zone and did a quick share of this on Adafruit’s Show and Tell. If the video doesn’t start at the right spot you can skip ahead to the 12:42 mark. Going back to watch, my¬†demo kind of sucked since¬†it’s hard to hold something up to the Mac camera and push buttons at the same time.

Update: Continue on to Part 3, where I create a matrix of buttons to act as a keypad.