Category Archives: Projects

Home automation, improvements and other large scale projects around the house.

Database Management System for Online Ticket Sales

Database Management System (DBMS) of online ticket sale for the stage play “Kusa-Paba” at the University of Calgary Theater.

Abstract and Project Description

The University of Calgary Theater has 500 available seats. This particular DBMS is built to allow users to order and purchase tickets online. Tickets sold by agents can also be entered to the system using the agents’ interface. Only a designated set of seats are available for sale. Some are as for reserved guests and others are designated as House Seats hence they are not available for sale. The designated seats for sale are categorized for different price levels; $50.00, $30.00 and $20.00 (Figure 1). The price levels are further broken down for adults and children.

Continue reading Database Management System for Online Ticket Sales

Updating Electrical Components

Last year I published an article on home electrical wiring basics. When I looked back at that document, I realized that I have missed several aspects of electrical wiring. This article will complement the previous by expanding the subject matter.

What can you do without professional help?

In Calgary, Canada, the municipal laws allow the home owners to replace devices from the home electrical system. Additionally, the laws also allow home owners to undertake small renovations (without adding or removing new walls or electrical/plumbing fixtures) without any professional help. However, if you decided to add a new electrical outlet, then you must get proper permits from the City Government. Please do not take this as a legal advice. Contact your municipal or other regulatory body for information on allowed modifications to your electrical system.

Electric shock alert

For the purpose of replacing traditional electrical fixtures with automated (or networked) fixtures with same certification, in municipalities you do not need a permit. It is like just replacing a light switch with another light switch. But if you are unfamiliar with electrical work do not attempt to replace electrical fixtures. Contact a professional electrician for help. I, Sanuja Senanayake or the site will not take any responsibility for any personal injury or property damage.

Not all switches can be replaced

In North America, the home electrical circuits are composed of several types of wires. Each type plays a different role in maintaining the current flow from the main box to the electrical fixtures. These wires are not interchangeable nor can be easily replaced. The type of wires in a typical household can be summarized as:

Hot Wire = Black; carries the electrical potential from the main box to the unit
Common/Neutral Wire = White; carries the return current back to the main box
Ground Wire = Copper (no coloured casing) or Green; used for grounding the circuit for protecting from electrical shock, overloads, lightning, etc.
Returns = usually white but check with a multimeter; also called “Runner(s)” used for light fixtures or such switch circuits.

Not all traditional switches can be converted to automated or remote (“smart”) control switches. Almost all smart switches require constant power. This is achieved using the Common Wire and the Hot Wire. While almost all electrical switches and receptacles will have a Hot Wire, not all of them will have a Common Wire. Especially for light fixtures, I found that some boxes in my house had Runners instead of a Common Wire. This can be a major problem for home automation enthusiasts.

If you have switches without a Common Wire, you have two options. The easiest one is to buy plug-and-play smart switch. For example, you can buy a Z-wave electrical screw-in lamp socket ON/OFF Module (Eg. Everspring AN145). The only downside is that the light switch itself must always be at ON position in order for the smart switch to work. This is however the safest and the cheapest way to fix the Common Wire problem. There are other modules for appliances and equipment that plug into wall receptacles (Eg. Evolve LDM/LPM-15). They are very easy to use and acts like mediator between the unit and the fixture.

The alternate option is to route a Common Wire from a nearby electrical box within the same circuit. The key is the Common Wire must be from the same electrical circuit as the unit that you will be replacing. Use the proper gauge white (cover) wire for the routing. Instead of routing a single wire, I recommend using a cable (lowest possible would be two wire cable) for added durability and protection. You can clip the extra wire on both ends and may be used for future electrical needs.

Common Wire is routed between two switches.
Common Wire is routed between two switches.

You can see the patches on the dry wall. I had to create few opening to route the wire within the wall. I also drilled holes on three vertical studs to pass the wire. Therefore I only used metal clips near the second switch to hold the wire to the stud.

Typical Electrical Switch

Following is a diagram of typical electrical writing for a light switch. Electricians may have wired your house differently. Please use due diligence and trace each cable and wire to what it is connecting. I found so many “questionable” circuits.

You can search online for electrical diagrams, but as mention above, make sure your circuit is wired properly. Do not always trust the colour of the wire, but trace each wire.

Very Important Points

Please us common sense when replacing electrical fixtures. If you are replacing an outdoor receptacle, make sure you have adequate weather projection for the new unit. It is also very important to either use an outdoor rated fixture or install an outdoor cover/box. Electricity and water should never mix and inadequate protection from environment may result in electrical fires or major malfunctions in the circuit.

If you are replacing a fixture on a critical circuit, make sure your new smart fixture does not interfere with the normal operations of the circuit. For example, if you are replacing a switch on a circuit that also provides power to your home security system, make sure the switch will not adversely affect the security system’s power.

Another issue is heat. Since all network connected smart switches have antennas to broadcast and receive data, they produce heat. In fact, you can feel the heat on some switches. It is not a problem as long as you provide adequate ventilation. To do that, you should increase the depth and size of the electrical box. I have used 3 unit boxes for 2 switches just to add more room. With additional wires such as Common Wire and Ground Wire running directly to each smart switch, it also provide room for wire management.

When replacing a 60 W (watts) fixture, use a 60 W smart fixture. Do not use a fixture with lower energy rating. Using a lower wattage rated unit may result in electrical fires.

Before closing the electrical boxes with their covers, make sure all the wires are properly installed and nothing is lose. Use insulated tools such as rubber handle screw drivers. Ground yourself to avoid static discharge. Do not leave open electrical boxes or wires for long period (Eg. Overnight) even if the circuit is shut off from power.

If you are unsure of something or uncomfortable with electrical work, please contact a professional.

Choosing a thermostat

In most parts of the developed world, we live in houses that are at least ten years old (or often older). Hence homeowners spent their money on home improvements. One of the easiest ways to renovate your house is to replace the old units with new ones. Today I am going to discuss a simple item found in every Canadian household; the thermostat.

Good old days

Thermostats in the past are based on mercury switches. The temperature and humidity information is passed to the furnace, air conditioner and humidifier from a mechanical leaver inside the thermostat. Today, the same task can be done either electronically or electrically without the use of mercury or mechanical parts. Almost all modern thermostats operate by sending electrical signals via two circuits built in to the controller and the receiver on the other end.



With electronic controllers, you can buy thermostats from several different manufactures. Additionally there are many models even from the same manufacture. This is expected because modern units are not limited to manual controls. Depending on the type of the unit, you may be able to control the temperature and other aspects either remotely or via an automated system.

When purchasing a unit, here are few pointers to think about;
How old is your current furnace/heater, air conditioner and humidifier?
What are the types of input controls in your current units (can it take an electronic signal)?

If your units are old enough to replace, it may be time to replace them with a modern cutting-edge units. This way you can use any thermostat to control them. If you have an older unit, then make sure you have the right configuration for whichever the thermostat you want to install. For example, if you are missing a specific wire required for an electronic automated thermostat, you may either have to add an additional circuit box in between the controller and the heading/cooling unit or you may have to opt in for a traditional older thermostat. This is where the return policy of the store will help you out! However, you can avoid retuning an item by doing your research before you buy one.


There are several technologies in the consumer market. Most of them are proprietary technologies made by companies like Nest and Honeywell. Others have little more flexibility with built in standards like Z-wave, which can be used along with any Z-wave controller.

Most “smart” thermostats can be connected to your LAN (home network) and ultimately to the Internet. You can control these thermostats from computers and mobile devices in addition to physical controls. You can create accounts and enforce restrictions on who can control what. You can create schedules or in some thermostats can learn from your behavior and automatically create schedules for you (eg. Nest). You can create relationships between the thermostat and other units in the house. For example, you can connect a Z-wave thermostat to your front door sensor. Then you can set it up so that if the front door is opened between 4-6 PM, the temperature will increase from 19 C to 21 C. This way, when you come back from work, the house will be warmed up in few minutes. With the electronic and Internet age, the possibilities to make your house a home with technology are endless.

So when you are ready to buy a thermostat, ask yourself what do you want to do with it. Do you simply want to control the temperature? Or do you want to control the temperature via a computer in the house or mobile device or anywhere in the world? Of course, how much will you be spending?

Proprietary or Independent

Personally, I prefer flexible options because it limits dependencies. If you have a Nest thermostat, for your remote controls you will depend on the Nest network. Any issues there including technical or otherwise (like free to paid service), must go through Nest company. Contrast this with a Z-wave unit like Honeywell VisionPro Thermostat, in which the remote control is done through your home LAN and Internet connection. To me, it is no brainier; Z-wave is better for independence.

Here are some key things about proprietary verses the Z-wave based thermostats (or any other equipment). With proprietary technologies you get much better security and reliability. Since millions of others also use the same network and technology, you will provide with cutting edge support for your thermostat. It is also easier to setup a Nest thermostat than to setup a Z-wave thermostat for most people. However, you will be giving up your personal information such as “Away from home time/temperature” to a server somewhere in the world. Since you are one of millions of others on the same network, you may be vulnerable to cyber security issues. Additionally, you have no control over the network itself. While it may be reliable and secure, if the company responsible for the network decided to charge you for the remote service, you have no choice but to pay (or stop using the remote features).


Installation is very simple assuming you have all the right wires. In other words, as long as you have a compatible heating/cooling unit, you can install the thermostat by yourself. I found the programming the thermostat is harder than the actual installation process. But it is just me!

How to build a basic antenna

We use wireless devices to send and receive information without worrying about physical obstacles. In the old days, most consumer grade wireless devices such as mobile phones, routers and RC controllers came with large antennas. Today some manufactures decided to go with internal or built-in antennas. This is not always beneficial to the consumer. For example, if you have a weak signal in an area, it would be difficult to change the position of the antenna because; you do not know where is it in the casing and you may not be able to place the device in a position. The solution is to add a external antenna.

Antenna Theory

This is a very specialized area of engineering and physics. In fact, I do not think that I am qualified or educated enough to go into details on antenna theory. Likely, an experienced Engineer has posted all the details here. If you need extensive information on how antennas work, that is the best place to start.

For our purpose of building a home made antenna, we only need few details from basic physics. This is because I will introduce you to a basic antenna design.

Antenna Length

All radio equipments comes with details on specific frequencies in which the data is transmit. We can use that information to build a whip antenna (single wire). The length of the antenna itself (“the exposed wire”) depends on the frequency of the device. To calculate the length, we take the speed, c in which the wave propagate (travel) and divide that by the rated frequency of the particular device.

The formula for length (actually it is the wavelength) is, l = c/f and since most waves travels close to the speed of light in a vacuum, we can assume that c = 2.998 x 108m/s. Now we know two unknowns (frequency is taken from a published documentation of the device), we can calculate the required length. For example, if I were to build an external antenna to my Vera home automation controller with the f = 908 MHz, I would have to build an antenna that is about 33.02 cm in length. But generally we do not built at full wavelength. Instead, most antennas use either 1/2 or 1/4 of the wavelength. As long as the antenna length is within those multipliers, it will work fine.

Antenna length difference due to wavelength difference between 2.4 GHz vs 900 MHz
Antenna length difference due to wavelength difference between 2.4 GHz vs 900 MHz

If you hate calculations, search for a online calculator. Make sure you are using the right calculator because depend on the type of antenna, the information is varies.

Build it

Once you have calculated the required length, you may use a piece of coaxial cable (with the copper core) to build your antenna. Strip the outer cable (ground plane) to expose the inner core copper wire. The length of the exposed core must be the exact same length as what we calculated for our antenna length. Let’s say we want a 908 MHz antenna. Then the core wire should be exposed exactly 33.02 cm or close to that. The length of the rest of the cable will not effect your wireless signals. But longer the cable, higher the impedance hence may even weaken the signal.

There are several choices on how to connect the other end to the device’s circuit board. I recommend against soldering directly onto to the PCB. Instead, use a pigtail connector or a wire. Some PCBs come with removable antenna wires (“clip ons”). They are usually U.fl connectors. Yes you can buy them online (cheap) with all the connectors and wires attached. If your board does not have removable connectors, you can solder a wire between the board and the pigtail connector. By keeping the antenna wire itself separate from the PCB, you now have greater flexibility in future modification.

If you do have removable connections between the PCB and the antenna wire, then it is most likely a U.fl type connector. Read more about other types of connectors here.

If you are building a GSM (~ 900 MHz) antenna, order something like, SMA female straight to U.fl/IPX Pigtail cable. The other option is to take the PCB connector from an old router (regardless of wifi frequency) and use a RP-SMA connector type antenna. Note that RP-SMA is the type that comes in 99% of all WiFi routers with external antennas. However, most GSM based antennas such as ~ 900 MHz requires a SMA female connector.

Most consumer products with antennas do not come with a good ground plane connection. You can connect a wire between the antenna lead and any of the socket plates (Example of a socket plate is highlighted by B on the following image) for a good ground connection. Make sure you clean the socket plates before attaching the ground wire.

Internal view of D-Link LAN Switch.
Internal view of D-Link LAN Switch.

Special note: if you are an electronics enthusiast in Calgary, try MRO for supplies. I am not affiliated with them nor promote them. However, I was able to find most electronics parts such as ICs, resistors, transistors, antenna parts, etc over there.

Modification to extend wireless range

Consumer Electronics Design not always beneficial if it retards the primary functions of a device. The internal antennas are such a design concept that cause a lot of headaches for tech guys like me. The primary function of a antenna is to transmit a signal, capture a signal or both. Since most modern equipments are manufactured with plastic casings (as opposed to metal), a lot of manufactures have opted for internal antennas. The advantage; now nothing is sticking out, they can make the equipment more desirable to mainstream consumers by making “beautiful” equipments boxes. I am on the other hand one of those people who would buy a device for its’ practical functionality over looks.

The following modification was made on my VeraLite (Vera3 variant) to remove dead-zones in my Z-wave network. However, using the same principles and steps, you can also extend the range of your WiFi network. I will add bits of information specific to WiFi extension on this article.

Vera3 and VeraLite controllers

The door locks on Z-wave networks almost always accept only secure authenticated signals. In order to operate the locks you must send the signal either directly from your Z-wave controller (in this case VeraLite) to the locks or use repeaters (or modules with secure repeaters) that are capable of secure signal handling. I found it is extremely hard to find such repeaters in Canada.

So I went with the second option; direct communication between the locks and the controller. However, my controller is in a locked cabinet far away from the locks. This causes reliability issues because unlike Z-wave light switches, door locks cannot take unsecured signals repeated from nearby low security switches.

Modification to the controller

Warning: This modification will void your manufactures’ warranty. Beware of the static charges. Static electricity could burn out your circuit board. Either use a grounded anti-static wrist strap or use extreme caution. Remove all power supply units (batteries & DC power unit) before opening the case.

Parts, tools and technical information

  • Antenna must be able to handle frequency range of the device (for this mod, 908 MHz)
  • U.fl/IPEX to RP-SMA Pigtail with at least 5 cm; 10 cm is too much; find happy medium) of wire length between the connection points
  • GSM antenna extension cable (optional and longer the cable, more problems arises)
  • Small needle nose pliers
  • Small Phillips screwdriver and a large slotted screwdriver or a flat plastic or mental piece
  • Small electric drill or a utility knife

It is very easy to take apart VeraLite unit. Only two screws and few plastic clips that holds the plastic casing. One of my readers (“Jack”) pointed out that the screws will not come out from the casing. In that case do not try to pull it out. Once the screws are lose, you do not have to take them out of the holes in order to separate the green cover from the case. Use a flat head screw driver or a flat object to pull the cover apart. Be careful to not to break the clips that holding the two parts.

Inside you will find the internal antenna attached to side of the box with a connection wire going to the Printed Circuit Board (PCB). Click on the the image below for more detailed information.

VeraLite PCB: A = Internal antenna, B = Cutout made for ext. antenna. C = Antenna connector
Figure 1: VeraLite PCB: A = Internal antenna, B = Cutout made for ext. antenna. C = Antenna connector

Disconnect the internal antenna wire from point C (refer to above image) by gently twisting and pulling on the connector. Do not pull from the wire because it will break the wire from the connector. I recommend using a small needle nose pliers.

Make a hole through the casing, either on the back or on the side. Make sure it is large enough to pass the SMA (SubMiniature version A) male connector but not its’ neck. I used a box cutter to be safe, but you can also use an electric drill. If you are using a large construction grade drill, please be careful to not to break the box. I found the utility knife to be the best option.

Creating a circular cutout to pass the male SMA end
Figure 2: Creating a circular cutout to pass the male SMA end

Take the U.fl/IPEX to RP-SMA Pigtail (Figure 3) and connect the U.fl side to the board. Then pass the SMA side from inside to outside. Then connect the other end to the point C (Figure 1) on the board.

U.fl/IPEX to RP-SMA Pigtail
Figure 3: U.fl/IPEX to RP-SMA Pigtail

Internal and external view of the final product.
Figure 4: Internal and external view of the final product.

Put the box back together and your done! For the external antenna now you have the option of adding it directly to the device shown in Figure 3 or you can add a antenna cable before adding the antenna itself. This is what most people do when they want to secure their devices in a cabinet. You can keep the network controller inside while antenna outside for greater coverage.

It is quite possible to salvage antenna and U.fl/IPEX to RP-SMA Pigtail connection wire from old devices such as wireless routers and GSM devices. But unfortunately most WiFi routers are on 2.4 GHz band while Z-wave is in 900 MHz band. For example, this particular model is at 908 MHz frequency. If you cannot find a GSM device to get an antenna, please buy one (~ $8 – $12 CAD) to take the full advantage out of this modification. Connection wire from a WiFi router is suitable for Z-wave broadcast.

Antenna length difference due to wavelength difference between 2.4 GHz vs 900 MHz
Antenna length difference due to wavelength difference between 2.4 GHz vs 900 MHz

If you would like to know more about how antennas work, try this site.

Modify WiFi Routers

Yes, you can modify your b/g/n/ac WiFi routers with built-in antenna(s) by following the same instructions. The only difference is now you can use any old 2.4 GHz or 5 GHz (not very popular) antennas for your project.