Tuesday, February 1, 2011

Marble run

Lately I have been chopping up dead hard drives to use the motors. As a result, I found myself with a small pile of strong magnets. I have also been collecting the balls out of old discarded ball-mice for some time. I now have over sixty of them in an urn in my living room. It is a good conversation starter.

This weekend I put together a marble run for my kids in an attempt to win their favor for a time. I glued the magnets to the backs of pieces of wood and PVC pipe. I also had an old vacuum hose that was not yet thrown away (despite my wife's best efforts). These pieces could then be positioned on any metal surface and the mouse balls rolled down them. The most convenient surface was the front door and my children have been playing with this toy made out of garbage for a week non stop. Definitely a success.

I wanted to add a component that would light up when the ball rolled through it.

First, I considered using an IR or capacitive sensor to trigger a microcontroller to light my lights.
This was a little overkill. I wanted the project to run for a very long time on small batteries and polling a sensor would be a waste. The natural solution would be to use a simple mechanical switch. The mouse balls were not heavy enough to trigger any of the microswitches that I had on hand so I started to think of what I could make homemade.

My first prototype attempt was to create a strip of pressure switches. These consisted of a strip of foil for one side of the connection and a coiled wire for each LED. A straw was used as a spring to keep them separated. This configuration worked as a switch but it was mechanically impossible to get the mouse balls to trigger the switches.

The design that worked was to hang the switches from the top of the PVC pipe.

It is important to be able to insert all the switches as one unit because assembling anything inside of the pipe is well beyond my fine motor skills. The switches were constructed on a strip of cardboard and could easily be inserted and removed.


One lead of each LED is tied together and to +3V from the battery. The other lead of each goes to the switch. I fashioned the switches out of paperclips. The triangle at the top of the paper clips was designed to press against a strip of aluminum foil. Care, and some adjustments, had to be taken to get the correct angle on this triangle so that when it just pressed against the foil, the bottom of the clip was elevated a distance equal to the diameter of a mouse ball.

The other problem to overcome was the hinge. I first tried soldering the wires directly to the paper clips but this interfered too much with their ability to move. I rolled tubes out of foil around the clips and passed the wire leads through them. This allowed the clip to swing freely and kept an adequate electrical connection.

I taped the hinges down but found that the tape I was using did not hold nearly well enough. Sewing the hinges in place worked wonderfully and the unit has shown no signs of wear after a week of near constant use.

Currently the batteries are held in place with bent header pins. I have not yet figured out a more suitable enclosure for them. The current limiting resistor is soldered with the batteries. As only one LED should be lit at a time, only one resistor was required. The resistor was chosen to run the LEDs at half current. Brightness is not required but battery life is.

After the pipe was constructed I glued the magnet on the pipe. I found that the magnet was strong enough to attract the switches and keep a ball from rolling through the pipe. It was necessary to remove the bare magnet and glue it in place with the piece of metal that it was attached to in the hard drive. This made the magnetic field inside the tube negligible and had the added bonus of greatly increasing the magnet's holding force.

It was a simple project and took a couple hours but has already provided hours of brain-exercising entertainment for my kids. There's something hypnotizing about moving lights. It reminds me of KITT or cylons. I could watch this all day.


Thursday, June 24, 2010

The Bare Bones Board



The Bare Bones Board was designed by Paul Badger and is sold at ModernDevice.com. Besides the BBB, ModernDevice also sells a radio enabled version and several useful sensors.

Differences from an Arduino

This rework of the arduino design is completely compatible with the Arduino software. The Arduino software is a big part of what makes the platform easy to work with. Reusing the bootloader and the community libraries is important. The microcontroller that comes with the BBB is preprogrammed with the Arduino boot loader.





The first, and most obvious difference between the two is the layout of the I/O pins. The BBB was designed to be plugged into a breadboard for easy debugging and prototyping. This change means that the many Arduino expansion boards, called shields, will not fit the BBB. I felt this is a valuable tradeoff as I don't personally use shields.

Another significant difference is the USB connectivity. The on-board usb-serial connection that the Arduino provides is one of the more expensive components on that board. In low quantities this single chip costs about $5 which is 1/4 the cost of the whole Arduino. This allows the Arduino to be programmed over USB- however, in many devices if only needs to be programmed once and may not be used again. The BBB saves this cost by offloading the USB chip onto a separate board. You can use this separate board to program any number of microcontrollers.

Lessons learned

The BBB also saves costs by coming as a kit. This means you have to solder it yourself. It's good practice. It builds character. It comes with very complete instructions for the soldering and to help understand what the various components are for.

I am not going to include a full tutorial on soldering in this blog. There are plenty of web sites that do a much more thorough job of it than I would. There were a couple techniques that I found to be very helpful when putting together the BBB.
  • Solder components shortest to tallest. This will make it easier to rest the board upside down without components falling out
  • Use sockets for the expensive components. An IC socket may be $0.30-$0.50 but it is well worth it if it keeps you from burning up a $5.00 microcontroller. And if (when?) you do burn one out by not using a flyback diode when driving a relay you can replace it without any soldering.
Components


Some of the components I remembered from my physics classes. Some of them were new to me.
  • Microcontroller
    Abbreviated uC. This is the brain of the board. This has an internal clock, program storage and memory, timers, interrupts, Analog To Digital converters, digital I/O, PWM generation, I2C and serial communication. It is the most expensive component of course (except for the PCB itself) and is fragile. It can be easily destroyed by a stray voltage spike.
  • Resistors
    Limit the flow of current. One of these resistors is used to keep the LED from burning up.
  • Capacitors
    Caps store a charge. They fill up when the voltage to them is high and discharge when it is low. They are filters that try to keep voltage constant the same way a water tower tries to keep water pressure constant. The big capacitors help even out the incoming DC power. The little ones are filters that the uC uses.
  • Diodes
    Allow current to flow in one direction only.
  • Inductor
    An inductor simply generates a magnetic field. As a capacitor stores charge in an electric field, so an inductor stores a charge in a magnetic field. On this board, the little inductor is being used as a filter for the uC.
  • External clock
    The uC has its own internal clock but it can use an external clock for slightly faster speeds.
  • Linear Voltage Regulator
    A linear voltage regulator takes in a DC voltage and outputs a specific DV voltage. In this case the regulator outputs the 5V that the uC requires. It is very important to note that all the extra power from the voltage drop is wasted as heat. If you supplied 9V then 4V would be burnt off. The uC can draw around 300mA. Using the power function P=IV this would mean at 9V the regulator would have to dissipate 1.2W- not too bad. However, if you supplied 12V the resulting 2.1W might be too hot.

    Power supply considerations are a future topic of discussion.

Thursday, October 8, 2009

It began with an Arduino

Summary of things I learned
  • Hackaday.com 
    • A blog that posts writeups of various projects everyday.
  • The Arduino
The Details

Hackaday.com

A few years ago a coworker sent me a link to the writeup of an interesting hardware project on a blog called hackaday.com. This blog consisted of a writeup and link to one interesting hardware hack everyday.

Reading through some of the posted projects, it was obvious that I did not possess the skills necessary to reproduce most of them. Occasionally there would be a post about a software project that I knew I could do. I added the rss feed to the blogs that I follow and over the years I read about many interesting projects that seemed impossibly out of my reach.

I highly recommend taking a look at this blog to get a feel for the kind of things that are possible for hobbyists and to get good ideas.

Reading about other people's projects increased my interest in electronics in general. Many of the projects were centered around something called an Arduino.

Arduino

I want to learn how to write software that could interact with real life. I have a temperature sensor and a computer. How do I connect the two so that my software can use it?

The breakthrough that launched me into this hobby happened in a conversation with another coworker, Charles, who showed me an arduino that he had purchased and explained what it was.

What is an Arduino?

An Arduino, according to their web site, is:
"an open-source electronics prototyping platform based on flexible, easy-to-use hardware and software. It's intended for artists, designers, hobbyists, and anyone interested in creating interactive objects or environments."
The Arduino, developed by a team in Italy, consists of a fairly simple microcontroller board and the development environment to program it.

The hardware is centered around an Atmel microcontroller. Different versions of the Arduino use different microcontrollers. The mc has a number of Analog inputs that measure voltage, and digital inputs and outputs that input or output high or low voltage meaning 1 or 0. the rest of the board is simply components to support the mc such as, voltage regulators, a clock, a reset switch, capacitors, and a status LED. I will talk about the mc and the board more in future posts.

The true beauty of the Arduino is the software. The Arduino software is open source and free to download. It is written in Java and runs on many platforms- including Linux where I use it. It includes a very simple IDE and the avr compiler that produces binaries for Atmel microcontrollers. The IDE also comes with several libraries to do more advanced tasks such as networking. The Arduino community is very active and various libraries, and examples can be found on their forums.

Most importantly- to me as a software guy- the mc on the Arduino is preprogrammed with a boot loader. Microcontrollers require special hardware to copy the code to the chip. These programmers can be very expensive and represent a significant barrier to entry to novices such as myself. The Atmel microcontrollers used on Arduino boards are programmed with a simple boot loader that allows code to be copied to the mc over the built in serial interface. The end result is that you can write your program in the Arduino IDE and press a button and the code is compiled and uploaded automatically.

The Arduino elimates all the obstacles that have to be solved before software can be run: choosing a microcontroller, obtaining a programmer for it, designing a board that can support it, and getting the right compiler that runs in your OS.


Where can you get an Arduino?

The Arduino web site (http://arduino.cc/en/Main/Buy) lists many resellers in several countries that sell the hardware. The software is available for download. (http://arduino.cc/en/Main/Software)

As of the writing of this post, you should expect to pay around $30 for the newest version of the board. You can find older editions for less but they won't be as powerful.

I did some reading and shopping and found a few places that made their own board that is built around the same Atmel microcontrollers. They have different form factors but the software will work identically. I ended up buying my Arduinos from moderndevice.com. This board is designed to be used with breadboards for easy prototyping. It is also a little less expensive.

I bought 4 kits and a TTL serial to USB converter for about $60. Not bad.

In the next post I will go into more detail about assembling the kits and what I learned from it.

Wednesday, October 7, 2009

Preamble

Summary
  • I'm a software guy who started learning electronics
  • I'm writing this blog because if I think this is interesting then someone else probably does too.
The Story
 
I have been programming since 7th grade when I first found that you could modify the Gorillas game written in QBasic that came with MSDOS. I would make the bananas all different colors. Very sophisticated. Later I wrote a flashcard program for learning Turkish vocabulary. My Turkish teacher was very impressed. I never really decided to go into Computer Science in college. I just kept doing what I had always been doing and ended up with that degree.

Hardware is nice. Without it I wouldn't have a place to run my software. After 15 years of programming I have finally decided to learn the basics of electronics. I want to write software that makes things move. I am interested in home automation- especially for tasks that are a chore like watering the garden. I also want to learn something new and this promises to be fun.

Somewhere there is a geeky software engineer like me with a decent knowledge of computers, a rudimentary understanding of electromechanical physics, and an interest in electronics. Hopefully this will save them some time.

Learn something new and go build something cool.