IR detector


Closed Thread
Results 1 to 29 of 29

Thread: IR detector

  1. #1
    Join Date
    Aug 2006
    Posts
    91

    Default IR detector

    Hi all I'm really new to picbasic and to electronics in general.
    So please don't be too harsh on me.

    I bought this
    http://www.radioshack.com/product/in...entPage=search

    Here is the back of the package should give more info


    What I want to do is basically start a timer when the beam is broken and count every time the beam is broken till its broken 100 times then report back the time.

    Lets start with the basics.

    So far I have 9V in to a 510 Ohm resistor to the IR led then to ground.
    Across from that I have 9V to 10K resistor to the collector side and emitter side to ground.
    (connecting a led in series I have been able to get the led to light when the beam is broken
    What I'm not sure how to do is get a signal off the detector to a 16F628A input so when the beam is broken I can detect it.

    Anyone offer any assistance?

  2. #2
    Join Date
    Sep 2004
    Location
    Mentor, Ohio
    Posts
    352


    Did you find this post helpful? Yes | No

    Smile

    Hello Geckogrotto,

    Well you're almost there. First you will need to get a 5 volt regulator to drop your 9 volts down to 5 volts for the PIC. Then connect the 10K resistor between 5 volts and the collector of the phototransistor. You can then connect the junction of the 10K resistor and the collector to the input of your PIC. Your program should "see" a low (ground) condition when the "beam" is being detected and a high (5volts) when the beam is broken.

    Hope this helps you!

    BobK

  3. #3
    Join Date
    Aug 2006
    Posts
    91


    Did you find this post helpful? Yes | No

    Default

    Thanks for the help Bob. Like I said im really new to electronics even but is there a way to use resistors instead of a voltage regulator?

  4. #4
    Join Date
    Aug 2006
    Posts
    91


    Did you find this post helpful? Yes | No

    Default

    WOOT Thanks again Bob I dropped the voltage down to like 4.5V using 3AA batteries instead of a 9V, reduced the resistor on the LED and connected like you said... It works perfect! thanks I would like to know if there is a way with resistors to do the same thing and use a 9v if possible.

  5. #5
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    You could use a 5.1v zenner diode to reduce the 9v down to 5v, but a small 5v regulator should be a better bet.

  6. #6
    Join Date
    Aug 2006
    Posts
    91


    Did you find this post helpful? Yes | No

    Default

    I guess this is where I get confused with electronics.
    I can take a 9V battery and use a resistor to run a 1.5V led without problem but I can't use a resistor the same way to run a 5V chip.

    This seems to make sense to everyone but me lol

    Ok on to the coding would this chip be able to handle the timer part of this or would I need a dedicated timer chip?

    My guess is that there will be about 100 breaks in the beam in a 30 second time.

    Currently I'm testing with this code and a led on RB1.
    Main:
    if PORTB.0 = 1 then
    high PORTB.1
    else
    low PORTB.1
    endif


    Now that looks like it will work fine but, if the loop happens more than once before the bean is brought back it could count 10 times for every break...

    Would this code work and only count once?

    broken var byte
    broken = 0
    Main:
    if PORTB.0 = 1 and broken = 0 then
    broken = 1
    high PORTB.1
    else
    low PORTB.1
    endif
    if PORTB.0 = 0 and broken = 1 then broken = 0

    goto Main
    Last edited by geckogrotto; - 16th August 2006 at 18:32.

  7. #7


    Did you find this post helpful? Yes | No

    Default

    Hi geckogrotto. Try something like this.
    START:
    LET BROKEN = 0
    LOW PORTB.1

    Main:
    IF PORTB.0 = 1 then ACTIVATE 'BEAM BROKEN
    GOTO MAIN 'BEAM NOT BROKEN

    ACTIVATE:
    IF PORTB.0 = 1 THEN ACTIVATE 'WAIT FOR BEAM TO RETURN
    LET BROKEN = BROKEN + 1
    IF BROKEN >= 10 THEN LIGHTUP 'BEAM NEEDS TO BE BROKEN 10 TIMES
    GOTO MAIN

    LIGHTUP:
    HIGH PORTB.1
    GOTO LIGHTUP

  8. #8
    Join Date
    Aug 2006
    Posts
    91


    Did you find this post helpful? Yes | No

    Default

    Thanks for your suggestion.

    Can anyone tell me how to turn on a timer then turn it off and get the amount of time that was timed?

  9. #9
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default Voltage divider

    Hi, yes you can reduce the voltage to any set level you choose.
    Using Ohm's Law
    V. out = V in X (r2 / r1 + r2)

    where r1 is the resistor closest to the power in
    and r2 is the resistor closest to ground

    Example v out = v in or 10 volts X r2, say 500 ohms . . . 5000
    divided by r2 + r1, so if r1= 500 ohms you would get 1000 ohms,
    so 5000 / 1000 = 5 volts. Simple huh? The problem here is if you lose the ground
    foe even an instant then your input sees full supply voltage, also a voltage divider uses power all the time, in this example .01 amp.
    OK the attachment didn't work so basicly two resistors in series, one end attached to + and the otherend to minus and you pull power from the connection in the center.
    Last edited by Archangel; - 16th August 2006 at 20:21. Reason: TRy to add BMP of schematic

  10. #10
    Join Date
    Aug 2006
    Posts
    91


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Joe S.
    Hi, yes you can reduce the voltage to any set level you choose.
    Using Ohm's Law
    V. out = V in X (r2 / r1 + r2)

    where r1 is the resistor closest to the power in
    and r2 is the resistor closest to ground

    Example v out = v in or 10 volts X r2, say 500 ohms . . . 5000
    divided by r2 + r1, so if r1= 500 ohms you would get 1000 ohms,
    so 5000 / 1000 = 5 volts. Simple huh? The problem here is if you lose the ground
    foe even an instant then your input sees full supply voltage, also a voltage divider uses power all the time, in this example .01 amp.
    OK the attachment didn't work so basicly two resistors in series, one end attached to + and the otherend to minus and you pull power from the connection in the center.
    Ok I don't think these actually exist but lets say they do.

    If I had exactly 9V in and used
    R2 950
    R1 760
    That would give me exactly 5V out?

    About the connection what your saying is resistor to + and the other resistor connected to that and then to the negative and sandwiched in between the 2 would be my output of 5v?

    Also if you want shoot me over the attachment to [email protected]

    Thanks

  11. #11
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default Yes

    That is correct as would 400/500 (notice it adds up to 900) or any variant of above say 1200 /1500 12k/15k what changes as you go upscale is the circuit impeadance (the ability to load the circuit without significant loss of voltage).
    If you only want to drive a PIC input pin and not light leds or run motors then use the larger (higher resistance) resistors, that way if you mess up your code and cause an input to become an output, set to low, you will not create a big short.

  12. #12
    Join Date
    Aug 2006
    Posts
    91


    Did you find this post helpful? Yes | No

    Default

    Thanks again Joe.

    Now I just need the most basic code I can find to start / stop the timer and get the results and I will be able to finish the rest.

    I searched around the forums but I'm not sure how to implement the code with my chip.

    There are internal timers right that you can turn on or off or am I thinking this whole thing wrong and I need to figure out how fast the chip is running then make my own count loop?

  13. #13
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    one way in my mind now... Use HPWM on your led emitter, place the IR receiver on RA.4/T0CKI. Use Timer0 to count, Timer1 or Pause to do your sample time. The read the TMR0 register.

    Another wich i don't really like but i saw many times... Led emitter directly to Battery via resistor, IR detector to RA.4/T0CKI. Jump in a interupt routine on a TMR0 overflow. Easy neat... may kill the IR Led soon.. battery too.

    Do a search for T0CKI, you should find some tips to begin.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  14. #14
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Smile

    Here is a table again to select a resistor value with respect to current (mA) vs input volt.
    Make the rounding as close as possible.



    --------
    Code:
    I(mA)	R (ohm)	R (ohm)
    	9V	12V
    
    1	9000	12000
    2	4500	6000
    3	3000	4000
    4	2250	3000
    5	1800	2400
    6	1500	2000
    7	1286	1714
    8	1125	1500
    9	1000	1333
    10	900	1200
    11	818	1091
    12	750	1000
    13	692	923
    14	643	857
    15	600	800
    16	563	750
    17	529	706
    18	500	667
    19	474	632
    20	450	600
    21	429	571
    22	409	545
    23	391	522
    24	375	500
    25	360	480
    26	346	462
    27	333	444
    28	321	429
    29	310	414
    30	300	400
    31	290	387
    32	281	375
    33	273	364
    34	265	353
    35	257	343
    36	250	333
    37	243	324
    38	237	316
    39	231	308
    40	225	300
    41	220	293
    42	214	286
    43	209	279
    44	205	273
    45	200	267
    46	196	261
    47	191	255
    48	188	250
    49	184	245
    50	180	240
    51	176	235
    52	173	231
    53	170	226
    54	167	222
    55	164	218
    56	161	214
    57	158	211
    58	155	207
    59	153	203
    60	150	200
    61	148	197
    62	145	194
    63	143	190
    64	141	188
    65	138	185
    66	136	182
    67	134	179
    68	132	176
    69	130	174
    70	129	171
    71	127	169
    72	125	167
    73	123	164
    74	122	162
    75	120	160
    76	118	158
    77	117	156
    78	115	154
    79	114	152
    80	113	150
    81	111	148
    82	110	146
    83	108	145
    84	107	143
    85	106	141
    86	105	140
    87	103	138
    88	102	136
    89	101	135
    90	100	133
    91	99	132
    92	98	130
    93	97	129
    94	96	128
    95	95	126
    96	94	125
    97	93	124
    98	92	122
    99	91	121
    100	90	120
    101	89	119
    102	88	118
    103	87	117
    104	87	115
    105	86	114
    106	85	113
    107	84	112
    108	83	111
    109	83	110
    110	82	109
    111	81	108
    112	80	107
    113	80	106
    114	79	105
    115	78	104
    116	78	103
    117	77	103
    118	76	102
    119	76	101
    120	75	100
    121	74	99
    122	74	98
    123	73	98
    124	73	97
    125	72	96
    126	71	95
    127	71	94
    128	70	94
    129	70	93
    130	69	92
    131	69	92
    132	68	91
    133	68	90
    134	67	90
    135	67	89
    136	66	88
    137	66	88
    138	65	87
    139	65	86
    140	64	86
    141	64	85
    142	63	85
    143	63	84
    144	63	83
    145	62	83
    146	62	82
    147	61	82
    148	61	81
    149	60	81
    150	60	80
    
    
    Sayzer August'06
    Selecting resistor value with respect to 
    Current vs input Volt
    Attached Files Attached Files
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  15. #15
    Join Date
    Aug 2006
    Posts
    91


    Did you find this post helpful? Yes | No

    Default

    After some searching I found this
    http://www.picbasic.co.uk/forum/showthread.php?t=190

    after making some changes I think I will be able to use this to do what im needing.

  16. #16
    Join Date
    Aug 2006
    Posts
    91


    Did you find this post helpful? Yes | No

    Default LCD Screen

    Due to all the help I have gotten here I have everything worked out. I decided to buy a lcd screen so I could output the results to it but I have no idea how to hook it up.

    LCD Display 16 characters with 2 rows LCD its Hitachi HD44780 compatible LSI controller

    It has 16 pins.
    1 GND Ground
    2 +5v Power
    3 Vcont Contrast voltage
    4 RS Select
    5 R/W Read/Write
    6 EN Enable
    7 DB0 Data bus
    8-14 .......
    15 LED K Backlight cathode
    16 LED A Backlight anode

    Ok 1 and 2 are pretty simple
    Im not sure what pins I would hook up to my 16F628A chip. just data bus?
    going to do some searching around to see what I can find was just so excited had to post Any help would be appreciated.

  17. #17
    Join Date
    Aug 2006
    Posts
    91


    Did you find this post helpful? Yes | No

    Default

    Ok looks like mine is almost exactly like the olympic timer
    http://www.picbasic.co.uk/forum/atta...4&d=1091819883

    So it looks like 7-10 should be data..?

    Man I still have so much to learn

  18. #18
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    I decided to buy a lcd screen so I could output the results to it but I have no idea how to hook it up.
    Free schematic in PBP manual in the LCDOUT section.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  19. #19
    Join Date
    Aug 2006
    Posts
    91


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mister_e
    Free schematic in PBP manual in the LCDOUT section.

    Thanks lol
    Good old fashion case of RTFM!

    I have one questions about it tho, pin 3 on the lcd connects to the middle of the 20K resistor? I don't understand that part.

    also I don't have a 20K resistor should I use 18K , 22K , 18K and 2K in series, or wait till I can get a 20K?

    Thanks

  20. #20
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    It's a 20K potentiometer or trimmer. It's there to adjust the LCD contrast. You can use lower value. 1-10K still work. You can also use two resistor to make a fix contrast. Wich value... ARRRGGH close to be impossible to tell, no lcd work the same way.

    You can still use HPWM to make a software controlled LCD contrast... for now, just plug-it and display on it.
    http://www.picbasic.co.uk/forum/show...light=contrast
    Last edited by mister_e; - 20th August 2006 at 22:15.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  21. #21
    Join Date
    Aug 2006
    Posts
    91


    Did you find this post helpful? Yes | No

    Default

    Got it thanks
    Last edited by geckogrotto; - 21st August 2006 at 02:50.

  22. #22
    Join Date
    Aug 2006
    Posts
    91


    Did you find this post helpful? Yes | No

    Default

    Ok last question

    I have read all over about floating points and I still can't figure out how to do this.

    My calculation is

    shotspersecond = count / seconds
    shotsperminute = shotspersecond * 60

    with floating points this would work fine and tell me shots per minute avg.

    Without FP if the seconds > count then I get 0 as shotspersecond and a number of other problems.

    I know this can't be too hard but I can't seem to wrap my brain around it.


    Any help would be very appriciated as once I get this I should be able to finish off my project.

    Any help would be very appriciated as once I get this I should be able to finish off my project.

    This is what I have so far... It may be accurate enough for what I am doing.
    SPS = 5 / TotalTime
    if sps = 0 then
    SPS = 5 // TotalTime
    SPM = sps * 60 / 100
    else
    SPM = SPS * 60
    endif

    Better way to do it?
    Last edited by geckogrotto; - 21st August 2006 at 20:38.

  23. #23
    Join Date
    May 2006
    Location
    Del Rio, TX, USA
    Posts
    343


    Did you find this post helpful? Yes | No

    Default

    My calculation is

    shotspersecond = count / seconds
    a) Declare your variables as WORDS

    b) Multiply count by something like 100 or 1000. This shifts the decimal place to the right. Pick a multiplier that will keep the result below 65536.

    b) Now, do the divide: shotspersecond = count / seconds.

    c) Display shotspersecond with something like:

    LCDOUT DEC shotspersecond/100, ".",DEC2 shotspersecond//100

    The key is to shift the decimal place prior to the division, then adjust the display to account for the shift.

    For more reading (and a better example of integer math), take a look at These threads from Darrel Taylor:
    Retrieving 32bit Multiply Result
    Retrieving Div32 Remainder
    32-bit Variables and DIV32, Hourmeter 99999.9.

    You might also try a search for integer math.

    HTH,
    Steve

  24. #24
    Join Date
    Aug 2006
    Posts
    91


    Did you find this post helpful? Yes | No

    Default

    Ohhh thanks Steve I was multiplying x 100 after the divide not before thanks I got it now

  25. #25
    Join Date
    Aug 2006
    Posts
    91


    Did you find this post helpful? Yes | No

    Default

    Ok really this time last question. This has more to do with eagle but figured you guys would know.
    I'm trying to find a LCD like the one on page 94 in the manual to use with eagle and I can't seem to find one.

    I downloaded all the LBR files I could find that said LCD on them but still no luck.

  26. #26
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Mat,

    Just select one of the connectors / Pin Headers that suit the number of connections on the LCD. This will allow you to either plug the LCD into your board if you use a suitable pin and header block, or solder wires directly to the pads if the LCD is remote from the board

  27. #27
    Join Date
    Aug 2006
    Posts
    91


    Did you find this post helpful? Yes | No

    Default

    Thanks malc that will work fine.
    For anyone who was interested or helped with the process and wanted to see the end result here is a video.

    http://www.gecko-grotto.com/workshop/lcd_counter.wmv

  28. #28
    Join Date
    Jan 2006
    Posts
    31


    Did you find this post helpful? Yes | No

    Question Infra Red Detection in PICBAsic

    Hi, i'm building a simple remote controlled project consisting of 8 12v Relays. I'm using TSOP1738 IR receiver from Vishay Telefunken. I'm using PIC16F84A microcontroller and PICBasic Compiler. I got it from a junked VCD player. Is there anyone who knows how to intercept the coded signal from any IR transmitter? How do i control individual relays independently.

  29. #29
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

Similar Threads

  1. Replies: 17
    Last Post: - 12th April 2014, 02:17
  2. PIC10F200 Automated IR Light Switch
    By Bruce in forum Code Examples
    Replies: 7
    Last Post: - 3rd May 2007, 11:40
  3. Replies: 10
    Last Post: - 16th October 2006, 18:23
  4. how to get pic to pic communication
    By kinsiro in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 30th August 2005, 17:12
  5. IR for robot on 16F877A
    By Samuel in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 9th April 2005, 20:57

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts