Saturday, November 6, 2010

A Microcontroller based Interrupter Gear

Figure 1: The hardware

During World War I and slightly before World War II, military fighter aircraft had machine guns mounted to fuselage of the plane. These machine guns were mounted right behind the propeller. The first question that comes to mind is how can the gun fire and not hit the propeller blades as they are spinning? Some planes had special steel plates mounted to the propeller to keep the bullets from shredding the propeller.

Figure 2: A machine gun shooting through a propeller.

(I had fun with this one. Sometime, I should use a color other than black and maybe draw some wings)

There are a couple of reasons hitting steel plates in the propeller is bad. First, it introduces a physical shock to the propeller. Not good if you would like to remain in the air. Second, it adds weight to propeller; there by slightly reducing the max RPM of the propeller, making the plane go slower. Third, it wastes bullets. You would like all of the bullets to go out into the wild blue yonder.

Most planes of the day used something called an “Interrupter Gear” to time the firing of the bullets between the blades of the propeller. To see much more information on the Interrupter Gear, check out this link:

There is a nice drawing on the page showing how the cam wheel and cam follower worked inside of the planes. So, this was done mechanically in the 1910’s to 1930’s.

My first thought was this could be updated by using a microcontroller coupled with an infrared sensor to sense the position of the propeller? Doing the project in small scale significantly lessens the chance of bodily harm, which is just awesome. The gun I used is an Airsoft pistol. For those of you unfamiliar with Airsoft pellets and guns, they are a family of plastic guns that shoot a plastic pellet. You can think of it as a miniature version of paintballs, except the pellets do not explode when they hit you.

The hardware

The pistol I originally chose for the project was battery powered and semi automatic. (A semi automatic pistol fires a pellet each time the trigger is pulled until the clip is empty) The problem I ran into was when a solenoid pulls on the trigger; a DC motor inside of the gun starts to compress a spring inside of the gun. Once the spring is fully compressed, the “hammer” is released and the gun is fired. It took about a second for the spring to compress. When you have a propeller that is spinning at 500 RPM, that is 8.3 revolutions per second. (500 RPM / 60 seconds = 8.3) There are two blades on the propeller I am using. The one-second delay between activating the trigger and the pellet firing was a showstopper.

The second pistol I used was a spring loaded Omega M650. This gun can send a pellet out of the barrel at 100 feet per second. The top has to be pulled back by hand to cock the gun.

Figure 3: This is the Airsoft gun used in project

The really nice thing is it takes only 20mS to 22mS from the solenoid on the trigger being activated to the pellet leaving the end of the gun. The pellet was detected by using a Sparkfun infrared sensor. This is how I determined the delay: Probe A on the oscilloscope was attached to the signal going to the solenoid. Probe B on the oscilloscope was attached to the IR sensor output at the end of the barrel. The oscope was setup to trigger once on Probe A. When the trigger was pulled by the solenoid, I could see a blip on the oscilloscope screen:

Figure 4: This blip is the pellet leaving the end of the gun.

If the propeller is spinning at 500 RPM, we know it takes 120mS for one rotation to occur. (60 seconds / 500 RPM = 120mS or 0.12 seconds) Since there are two blades, we’ll be seeing a blade every 60mS. Since the delay between activating the solenoid and the pellet leaving the gun is at maximum 22 milliseconds, we have no problem placing the pellet between the propeller blades.

Is the microcontroller even needed?

My thought process when I started the project had the microcontroller setting the delay between when the propeller is sensed and when the gun should be fired. If we use logic gates to immediately fire the gun when the button is pressed, this will work great unless the time between sensing the blades is 20mS to 22mS. Also, if the propeller blades are at multiples of 20mS to 22mS the pellet will hit the blade. So, it looks like a microcontroller is needed to dynamically set the delay for the solenoid.

A way to test the delay between the propeller and when the gun should fire is to setup a red LED to turn on when the pellet should be coming out of the gun. An excellent way to do this is to setup the LED so it is 90 degrees away from the propeller sensor and gun. The LED can turn on and you can see the reflected light on the propeller.

Figure 5: Infrared Sensors and the Solenoid

Once the software was completely working, I ran 20 pellets through the gun to see if any pellets would hit the propeller blade. None hit the blade. A better test would be to modify the software slightly to see if I could get the pellet to hit the spinning propeller every time. So, I added into the software a define statement “defHitTheBlade”. If you want the pellet to the hit the blade, remove the comment “//” at the beginning of the line. The pellet would hit the propeller about 4 out of 5 times. It was hard to find the pellets after they hit the propeller.

Each blade on the propeller is 0.5 inches wide in front of the Airsoft gun. The gun is 1.15 inches from the axis of the propeller. So, if we use Circumference = 2 * Pi * radius = 7.2 inches. So, we can figure if a blade is in front of the gun for 1 inch / 7.2 inches = 14 percent of the time.

The software isn’t too complicated. When the user presses a button, the analog comparator interrupt counts the time (using Timer 1) between the propeller blades passing the infrared sensor mounted under the gun. Once we know how fast the propeller is going, the software then looks for analog comparator interrupt and counts 1.5 times the time between the blades, minus the time it takes the pellet to come out of the gun.

The circuit was created on the solderless breadboard. Three power supplies were used. A 5V wallpack for the microcontroller, a 24V power supply for the solenoid, and a variable power supply for the DC motor (1 to 3V).

Figure 6: The schematic for the Interrupter Gear project

Overall, circuit worked well. Trying to hit the propeller with the Airsoft pellets was fun, it really let me know the system was working. Onto the next project… (the next one should be a little more practical)

Here is the source code for the microcontroller:

AVRGCC C source code

Tuesday, June 22, 2010

The Relocation of Robin

For those of you not familiar with American robins, the male bird is territorial. When he sees his reflection, he thinks it’s another robin and he tries to fight. The result is hours of “trying to run off” the other bird. Of coarse his reflection doesn’t leave.

Figure 1: An American Robin

A robin has been pooping all over a hand railing in front of my house. The robin has also been thumping on the window trying to fight his reflection. (Nickname: Evil Robin) My first attempt to remedy the pooping was to tape trash bags over the windows so he wouldn’t see his reflection. After a week, I took down the trash bags figuring he had moved on. He had not. So, I taped the trash bags to the window for another week. He found the back porch window to attack. Also, he had started eating mulberries, which made is poop stain the railing with spots of purple. A rubber snake was placed on the railing in the hopes of scaring away the robin. He pooped on the rubber snake.

Figure 2: The Robin Poop on the Railing

My next ideas were to either buy an owl decoy or build one out of cardboard. These ideas were scratch in favor of trapping the robin and relocate him to a distant location.

Being a new homeowner, the demands of the house seem to take several hours a day. Coming from apartment life, this has been a difficult change. So, the idea was to complete the trap quickly and easily. Building the trap, assembling the circuit on a solderless breadboard, and writing the ATTiny13 code took about 3 evenings.

Figure 3: The actual robin doing the pooping (image taken though a window screen)

Two words are needed to see how the trap was put together: cardboard and packaging tape. The cardboard box was originally used to hold several dozen-egg cartons. A mirror is placed in the back of the box to allow the robin to see his reflection. The lid flaps on the cardboard box were removed and replaced with a single piece of cardboard to act as the “flap”. The flap needed a little more strength near the edge. So, strengthening ribs were created out of cardboard and taped onto the edge of the flap. The flap is held open by a solenoid attached to a wood dowel. The wood dowel is taped permanently to the egg box.

Figure 4: Various parts of the trap

Figure 5: Solderless breadboard on the side of the cardboard box

The ATtiny13 microcontroller acts as a comparator for the analog voltage output of the Sharp sensor inside of the trap.

Figure 6: The sharp distance sensor in the trap

When the microcontroller determines the voltage from the sensor is above the set value, the output to the solenoid is changed from a high to a low. This turns off the solenoid (by turning off the n-channel FET) that is holding open the gate of the trap. Gravity then takes over and the lid closes. Two magnets from a “shaking powered flashlight” are used to help keep the door shut. Two pairs of pliers are taped in the bottom of the trap to allow the magnets to keep the corners of the door closed.

Figure 7: Robin trap schematic (a PDF is at the bottom of the post)

The sensor outputs an analog voltage based on the distance to a reflective object. The operational distance of the sensor is from 10cm to 80cm. The object we are looking for in this case is the robin.

The solenoid typically is powered when the circuit is turned on. The flap is opened on the trap and it is align so the solenoid keeps the trap open. When an object is detected by the distance sensor, the flap is released from the solenoid and the robin is trapped.

Figure 8: The solenoid on the wood dowel

Did it work?

The trap was set on the front porch, near where the robin likes to sit on the railing for about a week. (When it wasn’t raining) Apparently, the trap was visibly so frightening to the robin, he never came back. So, did the trap work? Yes, it took care of the robin problem; No, it didn’t catch him. Maybe I should have gone with the 4 feet tall cardboard owl।


Source code for the Attiny13

Hex file for the Attiny13