Tag: Arduino

Finished product
My apartment uses baseboard heaters and anyone who’s paid for hydro can tell you, they’re pretty inefficient. I wanted to collect some information about the inside conditions of my apartment so that I could better understand when and how to turn the heaters on. Normally a simple thermostat would do, or even a Nest, but my equipment is so basic, there is no read out available.

So I built my own. Here’s what I did.

In high level terms, I have an Arduino UNO using a WiFi shield and custom PCB connected to a DHT22 temperature and humidity sensor and photocell. This information is sent to data.sparkfun.com and is displayed in snapshot, table and graph form on my iPhone.

Setting up the Arduino

The components with the Arduino are all fairly well known, but I had not made anything with them together. Here are the parts and links to where to get them

I put them together on a breadboard and build the code. I can provide code if interested, but essentially I assembled individual modules in order to upload the data every 5 minutes. As far as the program goes, it’s laid out like this

  1. Include all libraries — this uses DHT, Timer, Wifi, SPI WifiClient, WifiServer and medianFilter
  2. Define base variables — Wifi shield configuration, website, pins, etc
  3. Create objects — Timer, client, server, filters
  4. run setup() — set pin modes, connect to Wifi and set the timers
  5. loop() only updates the timer
  6. Every 30 seconds all sensors are read and added to a filter
  7. Every 5 minutes the filtered data is sent to data.sparkfun.com

Creating a circuit

schematicA breadboard is fun for prototyping, but it wouldn’t look so good on a shelf, so I took the opportunity to test out a new PCB manufacturing website by building my own circuit. The pinouts of all components is fairly easily available online, or better yet, in EAGLE itself. The board doesn’t have many pieces, just some 0.1″ header holes, but the tricky bit is making sure that there are no pin conflicts with the Wifi shield.

Moving to a PCB

environmental_board
EAGLE provides a nice way to import a schematic to a board, and since I started with an Adafruit shield piece, there was a nice outline ready for me. At that point it was a matter of making sure that all traces have clean paths and there are 5V and GND planes.

1-IMG_7920
4-IMG_7930
3-IMG_7924
I tried a PCB service previously called OSHPark.com but was unhappy with the cost and lead time required. A friend pointed me towards dirtypcbs.com and that turned out to be a great choice. The name is basically entirely what you get: printed circuit boards at affordable prices, with a very reasonable 1 week lead time. I was also impressed with the shipping from China, as it was no more than an additional week with DHL. That’s 2 weeks for 10 custom boards.

Displaying it all on a phone

The data is sent to data.sparkfun.com, which provides a nice free way to store key-value data (eg. temperature=25,humidity=38, etc) and a way to retrieve it. During the day I work for a mobile software company, so building something to retrieve the data was fairly straightforward. I ended up with a way to view different properties in the latest data, table and graph form.
IMG_1565
This is the home page where the latest data point is displayed front and centre, along with the time it was retrieved. The time is relative, so a timer runs every second to indicate how old it is, but clicking the label shows the actual timestamp. Below that is some related information that might be useful: the 24 hour high value, 24 hour low value, and the current outside temperature according to forecast.io.
IMG_1569
Additionally the menu button at the top left presents a slide out “hamburger menu” that can switch between the different properties collected.
IMG_1570
The middle tab shows the last hour of data in table format and as you scroll downward, will load the next block from Core Data. In order to keep the actual internet request simple, the app retrieves the timestamp of the most recent datapoint and only requests points from Sparkfun that are after that. All points are stored in Core Data and loaded on demand.
IMG_1567
Finally the right most tab shows a graph of whatever property is displayed at the time, with options for last 4 hours, last day or last 4 days. At first I had last hour but I realized the data I was collecting wasn’t really changing in that time frame so it was largely useless.

For the most part the graphs are consistent, with my heater keeping the temperature at about 19-20C through the day. The light graph is very interesting because it clearly shows when the light goes off and how sunlight filters through the curtains in the morning.

Next plans

There’s one thing I’d change about the PCB design, and that would be to replace the fixed photo cell resistor with a potentiometer to adjust the threshold. Right now I’m using a 16k ohm (I think, something about 10k) and that produces a nice range between full bright and darkness, but it would be good to adjust as required.

With the data collected, I’d like to now make use of it somehow. You might notice how the board has 4 pins showing “relay” on it, which is so that I can connect an AC relay and control my lights or humidifier. Ultimately I’d like to work in some geocoding to my app so that I never come home to a dark apartment and have my light be smarter so that it doesn’t turn off while I’m still at my desk.

Tagged with: , , ,

Arduino, PowerSwitch Tail 2, humidifierMechatronics is described as the intersection between mechanical, electrical and computer engineering, and it covers just about anything that uses electronic signals to act on mechanical systems. It’s what I went to school for, and it’s where my hobby interests lie. The Arduino is a fantastic example of how people with limited experience can jump right into mechatronics projects. I’ve been tinkering with them for a few years, and decided to put the components I had to good use by taking a timid step to home automation.

Indoor humidity can affect the comfort level of a home pretty dramatically. Since warm air can hold far more moisture than cold air, the humidity inside during the winter falls dramatically. This drop can cause an increase in static electricity, sickness and dry, itchy skin. Too dry and a home can just feel downright uncomfortable. Too much humidity when the outside temperature is low can also cause condensation on the windows and mould growth. Some humidifiers have a built in control system to maintain the proper level of humidity, but what if yours doesn’t?

By combining an Arduino with a basic humidity sensor and relay, you can trigger your simple humidifier to only come on when needed.

Bill of Materials

With these pieces combined together, you can find the indoor temperature and humidity, and adjust the humidifier’s set point manually to achieve the proper moisture level.

Assembly

Complete breadboardHere are some links about connecting the different components that make up the system.

Additionally I have a few bonus status LEDs for displaying when the correct humidity has been reached (although you’ll be able to tell from whether the humidifier is on or off). The great part about the Arduino community is that most of the major components have libraries dedicated to their functions, so you can spend less time figuring out how the hardware works and more time thinking of projects.

Control System

The control system is the set of governing equations and parameters that determine what behaviour the system’s output should have. In this case, it takes in the current level of moisture in the air and tells the relay to switch the humidifier on or off. For that reason, it’s a type of control system called “closed-loop”, because turning the humidifier on will increase the sensor value and trigger it off.

There are many other different types of control systems but we’re fortunate that the main type in use here is called an “on-off controller” for its inability to adjust output values. Like a furnace, the humidifier can be either on or off, with the time in each state determining the magnitude of change. Compared to a PID controller, which uses error correction to maintain a system, the on-off controller is far simpler.

The complete source code is available to download below, but I’ll go through some of the important parts here.

Temperature and humidity outputEven in a relatively simple system such as this, it’s important to follow proper coding patterns. This means using the Model-View-Controller paradigm to retrieve sensor data and output to the screen and relay. In even simpler terms, it means storing the inputs as variables and refreshing the screen rapidly with those variables. For that, it’s a good idea to use something like a Timer class to handle running specific methods at an interval without blocking the main program.

With the button, I’m able to toggle between two states: normal and setting. Doing that is easy with enumerations.

Each time the button is clicked, the state of systemMode is changed, and the display is updated accordingly.

Toggling display modesThe ModeSetting value is where a new setpoint for the control system is entered. When TARGET is displayed on screen, the encoder LED flashes (again with another timer) and turning the encoder updates the value.

While the above links show a clear way of entering the new encoder value, here’s my function.

You only want to update the target value if the current mode is Setting and the new encoder value is different from the previous.

Whenever the system mode returns to normal, the controller checks if the current value is where it needs to be and updates the relay accordingly. However, it’s not as simple as turning the relay on when humidity is below the target and turning it off when it goes above. If that was the case, there would be far too much cycling. That means as the error approaches 0 (humidity reaches the target), the actual value could repeatedly go across the threshold and cause the humidifier to cycle on and off quickly. I’ve set the refresh rate to be 1 minute, but even that would be annoying if it cycled that quickly. To fix the problem, we need to introduce a control system property of hysteresis, which in simplified terms means making the humidifier stay on until it passes the target by a few percent, and not turning on until it’s a few points below the target. This way it cannot rapidly switch between the on and off states. In code, that might look something like this.

Here, the variable correct is the value of whether the system is currently at the desired level, and hysteresis is the percent of padding (2% here).

What this block is essentially saying, then, is “if the humidity is currently above the desired value, don’t turn on again until the humidity is below target – 2” or “if the humidity is currently below the desired value, stay on until the humidity rises to target + 2”. In this way, the system won’t turn on and off in quick succession.

Connect the PowerSwitch relay pins to ground and an Arduino 5V output, and set the state of the pin according to correct. Then sit back and listen to the satisfying click of the relay as computers do your job for you.

Controller and humidifier together

What’s next?

Since this current version requires you to set the target point on the humidifier manually, it’d be nice to make that automatic, too. But how? The problem is that indoor humidity is linked to outside temperature, as I mentioned above, so that means you need to find out the local temperature and adjust the humidity accordingly. That can be done any number of ways, like adding a WiFi or ethernet shield to the Arduino.

This is something I’m planning on doing, but I’m going a slightly different route so that I can build on it for more advanced home automation. By building an Xbee network, I can make nodes that act as sensors or outputs and connect them all to a central computer. Since I already have Ubuntu server, that part is taken care of. I can log data to the server and have it request local weather and tell this Arduino whether the humidifier should be on or off.

But the fun wouldn’t even need to stop there. By designing the network right, suddenly you can add other components to do things like turn lights or appliances on or off or alert you when a window is left open at night. Where will you take it?

Tagged with: , , , ,

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: , , ,


After choosing a mechatronics option in my final year of mechanical engineering, I’ve gotten more interested in electronics and computer integration. Sure, I’ve done programming in the past (and present) but there is something very satisfying about writing code on a screen and having it perform an action in the real world. With that in mind, I ordered myself an Arduino microcontroller from Adafruit and have spent the last few weeks learning the ins and outs of some of the included components. So far I’ve hooked up some LEDs, a DC motor and a servo motor to the breadboard and watched them blink and spin. The kit contains bonus material, but you can also get just the board to save some money. It includes components like red and green LEDs, resistors, transistors, jumpers, and the previously mentioned DC and servo motors. Programming the board requires very straight forward C language knowledge. There are dozens, perhaps even hundreds of tutorials online to program nearly all functions of the board itself.

What is it used for?

You may be wondering what the real purpose of the board is, but there is no definite answer to that. In reality, Arduino, being an open source hardware project, has been used in numerous projects seen around the web. Any component that can be plugged into one of the pins can be controlled, which means people have used it to create secret knock opening doors, a radio controlled lawnmower, even a laser harp. This only scratches the surface. My plans, without giving too much away, include building a panoramic camera mount and adding radio controls to household/garage items (project details will be here when they are completed). If you have any interest at all in electronics, I suggest picking one up and learning about it.

Tagged with: , , , , ,