Chronograph for Air Cannon

Introduction: Chronograph for Air Cannon

About: If you've got a problem, Yo, I'll solve it ! -Robert Matthew Van Winkle

This chronograph project consists of a sensor assembly and timer circuit box that can be used to measure the muzzle velocity of a projectile fired from an air cannon. 

I originally built this setup for use with a large air cannon with a 3" bore.

The sensor assembly is attached to the end of the air cannon barrel. It contains infrared sensors used to detect the passage of the projectile. A microprocessor measures the time it takes for a projectile to travel a known distance and displays it on an LCD. From this information, the velocity can be easily calculated.

Step 1: Overview of Operation

Below is a block diagram of the timer box and sensor assembly system. The sensor assembly is shown at the bottom of the diagram, with a round projectile traveling through it. The functional blocks within the grey box are located on the PCB. The switches, connectors, and LCD module are mounted on the case of the timer box.

The sensor assembly consists of a length of 3” diameter PVC pipe, with the two IR sensor pairs mounted 6 inches apart. The sensor assembly has a threaded fitting on one end, which allows it to be easily connected to another threaded fitting on the end of the barrel.

The timing circuit initially monitors the first sensor, waiting to detect that the beam has been broken by the projectile. After the first beam is broken, the processor starts an internal timer to record the time that has elapsed since the beam was broken. The software then begins monitoring the second sensor. When that beam is broken, the timer will be stopped. The processor then displays the time elapsed between the breaking of the beams on the LCD.

Step 2: Circuit Description

The schematic for the timer and sensor set up is shown below.  A brief description of the function of each componenent is as follows.

Power Supply

U4 is a 5 volt regulator used to produce the regulated 5 volt “VDD” supply for the microprocessor. C1 and C2 are input filter capacitors for U4, used to stabilize the input voltage. C4 is an output filter capacitor for regulator U4, used to stabilize the output voltage. LED1 is a “power on” indicator, and R43 limits the current through LED2.


The microprocessor U1 monitors the two sensors, measures the time elapsed between the breaking of the two sensors, and configures the results for display on the LCD module. C14 is the bypass capacitor for the VDD input of the microprocessor.

A reset switch is included, so the program can be restarted for another measurement without having to remove power to the circuit. R12 keeps the reset input of the microprocessor pulled high when the button is not pressed. R11 and C16 form a low pass filter to keep the microprocessor from being reset due to electrical noise. C17 is to arrest any ESD spikes that may come in on the switch lines. J5 is the connector for the SPST momentary reset switch on the front panel.

LED1 is a general purpose indicator that is mounted on the front panel. It can be used to provide feedback to the user to indicate any conditions that might be necessary. R15 is the current limiting resistor for LED2

Sensor Interface

Each sensor pair consists of an infrared LED and a phototransistor. The pair is mounted so that the light from the LED shines across the pipe to the phototransistor on the other side. When the phototransistor is illuminated by the LED, it is “ON” and it pulls its collector low. When the beam is broken and the phototransistor is no longer illuminated, it turns “OFF” and its collector is pulled high by the pull up resistor on the PCB.

IR LED Drive

The IR LEDs themselves are located on the sensor assembly. The microprocessor can turn each IR LED on or off. Once both the sensors have tripped, there is no longer a need for the LEDs to be illuminated, so they are shut off at that point. This is not strictly necessary, but since the unit is battery powered this feature was included to extend battery life.
R38 and R30 are current limiting resistors for the two infrared LEDs. Q1 and Q2 are used to turn the LEDs on or off. R6 and R8 are pull down resistors o the gates of Q1 and Q2, to keep them off when the microprocessor pins are floating during reset. R7 and R9 are not strictly necessary, but they are included here to limit any problems with ringing on the gate when the FETs are turned on or off. They can be replaced with jumper wires if there are no problems with ringing.

IR Phototransistor Inputs

The phototransistors themselves are located on the sensor assembly. When the IR LED is on and the beam is not obstructed, the microprocessor will read the input as low. When the beam is broken, the phototransistor turns off and a pull up resistor on the PCB pulls the microprocessors input high.

Connector J4 is the connection to the collectors of the two phototransistor sensors. R20 and R24 are the pull up resistors that pull the input to the microprocessor high when the phototransistor is off , such as when the beam is broken. R19/C20 and R23/C22 are low pass filters on the sensor inputs used to remove any false triggering due to noise.

LCD Module

The timing results are displayed on a 20 X 4 character LCD. This kind of LCD is used to display character data only. The interface is parallel, and it can be configured for either 4 bit or 8 bit. The 4 bit mode was used, so that fewer IO pins of the microprocessor are needed. In addition to the 4 data lines, there is a line called RS and another called E that are part of the process of sending commands or data to the LCD.

A potentiometer, R10, is used to control the contrast of the LCD. C15 is a bypass capacitor on the VDD pins of the LCD module.

Step 3: Construction

Timing Circuit and PCB

The circuit was constructed on a custom PCB. It was laid out using the free layout tool from expressPCB. The board was ordered per expressPCB’s mini board service.

Timer Box

The timing circuit PCB, LCD module, reset switch, power switch, and interface connectors are built into a small aluminum enclosure. The two IR switches on the sensor assembly connect to the unit via 9 pin D-sub connectors.

Sensor Assembly

The sensor assembly is constructed out of a short length of 3” diameter PVC pipe. There is a female threaded fitting on the sensor assembly, and there must be a male threaded fitting on the end of the barrel to make the attachment. Refer to the pictures below.

The two LED/phototransistor pairs are located 6 inches apart. The pair nearest the muzzle end of the assembly can be seen in one of the pictures below.

The LEDs and phototransistor are mounted in holes drilled in the side of the pipe. Care must be taken to get the pair aligned properly. The axis of the LED and the corresponding phototransistor should both lie on a line through the diameter of the pipe. The LEDs and phototransistors must not protrude into the inside of the pipe, or they will be destroyed by the projectile. They are secured in place with hot glue.

The last picture shows another sensor assembly, for an air cannon with a 1.5” diameter barrel. It is essentially the same in concept as the 3” diameter sensor.

Step 4: Software

The software was written in assembly using Microchip's MPASM tool, which can be downloaded for free from their website.

The source code *.asm file and assembled *.hex file for programming are attached. Also included is a high level flowchart of the main program.


The microprocessor used is a PIC16F628A.  The microprocessor runs on its own internal 4 MHz clock.  The internal instruction cycles therefore take 1 microsecond each.

The program turns an internal timer on when the first beam is broken. The internal timer (timer 0 on this PIC processor) counts up at a rate of one count per instruction cycle.  When the second beam is broken, the program turns off the counter. Timer 0 is only 8 bits, and so it overflows every 256 counts, or every 256 microseconds.  The software checks for overflows, and increments another variable each time an overflow occurs,  If that variable overflows (after 65536 instructions cycles), then another variable is incremented.  In this manner, a 24 bit count of the number of instruction cycles that have occured since the breaking of the first beam is generated. Since an instruction cycle takes 1 microsecond, the count is in microseconds.

If the count overflows the second variable, the program ends and displays a time out message.
24 bits can store a value of 16777215 counts, so the timer can measure an interval between events of as much as 16.78 seconds.

If the second beam is broken before the maximum time has elapsed, the program then proceeds to convert the 24 bit binary count into 8 ASCII decimal digits that are then displayed on the LCD.

When the unit is first power up or reset, an intro screen will appear on the LCD for about 1 second.  Afterward, it will display a prompt screen, reading "WAITING FOR START". It will continue to display this message until after the second beam is broken (throughout the interval between the breaking of the two beams).  After the second beam is broken, the results are then displayed as XXXXXXXX MICROSECONDS.  This message is displayed until the reset button is pressed or the power to the unit is cycled off and on again.

If the count exceeds the maximum, the message "COUNT OVERFLOW" will be displayed until a reset or power cycle occurs.

Step 5: Results

This chonograph was originally built for use with a 3” diameter air cannon. 

The cannon was test fired with the tank pressured to approximately 50 PSI.  A standard baseball was used as a projectile.  The timer results from several such firings were in the range of 2400 microseconds. The sensor pairs on the 3" sensor assembly shown earlier are located 6 inches apart, so this translates to a muzzle velocity of approximately 140 miles per hour.

Step 6: Other Uses

The timer circuit box can be used for other purposes beside a chronograph. It can be used to measure the time interval between any two events, where a switch opens for each event. Any kind of switches that change from closed to open when the event occurs can be connected in place of the phototransistors. This would include mechanical switches, relays, and reed switches, as well as semiconductor devices like transistors, Hall effect sensors, etc.

Microcontroller Contest

Participated in the
Microcontroller Contest

Be the First to Share


    • Make It Modular: Student Design Challenge

      Make It Modular: Student Design Challenge
    • Colors of the Rainbow Contest

      Colors of the Rainbow Contest
    • Tinkercad to Fusion 360 Challenge

      Tinkercad to Fusion 360 Challenge



    11 years ago on Step 4

    How do you get the files onto the chip, I have never done anything like this but really wan't a chronograph for, luck me, my 3inch air-cannon barrel. I also looked up the chip, but it says it is 20MHz not 4MHz, or are those separate things.


    Reply 11 years ago on Step 4

    You will need a PIC programmer to program the code onto the microprocessor. These can be ordered from many places. I got mine from a company called Melabs at

    You can also build your own programmer, but I have never tried it. There are instructables on how to build PIC programmers.

    The 20MHz spec refers to the maximum clock frequency that can be used. The chip also has an internal oscillator that can be used for the clock. The internal clock can be configured for a few different speeds, and this one uses the 4MHz speed. The internal clock generator can clock as fast as 8 MHz.

    The internal oscillator is handy, as it eliminates the need for the external oscillator. One small drawback is that the internal oscillator is not nearly as accurate as a crystal or other external oscillator chip. The interenal oscillator can be off by as much as 2%, but I used it here because it still gives good results.


    Reply 11 years ago on Introduction

    Thanks, I found a microprocessor with an internal crystal, would that be more accurate and get rid of the 2% or is still going to be less accurate. Also do you know where there are some good guides on learning the PIC language.


    Reply 11 years ago on Introduction

    The programmer from Sparkfun that you link to below should work.

    When I was learning the PIC assembly language, I started with materials from Microchip's own site. At that time at least, they had some good material that covered alot of the detail of the 8 bit families of micros they offer.

    Their site also has a large number of interesting application notes, some of which have assembly code with them.

    And of course there are books and tons of other web resources. I have never read any of the PIC books so I can't comment. Many folks use C language tools for writing code, but I have never used C.

    The PIC assembly language for the 8 bit micros has only 35 instructions, and the datasheet for each processor contains a section describing them, so the processor datasheets themselves are a good reference.


    Reply 11 years ago on Step 4

    I bet I have to get one of these right


    11 years ago on Step 2

    Will any 18 pin PIC micro controller work (with all of the files you have w/no modification)


    Reply 11 years ago on Step 2

    I can't say that they would work with absolutely no modification. Any PIC that you would plan to use as a subsitute would have to have the same features as those utilized in this program. I am using the Timer0 peripheral, and the 4MHz internal oscillator.

    So there are several other 18 pin PICs that could be substituted with very minor changes to the code, and possibly some that could be used without any modification. I can't say off the top of my head if there are any that I am 100% sure can be used as direct subsitutes. If you are familiar with the PIC assembly language you could relatively easily modify the source code to a different PIC that met the requirements.


    11 years ago on Introduction

    this is nice, will try to modify it so that i may use it on airsoft or airguns! ty


    11 years ago on Introduction

    I have been thinking about building my own air cannon, and I want to be able to measure the performance of various valve designs I have in mind. I thought that a commercial chronograph might be the only solution, but now there is another option. Great job, and thanks for the inspiration.

    By the way, have you considered making instrument packages to launch from the cannon? Something like an accelerometer with a data-logger to find out how much the projectile is getting “punched” by the launch. Maybe a timing circuit to trigger recovery devices or other activities. Launching potatoes and baseballs might be only the start.


    Reply 11 years ago on Introduction

    Yes, as a matter of fact I have pondered many different payloads I could launch from an air cannon. I am working on a rocket like projectile that will return via a parachute. Ideally I'd like the parachute to deploy on its own, with the nose cone and chute just falling out, without anything needed to eject it like with common model rockets. So far I can't get the chute to deploy conistently.

    Another project I'm working on it similar to the chonograph. It is a special barrel for the 1.5" diameter gun, with photosensors located every 2" along the barrel. That way, I could get a reading of acceleration during lauch that I could use to evaluate the effects of valve, tank pressure, etc.

    Lots of fun projects spawned by air cannons, but always too little time.