Saturday, 25 May 2013

Chronograph update

When I made the smaller screw on sensor that connected to the PC and fed the timing into a PC application, it got me thinking about different types of display that could be used and after a a good look around the net I came across a couple of options.

The first was a 7 segment LED display, these come in different shapes and sizes and could still be quite portable when added to the sensor.

The only problem with these displays is the amount of IO needed to drive them as each of the segments require driving. I then came across the Adafruit 7 display backpack, which takes all the hard work out of controlling the 7 segment displays.
The backpack details can be found here

The device is based on an Holtek HT16K33 chip that controls the LED segments and connects to the Arduino via the I2C bus and has a library that makes sending data to the display easy.

I bought one of the displays from Ebay and stuck it on the side of the sensor tube then added the code to the sketch to send the value for feet/second to the display after sending the uSecond value to the PC.


This would allow the chronograph to be used in conjunction with the PC via the USB lead or remotely with a battery pack, just reading the Feet/Second value.


Showing the feet/Second would require a lookup table to get the power from the velocity and the weight of the pellet, I suppose with a couple of small buttons added you could enter the pellet weight after power-up but before the first shot it could then alternate between the FPS and the power reading every 10 seconds?.

I then tried it out using my CP Sport Co2 pistol and it looks good.

I then used some of that PVC heatshrink, normally used for battery packs, it's really good as it shrinks using a hair drier and is quite hard when cool but can easily be removed with a pair of scissors or a knife.

Ideally I would have liked to use some clear but I only have red or white but surprisingly the LED shows through the PVC quite well.

Things to think about: -

  • Writing the shot data to EEPROM for later retrieval
  • Adding buttons to allow pellet weight to entered
  • put together a battery pack for remote usage
  • Think about power saving schemes
  • Display battery power on power-up?
  • Who knows?
Nano Sketch can be downloaded here you can use it with or without a PC, if you want the PC application let me know in the comments, it's still very BETA.
Fritzing file here.

More about the second option I found later.....

133 comments:

Unknown said...

hi, this is a great read, im interested in the 7 segment one you completed. could you please tell me where you got the opl55c photodiodes from as i cant find them anywhere?

Gadjet said...

Jak,
Have a read of this post
http://gadjetsblog.blogspot.co.uk/2013/07/diy-chrono-shopping-list.html
Towards the bottom I've listed the sources for the leds etc.

g.broomfield said...

hi very intrested in the crony ,just got my first arduino uno and love air guns (shoot field target)this looks like a great project for mointering my gun ,very intrested in the pc software side to plot a string of shots as i am a complete noob when it comes to programming ,growen up on plc,s
not c++ or basic .could you please post a link for the software on your site thank

s3k0 said...

nice blog and projects

can we use a sensor other than opl550?

Gadjet said...

Thanks,
Yes you can use any IR LED and detector, I used the ones with a digital output to save on external signal conditioning circuitry.
You could use a simple phototransistor but it would be an analogue output also make sure that the response time is quick enough.

s3k0 said...

can't waiting my orders from china,
i will give you headache when arrived :)

s3k0 said...

again hi gadjet

i have i2c display like this;
http://www.mauroalfieri.it/en/elettronica/display-lcd-1602-i2c-pcf8574t.html

so how can i make skecth file for this screen thanks
serkan
sekocan at gmail.com

Gadjet said...


serkan,
Not certain what you question is, the page you link to inyour post contains the code for the screen have you tried this code yet?

s3k0 said...

sorry for my newbies question for you..
i bought 16x02 lcd-i2c protocol and on chip says "pcf8574t"
so how looks like code(adress) in skecth file for this lcd
i mean;
// initialize the library with the numbers of the interface pins
//standard LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
LiquidCrystal lcd(7, 8, 6, 5, 4, 3);
that thing only 4 pin 5v,gnd,sda,scl like adafruit i guess but i dont know how to :(

another question;
i had 2 pin ir led and emitter i looked your fritzing draw(7 seg disp) opl550 3 pin (+,logicOut,-)

Does this make a difference?

Gadjet said...

No problem, I was a newbie once.
The I2C interface doesn't use the standard LCD library with all the pins defined.
The I2C LCD uses a different library with just the LCD I2C address specified, i.e. 0x27.
The link to the library is here http://www.robot-italy.com/download/LiquidCrystal_I2C1602V1.zip
Save the library into a folder inside your libraries folder in your Arduino program folder and then you can use the code as shown on the web page link you sent me, it should work, let me know how you get on or if you have more questions.

You could also visit the www.arduino.cc website there is a good forum to get answers and tutorial code.

Gadjet said...

s3k0,
If you are using a two pin IR detector you will need to convert the analog output from the detector to a digital output to feed into the input pin of the 328p, that's the main reason O chase a detector with a digital output.
What is the part no. of the IR receiver you are using?

Gadjet said...

sk30,
Here's a link to some information regarding photodiode circuits.
http://www.fiz-ix.com/2013/04/ir-photodiode-circuit-schematic/

Hope it helps.

s3k0 said...

im using 5mm ir led and emitter,i dont know what are they exaclty :)
http://www.aliexpress.com/item/20pcs-5mm-940nm-LEDs-infrared-emitter-and-IR-receiver-diode-10pairs-diodes-301A/1579718658.html

and screen this;

http://www.aliexpress.com/item/IIC-I2C-1602-blue-LCD-module-provides-libraries-For-Arduino/1062018842.html

http://s27.postimg.org/3r9iz9ttv/IMG_20140416_072842.jpg

http://s27.postimg.org/6mmm64xtv/IMG_20140416_073028.jpg

Anonymous said...

s3k0,
I'm a bit stuck really, the things you need to consider with the ir receiver is the speed, phototransistors have a response time to the changing light level, some are quicker than others, I cannot find the speed of yours in the specification.
Ideally you need to put the receiver in series with a resitor ( as per the Circuits on the page link I posted) and use an oscilloscope to look at the waveform as you pass something in between the emitter and detector.
This is the reason why I used the more expensive detector with the digital output, it's a lot less hassle......

s3k0 said...

finally i got picture on lcd screen :)

edited skecth like this for my lcd;
https://docs.google.com/document/d/1tuZnfQ873t8fuN8SA_UkAH5Sd_z5usaBuBNfiaWjLjo/edit?usp=sharing

now, im trying-stucking :) ir emitter-receviers

Gadjet said...

s3k0,
One other thing about your set-up, the IR emitter/detector should be shrouded to stop IR leakage around the object breaking the IR beam, in my test setup I used a tube with holes in ....

http://3.bp.blogspot.com/-i10QqXOQeDA/URfGY4-MhzI/AAAAAAAALHk/OOKinhG2BHk/s1600/Prototype+tube+setup.jpg

s3k0 said...

again hi there phill,
u said "If you are using a two pin IR detector you will need to convert the analog output from the detector to a digital output to feed into the input pin of the 328p, that's the main reason O chase a detector with a digital output"
yes im using 2 pin ir detector, how can i doing this?
can u draw schema for dummy(me)how exactly

Gadjet said...

s3k0,
This link shows the circuit to try.
http://www.fiz-ix.com/2013/04/ir-photodiode-circuit-schematic/

This will give a varying output for the ADC input but there will be a point at which the level will be seen as a digital 1 or 0, i think it is one third of VCC or below to be a 0 or above two thirds of VCC to be a 1.
You could also feed the signal through a Schmitt Trigger or opamp buffer to get a clean digital output.
It would really be a lot easier to use the same IR detectors that I used...... :-) especially if you're not familiar with electronics.

Gadjet said...

Here are some links that might help.
http://www.boondog.com/tutorials/irled/ir.html

http://www.electroschematics.com/tag/photodiode-circuits/?ModPagespeed=noscript

Hope they help.

s3k0 said...

still can't understood that ir-led-receivers :o
im getting blinking 999fps on screen if am block 1 emitter it is stop while serial monitor tell me 20 us 20 us loop :) somethin wrong but i cant tell u :(

http://www.youtube.com/watch?v=tAWjfIinq3I

can you make Fritzing file for me ?

s3k0 said...

if i will go buy opl550 sensor can i get good result i mean is it work :)

Gadjet said...

Did you try the fritzing file?

Mine works so your should! Just remember the LEDs should be each side of a tube.

s3k0 said...

Still i cant get it work ..can i need change something in skecth file??

Gadjet said...

Go back to basics.
Use the sketch from this post, don't bother with the display just use the serial output. (Add your display code later)

Connect two switches to the inputs (pins 2 and 3 I think) and use the switches to trigger the inputs and make sure the serial data agrees.

Once that works as expected then add the IR triggers but make sure your setup is suitable to get a good break beam trigger.

s3k0 said...

random clicked buttons and results;

Duration 24 uS
Duration 268740 uS
Duration 73940 uS
Duration 24 uS
Duration 20 uS
Duration 20 uS
Duration 20 uS
Duration 20 uS
Duration 88064 uS
Duration 20 uS
Duration 166816 uS
Duration 145036 uS
Duration 91928 uS
Duration 20 uS
Duration 107672 uS

Gadjet said...

I held both switches under my thumb and pressed at the same time (rolling my thumb) in such a way that the trigger 1 input was always pressed slightly before trigger 2 input or one switch in each hand and following a stopwatch press then a second apart.

If the readings look good then the sketch is fine. Next will be to sort out the IR beams.

s3k0 said...

finally i got progress...
all i need was opl550a :) problem solved..
now the next question max fps 999 can i get more ?

Gadjet said...

Great news, you aren't in the UK then if you want more than 999 fps.
I will look at the code tonight but is there a simple check to see if the value is below 999 and only send out data if it is, this can be changed to whatever value you like.
There will be a limitation to how fast the detection will be but I've not figured it out.

Gadjet said...

This is the line in the code
fps = constrain(fps,0,999); //limit fps to plus value upto 999

Also have you set your sensor distance correclty.

unsigned long SensDist = 333333; //Distance between sensors in feet *1000000

s3k0 said...

hi again,
im tested system today so i got 1515fps :) i know its wrong cuz i have mk4is 16grain 875-876fps always
so u said;

Also have you set your sensor distance correclty.

unsigned long SensDist = 333333; //Distance between sensors in feet *1000000
how u got 33333? what is formula this thing can u explain to me thanks...

Gadjet said...

Sorry if you've already said but what's the distance between your sensors, the calc to give 333333 ois for 100mm.
Calc for 60mm =
((60mm/2.54)/12)×1000000= 196850
Hope this sorts it out, this would give 896.4 fps

Gadjet said...

s3k0,
Did you get it working correctly?

s3k0 said...

edited skecth file to for correct trigger distance but i cant test yet, i will let u know when i tested

s3k0 said...

i tested today couple shots i got the 820-805-824fps something wrong but i dont know cuz same rifle with orginal chrony 860-865fps with 13.43 grain(fx t12 with regulator)

Gadjet said...

Seems to be better than before but still not consistent.
PCP with regulator would be more consistent, some things that could be affecting readings: -
the mounting and distance between sensors, I face the emitter detector pair at each other through a 2mm hole to try to make a norrow area of triggering.
The metal tube I use keeps most of the ambient light out.
The holes are exactly through the centre of the tube so the pellets travel through the centre of the beam.
The tube is firmly secured to the barrel.

I must admit I've not really looked at the variance of fps over a string of shots I've been only interested in the power aspect, it's possible that the software could be introducing a variance in the reading, maybe using interrupts to trigger the measurement could improve the consistency, I'll look into it.

Gadjet said...

Another thought, the FPS is quite high, in the UK 760 fps is more usual, with a higher speed there is less time to measure the travel 96uS at 860fps, this would mean a few uS difference would make a bigger change to the indicated fpes.

How far apart are your beams? try increasing them, 100mm maybe, this would give a longer interval making any processor cycle variance less important.

Gadjet said...

96uS/inch that is.

Unknown said...

When trying to verify the following section is highlighted "Adafruit_7segment matrix = Adafruit_7segment{}; with the comment stating "'Adafruit_7segment' does not name a type". The highlighted section is in the begining of the sketch just after "#include "Adafruit_GFX.h". Does this need to be changed or am I missing something else in my set up.? Any help would be greatly appreciated. I have little to no experience with Arduino sketch writing but found your design on line and really liked the chronograph characteristics and really wanted to make one. So, I really hope you can ease me through this hang up and get me out shooting. Thanks again for your time and help with this issue.

s3k0 said...

i did another chrono using with attiny2313

http://www.youtube.com/watch?v=zFlcWr1jlRg

Gadjet said...

Brian,
I assume you mean you are getting an error when you compile the sketch, have you downloaded the adafruit libraries and placed them in the library folder? I think your sketch is looking for the library.

Gadjet said...

sk30,
That looks really good,I like the fact that the display is facing you.
any chance of some better pictures or maybe some code , I have some smt attinys kicking around somewhere, I would like to make a pcb including the leds and processor, it would be quite small.

Chronograph said...

This would allow the chronograph to be used in conjunction with the ... ochronograph.blogspot.de

Anonymous said...

Hi

Is it possible to make a sketch of how components are connected to each other ?

Gadjet said...

Sorry, I don't understand, there is a sketch in the post, do you mean something else?

Anonymous said...

Gadjet, thank you for your answer.
I bought the items as below:
Photo sensor OPL550A
IR Emitter LED OP240A
I wonder. Did I should add a resistor?

Gadjet said...

My apologies you are correct, add a resistor to the LED emitters supply as required to limit the current, I should have added them to the circuit.

Anonymous said...

What kind of values ​​should be resistors for LED OP240A?
I'm not an expert in this but I think 160Ω will be good.
The calculation result data http://optekinc.com/datasheets/op240-245.pdf
Is something going to happen if I give a larger resistor 200Ω

Gadjet said...

If I remember correctly I used 180 ohms with a 5 volt supply, see here http://3.bp.blogspot.com/-69QqEtS5g9I/USFD-Nn_MOI/AAAAAAAALIg/t_yUagkrYvY/s1600/Tube+sensors4.jpg


Anonymous said...

In my resources I have only 200 ohms.I checked it looks like it works :)
OPL550A do not need a resistor? (Arduino Nano 5V supply)

Anonymous said...

Something works :)

Duration 534040
Duration 224540
Duration 200288
Duration 3414768
Duration 90524
Duration 32500
I move the pen from one to another sensor.
The slower I do it the higher score.
I have to decipher the code. At the same I 'm bad :(

Gadjet said...

Great news.
200 ohms should be fine, the led emitters are very close to the sensors so you could probably use even higher values to save power if running off a battery.

Anonymous said...

In the code I made some changes. You can see them in the link below.
https://drive.google.com/file/d/0B_EqFfSmX6RhY1V2eV8tTWg0eE0/view?usp=sharing
I added fps , mps.
The distance between the sensors should be exactly 60mm?
How accurately do the prototype?
Intuition tells me that it must be the most thoroughly :)

Gadjet said...

Please change the code as you wish and post it so others may use it.
The distance between the sensors is very important, having said that you can make it whatever you wish and then adjust the value code to suit, the greater the gap the more accurate the count but then there will be more deceleration in the pellet over the distance.
I have two sensor tubes, one 60mm and 100mm.

Anonymous said...

I modified the code. I wrote to view fps , mps , jouls .
I wonder how to add a feature that downloads the wage pellets in grams?
https://drive.google.com/open?id=1VLVPHUSnKKl691OgpLndaJ_OxpwaWugRQrbOU3TlQTc

Gadjet said...

Anonymous,
There are several options ...
1. Add the calculation for power in your sketch (formula is in one of my sketches or just google it) and send it out serially.

2. Use some PC software, (link in another one of my posts) to show data and input weight of pellet.

3. Add a Bluetooth serial interface (discussed in another post) and send the time to your phone and use the app to add the weight and calculate the power. (link to app also in a post)

4. add a local LCD display to show FPS and Power.

Anonymous said...

So far I am too weak for points 2; 3
On the web I found a point 2; 3 but no 1
I do not know how to retrieve data from PC console and use the program :(

Gadjet said...

For no. 1 see here for the formula
http://www.pyramydair.com/article/What_is_Muzzle_Energy_August_2003/5

You can get the PC software install here
https://dl.dropboxusercontent.com/u/2253850/PC%20Chrongraph.rar
Unzip and run setup, It's been a long time since I looked a this so there maybe some issues.
Try it and let me know.

Anonymous said...

Gadjet thanks for your reply
I understand calculations . All I was able to implement.
Now I want to add the weight of pellet from the keyboard.
For instance when the program starts.
Now the weight is entered permanently in code.

The program requires Windows 32bit?

Gadjet said...

OK good.
I'm not sure how to enter the weight into the program, maybe use the serial port and use the terminal in the Arduino IDE to send a value to the Arduino to store in the eeprom?

Yes, 32bit windows

Anonymous said...

"Sorry if you've already said but what's the distance between your sensors, the calc to give 333333 ois for 100mm.
Calc for 60mm =
((60mm/2.54)/12)×1000000= 196850
Hope this sorts it out, this would give 896.4 fps"

If the distance between the sensors is 100mm the result is 328083. Is this the result requires rounding to 333333?

Gadjet said...

Anonymous,
The calculation is correct, I have two sensors 100mm and 60mm, the code I posted was probably for 100mm and I probably adjusted it because the distance wasn't exactly 100mm when I measured it with a digital vernier.

I also used an oscilloscope to check the timing between pulses and compare to the measurement calculated by the sketch.

BTW I've since modified the sketch to use the interrupts but not fully tested it.

Anonymous said...

Photo sensor - OPL-550a and IR Emitter LED OP240A they are arranged in the tube. Elements are spaced apart by 32mm. It Appears That this distance is too big. System oblicza szaleje więcej strzałów w nieskończoność. Did you have a similar problem ?

Gadjet said...

I had a smaller gap than that, about 20 mm apart.
Do you have them either side of a tube or in the open air?

Anonymous said...

I tried many times. In the pipe and the open air . Confirm the action on the open air to 30 mm. The pipe has exactly 32,08mm and no longer works. On the open space it behaves strangely . If the sensors aligned to each other and then increasing their distance then it starts to work on up to 32mm . If the operation of the system with a fixed distance of 32mm sensors do not see. I assumed it would be like the remote control for the TV. At first, the distance was not an problem.

Gadjet said...

Have a look at this post, the idea is to form a beam that will be broken with a pellet, it the sensors are in the open air or too far apart then there will be a wider beam that gets around the pellet.

I use a thick walled tube around 3 to 5mm with an OD of 20mm, this creates a sweet spot for the detector and allows the passing pellet to block the IR light from reaching it.

see picture http://2.bp.blogspot.com/-R3_HMY4XC-k/USFBvyr81hI/AAAAAAAALIM/Khj9x4Qrelw/s320/tube+sensor+section+cut.jpg

Hope this helps.

Anonymous said...

I think that I am doing something wrong . Even if I can cross the two goals on the display I see strange readings. 0.01 ms . It looks as if he did not read fast shots.

Gadjet said...

I can say that I've spaced my sensors 60mm apart and I have no problems detecting shots reliably, the only time I have issues is when I used it on my CO2 pistol and the first couple of shots were way too fast, I pout it down to a fresh CO2 cartridge and CO2 gas causing false detection.
I use it with my PCP with no problems, what tube are you using, material and size and how far apart are your sensors?

Anonymous said...


The distance is 100mm I try to measure the speed of HW97k. Maybe too fast for Arduino Nano.

Anonymous said...

I tried with a ball of paper. The ball is large enough not miss the sensors :) At bigger speed no reads. I tried to Arduino Nano and Leonardo. It is possible to speed up the reading?

Gadjet said...

I wouldn't use a ball of paper, you need to use something solid and opaque so no light can make it through.

I used an aluminium tube (about 20mm OD with 14mm hole) then drilled the two 3mm holes across the tube 60mm apart and fixed the sensors to the sides of the tube I then used a cheap bic pen with the ink tube removed and used it to drop pellets into the aluminium tube so they fell through the centre between the sensors.

You could also use a ball bearing just smaller than the tube internal diameter, this will guarantee that the beams are broken.

Anonymous said...

Can you explain why the distance between sensors counts in such a way?

"Calc for 60mm =
((60mm/2.54"inch")/12"inchy")×1000000"?"= 196850"
Thank you very much

Gadjet said...

OH!now you asking.
If I remember it's all about how many microseconds it takes to travel over the 60mm and also convert from the mm into feet per minute.

60mm divided by 25.4 gives distance travelled in inches = 2.36 inches

divided by 12 to give the part of a foot = 0.197 feet.

The 1000000 is because we're using the microsecond timer.

When the value 196850 is divided by the time taken in microseconds it give the answer in feet per second, if the space between the trigger beams is changed then the value changes to still give the FPS.

Does that help?

Anonymous said...

So that solved the case. Thank you very much!

Gadjet said...

Glad to hear it. By the way which sketch are you using?

Anonymous said...

I got help in another forum to change the code . The device runs faster and there is no problem with the detection of the missile. I added some lines of code but the speed of the program has provided Polish forum www.forbot.pl

#include
#include
#include

#define I2C_ADDR 0x27 // <<----- Add your address here. Find it from I2C Scanner
#define BACKLIGHT_PIN 3
#define En_pin 2
#define Rw_pin 1
#define Rs_pin 0
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7

#define firstsensor_1 10
#define secoundsensor_2 11



unsigned long time1;
unsigned long time2;
float fps, elap, ms, joule;



float bullet_weight; //The mass of the projectile (gr)
float bullet_weight_kg;

int counter_shots = 0; //After each shot 1++

LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);

void setup() {
lcd.begin (16,2); // <<----- My LCD 16x2
lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
lcd.setBacklight(HIGH); // Switch on the backlight
Serial.begin(9600);
pinMode (firstsensor_1, INPUT);
pinMode (secoundsensor_2, INPUT);
digitalWrite(firstsensor_1, HIGH);
digitalWrite(secoundsensor_2, HIGH);
reset_variables();
}


void loop() {
lcd_i2c();

Serial.println("I am waiting for a shot - YOU can shoot!");


while(digitalRead(firstsensor_1) == 0);

while(digitalRead(firstsensor_1));
time1 = micros();


while(digitalRead(secoundsensor_2));
time2 = micros();


printserial();

}


void printserial(){
Serial.print("Shot number:\t");
Serial.println(counter_shots++ );
elap = time2 - time1;
fps = 328083/elap;
Serial.print("FPS\t");
Serial.println(fps );

ms = fps * 0.3048;
Serial.print("MPS\t");
Serial.println(ms );


bullet_weight = 0.51;
bullet_weight_kg = bullet_weight/1000;

joule = pow(2, ms)*bullet_weight_kg/2;
Serial.print("JOULE\t");
Serial.println(joule );
}

void reset_variables() {
time1 = 0;
time2 = 0;
}

opango said...
This comment has been removed by the author.
opango said...
This comment has been removed by the author.
opango said...

hello it's very interesting project, i use Catalex TM1637 7 segment display, can u modified the sketch for the display pliss

i try to make the sensors, the distance of the sensor 0.5 feet, when i modified the sketch using TM1637 display, it says: "error: 'matrix' was not declared in this scope" then what should i do?

thx before

Gadjet said...

Have you loaded the library ?
Have a look here https://github.com/avishorp/TM1637

opango said...

yes, i have loaded TM1637 library,
i just modify for it's display and sensor distance:

#include
#include
#define CLK 2 //can be any digital pin
#define DIO 3 //can be any digital pin
TM1637Display display (CLK, DIO); //set up the 4-Digit Display.

#define Trip_in_1 2 //set light Trigger 1 to pin D2
#define Trip_in_2 3 //set light Trigger 2 to pin D3
#define WAIT_STATE 0
#define MONITOR_STATE 1
#define OUTPUT_STATE 2

unsigned long Trigger_1 = 0;
unsigned long Trigger_2 = 0;
volatile unsigned int current_state = WAIT_STATE;
char my_oldSREG; //to hold status register while ints are disabled
unsigned long SensDist = 500000; //Distance between sensors in feet *1000000 0.5 feet
unsigned long duration = 0; // time between triger 1 and 2
volatile boolean is_timeout = false;

.
.
.
.
.

the sensors is not connected yet and i try to verify,
but still unverified:

exit status 1
'matrix' was not declared in this scope

i just wonder where the name 'matrix' came from, is it from Adafruit_7segment matrix = Adafruit_7segment(); properties? if yes, sure there is no connection for TM1637, so the sketch must be change but i don't know how.. i'm newbie and need help



opango said...
This comment has been removed by the author.
opango said...

sorry, missing fonts for

wire.h
TM1637Display.h

Gadjet said...

Looking at the code you posted you are defining the display control pins to the same pins you are using for monitoring the sensors, 2 ad 3.

You need to use different pins for the display
#define CLK 2 //can be any digital pin >>USE ANOTHER PIN
#define DIO 3 //can be any digital pin >>USE ANOTHER PIN

TM1637Display display (CLK, DIO); //set up the 4-Digit Display.

I'm not familiar with the display so I will have to have a look but I cannot do it straight away.

opango said...


finally i could upload the sketch for TM1637! but..
one thing that made me crazy because my display won't power up, several hours thinkin about it huh.. then i check continuity one by one all the cable jumper and found one of the cable jumper is bad, broke in the middle, that's it, after changing the jumper my display finally show up.

i don't have op550 ir sensor, it's difficult to find here in indonesia, so for testing it work or not, i use 2 IR avoidance sensor modules, connect the output to pin 4 & 5. i put that modules on breadboard just 1 inch distance between sensors only just for testing, open air sensors, set the modules potensio just before led indicator lights on then i move my finger +- 1 inch upon sensors as quick as possible for several times. it's works, sensors led indicator blink, and the display shows values. i try to shot with air rifle upon sensors but unfortunately sensors wont detect the pellet, maybe pellet is too small or too fast..

Then i bought IR led and universal IR receivers usually for tv/dvd remote control, set them on breadboard, but shows continuity random values..

may be tomorrow i'll try another type IR sensor


*/
#include Wire.h
#include TM1637Display.h
#define CLK 2 //can be any digital pin
#define DIO 3 //can be any digital pin
TM1637Display display (CLK, DIO); //set up the 4-Digit Display.

#define Trip_in_1 4 //set light Trigger 1 to pin D4
#define Trip_in_2 5 //set light Trigger 2 to pin D5
#define WAIT_STATE 0
#define MONITOR_STATE 1
#define OUTPUT_STATE 2

unsigned long Trigger_1 = 0;
unsigned long Trigger_2 = 0;
volatile unsigned int current_state = WAIT_STATE;
char my_oldSREG; //to hold status register while ints are disabled
unsigned long SensDist = 500000; //Distance between sensors in feet *1000000 0.5 feet
unsigned long duration = 0; // time between triger 1 and 2
volatile boolean is_timeout = false;


void setup () {
//Serial.begin(57600);
Serial.begin(9600); // use for unmodified BT module
display.setBrightness(0x0f); //Setup 7 Seg Display
pinMode(Trip_in_1, INPUT);
pinMode(Trip_in_2, INPUT);
digitalWrite(Trip_in_1, HIGH); //turn on pullup resistor
digitalWrite(Trip_in_2, HIGH);
display.showNumberDec(8888);
reset_variables();
}


void loop () {

switch (current_state) {
case WAIT_STATE:
if (digitalRead(Trip_in_1) == LOW) {
Trigger_1 = micros();
current_state = MONITOR_STATE;
// Timer1.setPeriod(my_timeout);
}
break;
case MONITOR_STATE:
while (digitalRead(Trip_in_2) == HIGH); //loop until the Trigger goes LOW && !is_timeout
if (!is_timeout)
Trigger_2 = micros();
current_state = OUTPUT_STATE;
break;
case OUTPUT_STATE:
//if (Trip2 > Trip1) {
output_serial_info();
reset_variables();
current_state = WAIT_STATE;
//}
break;
}
}

void output_serial_info() {


// Serial.print("Duration\t");
Serial.println((Trigger_2 - Trigger_1));
//Serial.println(" uS");
display.showNumberDec(500000 / (Trigger_2 - Trigger_1));

}

void reset_variables() {
Trigger_1 = 0;
Trigger_2 = 0;
is_timeout = false;
//Timer1.stop();
}

Gadjet said...

Good to know you got it working, I hate it when something like that happens when you spend a long time trying to find it.

The reason I use the IR detectors is they are very fast and have a digital output.

Gary lim said...

Hi gadjet!! Nice work... i have some few request.. can you sketch this.. display for fps and then rate of fire using single button.. i know nothing about programming.. i just tinker with electronics... thank you!

Gadjet said...

Thanks, I suppose it's possible to add a button to switch between FPS and rate of fire. I'll have a look at it but I may not be quick at doing it!

Gary lim said...

Thanks Gadjet!

Unknown said...

Hi Gadjet,

I have a Arduino Nano with a TM1637 with the following commands.

/*

*/

#include
#include "TM1637Display.h"
#define CLK 2 //can be any digital pin D2
#define DIO 3 //can be any digital pin D3
TM1637Display display (CLK, DIO); //set up the 4-Digit Display.

#define Trip_in_1 4 //set light Trigger 1 to pin D4
#define Trip_in_2 5 //set light Trigger 2 to pin D5
#define WAIT_STATE 0
#define MONITOR_STATE 1
#define OUTPUT_STATE 2

unsigned long Trigger_1 = 0;
unsigned long Trigger_2 = 0;
volatile unsigned int current_state = WAIT_STATE;
char my_oldSREG; //to hold status register while ints are disabled
unsigned long SensDist = 196850; //Distance between sensors in feet *1000000 60mm
unsigned long duration = 0; // time between triger 1 and 2
volatile boolean is_timeout = false;


void setup () {
//Serial.begin(57600);
Serial.begin(9600); // use for unmodified BT module
display.setBrightness(0x0f); //Setup 7 Seg Display
pinMode(Trip_in_1, INPUT);
pinMode(Trip_in_2, INPUT);
digitalWrite(Trip_in_1, HIGH); //turn on pullup resistor
digitalWrite(Trip_in_2, HIGH);
display.showNumberDec(8888);
reset_variables();

}


void loop () {


switch (current_state) {
case WAIT_STATE:
if(digitalRead(Trip_in_1)==LOW) {
Trigger_1 = micros();
current_state = MONITOR_STATE;
// Timer1.setPeriod(my_timeout);
}
break;
case MONITOR_STATE:
while(digitalRead(Trip_in_2)==HIGH); //loop until the Trigger goes LOW && !is_timeout
if(!is_timeout)
Trigger_2 = micros();
current_state = OUTPUT_STATE;
break;
case OUTPUT_STATE:
//if (Trip2 > Trip1) {
output_serial_info();
reset_variables();
current_state = WAIT_STATE;
//}
break;
}
}

void output_serial_info() {


// Serial.print("Duration\t");
Serial.println((Trigger_2 - Trigger_1));
//Serial.println(" uS");
display.showNumberDec(199475 / (Trigger_2 - Trigger_1));
}

void reset_variables() {
Trigger_1 = 0;
Trigger_2 = 0;
is_timeout = false;
//Timer1.stop();
}

But I can't write it to my Arduino Nano. Can you help me what I do wrong.

Gadjet said...

I need a bit more info than that to try and help, are you getting an error from the IDE when you try to program?

Unknown said...

I have the same parts as you got. Only I have a TM1637 instead of the adafruit.
When I want to upload/verify it to my arduino nano by the arduino web editor.
I got a error ( a red bar) but there is no text on it what is wrong and I can't upload it.
Also have I import the tm1637display.h in the sketch.

Gadjet said...

Rob,
I haven't come across a "red bar" before, do other sketches load OK, have you selected the serial port and the correct arduino board etc.?

Unknown said...

I just try the Arduino 1.8.1 and it is a compile error.
Do you use another software?

Unknown said...

Yes I tried youre sketch. And thay was not a problem.

Gadjet said...

OK, You have an include statement at the top of your code that does nothing, remove that.

I downloaded the TM1637Display library and included it and the sketch compiled fine in Arduino 1.8.0, did you install the lbrary correctly?

Here's the code that works for me:

#include "TM1637Display.h"
#define CLK 2 //can be any digital pin D2
#define DIO 3 //can be any digital pin D3
TM1637Display display (CLK, DIO); //set up the 4-Digit Display.

#define Trip_in_1 4 //set light Trigger 1 to pin D4
#define Trip_in_2 5 //set light Trigger 2 to pin D5
#define WAIT_STATE 0
#define MONITOR_STATE 1
#define OUTPUT_STATE 2

unsigned long Trigger_1 = 0;
unsigned long Trigger_2 = 0;
volatile unsigned int current_state = WAIT_STATE;
char my_oldSREG; //to hold status register while ints are disabled
unsigned long SensDist = 196850; //Distance between sensors in feet *1000000 60mm
unsigned long duration = 0; // time between triger 1 and 2
volatile boolean is_timeout = false;


void setup () {
//Serial.begin(57600);
Serial.begin(9600); // use for unmodified BT module
display.setBrightness(0x0f); //Setup 7 Seg Display
pinMode(Trip_in_1, INPUT);
pinMode(Trip_in_2, INPUT);
digitalWrite(Trip_in_1, HIGH); //turn on pullup resistor
digitalWrite(Trip_in_2, HIGH);
display.showNumberDec(8888);
reset_variables();

}


void loop () {


switch (current_state) {
case WAIT_STATE:
if(digitalRead(Trip_in_1)==LOW) {
Trigger_1 = micros();
current_state = MONITOR_STATE;
// Timer1.setPeriod(my_timeout);
}
break;
case MONITOR_STATE:
while(digitalRead(Trip_in_2)==HIGH); //loop until the Trigger goes LOW && !is_timeout
if(!is_timeout)
Trigger_2 = micros();
current_state = OUTPUT_STATE;
break;
case OUTPUT_STATE:
//if (Trip2 > Trip1) {
output_serial_info();
reset_variables();
current_state = WAIT_STATE;
//}
break;
}
}

void output_serial_info() {


// Serial.print("Duration\t");
Serial.println((Trigger_2 - Trigger_1));
//Serial.println(" uS");
display.showNumberDec(199475 / (Trigger_2 - Trigger_1));
}

void reset_variables() {
Trigger_1 = 0;
Trigger_2 = 0;
is_timeout = false;
//Timer1.stop();
}

Unknown said...

Hi Gadjet,
Thank you very much.

The first time I was getting the same problems. I have uninstall al the software.
And I try it again. now it works with my sketch and the sketch of you. The problem was a hard- and software problem of my pc.

But now it is working. Thanks.

Gadjet said...

Great news.

Anonimoqlo said...

where can I found the sketch?

gab said...

Hello Phil,
I have all my product and now i can upload sketch.
but with my arduino nano and 7 segment screen.

The sketch on two post upper this one, don't work (compilation / build problem with nano board).

could you me the good sketch please ?
Also, this sketch ca work too with bluetooth module ?

regards

Gadjet said...

Gab,
Have you downloaded and installed the library for the display?

What is the compiler error?

Unknown said...

hi gadjet, i need sketch that works with TM1637 display, would you give a link for me. thank you

Gadjet said...

bayu,
There are several sketches in the comments above, try one of those :-)

Unknown said...

hi gadjet, there an error while compiling your sketch above, exit status 1 error compiling for board arduino nano. i use arduino 1.8.5 on win 7. any clue?

Gadjet said...

I've no idea, what is the error?
Did you install the display library?

Unknown said...

Can we use this model?

I printed it in 3D, but the distance between the two led is 30mm

It's not too short the distance of 30mm between the two led?

I see you have 60mm

https://www.thingiverse.com/thing:1633392

Gadjet said...

You could use that model and change the code to use 30mm instead of 60mm or you could use my 3D model here https://www.thingiverse.com/thing:2784926 with a piece of aluminium tube or even print a tube maybe?.

Unknown said...

I want to make a simple system connected to the pc by jack,
and use the software provided on this forum.

http://www.france-airsoft.fr/forum/index.php?showtopic=111787

rather than making a tube with 10cm spacing led,
I would like to use your support, in the software "Kronyview" on the forum
we can adjust the distance between the led,

but I wanted to be sure that the result remains accurate on this short distance

my system is composed of 4 LEDs (2ir and 2PT) powered by 2 battery and a jack connected to the pc.

The cost is cheaper than getting into $ 40 worth of material, which would be like taking a new chronograph on aliexpress (xcortech ...)

Gadjet said...

I agree your solution is very simple and looks to work well but I required a link to a smartphone app or a PC program therefore I use an Arduino £2 from China and the IR LED receivers have a digital output reducing the requirement for electronics to condition the analog signal.

Not sure what you mean by
"I would like to use your support, in the software "Kronyview" on the forum"

How can I help? is it your software? do you have the source code?

Unknown said...

No, the software does not belong to me.
I just wanted to know if the distance of 30mm is able to be read by the microphone jack of the pc.

The software is available here : http://www.progvision.com/kronyview/Kronyview.zip

but does not belong to me.

Gadjet said...

From what I can see there is a setting at the top right of the SW to change the distance and it can be adjusted to 0.030m.

Unknown said...

Yes I saw, but the computer is able to calculate a small distance?
+ it's long better know?
or + it's short better know ?

I will try this,

it will do the trick while the arduino card arrives from China.


And congratulations for your tutorial & Blog;)

Gadjet said...

Thanks.

I would think the PC would be quick enough but it may be a problem if there is an input filter on the audio input, can you ask the question on the forum? I would think it would be ok if the software let's you select it, maybe you could work it out to equate it to a frequency and see if it's below 20khz?

Unknown said...

I do not know if you have to look at the software, but at the top, you can set the filter too;) the software is very complete.

For the rest I will see on the forum, but its date of 2009 ...

Do you have Facebook ? as his later I can discuss with you if I have a problem with the Arduino system.

Unknown said...

I order led, can you tell me if it is compatible with your Arduino system? :

2X https://www.gotronic.fr/art-diode-emettrice-sfh4554-24269.htm

2X https://www.gotronic.fr/art-phototransistor-ire5-2314.htm

(10X) https://www.gotronic.fr/art-10-resistances-1-4w-15-8486-15.htm

Gadjet said...

I have lots of questions about the IR receivers, mostly people cannot get the ones I used.
I suppose any IR sensitive photo transistor would be OK but you would need to interface it to the Arduino, I used the OPL550 because they have a digital output that connects directly to a digital input to the Arduino and they have a very fast response time, if you use a photodiode make sure it has a good response time and you can interface it to the arduino, it shouldn't be too difficult.

For the series resistors on the emitters I used 150 ohms not 15 ohms.

If you want to post your email address disguised I will send you an email and also delete the post straight away.

wawan said...

Can I get the .fzz or .ini file?

Link in article broken, thankyou

Gadjet said...

HI,
I've updated the links, try now, let me know if they don't work.

wawan said...
This comment has been removed by the author.
wawan said...

Thankyou very much, the files is succeed to download.

any substitude for OPL550? (or you've tried other type)
because i can't find here

Gadjet said...

wawan,
Check out this post for the parts details

https://gadjetsblog.blogspot.co.uk/2013/07/diy-chrono-shopping-list.html

It is possible to use standard IR photodiodes but they don't have a digital output so you would have to use some electronics to condition the output for the processor input and check the response times are fast enough.

This is a common question and it may help you to read through the comments from others.

Anonymous said...

Hello I need the sketch for the "7 segment display can you help me maybe in m / s

Dave said...

Excellent blog Gadjet! I've been reading with great interest.

I've tried to recreate a rather crude prototype using the same IR leds and photo-transistors from RS. I have the LED & sensor 20mm apart (not the distance between both sensors) mounted on two L shaped aluminum brackets - where I've drilled 3mm holes for the leds/sensors. Note: I have managed to get maximum of 30mm apart.

My code reads the sensor every 50ms within the main loop. However, I get random results. It records the presence of a finger covering the sensor, but it doesn't always return to it's default state - just fluctuates between on and off.

Here's the code:

const int sensor1 = 2;

void setup () {
Serial.begin(57600);
Serial.print("Starting...");

pinMode(sensor1, INPUT);
digitalWrite(sensor1, HIGH);
}


void loop () {
Serial.print(digitalRead(sensor1));
delay(50);
}

Can you shed any light (sorry for the pun) on why the random results please?

Dave

Gadjet said...

Dave,
Thanks for the feedback, there are a few things to take note of.
- Your code only looks at one sensor? you would need to have two triggers, one to start the timer and one to stop the timer.
- The code I wrote was designed to scan the first input without any delays, maybe uSeconds, then when triggered it then monitors the second trigger and when it's triggers it captures the time between triggers
- If you've got the sensor outside of a tube then they may be susceptible to ambient light and may get false triggers but it's more likely to be your code, there shouldn't be any delays.

Dave said...

Thanks for your quick response.
I only have one sensor coded to prove out that the alignment is ok, so was expecting the results to be consistent before moving to two sensors, hence the forced delay between reads.

I will try and test covered up or in the dark to see if that changes the results.

Thanks

Dave said...

Just tried again now it's dark, and I get consistent results. So must have been too much ambient light when testing before. I think your idea of using a tube is next on my list :)

Gadjet said...

Good to hear you got it working as you expected, the tube with quite thick walls is crucial to the success of the design as it helps to align the emitter and detector an also, with the detector mounted at the bottom of a small tunnel it excludes external light other than the emitter. As shown in one of the images in this post https://gadjetsblog.blogspot.com/2013/07/diy-chrono-shopping-list.html

Dave said...

Using a tube seems to work better. Thanks ��
Do you know what the minimum distance could be between sensors?
I know you've done both 60mm and 100mm, was there much of a difference in results?

Gadjet said...

The distance between the first and second sensor is just a difference in measured uSeconds, the longer distance the more resolution but I suppose the pellet loses more speed over the longer distance. In the end I don't think it matters too much between the two distances, I never made any direct comparisons.

Anonymous said...

Gadjet,
Thankyou for posting this project. I'm onto building one.

I will be using OPL550A, - does it need a current Limiting Resistor??

It will be powered from a 3.7V to 5V DC-DC booster converter
(which has Input = 3.7V DC, and, OutPut = 5V DC, 500 milliAmps)

Thanks

Gadjet said...

Hi, the opl550a will work fine at 5v I think the max supply is 5.5v

Anonymous said...

Thanks Gadjet.
Yes, OPL550A has a max supply of 5.5V
Actually I was more worried about the Current, because output of the converter is 500illiamps, where as OPL550A datasheet shows max current input of 15mamps.
so, is this something to worry about?
Thanks.
Raj.

Gadjet said...

No, it doesn't work like that, the powere source has a capacity to supply current and the power sink (OPL550A) will consume some of that current (15mA), the supply doesn't force more current throught the OPL550A than it needs as long as the voltage is kept within it's supply range, the OPL550A draws the current from the supply.

The IR emitter LEDs on the other had will probaly need a series resistor to limit the current because they work at 1.8V not 5V, I think I used 180R resistors in series.

Anonymous said...

Gadjet,
Thx-a-ton
It is now Crystal Clear! Thoroughly understood!!
Thx.
Raj.

 Time for another post. A while ago I bought a new Oscilloscope, a RIGOL DHO914, but this scope doesn't have WiFi built in just a LAN co...

Popular Posts