Wednesday, January 28, 2009

Finally, the serial port is interfaced

The Transmit Data pin (#3) will require a little more attention. How will the signal (in other words: the wave) be interpreted by the IC? I'll be sending data according to the RS232. The signal is a block type wave, a 0 bit is represented as positive voltage (also called a “space”), a 1 bit is represented as negative voltage (called a “mark”). Furthermore, if the data line is idle, the signal is “spacing” (meaning, it's negative). How a byte is sent, depends on the following parameters: baud rate, byte encoding (e.g. 7-bit or 8-bit), presence of the parity bit (which is optional) and the number of stop bits. I stuck with the default parameters and thus didn't give them any special attention.

Let's visualize how this wave will look like:

Now that I know how it's looks like, I can modify it to my liking. First of all, I do not want it to send out a signal when the line is idle (or else my front door would be open all the time!). This is accomplished by adding a diode to the TD wire. This means that I can only use the positive signal to send to my front door switch. Next, whenever I send a byte out the serial port, I'd like it to be as continuous as possible. Therefore I send out only 0 bits, this is called a null character.

Serial ports cannot give a lot of amps, and I actually don't know how much amps my front door system will ask of my serial port (or even if it will ask any at all) once the current starts flowing. As it turns out, anything below 500 mA should be safe, so that's the rated current for my fuse (if it breaks I'll know my front door system sucks out to much juice and I'll have to come up with something else).

Finally, I know how the entire picture looks like, here's how it looks like schematically:

(click for larger image)

It's all in place, it's time to test for the first time if all my research that I've done so far will suffice! I plugged in the connector, fired up a prompt, and elegantly typed:
$ echo 0 > /dev/ttyS0
Side note: I'm actually sending out the bits 0110000 (= ASCII code 48 = 0). I was anxious to try it out and I couldn't be bothered at the time on finding out how to send a null character to my serial port from command line :-) (which is "echo -en \\0000 > /dev/ttyS0" on Linux, btw.)

Side note #2: /dev/ttyS0 is the serial port under Linux, doing a “echo 0 > COM1” in Windows will have the same effect.

W000000000000000T! My doors opened! I couldn't believe it! So naturally I tried it again, hmm, that's odd, the doors didn't open...

My first assumption was that the fuse had blown, so I checked that, but it wasn't. Next, I tried to echo data to the serial port again, and again, and again, but this time with more bytes:
$ echo 0000000000000000 > /dev/ttyS0
That worked! Apparently the front door black box system has to receive the signal at a given moment for a given amount of time, or else the door will not open. I just was VERY lucky that it opened on the first time, with just sending 1 byte (or else I might have assumed something wasn't working and I'd be stuck for a long time figuring this out). Maybe that adjusting the baud rate of the port would solve this problem, but I'll settle for sending more bytes (so I can send “I AM 1337! 101100111001!” to my front door, and it opens in fear of me :-))

So far so good, this was the easy part! I'll be posting about my Java Bluetooth application for my server and phone in a short while.

Tuesday, January 27, 2009

Never buy indentical Bluetooth adapters

I recently bought 2 Bluetooth adapters, so that I could test between 2 computers. However, both adapters have the same MAC address, and you cannot pair to your own MAC address, yay! So here's a piece of advice, when buying 2 adapters for testing, do not buy identical ones! ;-)

So far I haven't found out how to change the MAC address of the adapter, if anyone has a suggestion, I'm more than happy to hear it. The brand is Qmotion.

Monday, January 26, 2009

Further research on how to interface the serial port

I choose the 9-pin serial port, so how do I proceed now? I asked myself the following questions:
  • What does each of the 9 pins do?
  • Which pins do I actually need?
  • What will my cable look like?
  • What does the signal coming from the data pin look like?
The connector
So I fired up Google, did a search on “serial port” and lots of information about the connectors showed up, I'll summarize it here (for the 9-pin variant):

Pin #






Carrier Detect

Used by modem to signal that it is connected to a working phone line.



Receive Data

Local device receives data sent from the other device.



Transmit Data

Local device transmits data to the device at the other end.



Data Terminal Ready

Local device sends a signal that it is ready to transmit.



Signal Ground




Data Set Ready

Remote device signals if it's ready to transmit.



Request To Send

Local device requests if remote device is ready to receive data.



Clear To Send

Remote device acknowledges that it's ready to receive data.



Ring Indicator

Used by modem to indicate that it has detected a ringing signal on the phone line.

Well, since my IC is not a modem, I am not going to use pins 1 and 9. My IC does not send feedback, so that excludes pin 2. So far, that leaves pins 3 – 8. Let's examine pins 4 and 6 a little closer: pin 4 sends a signal out that to tell that it's ready to transmit, and pin 6 is waiting for an incoming signal which means the other device is also ready to transmit. The IC is ready to receive data at any given time, so I will connect pin 4 to pin 6, which in fact tells the port that it's ready to transmit as soon the computer itself is ready. I also will connect pin 7 to pin 8 (check out the table to see why that is). Pin 5, I will leave this pin unconnected, since my IC is already grounded at another point. And last but not least, the Transmit Data pin (#3) will be used to send data to the IC.

So the connector which goes into my computer will look like this:

Side note: there are 9 pin connectors which are easy to disassemble, specially designed to be altered to your own needs. I used one that looks like this:

Side note #2: on Ubuntu, I used the program “statserial” to inspect the idle state of my serial port, when my connector was connected.

The question remaining here, is how does the signal (or wave) coming from the TD pin look like? I will be going into more detail about this in my next post. Stay tuned!

Determining which port to interface on

There are multiple ports on a computer to which you can interface, each has it's own pros and cons. My requirements were as follow:
  • it must be cheap,
  • it must be able to operate over distances greater than 10 meters,
  • I prefer not to use soldering iron extensively, because I suck at it :-) (note to self: take a soldering course).
I opted for the serial port, since I only needed 1 output pin which either has a signal or no signal; and it's cheaper compared to the other options. There were 3 ports which came to mind when deciding which one to use:
  • Parallel port
  • Serial port (also known as the COM port)
  • USB port
Let's review their characteristics first:

Parallel port
The parallel port offers 8 pins for data (it can send 8 bits, 1 byte, at the same time, hence the name parallel port). A bit with the value 1 is represented as a 5V signal, and a 0 bit is simply no voltage (0 V). 5V is perfect to work with, since IC do not require a high voltage. This port has 25 (!) pins in total and the male side of this cable has 36 pins (soldering hell!!).

Serial port
This port has 2 data pins, namely a read pin and a write pin. The total number of pins is 9. Not all pins need to be connected, hence a cable for this port is easily self-constructed and relatively cheap compared to a parallel cable. The data pins can deliver a voltage between -25 V and +25V, so a 50V peak-peak voltage can be drawn from this port. Note that a lower voltage may be drawn (it usually operates at ± 5 - 12 V), which is more desirable.

USB port
This one is tricky, I realized that when you connect an USB-device, the operating system usually asks the device what kind of device it is and other sorts of information. So in order to provide this information to the OS, you need an USB micro controller. I don't have an exact price range for this kind of hardware, but a quick search at my favorite supplier told me they have USB micro controller starter kits in the range of 65 – 200 Euro. (The actual controller itself is cheaper, but since neither the intended audience, or myself for that matter, has a clue how to use that thing, it's likely we need the starters kit which has some examples and documentation with it). The USB port has 4 pins, 2 for the power circuit which gives a continues ~5V and the other 2 are for data transmission.

Side note: In my case, I used an external power source for the IC, so I did not need to pay attention to the maximum amount of amps I can draw from the port, if you're planning on using the port as a power source, find out how much it can supply before it fries (it's usually not very high).

So the serial port is the cheapest option, requires the least amount of soldering and since I can create my own cable, it will be possible to make it over 10 meters long. Perfect!

In my next post I will explain how to create the connector.

Sunday, January 25, 2009

Integrated Circuit to open the front door

I'm blessed with a home that has an automatic sliding door, and these generally come with a button that opens the door from the inside (our door is set not to open on proximity, since the entrance is unmonitored). Of course, if you have a door that has to be manually operated, you'd have to create your own opening mechanism, which I won't be writing about (at least not anytime soon). The button looks like this:

(click for larger image)

The red arrows indicate the contact points. What happens when the button is pressed, is that a contact is made and the door opens. What we want to achieve is simulate that the button has been pressed by creating the contact ourselves (no, not by creating a robot with wi-fi that presses the button on command, there is an easier way ;-)). We can do this simply by the means of a transistor and it would look like this:

This diagram is made with KTechlab (linux users), by the way. If you're a Windows user and want to simulate a circuit, try getting your hands on a student license for Multisim if your university offers this. You can also download a trial.

Come to think of it, I wasn't entirely accurate about the "simply" part. It was possible in my situation to use a (NPN) transistor, but I had to account for the following:

Let's examine the transistor I used a little closer, it has 3 terminals: Collector, Emitter and Base. As the symbol indicates, the current can flow from C to E, but not the other way around from E to C (if you don't have a clue why, that arrow is called a diode and it only allows current to pass in the direction the arrow is in; but then again you probably should know that). This means that only a Direct Current (DC) is allowed to pass! Hmm, wait a second, do I know for sure that the circuit that controls the door operates on DC? No, I don't! So, I get out my multimeter and test for it (which I had to buy for this purpose, but I didn't think it would be the last time I used it, so I decided it was worth it. Those things are cheaper than you'd expect, I got one for 8 euro at a local shop I deem expensive). As it turns out, the door switch circuit operates on AC (the voltage on the switch was about 82 Volts).

But, if I send a direct current (DC) in the right direction, the door opens anyway. Lucky me! I found this out while doing measurements with the "Diode and buzzer" setting on my multimeter. What this setting does is, that it allows a DC to pass, and when it does, the buzzer sounds to indicate that the two points are connected. (If this doesn't work for you, you need a relay instead of a transistor, which allows for AC to flow. Mirror in case of failure.) So when putting the transistor in place, I have to take notice that the DC that activates the door switch is allowed to pass.

Later on, we will see that interfacing this IC to a computer, will need some precautions that are not yet shown here.

If you want to learn more about transistors, Wikipedia is always a good place to start and Google (click for search results on "Transistor") is your best friend.

Open front door using Bluetooth

Well, this is the start of a description of a project I recently finished! I can open my front door, without even touching the door, using my phone! Here is a preview of what I used for this and what's to come on this blog:

- Java MIDlet on my phone,
- Java application on a server near the front door that listens for incoming requests,
- Integrated Circuit (IC) which opens up the front door,
- Interface to that IC, using the serial port of the server.

Check out the video below to see it working in action!

Note: click on the tag Project Open Sesame for all posts related to this project.


Welcome to the 10100111001est (that's 1337est in binary ;-)) blog in the world! You guessed it, it's a geek blog! The purpose of this blog is actually very simple: when I look on the internet, I see all kind of cool home projects and I wonder "how do they do that?!" (e.g. DIY multi touch table). There is only one thing to do for a nerd who asks that question to himself/herself: find the answer :-)

This blog is about projects I do in my spare time and it will describe them in more detail than you would find on other sites. These are just a few examples of what you will be able to find here:
- interface custom made Integrated Circuits to your PC,
- how to build a multi touch table,
- how I managed to open my front door, just by pressing a button on my phone (awesome!!),
- MIDlet on my phone to remote control my media player,
- fun things to do with a Wii Remote,
- more!

Ultimately, this blog will be a source for people like me who want to create cool things, but don't have a clue about where to start (like me most of the time) and it'll save them some time by looking at my experiences :-) Or better yet, inspire them to create even more mind-boggling projects!