Temperature Monitor for Arduino

I’ve got a 1-year old, and the ducted heating system we have is only a single-zone model with the thermostat in the lounge room.  Since the bedroom doors are typically closed at night, I was always a bit concerned that there may be a large and non-linear temperature differential between the baby’s room and the lounge room.  So I needed a way to track temperature between the two rooms overnight.

The ENVI-R I had fitted is sitting in the return air vent for the heating system and has a built-in temperature monitor which I’m tracking via MRTG.  Given its position, the figures coming back from it should be the same as the temperature recorded by the thermostat in the lounge.
What I then did was pull out my Arduino Inventor’s Kit and assemble Circuit 10, which basically hooks up a TMP36 temperature sensor to Analog pin 0.  However, I heavily “adjusted” the code they gave to make it suited to my purposes.

Code segment is available at Google Code – temptracker.pde

Essentially what happens is that the temperature monitor accumulates temperatures from the TMP36 once a second, and then once every five minutes writes the accumulated average to the EEPROM.  On startup the Arduino dumps the contents of the EEPROM out to the serial port in CSV format so you can recover it.  Given 5 minutes between samples, the Arduino can record a bit over 21 hours of temperature data like that, with no fancy shields or anything required, just a 9V power supply and the TMP36 sensor.
After you’re done, you should load up the EEPROM_clear example and run it to wipe the EEPROM back to 0.
 So, hauling out the data from MRTG and the Arduino and charting them in Excel gave me this;
Room Temperature Comparison

The big spike at midnight was where my wife had to get up and left the door open, so the bedroom temperature normalized to close to the lounge room temperature.  It looks like the room temperature differential is on average 7.5 degrees C, and it looks pretty linear.  It also looks like the heater system (which was set to 19 degrees) didn’t come on, since there’s no spikes on the lounge room chart.

Now, something notable.  These temperature monitors occassionally return garbage data.  The TMP36 on the Arduino sometimes returns 9.08 degrees, and the ENVI-R’s temperature sensor sometimes returns 0.  Why this happens I don’t understand, but the point of the averaging on the Arduino is to reduce the effect of those broken results (a couple of 9.08’s in a whole field of 300 x 15’s isn’t going to change the average much).  In the case of the ENVI-R, I just manually chopped out any obviously broken data.  I should go and fix my collection script to disregard broken results in MRTG.

Anyhow, it turned out to be pretty useful, and I imagine that code could be used as a base for a whole bunch of simplistic data logging applications, where you only need a small number of samples and want minimal hardware.

Building a Workbench

Let’s face it.  I’m a handyman nub.  I’ve got a reasonably functional brain, and I’m technically minded, but I haven’t done any real woodworking since high school (I did Tech Studies in years 8, 9, and 10, both woodworking and metalworking).  So it’s fair to say I’m pretty bad.

I’ve used the fact I haven’t had a workbench as an excuse for years.  I’ve been using a card table, which isn’t the most stable of things.  Given that I’m wanting to make an AeroQuad, I need a proper workbench, damnit!  Metal would be best, but I can’t really make a metal workbench without space in order to weld (which I’m also terrible at), and without a bench already.  So wood it is.  I can make a wood workbench without already having a workbench!

Hitting the ‘net, I came across this design at Bunnings.  Fantastic!  All I need to assemble that is a drill (check), a 10mm wood boring bit (check), a hand saw (check), a bit of wood to lean on (check), a carpenter’s square (check), two quick-clamps (check) and a hammer (check).  And then a crapload of wood and some coach bolts.  And some polyurethane coating and Aquadhere.

The finished product!

Going straight from the materials list and diagram from the link is a mistake if you’re a nub like me.  For one, I have absolutely no idea what a housed joint is or how to make it (I do now).  In addition, the top planks aren’t available in 290mm width, only 240mm, so this necessitates a few changes.  And since you can’t buy 70x70mm legs any more, I had to settle for 70x35mm legs, and bolt two of them together in order to make a 70x70mm leg.  But the bolted together legs also necessitate a slight design change.

So, there’s a few gotchas to be aware of if you follow that plan.  The final result turned out well and I’m happy with it, but be aware of it if you’re a woodworking fool like me so you wind out with a decent product;

  • Since your base structure will be ~600mm wide, the two 240mm width top planks you get will be insufficient.  Get a 140x45x2400mm top plank to go in the middle.
  • Since you’re now adding a plank in the middle, that plank will have no support beam.  Get an extra 70x45x1800mm under bench support.
  • That under bench support will require a few 90mm coach screws to fix it to the top cross supports.  You can’t use your coach bolts for that.  Get 90mm so you have 45mm penetration on both the under bench support and the top cross support.
  • You probably won’t be able to get untreated pine for the top planks.  Treated is OK, but please wear a dust mask and safety glasses when drilling and doing anything with it until you get that polyurethane coating on.  It’s treated with arsenate.
  • Whenever you’re joining two pieces together, chuck a layer of Aquadhere or other PVA glue in there.  It’ll add strength, hold the pieces together, and also reduce rot.
  • It’s not mentioned, but get M10 galvanised washers for the nuts and coach screws.  They’ll dig into the relatively soft pine otherwise.
  • Since your legs will be made of two 70×35 pieces bolted together, you can’t put a hole straight in the middle to hold the top and bottom cross supports on.  You’ll need to put two in, one through the middle of each of the component pieces.  I’ll attach a photo to demonstrate what I mean.
  • Since you therefore have two bolts going through the wood structure, keep in mind that you can’t have bolts going through each other.  You’ll need to drill carefully to make sure that they don’t intercept somewhere you weren’t expecting.
  • Given that you arent’ going to be housing the cross supports into the legs, the total thickness of leg + cross support will be 115mm – too long for the 120mm coach bolts you’ll be getting.  You have two choices – get longer coach bolts, or do what I did and counter-sink the head of the coach bolt.  In order to do this, use a 22mm wood boring bit and drill in about 5-7mm, then finish off the hole with the 10mm wood boring bit.  That provides enough room for the head of the coach bolt to get in and lets you attach the washer + nut on the other end.
  • For the same reason you’ll want to counter-sink the heads of the coach bolts on the top of the bench by a similar amount.  That’s also to keep the top of the bench flat.
  • When Bunnings cuts off the wood for you (get them to do it, they’ll use a table saw and will be more accurate than nubbins with a hand saw), make sure you measure everything before drilling and cutting anything at all.
  • While I’m harping on about it, measure once, measure twice, measure three times, and measure again.  And then measure it another time.  And then check it again.  Be absolutely, absolutely sure you’re completely happy with where the piece is so you don’t whack a hole in where it’s not supposed to be.  It’s easy to stuff it up when you have little idea what you’re doing, like me.
  • Put an extra coach bolt into the middle of the bench top planks.  Keep in mind that the front and back bench top supports aren’t in the exact middle of the bench top plank before you drill!  The purpose of this is to pull the bench top planks tight against the supports and stabilize everything a bit more.
  • The pine will soak up the polyurethane like a sponge.  I put on two coats everywhere, and three on the top planks (on all sides).  That used up a 1 liter can.
  • If you make sure that you get your 140mm center plank exactly in the middle of the bottom frame, you can use that as a guide to get the front and back planks on much easier.  You may need to flip and rotate your planks to find the flat and good side so they line up nicely.

After all that (it took me a weekend!), you’ll have a workable bench – with a benchtop that’s 945mm high, 2.4 meters long, and 620mm wide.  Cost wasn’t too high, under $150 – of which half was the top planks alone.  It’ll be damned heavy, so you may want to get it near its final home before putting the top on.

I got it pretty square, which I was happy about, but the floor I put it on isn’t entirely square, so I had to slip a 70x70mm bit of untreated pine under one foot to stabilize it, but it’s as steady as a rock.  I’m pretty happy with it.

Detail of leg bolt countersinking and offsets
Detail of added in middle top shelf support

AeroQuad – Arduino-based multi-rotor aircraft

While I was poking around about what kinds of cool things people do with an Arduino, I stumbled across AeroQuad.  It’s a site and community for folks who are developing an open-source multi-rotor RC helicoptor.

An AeroQuad (pic courtesy AeroQuad.com)

Now that’s awesome.

As soon as I saw that, I thought to myself “Dude, you totally have to make one of them!”.  Cue the research frenzy, cost analysis, and wife justification strategies (love you, snookums).  And guess what, it looks like it’s pretty viable, and should make a great project to get me back into electronics and also leave me with something totally awesome at the end of it.

So, in order to make a Quad, there’s quite the number of items that are required.  Later posts will detail just how I’ve gone about actually getting those items and putting everything together into a (hopefully) working quadcopter;

  • A work area.  My shed’s a storage disaster.  So the need for a work area has triggered off a cleaning frenzy of throwing out lots of stuff, installing shelving to get boxes off the floor, and I also charged out and bought all the stuff to build a (wooden) workbench.  The bench I’ll discuss in brief later.
  • A variable power soldering iron or a 15W and a 30W iron.  I only owned a 40W iron, which is a bit hefty for delicate electronics on sensors, so I picked up a $99 soldering station from Jaycar.  According to the salesman, the “temperature control” actually just varies wattage, so it can stand in for a 15W iron.
  • Arduino UNO.  You can also use an Arduino Mega for more sensors, but I want to start small and simple.  I got a Uno with my Inventor’s kit, but I’ve ordered a second off eBay.
  • AeroQuad Shield.  This is a board that sits on top of the Uno and provides connectivity to the sensors.  It’s not technically required, but I just got the v1.9 board from the AeroQuad store to get it over and done with.
  • Nintendo WiiMotion Plus.  The WMP has a 3-axis gyroscope in it, which is useable with AeroQuad, and is pretty damn cheap.  I picked up one from eBay, and am planning to use it in the build.  There’s been reported issues with AeroQuad 2.4 software and Wii components, but it’s a work in progress and being fixed.
  • Nintendo Wii Nunchuk.  The Nunchuk has a 3-axis accelerometer in it, which goes with the WMP and the shield to make a 6DOF IMU (inertial measurement unit).  These three items make the navigation heart of the AeroQuad.  The Mega can also take a barometer, magnetometer and such for even better navigation.
  • Miscellaneous Cabling & Stuff.  Various connectors and stuff are required, I’ll get them as I need them.
  • Frame.  I haven’t bought the frame components yet, since they aren’t needed in the early stages.  But I’m planning on using a X of square-section aluminium tube for the arms, with a plastic case for the electronics.  Motor-to-motor diameter will be about 20-24 inches.
  • Battery.  Not required just yet, but a main 3S1P LiPo (lithium-polymer) battery is required to drive the motors.  I’ll probably aim for a 4000mAh version.  Most advice seems to be to pick a 3S1P battery (11.1 volts) which weighs about the same as the rest of the quad.
  • Charger to suit Battery.  Not required yet, but a charger with an automatic balancing feature is pretty key, especially with LiPo’s which tend to explode if they’re badly charged.
  • Propellers.  Not required yet.  They have to be balanced and in counter-rotating pairs.  I’ll probably be going with cheapo 10×6 inch props, since I’m likely to break heaps.
  • ESC’s.   Not required yet.  Electronic Speed Controllers drive the main motors at a speed as governed by the servo connection on them.  They’re basically like a relay, but variable.  The DC brushless motors used in a quad can draw a lot of current, and given the motor/prop combo I’m probably going with, I’ll likely be getting Turnigy Plush 25A ESC’s.
  • Motors.  Not required yet.  Motor/Prop combination is a bit tricky, and also relies on the size and mass of your quad.  I figured out that the Turnigy 2217-20 motors should give me the thrust I want (3kg, which will be a bit more than double the weight of the quad), while not overdriving the ESC’s.
  • Transmitter and Receiver.  I wound out ordering a HobbyKing HK-7X radio and receiver.  Honestly, I would have preferred a Spektrum DX7, but they are very expensive, and I just can’t justify the money on a first quad.  As long as the HK-7X actually works, it should be $60 well spent.  I can go with the Spektrum later, if I wind up getting more models or need the better quality.

I’ve ordered in all the electronics – so that’s the controller, IMU components, and Tx/Rx.  I’ll wait until I’ve settled on a frame and have a better idea of weight before I start ordering ESC’s, props and motors.  I’ll have plenty to play with in the meantime.

So as you can imagine, I’m impatiently awaiting my parts arriving.

Electronics & Me – A History

Rewind 25 years or so.  I’ve always had an interest in electronics.  Mostly in pulling stuff apart and tinkering with it – I even built a few little FM radio transmitters in my early teens.  Of course, then I discovered computers, and the hardware side of things took a pretty big back seat from then.  And when I discovered the Internet in 1992, that was the end of that.  For a while at least.

Besides the assembly part of computers, I didn’t really have much more to do with low-level electronics for quite a number of years after then, until I was about 21 or so.  It was around about then that I decided to go back to study, and I decided I’d go and do Electronics at TAFE.  TAFE is the Australian equivalent of a tech school or community college.  I started off with a Cert II in Electronics, which covered off soldering and other basic electronics, and then I moved up to an Adv. Dip IV in Electronic Engineering (which did some microcontroller stuff, and a lot of maths).  Since I’d grown up a bit by then, was paying for the course out of my own pocket, and wanted to study, I actually did the work, did the homework, and practically aced every subject I went into.

Then I wound out moving to another state, and I transferred across from the Adv. Dip to a Bachelor of Information Technology, where I did a big heap of subjects in programming, discrete maths, cryptography and the like.  I got the Bachelor’s degree in the end, and that led me into my first professional job in IT, and the rest there is history.  I now work in IT.  And again, electronics took a back seat to the stuff I was doing with programming and general IT.

But during all this, I still kept all my old stuff – my soldering iron, my breadboards, benchtop power supply, parts, IC’s and such.  It just sat in the shed, in a box which time forgot.

Fast forward to a few months ago.  I received a whopping huge power bill, which scared the living bejesus out of me.  So I resolved to get to the bottom of my power usage, and I set up an ENVI-R, hooked up through USB to a Linux box using MRTG to track my power usage.  The story of that will be for another post.  Anyhow, I got talking to a colleague of mine who said he’d built his own power meter using an Arduino microcontroller.

Meet the Arduino Uno microcontroller.

Arduino.  There’s a word I hadn’t heard of before.  What was this thing?  So I did some digging.  You see, when I last was heavily into electronics, microcontrollers were clunky, difficult things, which were usually pretty expensive to boot, so I’d never really looked into them.  But when I looked at just how the field had grown in the last ten years (incredibly, it’s been that long!), my jaw dropped.

A single-board, all-in-one microcontroller, with multiple analog inputs, many digital inputs and outputs, which has built-in flash, an EEPROM, and enough onboard storage to hold a pretty hefty amount of code?  And it can be programmed with USB?  And it has an onboard voltage regulator?  And you can program it in a familiar C-style programming language?  And it’s only $30 for the board??  What the hell happened while I was sleeping?

Course, the answer to that is simple.  Times changed.  The open source revolution sprung up and started getting into hardware.  Flash became really cheap (back when I was first doing this stuff, microcontrollers were programmed via an EPROM you had to wipe with a UV light!).  Integration moved ahead to the point where you can pack all that stuff into a single DIP at low cost.


So I charged right out and got myself a Sparkfun Inventor’s Kit for Arduino.  In between all my other things, I’ve been messing about with it.  And collecting ideas for what I want to do with my newfound discovery.

So, I realize I’m pretty late to the game with this sort of thing, but I just wanted to share my joy at discovering that such a thing exists and is practical and low cost.

PowerCLI: Get-VMSize

I’m employed as a server admin, with most of my time spent working with VMware and managing a reasonably sized fleet of machines.  As such, I have a range of various Powershell scripts I’ve written to take advantage of VMware’s PowerCLI interface for Powershell.  PowerCLI is, in a word, great.  It provides some pretty good in-depth insight to what’s going on in vCenter, and since it ties into Powershell, it’s easy to script up whatever you want to do.

Anyhow, below is a filter script, which was cobbled together from some code from a source I can’t recall (if you know the original source, let me know so I can attribute it properly!).  The purpose of this script is to take a bunch of VMs, calculate the Size and Used disk space of those VMs, and dump that out.

Begin {


Process {
    $vm = $_

    $report = $vm | select Name, Id, Size, Used
    $report.Size = 0
    $report.Used = 0

    $vmview = $vm | Get-View
    foreach($disk in $vmview.Storage.PerDatastoreUsage){
           $dsview = (Get-View $disk.Datastore)
        $report.Size += (($disk.Committed+$disk.Uncommitted)/1024/1024/1024)
        $report.Used += (($disk.Committed)/1024/1024/1024)

    $report.Size = [Math]::Round($report.Size, 2)
    $report.Used = [Math]::Round($report.Used, 2)

    Write-Output $report

End {


 An example of its use follows;

Get-VM | .\Get-VMSize.ps1 | Measure-Object -Property Size -Sum

The input should be a VMware.VimAutomation.ViCore,Impl.V1.Inventory.VirtualMachineImpl object, such as what gets returned by Get-VM.  Each output object from the script will contain the following fields;

  • Name – The text name of the VM as given by the Name field in the input object.
  • Id – The ID of the VM as given by the Id field of the input object.
  • Size – The sum of the sizes of all disks used by the VM.  This size is the figure set when provisioning the disk, not the actual on-disk allocation (ie, it will be bigger than the disk use if you are using thin provisioning).
  • Used – The amount of actual disk space being used by all disks on the VM.  This size is smaller than Size if the VM is thin provisioned.


It Lives!

It’s alive!  ALIVE!!

Wow.  It’s been a very long time since I’ve posted here.  I created this blog a long, long time ago with the intention of regularly posting my forays into IT.  However, it appears I never really got around to posting anything except for a few little snippets.

We’ll give it another go.

This blog is having a minor change in purpose.  There will be all kinds of eclectic stuff posted here, so use the tags if a particular subject matter does / doesn’t interest you.

Let’s see whether I can keep the posting up this time around.

WIDCOMM Bluetooth = Crap

So, I got hold of an i-Mate Smartflip smartphone for work, and wanted to configure it for ActiveSync over Bluetooth. I’ve got a Compaq nc8430 laptop. Here’s where the fun begins.

In a nutshell, ActiveSync doesn’t work using the default WIDCOMM Bluetooth stack that comes with the HP. And the Bluetooth chip that’s on the nc8430 doesn’t work with Microsoft’s Bluetooth stack (that comes with Windows XP SP2).

That’s not entirely true. The chip is completely compatible with Microsoft’s Bluetooth driver and stack. It’s just not in the INF file, so the MS driver won’t install. To fix, we crack out Notepad, open up C:\WINDOWS\INF\BTH.INF, and add in a line for the transceiver, as follows;

“HP USB BT Transceiver [1.2]”= BthUsb, USB\Vid_03F0&Pid_0C24
“HP Integrated BT Transceiver [2.0]”= BthUsb, USB\Vid_03F0&Pid_171D

The bolded part is the bit you add. This then allows the Microsoft Bluetooth driver to think that the BT chip in the nc8430 is compatible, and then allows you to install it (when you select Advanced and pick the driver). When you go and install the driver again, the Microsoft Bluetooth stack installs itself and you’re rolling.

Once that’s done, create an incoming COM port on your laptop. Then turn on discovery, and in ActiveSync on the phone, tell it to connect via Bluetooth, and follow the instructions to pair. Fixed.

Of note, the Microsoft stack doesn’t seem to work too well with the Nokia 6230i. You need to use the WIDCOMM stack for that.

Fixing W32Time in a Guest OS

NOTE: For informative purposes only. I take no responsibility at all for any harm that may result to your environment as a consequence of this information. Use at your own risk, and research appropriately!

Sometimes you must run W32Time on a guest OS, but it’s not a good idea to run it at the same time as using VMWare Tools time synchronization. A good example of this is a domain controller – it must have W32Time running, must have accurate time, and must supply time to member servers.

First, a note. Don’t just go and point your PDC at some dummy NTP source that doesn’t exist. If you do that, after some period W32Time will just shut down and stop serving time. Instead, we need to find a way to get W32Time and VMWare Tools to co-exist peacefully.

The solution is to set W32Time so it only tries to slew the clock very occasionally, so the adjustments made by VMWare Tools dominate the clock and keep it in sync. Since W32Time is still in contact with a valid time source, it doesn’t commit seppuku.

You can do this by changing this registry key to “Weekly”. Data type is REG_SZ, if you need to create it;


Restart the W32Time service when you do that, and then all should be well. Oh yeah, and after giving it a little while to settle down, don’t forget to check your event viewer, and do a;

w32tm /stripchart /computer:ANOTHER_DC

to check that your machine is still in sync with the rest of your domain.

VMWare & the System Clock

The system clock behaves … strangely … under VMWare in a guest OS. It tends to run slow, and the amount by which it runs slow varies wildly from day to day. Without a fixed time synchronization source, guests will quickly fall out of synchronization and time-critical mechanisms such as Kerberos will break.

This happens because the guest OS assumes that there is a constant period of time between instructions – ie, it has all of the processor’s attention. The system clock is a high-precision clock maintained by this fact. When you put a guest OS into a virtual environment this goes out the window – the guest no longer has a consistent period of time between instructions, in general this time is longer than expected. Therefore means that individual ticks of the system clock take longer than the fixed (outside) time periods they should, and the system clock runs slow.

So, how do we stop this? Well, one solution is to use a guest-internal NTP client such as W32Time. This is a very bad idea. NTP clients adjust the system clock by slewing (speeding up or slowing down) the clock progressively so they can converge the system clock with NTP time. Since the system clock is running at an unpredictable rate, slewing the clock is a recipe for disaster – it causes the clock to swing to and fro and never stabilize. An unstable clock can cause very strange things to happen.

We could also just keep setting the time as we need to. This is also a very bad idea. Modern OSes rely on the continuity of time. If you just keep resetting the clock, the system ‘loses time’, and tasks that were supposed to run in the lost time just don’t happen.

The solution is to let VMWare Tools handle the problem, and check the box that lets it synchronize with the host. When you do this, VMWare Tools slews the clock appropriately so it doesn’t break anything, and your time converges as you’d expect. When you do this, you must turn off any other kind of time sync software such as W32Time, otherwise they will fight over the clock and much havoc will ensue.

There are certain times when you must run an NTP time server such as W32Time (such as on a domain controller). How you go about preventing W32Time and VMWare Tools fighting is an issue for another post.

NTP Time Synchronization in VI3

Time synchronization is of critical importance in a VMWare infrastructure. If it goes wrong, all hell breaks loose, especially in a Windows 200x environment using Kerberos.

Due to how system clocks work in VMWare, this means that you need to use VMWare Tools’ sync capability to keep your VMs right on time. This means that all your hosts need to be properly synchronized.

So, how do you do this? If you’re using any fancy deployment solution like Altiris, disable time synchronization in it. Why? Because if you don’t, you’ll forget six months down the track, virtualize your deployment solution, and then wonder why all your clocks go crazy.

Read this article and implement it. That’ll get your NTP daemon sorted out, but that’s not quite enough. You need to get your machine’s system clock and hardware clock in sync before NTP can slew the clock and keep it synchronized.

In order to do that, get into a console on your VI3 server, and do the following (I assume that firewall.contoso.com is one of your NTP sources, change to suit);

service ntpd stop
ntpdate firewall.contoso.com
hwclock –systohc
service ntpd start
watch “ntpq -p”

That will configure your system and hardware clocks to be close to the NTP source you named, and then start a watch process showing you the state of your NTP peers.

After a while, you should see an asterisk appear next to one of the peers (not LOCAL, that’s your host’s internal clock). When that happens, you’re all good.