Saturday, April 30, 2011

Show Love in a Heartbeat

I wanted to show my appreciation for the patience my girlfriend has with me when I'm hooked on a new project, so I decided to dedicate a project to her. Well she also pushed me a little bit by buying a small plastic heart and telling me to create something for her for a change :).

This could be a perfect gift for your loved one as well.

You need the following parts:

  • transparent and hollow heart shaped object 
  • 2 x red LEDs
  • 2 x 100kΩ resistors
  • 2 x 470Ω resistors
  • 2 x 100μF capacitors
  • 2 x NPN transistors (BC547)
  • 9V Battery with connector
  • transparent layer as a circuit board
I wanted a thin transparent circuit board so I took a transparent plastic sheet cut out of a grocery box. You can take anything you like but you may want to make sure that is transparent to let the whole heart glow in the front and in the back. After cutting it to the heart shape of the container object the fun part begins. Make the required holes for the components in your circuit board and assemble the cicuit in the following way:


Since I used a plastic layer, I had to be very careful to not melt it with my soldering iron. Due to the limited space I had on my circuit board, I had to assemble the circuit on both sides and had to place the capacitors on opposing sides. My finished circuit looked like this:

The red LEDs are already diffused, but still you would only see two dots blinking in the dark. To diffuse the light even more, you can fill your heart shaped container with a thin layer of soft tissue. The heart container I had wasn't big enough to hold my 9V battery block so I cut a small hole at the top to let out the connector wires.

As a last step I attached the 9V battery block at the back of the heart with some tape and connected it to the heart. When everything is finished it looks like this:

You can see that the load and unload cycles of the capacitors produce a heartbeat like effect.

Monday, April 25, 2011

Custom QR-Codes

While I was in the process of creating a QR-Code for this blog, I stumbled upon some pretty cool techniques to make those standard black/white edgy QR-Codes a little more appealing. I want to show you how to create an QR-Code and how to add some visual tweaks to it. Most QR-Code generators work with a failure tolerance up to 30%. Meaning that if some parts of the image get corrupted, the QR-Code can still be functional. That's basically what we are about to do.

First, find a QR-Code generator online which generates the code for your content.
The generator from the ZXing (Zebra Crossing) project has a great set of features. The more basic generator from Kaywa will work just as fine.

Now that you have your generated QR-Code image, it's time to make some changes. First let's make the edgy fragments a bit smoother so that they are much more easy on the eyes. I show you how to do that with Gimp but any advanced graphic software will work just fine.

You have to follow several steps to round up those edgy fragments. First you might need to convert the black and white image to RGB mode to allow some filter algorithms to be applied.

Afterwards you need to blur the image with an gaussian filter to achieve an anti-aliasing effect.

A blur radius of 10 pixels produced a good result in my case.

To sharpen your blurry QR-Code you use a color curve adjustment.

Now you need to experiment with the settings to produce a sharp contrast. I used the settings depicted here to achieve a good result.

When you are done you end up with a QR-Code with really smooth fragments.

Much better but still not very eye catching. QR-Codes don't have to be so colorless. You can choose different colors for the background and foreground as long as you keep in mind that the foreground color has to have a stronger contrast color. So if you would choose to bright colors, your QR-Code can be difficult to identify. Let's change the foreground color of this QR-Code.

I chose a blueish color for the fragments, which still has a strong contrast to the white background.

Now we added some color to the QR-Code, but still there is more we can do. As I mentioned in the beginning, most QR-Codes have a failure tolerance of up to 30%. That means that we can add other graphics on top to make it more appealing, to describe the content of the code or to follow a corporate branding if you are a company. I just added my blogs logo on top as an example.

I found the center of the code to be a good place to add some graphics. Some side regions might work just as fine. Just remember to test your resulting QR-Code thoroughly as it might break if your graphics are in a sensible spot. I hope this small guide will help you produce more appealing QR-Codes so that we get rid of those unpersonal black and white default ones in the future. Let's be honest no one recognizes them anymore.

Sunday, April 3, 2011

Android / Arduino controlled remote wall socket

Today I want to show you how to replace a hardware switch on a remote or any low voltage electrical device to control it with a microcontroller.

To show the basic principal I used a remote wall socket which normally is switched with a remote via a radio frequency of 433 MHz. What I wanted was to have an Arduino controlling the remote switch to turn on/off the wall socket.

First off I want to show you how the final result looks like and then I want to tell you some details about the setup and the basic steps.

What you see here is an optocoupler circuit which is often used as a switching circuit. Those little black ICs are optocouplers. Internally they have a small IR-LED which triggers a photodiode which closes the circuit. With your microcontroller you power up the internal LED. Make sure to use a resistor to limit the current as the LED usually works with 5-10mA. On the other side of the optocoupler you attach the circuit which you want to close. In my case it was the button of the remote. The datasheet for the 4N35 optocoupler I used can be found here.

To prepare your device/remote for being switched externally, you first have to desolder the buttons. In my remote the circuit layout was pretty simple and I could desolder the buttons pretty easily.

Afterwards I attached breadboard cables to the sockets so that I could connect the cables to my optocoupler circuit.

Here is a basic setup plan and a circuit plan for this project:

All that was left to do was to write an Arduino sketch that listens to the Serial port for incoming data to switch the circuit, a small desktop program which transmits the control data and as a bonus a small android app which sends the switching state to the desktop program. Like I described in the last post, you can find serial communication examples in the Arduino IDE. For desktop serial communication using Java have a look into the RXTX project.

My final result demo video shows the switching of a desk lamp which is plugged into a remote wall socket.

With such kind of circuit you can also switch any low voltage device directly. I only used the remote example to present the general basic approach. As companies don't like that people tinker around in their circuits I feel obliged to tell you that the guarantee is void if you mess around with those devices and that they aren't intended to be modified :).


Some people were asking for the code for this project, so I wrapped it up and published it on github.
You will find two project folders and a single java file. The first one is the Android project which does the socket communication with the desktop. The single java file is a simple class which receives the socket data from the Android device and transmits the serial data to the Arduino, so I called it SocketToSerialMediator. The other project folder contains the Arduino sketch.

Note: In order for the SocketToSerialMediator to work you have to include the RXTX library in your Java installation. Please have a look into the project page of RXTX and follow the installation guide. After you compiled the java file just run it on a console and provide the serial port and the socket port.
java SocketToSerialMediator COM14 1234
 Have fun switching things ON and OFF!

Friday, April 1, 2011

Animatronics Lite

When you are being sick for a week, you really get a tingling in your fingers for coding or tinkering around with a new project. As I was waiting for some new hardware for the next weeks, I decided that I wanted to do something with a servo again. Coming up with something when you only have one servo lying around was pretty hard. I remembered that I kept a stuffed toy gopher in the attic from my childhood days. My girlfriend didn't like the gopher and already asked me why I still keep it. Now I knew.

Rather than throwing the gopher away, I decided to give it some new "life" and mechanical spirit.
At first there is the part of decapitating it to make room for the servo and to allow it to move the head from left to right. Make sure that no children are watching while you do it as this might cause terrible nightmares. Take some of the stuffing out to make the servo fit inside. You might need to attach the servo to the body and to the head so that the head doesn't fall down while it moves.

I connected my servo to an Arduino board and used the circuit and the sketch I already introduced on my blog for controlling a servo. You can find it here. Now I had two buttons to control the head movement of the gopher. I didn't want to just stop there and decided to use the accelerometer in my Nexus S Android phone to control the head movement by tilting the device. You can find an easy example for reading the sensor output in your Android SDK at ANDROID_HOME\samples\android-9\AccelerometerPlay. I shrunk the example to my needs and added some socket communication to address my desktop computer. On my desktop computer I wrote short serial communication class which transfered the current tilt value via serial to the Arduino. I used the RXTX library for serial support in Java. They also provide an example for doing serial communication in Java. The only thing left to do was to listen to the serial port on the Arduino and move the servo according to the tilt value. A simple example for serial communication can be found in the Arduino IDE's examples section. All that stuff can be easily done in an hour or two. When everything is done it looks like this: