Introduction: EMail Light: LEDs Show New Email
The idea behind the eMail Light project is to indicate the presence of emails that are currently on my email server with a flashing LED. I am often not right at my desk and I would like to know if I have email. Or I am near my desk, but my screen saver has kicked in while I’m working on something that doesn’t involve a constant mouse wiggle. By making a little black box with LEDs that can be controlled by USB through a mail monitoring program, I can be alerted to the presence of email on my server.
Step 1: Mail Light Parts
- a USBmicro U421 USB interface
- a ULN2803 driver
- a bit of circuit board
- 8 LEDs
- 8 330 ohm resistors
- a small plastic box
- 8 LED mounting rings (optional)
- wire-wrap wire for point-to-point circuit connections
- a small 4-40 machine screw
- an aluminum bar
- solder, solder flux
Various tools are appropriate and include (but are not limited to):
- a screwdriver
- a nutdriver (for the connection to the back of the monitor)
- a soldering iron
- a 4-40 tap (if you tap the bar - optionally use a nut)
- a vise with a brake for bending
- drill and bits for plastic box holes and hole in bar
- flush cutter
Step 2: Plastic Box
I chose a small plastic box with a black finish. Four LEDs will be mounted on one side visible from my position seated at my desk. These LEDs are bright, but not blindingly so. On the other side of this box are four very bright LEDs. These bright LEDs will be visible from my lab. I will be able to just glance into my office and see if I have email.
Step 3: Inside of Box
The inside of the box has enough room for the U421 and other parts. There will be a slot for the USB cable to exit the box. Eight 1/4″ holes will be drilled for the LEDs. The inside of the box has a little bit of extra plastic in the way.
Step 4: Altering the Plastic Box
I removed the extra plastic with the same tool I use to flush-cut component leads (flush cutter, or wire snip) on soldered boards. Then I removed the bits of plastic that remained with a small chisel.
The idea is to get that bit of plastic out of the way. Snipping it off was rough, but worked well. The the rough remainder was carefully sliced away.
Step 5: Drilling Holes
Each side of the box will have four LEDs. I drilled four pilot holes for the LEDs. After that I enlarged the holes to be one quarter inch to accommodate the LEDs in their mounting rings.
Mounting rings are optional. The LED's holes can be sized right to work without the rings.
Step 6: Printed Circuit Board (PCB)
I used the type of printed circuit board for this project that I frequently use for prototyping things. This board is a grid of holes spaced .1″ apart.
Step 7: Cleaning the PCB Copper
On the bottom of the board are isolated copper rings – donuts. The copper should be cleaned until shiny. I used a metal brush and scrubbed in two or three directions until the copper is shiny. Then I coated the copper with liquid flux and applied solder to completely cover the exposed copper.
Step 8: Cut the PCB to Fit
Before applying solder, I cut the board to fit the little box. To cut, you can score the printed circuit board with a knife, and snap the board. Some cleanup with a file might be considered.
Step 9: Adding Components
The USBmicro U421 USB interface can drive one or two low-current LEDs directly. But several of the LEDs I chose are not low current, and using a driver to pump a little more current through the LEDs will make the bright ones very visible from way over in my lab. The U421 provides 5V from the USB port. In the photo below the U421 was mounted on the PCB along with the ULN2803. Resistors will be mounted and connections will be made on the bottom of the board.
Step 10: PCB From Under
The bottom of the board with the U421 and ULN2803 in place will be mounted to the shell of the box that has the LEDs.
The LEDs that I picked for the project are each a unique color. I’ll assign an email account to an LED that will flash on each side of the box.
The LEDs are easy to mount in a 1/4″ hole when these little mounting rings are correctly employed.
Step 11: LEDs Mounted in Box
Eight LEDs are placed on one half of the box with the leads bent toward where the PCB will be. It was an adventure poking all 16 leads through the printed circuit board.
With the LEDs in place, and the PCB navigated onto all of the LED leads, the LEDs are then soldered in place.
Step 12: Soldering Connections
The connections for the components are made on the bottom of the board with wire-wrap wire. A soldered-in-place component on the top of the board leaves a small pyramid of solder on the component leads. When wire-wrap wire is used for making point to point circuit connections, a very small bit of the wire insulation is removed from the ends of the connecting wire. The “pyramid” of solder is melted and the wire wrap wire end is poked into the melted solder.
The USBmicro site had a guideline for driving an LED from the output pin of a U401 or U421. Extending that to use a ULN2803 for this project was easy. One of the app notes at USBmicro also has a ULN2803 driving LEDs and relays. Both schematic fragments are pictured below to serve as a guide.
Step 13: Testing the Electronics
One 8-bit port of the U421 is used. Each of those 8 lines leads to an input of the ULN2803. The outputs of the ULN2803 connect to each of the LEDs through a 330 ohm resistor. The anodes of the LEDs connect to the 5V line on the U421. Ground on the ULN2803 connects to the U421 ground pin.
The finished eMail Light electrical hardware is assembled and tested with the output test application from USBmicro.com.
Step 14: Mointing the Mail Light
The eMail Light will mount on the back of one of my LCD displays. I modified a straight stock aluminum bar for this.
The bar needed a short 1″ section bent. This I did by putting the bar in a vise brake.
The bent section of the aluminum bar will be screwed to the plastic box.
On the bent 1″ section of the bar I tapped a #4-40 hole. One half of the plastic box – the half without parts – will have a little hole in it for the screw. I also drilled holes of appropriate size and spacing on the long part of the aluminum bar for mounting on the back of my LCD monitor.
The plastic box half was tightly attached to the aluminum bracket and then the box was reassembled.
Mounted under my monitor and plugged in to USB, I was able to use the USBmicro output test application to verify that the regular LEDs were visible from a sitting position at my desk, and that the super-bright LEDs facing “back” were easily visible in my lab.
Step 15: REALBasic Software Development
The REALbasic development environment REAL Software is used for this development since it made the email code (pop protocol) very easy.
The goal of the software that I created was to connect to four different email accounts and monitor them for the presence of email. If email was found, a specific LED associated with that account should blink. The LED blinking rate should be changeable, the rate at which the email accounts are polled should be changeable, and the program should hide as a tray icon until needed.
Each of the four accounts has a quarter of the main window with a few text areas for account information. The quarter is pictured below.
Step 16: Software Details
Note: The compiled software is available for free from the CircuitGizmos blog.
Each account has a connect button for enabling that account. When connected, the email account is scanned for email. To the right of the connect button is a visual indicator that will blink in unison with the LED. To the right of that is a text field that shows the number of messages that are on the server of that account.
The box marked “server” should contain the server address. Something like “pop.flintstone.com”. This would need to be the right server for your email account. Below that is the name that you use to log in to your account. It might be “fred” or it might need to be “firstname.lastname@example.org”. Under that is the box for your password. It is a field that shows up as asterisks. My password happens to be: ******* :-)
Under the password field is a box that contains the rate, in minutes, that the email address is queried. Below that are two connection status boxes.
The other three email addresses are repeated.
To the lower right of the main window there is a box for the blink rate in 1/100 of a second. A value of 50 is a 1/2 second blink rate. Above that is a button to exit the program.
On the upper right of the main window is a button to hide the main window. A double-click on the program’s tray icon will expose this main window again. Everything keeps running with the main window hidden.
When the program is run, it needs to build up a tray icon and set that tray icon to a graphic (in this case called cg4) that is included with the project: (see pic)
When the program is closed, that icon needs to be removed from the tray: (see pic)
The app tray object itself has only the task of making the main window visible when the user double-clicks on the tray icon: (see pic)
The hide button on the main window just makes the main window not visible: (see pic)
When the main form is made visible for the first time that the program is run, the U421 USB interface is discovered and the defaults for the program are loaded. Communication with the U421 is done through a DLL that is opened by REALbasic when the function inside that DLL is defined. The code first declares the three functions needed (and creates a return value for the function call) before using the functions: (see pic)
USBm_FindDevices is the first call to USBm.dll. It searches the PC’s USB bus for U401 and U421 devices. In this simplified example code the true/false return code is not used. Non example code would want to process the return values for error. Port A of the U421 is set to output with this call: USBm_DirectionA(0, &HFF, &HFF). The 0 assumes that there is only 1 (indexed to 0) USBmicro device on the bus. If there were more, then additional code would be necessary to address the correct device. See the USBmicro information in the On-line Development Notebook (ODN) for all of the port direction command information.
Once the direction is set to output, all lines are turned off (0) to disable the LEDs: (see pic)
After that a file called “maildata.txt” in the same folder/directory as the executable maillight.exe is searched for. Again, in a program other than example code, more code should exist to handle errors such as the file not being found.
The file contains text information that is read into the text boxes in the main window. The first line of the file should contain the server name for Email 1, the second line should have the user name, etc. The last line has the LED blink rate. The comments in the code show the format: (see pic)
The file is opened and each line read into appropriate text boxes: (see pic)
The LED blink rate is the last of the edit field elements that are loaded on start up by loading this file. Changing the values in the text fields after the file is loaded is also possible by editing those boxes.
Step 17: Intermission
This is how the core routines were implemented. The core routines revolve around a timer that flashed the LEDs, four timers that check for email at a certain rate, and the REALbasic objects that manage the pop connection.
Step 18: More Software
Again, remember - This software can be downloaded for free from the CircuitGizmos blog.
The simplest component is the timer that goes out to get mail every couple of minutes. There is a timer for each of the four mail accounts. When the timer times out, it simply calls the pop3 object and tells it to connect:
After the connection is established, the pop3 object prints that status in the first status box. After it connects, then a login is attempted. When the login is successful, the number of messages that are on the server is counted:
The pop3 object counts the number of messages on the server and displays that number. If the number is 0, then a boolean variable is set to false. If there is 1 or more messages, then that variable is set. That variable determines that the LED will be blinking. After counting the number of messages, the pop3 object disconnects and clears the status text:
The timer that checks for mail doesn’t run until the connection is made for the fist time with the press of the connect button. When the button is pushed, the server, user name, and other data is passed to the pop3 object and a connection invoked. The timer is started (for next email checking time) and the button is changed from a connect button to a disconnect button:
If that same button is clicked after it has been toggled to be a disconnect button, then the pop3 object is disconnected from the server (if still connected), the timer is turned off, status cleared, the LED blinking is disabled, and the button again becomes a connect button:
This isn’t an email program – you don’t get to read the email that you have with this program – you are just notified that you have email waiting on your server. After you are notified that you have email, you would go get those emails with your email program. The LED will likely still be blinking after you get the email with the other program. Clicking the button to disconnect and reconnect will start another check and discover that your email had been cleared.
The LED blinking routine is actually the longest of all of these functions. When the blink timer times out, the USBmicro DLL stuff is defined. The value for the LED port of the U421 (port A) is set to 0 before accumulating the status of the email accounts:
The blink timer toggles the graphic indicator (and eventually the LED) on and off every other time that the timer times out. A boolean variable is flipped from true to false every other time. When false, the indicator is off. When true the indicator is on if there has been a message detected. And if the indicator is on, then LEDval is set to turn on a bit for turning on a specific LED:
The first LED on the front and the first LED on the back are turned on with the value of &H11. The 2nd LEDs with the value of &H22, the third with a value of &H44, the 4th with &H88.
Once these values are all combined, then the value is sent to port A ov the U421:
Download the REALbasic project and the executable code: eMailLights Project and program.
To set this up for your email, edit the maildata.txt file to include your four (or fewer) email settings. When you run the program, these settings are loaded. You can leave the password as a blank line if you don’t like having a password in this file.
Click connect on all of the accounts that you will use to start the mail checking process. Click hide to hide the window to the tray icon. Recover the main window by double clicking on the tray icon.
When the program discovers an email in the accounts that it checks, the visual indicator will flash. If you have built the Mail Light hardware, then you will see flashing LEDS.
There is a lot of flexibility in the LEDs/lights that you can put together for this project. Originally I had planned to put a stack of ping pong balls on the top of my monitor to light up with some LEDs. This looked great in a dimly lit room and in the evening. But with my office window open, the ping pong balls just were not light enough against the open window to see from my lab.
Code could be changed to do more than just light LEDs. You could attach an LCD display to the U421 that would display, in text, the number of emails that are in each account. The U421 could directly drive a pair of seven-segment LED displays. You could use multiple U421 with a combination of hardware designs.
Step 19: Enjoy!
Enjoy this project. I have found that it is a very useful device just in the week that I have been using it on my PC. It will be a permanent part of my PC sertup now. If I make improvements to the code I will share it here. You are free to make improvements, suggest features, and port the code to other development environments. Or you can just build the hardware and use the software freely to drive your own eMail Light. Share pictures of your email light and experiences building. :-)