Category: Hardware

Coffee pot and sensorsLike most tech offices, we go through a lot of coffee during the day. We have about 15 people spread between 2 rooms upstairs, and a single coffee pot between us. Generally this means someone makes a pot early in the morning and it’s done by lunch time, when someone else makes another. The problem is that it’s difficult to time your coffee intake with a fresh pot. Wouldn’t it be great if we could get some kind of alert when the pot was ready?

How to get that notification was pretty straightforward: we use HipChat, a very well done message platform from the folks at Atlassian. Even better is that HipChat offers an extensive API, with the simplest method being something called Integrations. These provide a self-contained URL request to make to a particular room and alert all of its members. All I’d need to do is track the coffee pot cycle and send an alert at the appropriate time.

Choosing the hardware

The first step is determining what method to use for tracking the cycle. Looking around online, people have done similar things by looking at the weight of the pot, the level of coffee in the pot and the current consumed by the maker itself. I don’t want to deal with weight (yet) and I find level monitoring overly complicated so I decided on current. Ideally I would be able to determine the cycle based on either the on/off times or the actual current consumption.

I have amassed a pretty large collection of Arduinos at this point, so choosing that platform was pretty easy. I also wanted to have everything self contained as much as possible, which meant looking for something with the following capabilities:

  • Analog inputs for connecting the current sensor
  • Digital output for local monitoring (LED, LCD)
  • Network connectivity for sending a notification
  • Logging to collect enough current data to notice a pattern

The only Arduino that satisfies these requirements is the Arduino YUN. The YUN is different from other Arduinos in that it is actually two chips in one, with a standard ARM chip on one side running the Arduino bootloader and a dedicated Linux board on the other side to run more complex operations. The advantage of this setup is that you can collect sensor input on one side and transfer that to Linux for processing.

For actual sensor monitoring I decided on the SCT-013-010 non-invasive current sensor. This is a version of the fairly popular SCT series, has capacity up to 10A and provides scaled 1V output. That last point is important, because I find it simpler to take analog voltage input than creating a circuit to make the scaled current output provide meaningful data.

Finally I added in a 128×32 OLED LCD I had from a previous project, for local monitoring of the current consumption. With that in place, I might even notice a pattern by glancing at the screen.

Collecting the data

While the current sensor is technically “non-invasive”, it does require some wire hacking to work properly. It works on the principle that a voltage can be induced in a neighbouring wire through an electric field. However since it works with AC lines, that power fluctuates through both wires at opposite time, effectively cancelling each other out. The solution is to split your appliance wire apart and wrap the sensor around only one of them.

After assembling a circuit according to numerous other current tutorials (like the Open Energy Monitor project), I was receiving current data to the screen, but it did not appear very useful. In fact, this was what I call Road block #1. I was reading the current data as if it was DC, but since AC power is a wave, I was effectively reading a single point in the wave and not the proper current. Fortunately the solution was to better follow that tutorial, and use the Emonlib Arduino library. This library monitors the entire power wave and does the correct math to give you a current value in amps.

With the current readings accurate, I needed to log them somewhere for later processing. To do that I used a MicroSD card in the YUN along with the example sketch called DataLogger. I modified that script to only save current when the reading is 0.1A or higher and to create a new file every day to keep things organized. After a day in the office, I had useful data, but I immediately ran into Road Block #2.

Setting a minimum threshold of 0.1A seemed to make sense, but after seeing the power consumption through the cycle, our particular coffee marker consumes 0.17A at idle. With a logging interval of 1 second, I ended up collecting a row of data every second for 2 days! It was not very useful so I cleared the SD card, reset the threshold to 0.2A and tried again.
coffee-pot-consumption-list
This is the data that resulted from a day of coffee pot monitoring. The Arduino provided a column containing the current time and the current usage, plus a filtered current value I didn’t end up using. I imported the data into Excel and added the column to the right, which is the difference between any one row and the time above it. Since there is no data logged when the machine is off, it became very easy to see the gaps. I also added the conditional formatting to highlight rows that are more than 2 seconds.

Looking through the rows, I was able to find this pattern for a typical coffee cycle:

  • It idles at 0.17A (idle meaning plugged in but not actively brewing)
  • At the start of the brewing cycle, the current changes to approx. 7.5A for 8-10 minutes
  • The end of the brewing cycle is indicated by 25 seconds on and 25 seconds off, twice
  • Once brewed, it repeats a cycle of 15 seconds on, 2 minutes off until someone turns the power off

With such clearly defined points along the cycle, it turned out to be pretty straightforward to detect. The notable complication is that the times are not precise, and it might be on for 8 minutes instead of 10 or heat for 25 seconds instead of 15. I was somewhat disappointed that it did not cycle differently depending on the volume of coffee to heat. I was hoping that it would heat less as the coffee level dropped and I could determine how many cups remained.

Doing the math

To detect the brewing cycle, I set the Arduino timer to compare current usage every second. I stored the previous value and used that to save a time reference for when the current level went above the threshold (set to 6A). By comparing those values, I could get an event when the coffee maker turns on and off, while checking the time between the two. If the appliance is on for more than 8 minutes, that’s considered the actively brewing stage. After that, if there is an on period of less than 30 seconds, that would be the start of the heating stage. The message alert would go out at the end of the brewing stage. I started with a 10 minute brewing cycle but ended up changing it to 8 when I found that the heater wasn’t always consistent. It turned out to be pretty accurate, though!

Triggered by the 1 second timer is this method

First I receive a UNIX timestamp from the Linux processor. This makes comparing times easy. Next I set a few variables based on whether the current usage is above or below the threshold set at the start. This is important because events are generally only triggered when things change. The logEvent() method logs the event to the SD card for future comparison and sendEventMessage() sends a notification to a HipChat room I set up specifically for monitoring my projects.

The brewing cycle checking works by using the current mode and checking the time between when the coffee maker when on or off. If it’s determined to be on for more than a minute nonstop, it’s considered “brewing”. Once it turns off and the gap between events is more than 8 minutes, that’s the end of the brewing cycle and the method sendMessage() is triggered to actually send a HipChat notification. After that a short on/off cycle is checked to look for heating and if it goes off longer than 5 minutes, the coffee maker is idle. The trick is generally to not detect another stage in the cycle if that stage is currently active. That usually removes the issue of sending a message continuously instead of once.

Sending a message

The YUN provides multiple ways of sending an HTTP request, but the easiest thing is to trigger a bash script inside Linux, instead of using Arduino directly. Finding that out was the solution to Road block #3. Throughout the internet, keyboard warriors warn about using Arduino’s string object and how inefficient it is. I started by generating a cURL request with a single String object, but that never worked. It turns out that I ran up against what appeared to be a memory limitation inside Arduino that probably limits string length to 256 characters. The cURL command I wanted to run was about 260 and would exit without error, but without actually sending a message. The solution to that problem is to move the cURL command to a separate bash script on the SD card and trigger that script from Arduino instead.

The last problem was that cURL would try to verify the SSL certificate that HipChat was using but was unable to. While probably not proper, the easiest thing is to disable that check using the -k flag in the command. After that, I set up the monitor and 10 minutes after brewing started, this appeared in our All Teams chat:
hipchat-coffee-bot-message
After a few days of operation, it seems to be fairly accurate and people have responded well to the little machine we call Coffee Bot.

Next steps

As mentioned I was hoping to be able to retrieve coffee levels from the current interval but since our particular coffee maker doesn’t do that, I’ll have to add a scale. With weight data available, I could know right away that a new pot is brewing and how many cups are left. It would even be possible to make the HipChat integration accept requests to know how many cups are left. You could write /coffee cups to know the number or /coffee time to know how long it’s been heating.

We also have tea drinkers so it would be reasonably straightforward to add a tea pot sensor. That cycle is even easier because it is either on and heating or off.

Finally I might make the hardware collection a little prettier for the shelf by maybe 3D printing an enclosure and making a proper PCB but that’s now pretty far down my list of electronics projects.

Electronic tinkering and building have become a bigger hobby for me as I finished my university degree. The Arduino development platform is quite a remarkable system, and the online community of users is growing every day. The problem with many of the projects that I do is that many systems require more power than the 50mA or so the Arduino can provide. You could use different AC-DC wall adapters, but that becomes unwieldy.

The DIY solution, as many Arduino users have discovered, is to repurpose a used computer power supply unit for cheap, regulated 3.3V, 5V and 12V DC power. I decided to build my own based on some other examples, while adding things that I need for my projects. I documented the procedure in an Instructable but thought I would expand on the design and build process here a little more.

Design Requirements

I did lots of planning before cutting any sheet metal because I wanted to follow the engineering procedure. The major requirement for this is to decide what features the final system needs to be successful. I chose the following:

  1. Ability to remove the 24 pin ATX cable to power other projects
  2. Access to all available PSU voltages (3.3V, 5V, 12V)
  3. Different connectors to make powering different components easy
  4. Fuses to prevent powered systems from breaking
  5. Keep some external cables for future expansion
  6. Connectors on the top of the PSU

Bill of Materials

With the requirements in hand, I started browsing for and collecting components. One of the things I noticed right away is that any power supply with a top mounted fan would not useable. This means that my system is limited to about 300W or less, which for desktop projects is completely fine. Older, cheaper and lower power units were the first place I looked, but I quickly discovered another requirement: a 24 pin ATX connector instead of the older 20 pin standard. This limitation meant that I had to build a new one from Newegg instead of on the used market. The cost worked out to be the same.

After waiting a few weeks for delivery, the following parts were on my table:

The ATX breakout board handles the operation of the PSU by properly shorting the on/off wire and providing indicator LEDs. It also breaks out each of the voltages on the cable to a useful screw terminal pad. If you choose to use a different method, turning the power supply on is as easy as shorting the green wire with a common ground. The other parts I found on eBay or various electronics retailers on the internet (try Adafruit, RobotShop, Sparkfun or OddWires).

Design Process

My first step was to measure and replicate each part as accurately as possible using a 3D CAD package. If you’re looking to do something similar, take a look at Solidworks, Autodesk Inventor, SketchUp or Pro/Engineer and decide which to learn. They all perform the same functions, although SketchUp is less about dimensions and more about sculpting 3D objects.

With the components in my system, I was able to lay out all of the holes on the PSU shell to confirm space. I was able to fit 5 2.1mm DC barrel jack connectors, the power distribution block and ATX board on the top surface, with the fuses moved to the side. The software made it very easy to print templates for the hole locations on each surface.

One of the things I needed to look out for was preventing interference between the barrel jacks on top and the internal heat sinks. That meant modelling additional components inside the shell, but doing that extra step prevented numerous hangups further down the process.

As a quick note, please keep in mind that this is a record of my procedure and by no means a complete step-by-step instruction manual for hacking power supplies. These units produce an evil amount of electricity and can be dangerous when misused. Remember that before breaking open the tool box and realize that it’s entirely your choice to void the warranty.

Drilling and installing the components

Cutting into the sheet metal container can’t be done by hand, of course, so here’s a list of tools I used:

  • Power drill
  • Assorted drill bits
  • Step drill (with 3/16″, 3/8″ and 1/2″ sizes)
  • Round file
  • Dremel deburring tool
  • Assorted screw drivers
  • Wire stripper
  • Diagonal cutters
  • Multimeter

If or when I build another unit, I’ll add a center punch to that list in order to accurately dent the material to start drilling. Without it, I needed a finishing nail and hammer, which reduced accuracy somewhat.

Start by ignoring the warranty labels and cracking open the PSU shell.

Inside you’ll find a semi-organized collection of wires, circuit boards, capacitors, MOSFETs and heat sinks.

Now is a good time to tape the hole template paper to the shell, if you’ve prepared one. For the most part the holes aren’t for accuracy relative to the shell, but more for proper spacing between the individual holes.

Drill the 1/2″ holes for the fuses with the step drill. The thin sheet metal will produce burrs on the underside that you’ll need to clean up for the fuse holder to sit flat.

Do the same for the 3/8″ holes for the DC barrel jacks. Both of those components can then be loaded into their respective locations because they’ll need to be installed in order to solder the wires.

Wiring and soldering the connections

Routing the cables from the bottom PCB to the fuses and on to the barrel jacks was somewhat of a challenge because of the arrangement of the heat sinks and bottom components. I cut the external connectors and passed the wires inside to test for length. The overall path for the positive cable of each voltage would be PCB – Fuse – barrel jack and the associated ground wire went directly to the barrel jack. Be careful not to pull too hard on the PCB because tracing the wire back to the soldering pad can be a real pain.

Generally the fuse to barrel jack wire was soldered first, because it was the easiest to trim and arrange. The fuse holder only has two pads, but the barrel jack has three, which means before soldering anything you’ll have to learn the pinout configuration. The most common barrel pinout is center positive, so that’s what I used. Finding which pad was which meant connecting a wire to the jack and checking continuity with a multimeter. Not difficult by any means, but it can be time consuming.

After reinstalling the shell, I soldered on the screw terminals to the ATX board and connected the 24 ATX cable. The brass standoffs are used on the ATX board to raise it from the metal shell, so those were installed next.

Testing the entire unit was a simple matter of connecting the multimeter to the screw terminals and barrel jacks.

After testing, how you use the power supply is completely up to you. The easiest way to incorporate the power is to feed lines from the screw terminals to a branch on a solderless breadboard. Saving the cut off internal wires is a great way to wire them together.

This was a great project for me to test design principles and following through with a project from start to finish. It now opens the doors to building systems with motors, thermoelectric coolers or any number of other sensors.

Tagged with: , , ,

As home networks become larger and larger, new technology will be required to get gadgets connected that are sprinkled around the house. D-Link, along with other manufacturers, has recognized that many electronics now require internet connectivity, but are either not wireless, or located next to an ethernet plug.

A possible solution to this problem is network adapters that work over existing electrical wires embedded in walls. There are multiple technologies in the market now, and many do not work together, but most work in the same way. An adapter is plugged into the wall socket, with an ethernet cable connected to a device, then another adapter is plugged into a socket and wired router. Now the device is connected to the network, and can enjoy (theoretical) speeds of 200 Mbps.

Setup

In terms of installation, I don’t think I’ve used a network product with an easier setup. With an adapter connected to my router, and another connected to my Playstation 3, I had internet within seconds. The adapters are small enough to fit in convenient places, and the LEDs provide feedback about device status and network connectivity.

Performance

I bought a set of these adapters to connect my PS3 to my network and enjoy media shared on my computer. After the setup and a quick connectivity test, I was excited to try a movie. Sadly, this was where the set fell short.

D-Link says that under ideal conditions, these adapters can provide up to 200 Mbps throughput (which is about 25 MB/s). In my house, I achieved about 3 MB/s. This was found by using my MacBook to transfer files over ethernet. Disappointed but not defeated, I moved the second adapter through my house to test the transfer speeds. Speeds ranged from 768 KB/s on the opposite side of the house to 6 MB/s in the same room as the router. This was about the same as my previous solution, so I decided to return the adapters.

Conclusions

I can’t say I’m all that surprised about the performance, as wiring varies from house to house. My house was especially tough because the router room is on a different subsystem than the living room. This product would probably work best in a fairly new house, with sockets in basically the same area.

If you’re planning on purchasing a set of PowerLine adapters, be sure to check your supplier’s return policy. Test them immediately in a variety of locations and configurations, and look at alternative solutions if they don’t perform close to the manufacturer’s estimation.

Tagged with: , , ,


It has happened. After 2 solid years of service, my MacBook has cracked on the top case, in the above picture.

I thought I was being careful with my computer, but even with careful usage, it seems that a combination of the monitor spacers and palm pressure cracks the case on the edge. Naturally the new unibody MacBooks don’t show this problem.

If this problem has happened to your computer, Apple now repairs the case free of charge, regardless of warranty. Take it to the Genius Bar and it should be taken care of.

Tagged with: , ,

Batteries are technology’s weak link. While tech like processor clock speed, hard drive capacity and graphics cards has accelerated rapidly over the last few years, battery capacity and total usage time has remained relatively constant. Sure, the newest lithium ion power packs can give your computer a solid 2 – 3 hours of charge, but we’re still a few years away from being able to work untethered for a good 6 – 8 hours.

I bring all this up because my MacBook has a problem with the battery that I’ve seen on others. As the above screen capture shows — from the iStat nano widget — the battery suddenly has 4% health after I used it for 10 minutes. The health is different from the actual charge because it represents the maximum possible charge the battery can take, which means how long the computer can run. What seems to happen on my computer is that it appears normal for a while, but then suddenly drops to less than 10% without warning. My friend had a MacBook with a similar problem — it would shut down when it had (supposedly) 30 minutes of power remaining.

Apple states that a battery is considered defective if it holds less than 80% of its original capacity and has fewer than 300 charge cycles. A charge cycle is the the time between a full discharge and charge — from full power to shut down. If the battery meets this criteria, it may be eligible for replacement. Since I have AppleCare, it seems that I will be taking the computer to the local Apple Store to see if a Genius can get me a new one.

Has anyone else seen a problem like this?

Tagged with: , , ,