Saturday, April 19, 2014

Vancouver housing market trends: 2 - Maintenance Fees

As a follow up to my previous post, here are my findings on comparing Maintenance fees and Area of an apartment in Mount Pleasant, Vancouver. The data set is the same one presented earlier, and consists of 24 apartments currently offered for sale.

Fig 1. Maintenance fees increase as the area of an apartment increases.
This data shows that maintenance fees (strata fees) generally increase as the area of the apartment increases (correlation of 0.76). This is significant because it substantially affects the size of mortgage you can have for a given income. Lower fees mean you can put more money each month towards paying the principle, and could potentially pay off the house faster.

It is also interesting to note that while this general principle shows increasing area is correlated with increasing fees, there is a bit of variance between maintenance fees for a given square footage. For example between 600 and 650 square feet you could pay as low as $195 and as high as $270 from the data set I am using. This means that you do have some choice in the fees you pay, if you choose the apartment carefully!

So where does this extra variance come from? I also took a look at age and maintenance fees to see if that might provide some more insight:

Fig 2. Maintenance fees are generally higher in older buildings
Actually, the effect here was not at all what I was expecting. I had heard terrible stories of buildings built between 1980 and 2000 leaking (wiki), and assumed that this era of building would have higher than average fees. But I guess the older buildings have more problems (or more cautious strata councils?) and tend to have higher fees (correlation of -0.46).

Vancouver housing market trends: 1 - Building Age and In-suite Laundry

As an interlude to my posts on electronics, I decided to apply my engineering skills to solving an interesting real-world problem: how to buy the optimal house for the optimal price. From an economics standpoint, this seemed quite straightforward: I planned to use the idea of unequal value to obtain a house that no one else would want, at a price that I liked. For example, if everyone else cares about pets, making buildings that allow pets more expensive than others, then I would pick a building with no pets and therefore save some money while still keeping the other criteria (like in-suite laundry) that are important to me.

My thought process was originally something like this:
1 - Obtain data on all the houses and apartments in Vancouver
2 - Determine the principle driving factors of prices to make a simple linear equation representing the price of a house as the sum of all its components
3 - Find the home with the criteria important to me, at a price I like

But alas, no one publishes tables of data that I could use. So my actual process looked something like this:

1 - Choose a small neighbourhood (in my case Mt Pleasant, Vancouver, Canada)
2 - Digitize all the data from houses currently for sale from my local MLS into an excel chart
3 - Identify driving forces using excel graphs

And in the end, I still don't have a great understanding of what people are paying for in a house. But I did make a couple interesting observations: the first one being house age and presence of in suite laundry.

First: the data set I used (sorted by asking price):


ListingPrice (April 19)Sq feetLaundryMaintenanceBuiltWalkscore
V1052669$169,900.005301$224.73198890
V1051480$188,000.005601$203.38199375
V1040689$198,500.006040$220.00198075
V1044617$209,000.004340$162.67198298
V1048130$220,000.005601$216.73199375
V1044627$228,000.006150$210.95197777
V1050003$229,000.004421$153.08198298
V1040699$229,900.005601$212.00199375
V1043115$235,000.004461$185.08199475
V1050473$239,000.006030$244.72196585
V1057152$239,000.006560$283.621976100
V1049518$239,000.006290$195.05198478
V1055063$239,900.005530$258.001975100
V1059296$243,000.006021$224.02199475
V1055712$249,000.006300$245.931972100
V1048892$249,900.006250$270.00197592
V1054910$252,000.005021$220.90199698
V1043052$258,000.006380$215.911973100
V1047691$259,000.007240$255.66198075
V1054803$265,000.005570$195.58198390
V1058317$269,000.006950$296.35197488
V1047831$279,000.005270$258.001976100
V1050340$279,900.005520$215.45197092

When I plot the presence of in-suite laundry and age, I got a figure like this:
Fig 1. In-suite laundry as a function of the year the apartment was built

It seems to me that if you care about having in-suite laundry, you can start by looking at the building's age (which is sometimes easier to tell from the ad). My guess is that older buildings do not have the sewer system in place to support in-suite laundry, while newer buildings do. 

Some other trends I looked at were: 
  • Maintenance fees and square-footage, 
  • Age of building and maintenance fees, and 
  • Walk score and housing valuation.
All of which I will discuss in upcoming posts. If it is successful, I may adapt this to other neighbourhoods, as well as try to find a more automated way of processing the data (right now it is quite manual).

For reference, there are a number of useful sites if you are trying to do some house finding analysis of your own: here are a few that I used:
http://vancouverpricedrop.wordpress.com/ - an interesting study of house listings over time, with 'desperation scores'. This author is putting effort into bringing transparency into the market which I applaud.
http://evaluebc.bcassessment.ca/ - Here is where I obtained appraised values for each house I was looking at (though I didn't find it so useful in my analysis)
http://vancouver.ca/your-government/vanmap.aspx - This is a very interesting map of Vancouver showing a number of useful data sets, though unfortunately not evaluations
http://www.geoweb.dnv.org/applications/propertiesapp/ - And this is the type of transparency I wish Vancouver offered: a map overlaid with property values. Good job North Vancouver!


Saturday, April 5, 2014

Greenhouse project - The Build

After hearing about some amazing Ikea Hacks, I decided I wanted to try one of my own. I bought a greenhouse (Socker) and two LED light strips (Ledburg) as a starting point.

The light strips were quite long, so I divided them into 3 and wired them together so I could place them side by side and mount them on aluminum angle.

6 lights total, mounted in 2 groups of 3 at the top of the greenhouse
To turn the lights on and off, I used a relay module to switch the load side (after the AC/DC converter). For safety I put the relay module and connections inside a box, which had the added advantage of being a nice place to mount my electronics later.

The grey electronics box (grey) holds my relay modules, but also provides a solid mounting point for my Arduino and camera 
Because I don't like wasting power, I salvaged an IR sensor from my Roomba robot, and connected it reverse biased in order to detect how much ambient light was around. This way I could switch the lights on when they were needed, and off during the day.

Of course any respectable greenhouse needs data collection abilities, so I used the SHT15 temperature/humidity sensor, which I have used in previous projects and has given me great results. It has an on-board processor which digitizes the sensor data and sends it over a 2 wire connection. I was able to find Arduino sketch examples to base my data collection software from.

The SHT15 is also mounted to the side of the electronics box and measures ambient temperature and humidity
To display my data, I connected an 2x16 character LCD display, that tells me the light value (L) ranging from 0-1027, the temperature (T) in degrees celsius and relative humidity (H) in %.

The 16x2 character LCD display on the outside of my greenhouse


But what really sets this greenhouse apart from others is its scientific abilities. I have a LinkSprite serial camera mounted inside to take a photo every minute. This will allow me to observe long term growth trends visually and compare to the data (temperature, light and humidity) to find the optimal plant growing conditions. These photos are logged to an SD file as .jpg images, which I can convert into a time lapse on my computer. On my LCD character display, the number of photos taken is shown in the top left, and in the top right are the number of bits remaing to be transferred in the current photo over the serial connection (in Hex).

Once I put some plants in it, the whole thing looks like a bit like a cyborg greenhouse. I have 3 plants, so now I can watch them race and see what grows the fastest.


From the side (top photo) and from the top (bottom photo) my cyborg greenhouse now has 3 plants which are racing to see which is fastest to grow. I will not be putting my bets on the cactus.
So what are the results? I took data and made a time lapse from the first 4 days of operation. First is the temperature and humidity result. The temperature seems pretty constant, varying only a couple of degrees, probably due to the heat in the environment. Humidity doesn't change much either.

Temperature and humidity over 4 days in my greenhouse
The timelapse consisted of 5700 photos, and took up 875 MB on my SD card. This means I should be able to capture somewhere around 2 months worth of photos if I continue to capture them every minute on my 16 GB card. I am thinking that increasing the interval between photos to every minute or so might be more appropriate for filming the growth of cacti however, so this might require a bit of tweaking.



A couple other notes about my design, for anyone looking to do something similar:
  • The program size is about 25 KB, which fits on a Duemilanove. A large portion of this was the SD FAT library I used. 
  • I used all the pins on the Duemileanove except A5
  • I used 4 libraries: SoftwareSerial, LiquidCrystal, SDFat and LinkSpriteCam (which is a library I wrote myself to control the camera). 

Sunday, February 16, 2014

Reverse engineering the Roomba

Since I was having difficulties with the Roomba's battery, and because it looked interesting, I decided to take my Roomba apart and see if controlling the individual components was feasible. Taking it apart took a couple of hours, and the first component I decided to play with was the motor.

I knew that it had some sort of encoder, but I was surprised how basic it was. The encoder consisted of a single photodiode and a toothed wheel... I presume that the engineers must have used additional information from the motor driver (current direction?) to resolve the direction of the rotation. I connected the diode to a 220 ohm resistor, 5 V power source, and reverse biased the photodiode with a 560 KOhm (also 5 V source). I then ran this through a comparator (LM311) against a 2.5V reference (I just used two 120 KOhm resistors in a voltage divider) to digitize the output.



With an Arduino, I wrote a simple sketch (posted after the break) to take the input from the comparator and increment a counter. I tested that turning the wheel increments the encoder. I ran the signal to an interrupt pin as well as a digital input, so that I didn't have to keep polling the pin. Should allow me to add extra inputs from my other wheel to the system easily I hope.

I don't want to drive the motor from my Arduino so I'm going to have to figure out a second power source and motor driver (perhaps a shield might be easiest) before going too much further with this.

Also below the break I posted a few more photos of the Roomba disassembly.

Thursday, December 5, 2013

Updates to the Christmas tree project

I made a handful of modifications to my Christmas tree this week! Using shift registers I eliminated most of the wires connecting the Arduino to the LED display. Programmed a few scrolling patterns and select between them randomly. And I neatened up the wiring a little bit, so the whole thing is not quite so ugly.




Seems to be a couple deficiencies though... I think its due to the way I tied the shift and latch clocks together, but I am not able to get the top row of my tree to light up. And I would love to make it battery powered and wireless and hang it on my actual tree. Might be a bit ambitious for now though, and would require taking apart one of my older projects which I don't know if I want to do yet.

Saturday, November 30, 2013

Christmas tree! Engineer style

Its the last weekend of november, and that means time for a Christmas tree. But, since I don't own one, I had to make one -- LED style!

First I laid out 27 LEDs in the shape of a tree. Didn't have all the same color or size, so had to be a bit mismatched. Also discovered that my camera does not like to autofocus on protoboard... must be all the little holes messing it up.



Step 2 was wiring. Each LED got two wires, one for cathode and one for anode. Tried to keep all the cathodes orange for distinguishing them later.



Third, I divided up the wires into rows and columns of the tree. This way I could individually address each LED in a logical manner. I used the Anodes for the columns and cathodes for rows.

Fourth I connected them to the digital pins 0-13 on my Arduino (I had 6 columns and 8 rows) and loaded some code from the Arduino Cookbook. Christmas is here!!!





Wednesday, October 16, 2013

Sensor readings

Finished the first iteration of code for capturing Roomba sensor readings. Now I have a function that can be used to access each individual sensor on the Roomba. I have some ideas to increase the speed of accessing the sensor values, right now it is quite brute force and wasteful, but it seems to work. The code posted includes some demo functions for outputting each sensor package. Code is available from my repository and a sample screenshot is given below:


Monday, October 14, 2013

Roomba Arduino Library

Haven't done much on any of my electronics projects over the summer, but I pulled my Roomba out of the storage closet this weekend to see if it was still capable of vacuuming a floor. Probably no thanks to all the modifications I had tried to do to it (see my previous posts), it turned off about a second after starting, but I was able to get the serial port to accept commands. Eventually I may try to write my own vacuuming routines for this, since the existing computer seems to be unhappy about something, but for now I've just been working on compiling a library for Arduino out of the Roomba SPI.

The result is the project I started (google code link). You can checkout with mercurial (once I get a more complete library I'll package it a bit better and write an API). So far LED and motor functions are included.

After the break are a short video and photo of the setup

Tuesday, June 25, 2013

Potentiometer and Next Photo Timer

I installed my potentiometer today, connecting it to the A0 analog input pin. It is used to select the time between consecutive photos. The way I have set it up, the analog values are mapped to times between 45 and 90 seconds. During photo transfer, the elapsed time since the photo was captured is recorded, and subtracted from the potentiometer "time" to tell the user the "Time until next photo". The time can be selected and changed during or after transfer by the user. The implementation was quite straightforward, though the number of wires hanging off the breadboard and Arduino tells me its getting nearly time to get a case set up for this thing! The photo below shows the potentiometer and updated LCD display... which is also getting full... might have to start scrolling or switching between 2 displays to fit all the information I want to show.


Saturday, June 15, 2013

LinkSprite library

I finally have most of my linksprite camera functions working, so I have migrated them into their own library inside of my code repository. Of course there are bound to be some bugs, if you find any, please do let me know, best would be with the issue tracker in the repo.

On the hardware side, I added a toggle switch that makes my life substantially easier when reprogramming the Arduino. Previously I would have to remove 2 jumpers on the XBee shield, so that the computer could talk to the microcontroller to reprogram its memory. Now, the switch (see photo below) allows me to easily select between the connected and disconnected states.


Next few times I work on the code, I will probably be fixing bugs with my library, and general issues in my issue tracker. Soon I do want to connect the DIP switches though. And I'm always looking for ideas on how to improve my transmission rates because that is the single easiest way to get my battery life to increase.

Wednesday, May 22, 2013

LCD character screen and photo resolution

It seems every day that my list of issues on my google code issue tracker are always increasing, or at least never decreasing. But I got a few knocked off or at least reduced in severity over the last couple days.

To reduce power consumption I used my DMM to study which parts of the system used the most power, and to validate the power savings mode on the camera. What I found:

  • Entire system was using 280 mA at the start of my fixes.
  • The power LED was using almost 13 mA, so replacing the resistor in series with the LED brought that down to 3 mA. Further savings might be made by flashing the LED instead.
  • The IR LEDs were always on, using about 140 mA of power. I replaced the photocell with a 1K resistor which made the system think it was always light, and turned the IR LEDs permanently off.
  • The power savings mode was not initially working, but a delay in the code fixed that. During power savings, the camera uses 50 mA, and during normal mode it uses 70 mA. 
  • The XBee uses 70 mA. There is some sort of cyclic power savings mode that might be applicable for my application, but the effort in implementing it does not yet justify it. 
Overall I managed to reduce my power consumption to about 40% of its original, which should extend the battery life nicely. 

Another feature I wanted to implement is a higher resolution photo mode. This was actually quite trivial, and just consisted of another command sent to the camera during startup. However I had a small bug to sort out: the files became longer than 2^16 bytes, meaning I could not use a 'word' to store the location of file I was currently reading. 

Adding an 16x2 LCD character screen was also remarkably easy with the LiquidCrystal library. The sample code was easy to implement, and now I can operate my camera basestation without needing a computer which is a huge bonus. The LCD character screen takes care of providing user feedback and indicating which photo is currently being captured, and how long is left in the transferring process.

Later I will add a couple photos and video of the system in action: I turned a couple plant pots around and I'm hoping to capture the plants turning back towards the sun over the course of the day. It will be a good test of how the battery is holding up as well.

Sunday, May 19, 2013

Issue trackers and Arduino serial buffer sizes

This week I started using the issue tracker that came with Google Code, and I really like it. Its a much better way of keeping track of my outstanding tasks than my whiteboard or keeping them in my head.

One of the main issues I identified was extending the battery life of the wireless unit. Currently I can take about 300 photos, which at 30 FPS means 10 seconds of time lapse video. Not great. I thought of a couple ideas that could help me here:

  1. Power savings mode when the camera is waiting between frames
  2. Faster data transmission so the camera is in power savings mode for longer
  3. Hardware modifications like disabling the IR LEDs

Power savings mode was fairly trivial to implement, it was just 2 commands I sent over serial to turn on or off the camera's power savings mode. Next I worked on the transmission speed. My first thought was to decrease the "interval time", or time between successive frames, but this started causing data transmission errors. So instead I worked on increasing the buffer size, so that more data was transmitted at once. However, the microcontroller only appears to have a serial buffer of 64 bytes, so when I tried to get more data than 56 bytes per frame, I was running into problems (due to the 5 extra bytes before the frame starts). What I ended up doing was removing the delays in my code, and implementing a loop to poll the receive buffer. In case of transmission errors, I also added a timeout, and flag that was set upon an unexpected frame size, which caused the erroneous frame to be resent. At the end, it was something like this:


// loop continuously until the data is ready
while(!Serial.available()){
  delay(1);   // 1 ms delay
  timeout++; // timeout counter
  if (timeout > TIMEOUT_MAX){ // if 1000 ms pass before data received, assume erroneous data
    i = 5;  // satisfy exit condition
    ResendFlag = 1;  // ensure data is resent since erroneous
    break;
  }
}
// if we get here, data is available so process it


This had some pretty good results, my transmit time was reduced by almost half. Now I'm running an endurance test to see if it actually improves my power consumption, and if so by how much.


Friday, May 17, 2013

A summary of progress and next steps

Over the last week or so I've made some pretty good progress on the time lapse camera. From a fully charged device, I can shoot a 327 frame video (see below), which lasts about 14 seconds.



After the break I'll summarize progress so far, as well as the next steps I plan on doing. My philosophy is to finish each section completely before moving onto a new task, limiting the complexity of potential bugs and problems.

Wednesday, May 15, 2013

Box for the outdoor unit

Bought a plastic box today at one of my local retailers and turned it into a custom case for my outdoor unit. This version isn't waterproof (a quick google search told me it would take some more in-depth engineering than I wanted to do for my first version), but it is a great proof-of-concept.



I cut holes in the plastic using a dremel tool. Most of the holes were in a removable side panel, making things easy, though the hold for the camera was in the box top. I learned a few lessons: when I routed the hole for the battery charging cable, I didn't think of how I would mount the circuit board and connector to the side-panel. In the end I found a piece of wood that was the right thickness to fit between the box and circuit, and used to 8-32 bolts to hold everything in place. Definitely will need a better solution for a water-proof model, as these are 2 unnecessary holes in the case. The rest of the build was quite straightforward, and took around 3 hours. After the break are some more photos and details.

Tuesday, May 14, 2013

Code Updates and a Time Lapse Video

Got my first time lapse video captured and online. Images were transmitted wirelessly using XBee radios from the battery-powered unit to the Arduino basestation. I copied the files to my computer, and converted them to jpg files using the converter in the code repository. Then, using Time Lapse Assembler, I made the 100 images into a 7 second movie at 15 FPS. The video is shown below:



Next steps will be on the hardware side:

  1. Making a waterproof case for the unit that properly secures all the wires
  2. Adding a potentiometer and LCD screen for some user controls and feedback over operation

Tuesday, April 23, 2013

Transmission errors fixed

Made a nifty change in my code allowing me to shorten delay times and eliminate transmission errors from propagating into the image. Now when a non-full frame is received, the code requests a repeat of that frame. Results seem good, while 10 ms delay does not work (probably not enough time for the signal to be sent and processed), 100 ms seems fine, and probably down to 80 or 70 ms could also work!

Fig. 1. Image taken at 100 ms delay time, which previously would have contained transmission errors (see previous blog posts).
Code is uploaded to the repository. This is much better than posting a new file each time!

Monday, April 22, 2013

Software Repository Up

The software repository is now up and available from Google code here and uses Mercurial. I'll be putting my files in here from now on, and try to do a better job to keep some naming consistency and documentation. That is all for today.

Sunday, April 21, 2013

Wireless photo transmission

Today is a pretty big milestone in my project. Actually over the last few days I've made a lot of good progress, so today's blog post will be a big one.

First the achievement:
I transmitted wirelessly from outdoors to inside. Still a lot of tweaking and streamlining to go, but the rough idea is there. Here is the photo:
Fig. 1. The camera took a photo outside, and transmitted it about 6 m to the Arduino indoors. The errors are probably due to missing bits or frames during transmission.

To get there, a bunch of work was necessary. To summarize:

  1. Modified my SD card photo storage program to communicate with the Lynxcamera over the UART instead of software serial. 
  2. Programmed my XBee transmitters to work at 38400 baud.
  3. Connected the Lynxcamera to the XBee and battery module, to capture photos remotely.
After the break I discuss the challenges with each of these separately, include some photos of the setup, and post my code.

Sunday, April 14, 2013

SD card adventures

This morning I went to NCIX and bought myself a microSD card. It was the ADATA 16 GB microsdhc class 10, and worked great with the Sparkfun microSD shield. The card came pre-formatted in FAT32. I found a copy of FAT libraries for the Arduino by William Greiman . After changing the CS pin in the software to be 8 (the software default was 4), the ReadWriteSdFat example code executed perfectly. I was also able to read the test file on my computer.


The next step was to collect a camera image, and store it on the microSD card. To do this, I adapted my previous LynxCamera code to make LynxCamera_SD. In this version of the software, the camera and SD card are both initialized. The user presses a keyboard button to tell the camera to take the photo. This time, instead of streaming the photo to the console, it is logged to the SD card. I can eject the SD card, insert it in my computer and use my conversion script to make it into the beautiful image of my apartment below.





While this works, I have observed a couple disappointments already. Getting the data from the camera onto the SD card is slow. I may be able to update the baud rate slightly, but at 38400 I was seeing transmission errors, so there is not a ton of speed to be gained here. The camera itself is a bit disappointing (though I was sort of expecting this). The photos have poor contrast, and are a bit dark. Seems the exposure time is automatically set, so I don't have a ton of flexibility here. Finally, I'm already at 15508 bytes out of a potential 30720... not leaving me a ton of room for doing LCD screen, radio and push button integration. 

But I think there is still lots of potential for this project! I'm charging my battery at the moment, so that, as the next step, I can start integrating the radios into this system. I think I will try to get all the aspects of this project integrated before starting to optimize the speed and space utilization.

Wednesday, April 10, 2013

Shift register working

Its a minor victory, but its been almost a month since I've had time to work on this project so I'll record it anyway :). Fixed a short to ground on one input pin of the shift register. The I used the Arduino shiftIn() function to read from each pin of the 74HC165. A simple sketch is available here. Hopefully soon I get the DIP switch soldered on, and can start using this as some input into the Arduino for testing and debugging.