¡ÒÃ㪠§Ò¹âÁ´ÙÅÇÑ´ÃÐÂзҧ SRF05
l
1
SRF05 Ultrasonic Distance Detector Module
âÁ´ÙÅ µÃǨ¨ÑºáÅÐÇÑ´ÃÐÂзҧ´ ÇÂÍÑŵà Ò⫹ԡ Distributed by Innovative Experiment Co.,Ltd., Thailand
¤Ø³ÊÁºÑµÔ 㪠ä¿àÅÕÂé § +5V µ ͧ¡ÒáÃÐáÊä¿¿ Ò 30mA l 㪠µÇ Ñ ÃѺáÅÐÊ §¤Å×¹è ÍÑŵà Ò⫹ԡ 㪠¤ÇÒÁ¶Õè 40kHz 㹡Ò÷íÒ§Ò¹ l
l ÇÑ´ÃÐÂзҧ㹪 ǧ
1 ૹµÔàÁµÃ¶Ö§ 4 àÁµÃ
l
ÊÑÒ³¾ÑÅÊ ÊÒí ËÃѺ¡Ãеع ¡Ò÷íÒ§Ò¹ µ ͧÁÕ¤ÇÒÁ¡Ç ҧ͠ҧ¹ Í 10 äÁâ¤ÃÇÔ¹Ò·Õ
l
ãË ¼ÅÅѾ¸ ¨Ò¡¡ÒÃÇÑ´ÃÐÂÐà» ¹¤ Ò¤ÇÒÁ¡Ç Ò§¾ÑÅÊ «§Öè à» ¹ÊÑ´Ê Ç¹¡ÑºÃÐÂзҧ·ÕÇè ´Ñ ä´
l ÁÕ¢¹Ò´àÅ硤×Í 43 ÁÁ. x 20 ÁÁ. x 17 ÁÁ. (¡Ç Ò§xÂÒÇxÊÙ§) l Ê×Í è ÊÒáѺäÁâ¤Ã¤Í¹â·ÃÅàÅÍà ÂÍ´¹ÔÂÁä´ ·¡Ø µÃСÙÅ ÍÒ·Ô àºÊÔ¡áʵÁ» 2SX/2P, PIC, MCS-51,
PSoC, 68HC11 l ÊÒÁÒöµÔ´µ Íä´ 2 Ẻ¤×Í áºº 2 ÊÑÒ³ (Echo ¡Ñº Trigger) àËÁ×͹¡Ñº SRF04 áÅÐẺ ͹ءÃÁÊÑÒ³àÊ ¹à´ÕÂÇ l ÊÒÁÒö㪠·´á·¹ SRF04 ä´
ÍØ»¡Ã³ àÊÃÔÁ ºÍà ´ ADX-SRF04 «Ö§è à» ¹ºÍà ´ÍÐá´»àµÍà ÊÒí ËÃѺÍíÒ¹ÇÂÊдǡ㹡Òà àª×Íè Áµ ͡ѺºÍà ´äÁâ¤Ã¤Í¹â·ÃÅàÅÍà áÅÐἧµ Íǧ¨ÃËÃ×ÍàºÃ´ºÍà ´ l
l
ÊÒ PCB3A ÊíÒËÃѺàª×Íè Áµ ͡ѺºÍà ´¤Çº¤ØÁËع ¹µ ¢Í§ i-nex
2
l
¡ÒÃ㪠§Ò¹âÁ´ÙÅÇÑ´ÃÐÂзҧ SRF05
SRF05 à» ¹á¼§Ç§¨ÃÇÑ´µÃǨ¨ÑºáÅÐÇÑ´ÃÐÂзҧ´ ǤÅ×¹è ÍÑŵà Ò⫹ԡ·ÕÁè ¤Õ ÇÒÁà·ÕÂè §µÃ§ÊÙ§ â´ÂÊÒÁÒöÇÑ´ÃÐÂÐä´ µ§Ñé áµ 1 ૹµÔàÁµÃ仨¹¶Ö§ 4 àÁµÃ SRF04 ¶Ù¡Í͡ẺÁÒãË ãª §Ò¹¡ÑºäÁâ¤Ã ¤Í¹â·ÃÅàÅÍÃ ä´ §Ò Ââ´Â㪠¢Òàª×Íè Áµ Íà¾Õ§ 1 ËÃ×Í 2 ¢Ò ¢Ö¹é ÍÂÙ¡ ºÑ ¡ÒáíÒ˹´ÃٻẺ¡Ò÷íÒ§Ò¹·Ò§ ÎÒà ´áÇà àËÁÒÐÍ ҧÂÔ§è ¡Ñº¡ÒûÃÐÂØ¡µ 㪠§Ò¹´ Ò¹Ëع ¹µ SRF05 ¨Ð·íÒ¡ÒÃÊ §ÊÑÒ³¤Å×¹è ÍÑŵà Ò⫹ԡÍÍ¡ä» áÅ ÇÇÑ´ÃÐÂÐàÇÅÒ·ÕÁè ÊÕ Ñ Ò³Êз ͹ µÍº¡ÅѺÁÒ àÍÒµ ¾µØ ·Õäè ´ ¨Ò¡ SRF05 ¨ÐÍÂÙã ¹ÃÙ»¢Í§¤ÇÒÁ¡Ç Ò§¾ÑÅÊ «§Öè ÊÑÁ¾Ñ¹¸ ¡ºÑ ÃÐÂзҧ¢Í§Çѵ¶Ø ·Õµè ÃǨ¨Ñºä´ ¤ÇÒÁ¶ÕÊè Ñ Ò³ÍÑŵà Ò⫹ԡ¢Í§ SRF05 ¤×Í 40kHz ¶Ù¡Ê §ÍÍ¡ä»ã¹ÍÒ¡ÒÈ´ ǤÇÒÁ àÃçÇ 1.125 ¿Øµµ ÍÁÔÅÅÔÇ¹Ô Ò·Õ (»ÃÐÁÒ³ 346 àÁµÃµ ÍÇÔ¹Ò·Õ) ´Ñ§¹Ñ¹é àÁ×Íè ·ÃÒº¤ÇÒÁàÃçÇ㹡ÒÃà¤Å×Íè ¹·Õè ¢Í§¤Å×¹è , àÇÅÒàÃÔÁè µ ¹Ê §¤Å×¹è áÅÐàÇÅÒ·ÕÃè ºÑ àÊÕ§Êз ͹¡ÅѺÁÒ ¨Ö§ÊÒÁÒö¤íҹdzËÒ¤ ҢͧÃÐÂзҧ ä´ ´Ñ§áÊ´§ËÅÑ¡¡ÒõÃǨ¨Ñºã¹ÃÙ»·Õè 1 ÃÐÂзҧ·Õäè ´ ¹¹Ñé ¨Ðµ ͧÁÕ¡Òäíҹdz¤ Ò¡ÅѺ·Ò§¤³ÔµÈÒʵà àÁ×Íè 㪠¡ºÑ äÁâ¤Ã¤Í¹â·ÃÅàÅÍà áŠǶ×ÍÇ Òà» ¹àÃ×Íè §Âا ÂÒ¡¾ÍÊÁ¤Çà ´Ñ§¹Ñ¹é SRF05 ¨Ö§»ÃÐÁÇżŤ Ò·Ò§¤³ÔµÈÒʵà µÒ § æ àËÅ Ò¹Õäé Ç àÃÕºà ÍÂáÅ Ç ¨Ò¡¹Ñ¹é Ê §¼ÅÅѾ¸ ·ÇÕè ´Ñ ä´ ÍÍ¡ÁÒà» ¹¾ÑÅÊ ·ÁÕè ¤Õ ÇÒÁ¡Ç Ò§ÊÑÁ¾Ñ¹¸ ¡ºÑ ÃÐÂзҧ·ÕÇè ´Ñ ä´ ¡ÒÃÊ §¼ÅÅѾ¸ ·ÕèÇÑ´ä´ ÍÍ¡ÁÒà» ¹ã¹àªÔ§¤ÇÒÁ¡Ç Ò§¢Í§ÊÑÒ³¾ÑÅÊ ÍÒ¨¨Ð´ÙÇ ÒÂØ §ÂÒ¡¡Ç Ò ¡ÒÃÊ §à» ¹¢ ÍÁÙÅ´Ô¨µÔ ÍÅÍÍ¡ÁÒ áµ ¡ÒÃÊ §ÍÍ¡ÁÒà» ¹¢ ÍÁÙÅ´Ô¨µÔ ÍÅÍÒ¨µ ͧ㪠ÊÒÂÊÑÒ³¨íҹǹÁÒ¡ «Ö§è ·íÒãË µÍ §ãª ¢Ò¾Íà µã¹¡ÒÃàª×Íè Áµ Íà» ¹¨íҹǹÁÒ¡µÒÁä»´ Ç ´Ñ§¹Ñ¹é ËÒ¡Ê §¼ÅÅѾ¸ ÍÍ¡ÁÒã¹ÃÙ» ¢Í§ÊÑÒ³¾ÑÅÊ ¨Ð㪠ÊÒÂÊÑÒ³à¾Õ§àÊ ¹à´ÕÂÇ ¨Ö§·íÒãË ÊдǡÁҡ㹡ÒùíÒÁÒàª×Íè Áµ ͡ѺäÁâ¤Ã ¤Í¹â·ÃÅàÅÍÃ
µÑÇÃѺ
µÑÇÊ §
ÃÐÂзҧ¨Ò¡Çѵ¶Ø
ÃÙ»·Õè 1 áÊ´§ËÅÑ¡¡ÒõÃǨ¨ÑºÇѵ¶Øâ´Âãª Ê Ñ Ò³¤ÇÒÁ¶Õàè ˹×ÍàÊÕ§ËÃ×ÍÍÑŵà Ò⫹ԡ
¡ÒÃ㪠§Ò¹âÁ´ÙÅÇÑ´ÃÐÂзҧ SRF05 GND MODE
GND
MODE äÁ µ Í : µÔ´µ ÍẺ 2 ÊÑÒ³ µ Íŧ¡ÃÒÇ´ : µÔ´µ ÍẺ 1 ÊÑÒ³
Trigger pulse input Echo pulse output
+5V
l
3
¡ÒáíÒ˹´ MODE ¢Í§ SRF05 à¾×èÍàÅ×Í¡¡ÒõԴµ ÍẺ 1 ÊÑÒ³ 㪠¨Ø´ Trigger pulse input ÊíÒËÃѺ Ê×èÍÊÒáѺäÁâ¤Ã¤Í¹â·ÃÅàÅÍÃ
MODE
Trigger pulse input
+5V
54. #
54. #
äÁ ÁÕ¡Òõ Í㪠§Ò¹·Õè¨Ø´àËÅ Ò¹Õé
äÁ ÁÕ¡Òõ Í㪠§Ò¹·Õè¨Ø´àËÅ Ò¹Õé
ÃÙ»·Õè 2 áÊ´§¢ÒÊÑÒ³¢Í§ SRF05 áÅСÒáíÒ˹´âËÁ´·íÒ§Ò¹
1. ¨Ø´µ Í㪠§Ò¹¢Í§ SRF05
ÁÕ¨´Ø µ ÍÊíÒËÃѺ㪠§Ò¹ÍÂÙ· §Ñé ËÁ´ 5 ¨Ø´µÒÁÃÙ»·Õè 2 1. ¢Òä¿àÅÕÂé § (+5V) ÊíÒËÃѺµ Íä¿àÅÕÂé §áç´Ñ¹ +5V 2. ¢Ò Echo Pulse Output (ECHO) à» ¹¢ÒàÍÒµ ¾µØ ÊíÒËÃÑºÊ §ÊÑÒ³¾ÑÅÊ ÍÍ¡¨Ò¡ SFR05 «Ö§è ¡ÒÃ㪠§Ò¹¨Ð¹íÒ¢Ò¹Õäé »µ ÍࢠҡѺ¾Íà µÍÔ¹¾Øµ¢Í§äÁâ¤Ã¤Í¹â·ÃÅàÅÍà à¾×Íè µÃǨ¨Ñº¤ÇÒÁ ¡Ç Ò§¢Í§ÊÑÒ³¾ÑÅÊ ·ÕèÊ §ÍÍ¡ÁÒà¾×èÍá»Å¤ÇÒÁËÁÒÂÍÍ¡ÁÒà» ¹ÃÐÂзҧÍÕ¡¤ÃÑé§Ë¹Öè§ 3. ¢Ò Trigger Pulse Input (TRIGGER) à» ¹¢ÒÍÔ¹¾ØµÃѺÊÑÒ³¾ÑÅÊ ·ÁÕè ¤Õ ÇÒÁ¡Ç Ò§ Í ҧ¹ Í 10 äÁâ¤ÃÇÔ¹Ò·Õà¾×Íè ¡Ãеع ¡ÒÃÊà ҧ¤Å×¹è ÍÑŵà Ò⫹ԡ¤ÇÒÁ¶Õè 40kHz ÍÍ¡ÊÙÍ Ò¡ÒȨҡµÑÇ Ê § ´Ñ§¹Ñ¹é àÁ×Íè ¤Å×¹è ¤ÇÒÁ¶Õ´è §Ñ ¡Å ÒǹÕàé ¤Å×Íè ¹·Õäè »¡ÃзºÊÔ§è ¡Õ´¢ÇÒ§·ÕÍè ÂÙà º×Íé §Ë¹ Ò¡ç¨Ðà¡Ô´¡ÒÃÊз ͹ ¡ÅѺࢠÒÁÒÂѧµÑÇÃѺ áÅж١á»Å§ÍÍ¡ÁÒà» ¹¤ÇÒÁ¡Ç Ò§¢Í§ÊÑÒ³¾ÑÅÊ ·¨Õè ÐÊ §ÍÍ¡ä»·Ò§¢Ò Echo Pulse Output ¹Í¡¨Ò¡¹Õãé ¹âËÁ´ 1 ÊÑÒ³ ¨Ð㪠¨´Ø ¹Õàé » ¹¨Ø´Ê×Íè ÊÒâ ÍÁÙÅ͹ءÃÁà¾×Íè ÃÑºÊ §¤ Ò¡Òà ÇÑ´¡ÑºäÁâ¤Ã¤Í¹â·ÃÅàÅÍà 4. ¢Ò MODE ÊíÒËÃѺàÅ×Í¡ÃٻẺ¡ÒõԴµ ͡Ѻ SRF05 »Å ÍÂÅÍÂäÇ (NC) : àÅ×Í¡ãË µ´Ô µ ÍẺ 2 ÊÑÒ³ ¼ Ò¹¨Ø´µ Í ECHO áÅÐ TRIGGER µ Íŧ¡ÃÒÇ´ : àÅ×Í¡ãË µ´Ô µ ÍẺ 1 ÊÑÒ³ ¼ Ò¹¨Ø´µ Í TRIGGER 5. ¢Ò GND ÊíÒËÃѺµ Í¡ÃÒÇ´
¡ÒÃ㪠§Ò¹âÁ´ÙÅÇÑ´ÃÐÂзҧ SRF05
front
¤Í¹à¹ç¡àµÍà IDC µÑÇàÁÕÂÊíÒËÃѺµ ͡ѺâÁ´ÙÅ SRF05
-
+
¤Í¹à¹ç ¡ àµÍà IDC µÑ Ç àÁÕ Â Êí Ò ËÃÑ º ÊÒµ Í Ç§¨Ã AWG#22 à¾×Íè 㪠¡ºÑ àºÃ´ºÍà ´
-
K3 I2C BUS
SRF05 adaptor
GND
¤Í¹à¹ç¡àµÍà PULSE (Trigger pulse)
PULSE/SCL ECHO/SDA +5V
SRF-05
¤Í¹à¹ç¡àµÍà ECHO
GND SCL SDA +5V
l
+
4
K1 ECHO/SDA
K2 PULSE/SCL
¹íÒºÍà ´ ADX-SRF04 ÁÒàÊÕºࢠҡѺ SRF05 ADX-SRF04
SRF05
ADX-SRF04
´ Ò¹¤Í¹à¹ç¡àµÍà ÊíÒËÃѺàª×Íè Áµ Í ¹íÒÊÒµ Íǧ¨Ã AWG#22 àÊÕºࢠҷդè ͹à¹ç¡àµÍà à¾×Íè µ Íǧ¨Ã
ECHO
PULSE
¨Ðµ ͧàÅ×Í¡µ ÍẺã´áººË¹Ö§è
¡ÒèѴ¢Ò¤Í¹à¹ç¡àµÍà 3 ¢Ò§Í ¢Í§ºÍà ´àª×èÍÁµ ÍáÅÐἧǧ¨Ã µÃǨ¨Ñº (Áͧ¨Ò¡´ Ò¹º¹) SIGNAL +5V
ºÍà ´¤Çº¤ØÁ¢Í§ i-nex ÍÒ·Ô Stamp-BOX, RBX-877, RBX-51AC2, AX-11 áÅÐ SCi-BOX
ÃÙ»·Õè 3 áÊ´§Ç§¨Ã¢Í§ºÍà ´ ADX-SRF04 áÅСÒÃàª×Íè Áµ ͡ѺâÁ´ÙÅ SRF05
GND
¡ÒÃ㪠§Ò¹âÁ´ÙÅÇÑ´ÃÐÂзҧ SRF05
l
5
2. ºÍà ´ ADX-SRF04
à¾×Íè ÍíҹǤÇÒÁÊдǡᡠ¼ãÙ ª §Ò¹¡ÑººÍà ´¤Çº¤ØÁËع ¹µ ¢Í§ºÃÔÉ·Ñ ÍÔ¹â¹àǵտ àÍç¡à¾ÍÃÔ àÁ¹µ ¨íÒ¡Ñ´ (i-nex : à» ¹µÑÇá·¹¨íÒ˹ ÒÂÊÔ¹¤ Ңͧ Devantech ã¹»ÃÐà·Èä·ÂÍ ҧ໠¹·Ò§¡ÒÃ) ¨Ö§ä´ ¾Ñ²¹ÒºÍà ´ÍÐá´»àµÍÃ Ã¹Ø ADX-SRF04 à¾×Íè ãË ¹Òí âÁ´ÙÅ SRF04 ËÃ×Í SRF05 ÁÒµÔ´µÑ§é (¨Ñ´ÁҾà ÍÁ ¡ÑºÊÒÂàª×Íè Áµ Í㹪ش¢Í§ SRF05) à¾×Íè ãË ãª §Ò¹ä´ Êдǡ¢Ö¹é º¹ºÍà ´ ADX-SRF04 ä´ ¨´Ñ àµÃÕÂÁ¤Í¹à¹ç¡àµÍà PCB 3 ¢ÒµÑǼ٠2 µÑÇᡡѹÃÐËÇ Ò§ÊÑÒ³ ECHO áÅÐ TRIGGER ÊíÒËÃѺàª×Íè Áµ ͡ѺºÍà ´¤Çº¤ØÁËع ¹µ áÅФ͹à¹ç¡àµÍà IDC µÑÇàÁÕÂá¶Ç à´ÕÂè Ç 4 ¢ÒÊíÒËÃѺàÊÕºÊÒµ Íǧ¨ÃàºÍà AWG#22 à¾×Íè µ ͡Ѻἧµ Íǧ¨ÃËÃ×ÍàºÃ´ºÍà ´ â´Âǧ¨Ã ¢Í§ºÍà ´ ADX-SRF04 áÅСÒõԴµÑ§é à¾×Íè 㪠§Ò¹áÊ´§ã¹ÃÙ»·Õè 3
3. ¡ÒÃ㪠§Ò¹¡ÑºäÁâ¤Ã¤Í¹â·ÃÅàÅÍà 3.1 ¿ §¡ ª¹Ñè â»Ãá¡ÃÁÀÒÉÒ C ÊíÒËÃѺµÔ´µ ÍÃÐËÇ Ò§ P89V51RD2 ¡ÑºâÁ´ÙÅ SRF05 ã¹âËÁ´¡ÒõԴµ ÍẺ 2 ÊÑÒ³ 㹡ÒÃà¢Õ¹â»Ãá¡ÃÁÀÒÉÒ C ÊíÒËÃѺäÁâ¤Ã¤Í¹â·ÃÅàÅÍà P89V51RD2 à¾×Íè 㪠§Ò¹âÁ´ÙÅ SRF05 ÊÔ§è ·Õ¤è Ç÷íÒ¤×Í Êà ҧ¿ §¡ ª¹Ñè 㹡ÒõԴµ Íà¾×Íè Í Ò¹¤ ÒáÅлÃÐÁÇżŠµÑÇÍ ҧ·Õ¹è Òí ÁÒàʹÍã¹ º·¹Õ¤é Í× ¿ §¡ ª¹Ñè distance ¿ §¡ ª¹Ñè ¹Õ¹é Òí ÁÒ㪠ÍÒ ¹¤ ÒÃÐÂзҧ·ÕÇè ´Ñ ä´ ¨Ò¡âÁ´ÙÅ SRF05 àÃÔÁè µ ¹´ Ç¡ÒáíÒ˹´ãË ¢Ò¾Íà µ P1.0 ¢Í§äÁâ¤Ã¤Í¹â·ÃÅàÅÍà P89V51RD2 µ ͡Ѻ¢Ò ECHO ¢Í§âÁ´ÙÅ SRF05 áÅСíÒ˹´ãË à» ¹ ¾Íà µÍÔ¹¾Øµ â´Â¡íÒ˹´ãË ÁÅÕ Í¨Ô¡ 1 à¾×Íè àÃÔÁè µ ¹·íÒ§Ò¹ Ê Ç¹¢Ò TRIGGER ¢Í§âÁ´ÙÅ SRF05 µ Íà¢ Ò ¡Ñº¢Ò¾Íà µ P1.1 ´Ñ§¹Ñ¹é ¨Ö§µ ͧ¡íÒ˹´ãË à» ¹àÍÒµ ¾µØ à¾×Íè Êà ҧÊÑÒ³¾ÑÅÊ ºÇ¡·ÕÁè ¤Õ ÇÒÁ¡Ç Ò§ 5 ¶Ö§ 10 äÁâ¤ÃÇÔ¹Ò·Õ à¾×Íè à» ¹¡Ãеع ãË âÁ´ÙÅ SRF05 àÃÔÁè µ ¹¡Ãкǹ¡ÒÃÇÑ´ÃÐÂзҧ ·Ñ¹·Õ·âÕè Á´ÙÅ SRF05 ä´ ÃºÑ ÊÑÒ³¾ÑÅÊ ºÇ¡à¢ Ò·Õ¢è Ò TRIGGER âÁ´ÙÅ SRF05 ¨Ð´íÒà¹Ô¹ ¡ÒÃÊà ҧ¢ºÇ¹¾ÑÅÊ ¤ÇÒÁ¶Õè 40 kHz ÍÍ¡ÊÙÍ Ò¡ÒÈ ¢ºÇ¹¾ÑÅÊ ¤ÇÒÁ¶Õàè ˹×ÍàÊÕ§ËÃ×ÍÍÑŵà Ò⫹ԡ¡ÅØÁ ¹Õé¨Ðà´Ô¹·Ò§à» ¹àÊ ¹µÃ§ ¨¹¡ÃзÑ觡ÃзºÇѵ¶Ø·Õè¢ÇÒ§ÍÂÙ àº×éͧ˹ Ò ·íÒãË ¢ºÇ¹¾ÑÅÊ ÍÑŵÃÒ⫹ԡ Êз ͹¡ÅѺࢠÒÁÒÂѧµÑÇÃѺ¢Í§âÁ´ÙÅ SRF05 ËÅѧ¨Ò¡¹Ñé¹Ë¹ Ç»ÃÐÁÇżÅÀÒÂã¹âÁ´ÙÅ SRF05 ¨ÐÇÔà¤ÃÒÐË áÅÐãË Ê Ñ Ò³àÍÒµ ¾µØ ÍÍ¡ÁÒà» ¹¤ÇÒÁ¡Ç Ò§¾ÑÅÊ ºÇ¡·Õàè » ¹ÊÑ´Ê Ç¹â´ÂµÃ§¡ÑºÃÐÂзҧ ·Õµè ÃǨ¨Ñºä´
6
l
¡ÒÃ㪠§Ò¹âÁ´ÙÅÇÑ´ÃÐÂзҧ SRF05 ÊÑÒ³¾ÑÅÊ ¡Ãеع ¡Ç Ò§ 10 äÁâ¤ÃÇÔ¹Ò·Õ ÊÑÒ³¡Ãеع ·Õ¢è Ò TRIGGER ÊÑÒ³ÍÑŵà Ò⫹ԡ ¶Ù¡Ê §ÍÍ¡ÁÒ 8 ä«à¡ÔÅ ÊÑÒ³¤Å×¹è ¤ÇÒÁ¶Õàè ˹×ÍàÊÕ§ (ÍÑŵà Ò⫹ԡ) ·ÕÊè § ÍÍ¡¨Ò¡ âÁ´ÙÅ SRF05
˹ ǧàÇÅÒ 10 ÁÔÅÅÔÇ¹Ô Ò·Õ ¡ Í¹Ê §¾ÑÅÊ Å¡Ù µ Íä»
¤ÇÒÁ¡Ç Ò§¾ÑÅÊ Êз ͹ ¶ Ò¾ÑÅÊ Êз ͹·Õäè ´ ÁÕ 100 äÁâ¤ÃÇÔ¹Ò·Õ ¤ÇÒÁ¡Ç Ò§¡Ç Ò 30 ÁÔÅÅÔÇ¹Ô Ò·Õ ¶Ö§ 25 ÁÔÅÅÔÇ¹Ô Ò·Õ áÊ´§Ç ÒµÃǨ¨ÑºäÁ ¾ºÇѵ¶Ø
ÊÑÒ³àÍÒµ ¾µØ ª ͧ ECHO ·ÕÊè § ÍÍ¡ÁÒ¨Ò¡âÁ´ÙÅ SRF05
ÃÙ»·Õè 4 ä´ÍÐá¡ÃÁàÇÅÒáÊ´§ÊÑÒ³·ÕÊè § ä»Âѧ SRF05 áÅÐÊÑÒ³·Õµè ͺÃѺ¡ÅѺÁÒ¨Ò¡ SRF05 㹡óյ´Ô µ ÍẺ 2 ÊÑÒ³
ÊÑÒ³¾ÑÅÊ ¡ÃÐµØ ¹ ¡Ç ҧ͠ҧ¹ Í 10 äÁâ¤ÃÇÔ¹Ò·Õ ¾ÑÅÊ Êз ͹ (echo) ·ÕèÊ §ÍÍ¡¨Ò¡âÁ´ÙÅ SRF05 ÁÕ¤ÇÒÁ¡Ç Ò§ 100 äÁâ¤ÃÇÔ¹Ò·Õ¶Ö§ 25 ÁÔÅÅÔÇÔ¹Ò·Õ ËÒ¡¡Ç Ò§¡Ç Ò 30 ÁÔÅÅÔÇ¹Ô Ò·Õ¶Í× Ç Ò µÃǨ¨ÑºäÁ ¾ºÇѵ¶Ø
ÊÑÒ³¡ÃÐµØ ¹ ·Õè¢Ò TRIGGER ÊÑÒ³ÍÑŵà Ò⫹ԡ ¶Ù¡Ê §ÍÍ¡ÁÒ 8 ä«à¡ÔÅ ÊÑÒ³¤Å×蹤ÇÒÁ¶Õèà˹×ÍàÊÕ§ (ÍÑŵà Ò⫹ԡ) ·ÕèÊ §ÍÍ¡¨Ò¡ âÁ´ÙÅ SRF05
ÃÙ»·Õè 5 ä´ÍÐá¡ÃÁàÇÅÒáÊ´§ÊÑÒ³·ÕÊè § ä»Âѧ SRF05 áÅÐÊÑÒ³·Õµè ͺÃѺ¡ÅѺÁÒ¨Ò¡ SRF05 㹡óյ´Ô µ ÍẺ 1 ÊÑÒ³ (¢Ø´µ Í MODE µ ͧµ Íŧ¡ÃÒÇ´ )
¡ÒÃ㪠§Ò¹âÁ´ÙÅÇÑ´ÃÐÂзҧ SRF05
l
7
ÊíÒËÃѺ¡ÒùѺ¤ÇÒÁ¡Ç Ò§¾ÑÅÊ ·¢Õè Ò ECHO ¨Ð㪠ä·àÁÍà 1 ã¹âËÁ´ 16 ºÔµ à» ¹µÑǹѺàÇÅÒ ¤ÇÒÁ¡Ç Ò§¢Í§ÊÑÒ³¾ÑÅÊ â´Â¨ÐàÃÔÁè µ ¹¹Ñº àÁ×Íè ¾ºÇ Ò ÁÕ¡ÒÃà»ÅÕÂè ¹á»Å§ÅͨԡẺ¢Ò¢Ö¹é ¨Ò¡ 0 ä»à» ¹ 1 áÅÐËÂØ´¡ÒùѺàÁ×Íè ¾º¡ÒÃà»ÅÕÂè ¹á»Å§ÅͨԡẺ¢Òŧ ¨Ò¡ 1 ä»à» ¹ 0 ËÅѧ¨Ò¡¹Ñ¹é ¤ Ò·Õäè ´ ¨Ò¡¡ÒùѺ¹íÒä»ËÒô Ç 114 ¨Ðà» ¹¤ Ò»ÃÐÁÒ³·Õãè ¡Å à¤Õ§¨Ò¡¡ÒÃá»Å§ ¢ ÍÁÙÅÃÐÂзҧ·Õäè ´ ¨Ò¡âÁ´ÙÅ SRF05 ä·àÁÍà ¢Í§äÁâ¤Ã¤Í¹â·ÃÅàÅÍà ·ãÕè ª ¹¹Ñé ¨ÐÍ Ò§ÍÔ§ÊÑÒ³ ¹ÒÌ ¡Ò ¤ÇÒÁ¶Õè 11.0592 MHz áÅÐäÁâ¤Ã¤Í¹â·ÃÅàÅÍà P89V51RD2 ·íÒ§Ò¹´ ǤÇÒÁàÃçÇ 6 ÊÑÒ³ ¹ÒÌ ¡Òµ Íä«à¡ÔÅ
+5V 31 C2 1/50V
RESET 9 R1 10k
RST
+5V
C1 0.1/50
40
5 6 4
16 P3.6 17 P3.7
C5 0.1/ 50V
IC1 2&'8# 4, P0.7
R2 10k x8
32
+5V
2 R/W E
DSP1 LCD 16x2
RS D7 D6 D5 D4 D3 D2 D1 D0 14 13 12 11 10 9 8 7
3 1
33 P0.6 34 P0.5 35 P0.4 36 P0.3 37 P0.2 38 P0.1 39 P0.0
+5V R3 4k7
P1.0 P1.1
1 2
R4 4k7
+5V MOD1 54. " ECHO TRIGGER GND
20 18 C3 33pF
19 C4 33pF
XTAL1 11.0592MHz
ÃÙ»·Õè 6 ǧ¨Ã·´ÅͧµÔ´µ ÍäÁâ¤Ã¤Í¹â·ÃÅàÅÍà P89V51RD2 ¡Ñº SRF05 âÁ´ÙÅÇÑ´ÃÐÂзҧ
VR1 10k
8
l
¡ÒÃ㪠§Ò¹âÁ´ÙÅÇÑ´ÃÐÂзҧ SRF05
/*————————————————————————————————————————————————————————————————————————*/ // Description : Distance detector by SFR05 display value on LCD // Filename : V51SRF05.C // C compiler : RIDE 51 V6.4.35 /*————————————————————————————————————————————————————————————————————————*/ #include <REGLV51RD2.h> // Header file register for P89V51RD2BN #include <lcdV51.h> // Library for LCD display #include <intrins.h> // Include library for nop function sbit echo = P1^0; // Define received pulse pin(SDA) sbit trigger = P1^1; // Define trigger pulse pin(SCL) /***************** Function Trigger pulse for start process ******************/ void trigger_pulse(void) { unsigned char i; // Variable for counter trigger = 1; // Start positive pulse for(i=0;i<10;i++) // Loop 10 times _nop_(); // Delay 1 microseconnd function trigger = 0; // End of positive pulse } /******************** Distance reading function ****************************/ unsigned int distance() { unsigned int mc; // Variable for internal function trigger = 0; // Initial logic low echo = 1; // Initial logic low TMOD &=0x0F; // Configuration Timer1 mode 2(16-bit counter) TMOD |=0x10; TH1 = 0x00; // Initial Timer1 counter value to zero TL1 = 0x00; TF1 = 0; // Clear overflow flag TR1 = 0; // Start Timer1 trigger_pulse(); // Send trigger pulse while(!echo); // Detect rising pulse TR1 = 1; // Start timer count while(echo); // Detect falling pulse TR1 = 0; // Stop timer TF1 = 0; // Clear overflow flag mc = TH1; // Keep high byte mc <<= 8; // Shift to high byte mc += TL1; // Keep low byte delay(10); // Delay 10 millisecond return(mc/114); // Return distance value in centimetre unit } /************************* Main Program **************************************/ void main() { unsigned int value,old_value; // Variable for storing distance value lcd_init(); // Initial LCD lcd_puts(0x80,”SRF-05 Demo...”); // Display message lcd_puts(0xC0,”Distance: cm”); // Show distance value on screen while(1) // Infinite loop
â»Ãá¡ÃÁ·Õè 1 â»Ãá¡ÃÁÀÒÉÒ C ÊíÒËÃѺ·´Åͧ¡ÒÃ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà P89V51RD2 ¡Ñº SRF05 âÁ´ÙÅÇÑ´ÃÐÂзҧ (ÁÕµÍ )
¡ÒÃ㪠§Ò¹âÁ´ÙÅÇÑ´ÃÐÂзҧ SRF05
l
9
{ value = distance(); if(value != old_value)
// Read distance // Compare new and previous value to update display
{ lcd_puts(0xCA,” “); inttolcd(0xCA,value); delay(500); } old_value = value;
// Clear previous value // Update new value // Delay for displaying
// Keep previous value for comparison next time
} }
¤íÒ͸ԺÒÂâ»Ãá¡ÃÁ ¡Ò÷íÒ§Ò¹¢Í§â»Ãá¡ÃÁ¹Õéà» ¹¡ÒõԴµ ͡ѺâÁ´ÙÅÇÑ´ÃÐÂзҧ´ ÇÂÍÑŵÃÒ⫹ԡ SRF04 ¢Í§äÁâ¤Ã ¤Í¹â·ÃÅàÅÍà P89V51RD2 â´ÂÀÒÂã¹â»Ãá¡ÃÁËÅÑ¡à» ¹¡ÒÃÇ¹Í Ò¹¤ ÒÃÐÂзҧ·ÕÇè ´Ñ ä´ ÁÒáÊ´§¼ÅÍÂÙµ ÅÍ´ àÇÅÒÀÒÂãµ while(1){} ·Õàè §×Íè ¹ä¢à» ¹¨ÃÔ§ Ê Ç¹¡ÒÃáÊ´§¼Å¨Ðà»ÃÕºà·ÕºÃÐËÇ Ò§¢ ÍÁÙÅà´ÔÁáÅÐãËÁ ·Õè Í Ò¹ä´ ¶ ÒÁÕ¡ÒÃà»ÅÕÂè ¹á»Å§¨Ö§¨Ð¹íÒ¤ ÒãËÁ ä»áÊ´§¼Å
â»Ãá¡ÃÁ·Õè 1 â»Ãá¡ÃÁÀÒÉÒ C ÊíÒËÃѺ·´Åͧ¡ÒÃ㪠§Ò¹äÁâ¤Ã¤Í¹â·ÃÅàÅÍà P89V51RD2 ¡Ñº SRF05 âÁ´ÙÅÇÑ´ÃÐÂзҧ (¨º) 㹡Ò÷´Êͺ¹Õàé » ¹¡ÒÃà¢Õ¹â»Ãá¡ÃÁÀÒÉÒ C ¤Çº¤ØÁäÁâ¤Ã¤Í¹â·ÃÅàÅÍà P89V51RD2 à¾×Íè µÔ´µ ͡Ѻ SRF05 âÁ´ÙŵÃǨ¨ÑºáÅÐÇÑ´ÃÐÂзҧ´ ǤÅ×¹è ÍÑŵà Ò⫹ԡ 1. ·íÒ¡ÒõԴµÑ§é âÁ´ÙÅ SRF05 ࢠҡѺºÍà ´ ADX-SRF04 2. µ Íǧ¨ÃµÒÁÃÙ»·Õè 6 3. à¢Õ¹â»Ãá¡ÃÁ·Õè 1 áÅ Ç·íÒ¡ÒÃá»Å§ãË à» ¹ä¿Å .hex ´ Ç RC51 ¼ Ò¹¡Ãкǹ¡Òà Êà ҧä¿Å â»Ãà¨ç¡µ ¢Í§ Rkit-51 â´Â㪠RIDE ä´ ä¿Å v51srf05.hex ´Òǹ âËŴŧã¹äÁâ¤Ã ¤Í¹â·ÃÅàÅÍà P89V51RD2 â´Âµ ͧź¢ ÍÁÙÅ¡ ͹â»Ãá¡ÃÁŧä»ãËÁ 4. ¨ ÒÂä¿ãË á¡ Ç§¨Ã ¹íÒÇѵ¶ØÁÒÇÒ§¢ÇÒ§·Õ´è Ò ¹Ë¹ ҢͧâÁ´ÙÅ SRF05ã¹ÃÐÂÐ 1 ૹ µÔàÁµÃ¶Ö§ 4 àÁµÃ áÅ ÇÊѧࡵ¼Å·Õâè Á´ÙÅ LCD ·Õâè Á´ÙÅ LCD áÊ´§¤ ÒÃÐÂзҧ·ÕÇè ´Ñ ä´ â´ÂÁÕû٠Ẻ¤×Í SRF-05
Demo...
Distance:
xxx
cm
5. ¨Ò¡¹Ñ¹é ·´ÅͧÇÑ´ÃÐÂÐË Ò§â´Â㪠äÁ ºÃ÷Ѵà¾×Íè à»ÃÕºà·Õº¼Å¡Ò÷´Åͧ·Õäè ´
10
l
¡ÒÃ㪠§Ò¹âÁ´ÙÅÇÑ´ÃÐÂзҧ SRF05
3.2 à¢Õ¹â»Ãá¡ÃÁà¾×Íè Í Ò¹¤ Ò¨Ò¡âÁ´ÙÅ SRF05 㪠¡ÒõԴµ ÍẺ 2 ÊÑÒ³ÊíÒËÃѺ äÁâ¤Ã¤Í¹â·ÃÅàÅÍà PIC16F877 â´Â㪠PICBASIC PRO compiler µ Í¢Ò RC4 µ ÍࢠҡѺ¢Ò ECHO áÅÐ ¢Ò RC3 µ ÍࢠҡѺ¢Ò TRIGGER ´Ñ§Ç§¨ÃÃÙ»·Õè 7 â»Ãá¡ÃÁ·Õè 2 à» ¹â»Ãá¡ÃÁµÑÇÍ ҧ·Õãè ª ÍÒ ¹¤ ÒÃÐÂзҧ·ÕÇè ´Ñ ä´ ¨Ò¡ SRF05 ¹íÒä»áÊ´§·Õè âÁ´ÙÅ LCD ¡Ò÷íÒ§Ò¹àÃÔÁè ¨Ò¡¡íÒ˹´ãË ¢Ò¾Íà µ·Õãè ª ÊÒí ËÃÑºÊ §ÊÑÒ³¡Ãеع ä»Âѧ SRF05 ÁÕÅͨԡ à» ¹ 0 ¡ ͹ ¨Ò¡¹Ñ¹é àÃÕ¡â»Ãá¡ÃÁ ÍÂÍ Ò¹¢ ÍÁÙŨҡ SRF05 â´Ââ»Ãá¡ÃÁ Í¨зíÒ§Ò¹´Ñ§¹Õé 1. ǹÅÙ» 5 Ãͺ à¾×Íè Í Ò¹¤ ҷѧé ËÁ´ 5 ¤Ãѧé áŠǹíÒÁÒà©ÅÕÂè 2. Ê §¾ÑÅÊ 10 äÁâ¤ÃÇÔ¹Ò·Õ â´Â㪠¤Òí Êѧè PULSOUT ˹ Ç¢ͧ¤ÇÒÁ¡Ç Ò§¾ÑÅÊ ÊÒí ËÃѺ ¤íÒÊÑ觹Õé¤×Í 2 äÁâ¤ÃÇÔ¹Ò·Õ·Õè¤ÇÒÁ¶ÕèÊÑÒ³¹ÒÌ ¡ÒËÅÑ¡ 20MHz ¶ Òµ ͧ¡ÒþÑÅÊ 10 äÁâ¤ÃÇÔ¹Ò·Õ µ ͧ¡íÒ˹´¤ ÒãË ¡ºÑ ¤íÒÊѧè PULSOUT ෠ҡѺ 5 3. Í Ò¹¤ Ò¤ÇÒÁ¡Ç Ò§¾ÑÅÊ à¾×Íè µÃǨÊͺÃÐÂзÕè SRF05 Í Ò¹¤ Òä´ â´Â㪠¤Òí Êѧè PULSIN ¤íÒÊÑ§è ¹Õ¨é ÐÇÑ´¤ Ò¤ÇÒÁ¡Ç Ò§¾ÑÅÊ ªÇ §ºÇ¡ã¹Ë¹ Ç 2 äÁâ¤ÃÇÔ¹Ò·Õ à¡çº¤ Ò·Õäè ´ äÇ ã¹µÑÇá»Ã RESULT 4. ˹ ǧàÇÅÒ 10 ÁÔÅÅÔÇ¹Ô Ò·Õ¡Í ¹·Õ¨è ÐàÃÔÁè µ ¹Ç¹ÅÙ»·íÒ§Ò¹µÒÁ¢ Í 1 ãËÁ ¨¹¤Ãº 5 Ãͺ áÅ ÇÍÍ¡¨Ò¡â»Ãá¡ÃÁ Í ¼ÅÅѾ¸ ¨Ò¡¡ÒÃǹÅÙ» 5 Ãͺà¡çºã¹µÑÇá»Ã RAW +5V 11
C9 0.1/50V
IC1 PIC16F877-20
+5V R1 4k7
32
1
12 31
MCLR
S1 RESET
54. #
+5V
+5V
ECHO
TRIGGER
+5V
R2 4k7
R3 4k7
RC0 15
4
24
6
RC5
23 RC4/SDA 18 RC3/SCL
RD7 RD6 RD5 RD4
CR1 Ceramic Resonator 20MHz
13
30
RS E
DSP1 LCD 16x2
D7 D6 D5 D4 D3 D2 D1 D0 R/W 14 13 12 11 10 9 8 7 5
+V Vo BLK GND 16 2
1 3
VR1 10k
BRIGHTNESS
29 28 27
14
ÃÙ»·Õè 7 ǧ¨Ã·´ÅͧµÔ´µ ÍäÁâ¤Ã¤Í¹â·ÃÅàÅÍà PIC16F877 ¡Ñº SRF05 âÁ´ÙÅÇÑ´ÃÐÂзҧ
¡ÒÃ㪠§Ò¹âÁ´ÙÅÇÑ´ÃÐÂзҧ SRF05
l
11
àÁ×Íè ÍÍ¡¨Ò¡â»Ãá¡ÃÁ Í â»Ãá¡ÃÁËÅÑ¡¨Ð¹íÒ¤ Ò·ÕÍè Ò ¹ä´ ÁÒËÒô Ç 30 ¼ÅÅѾ¸ ·äÕè ´ ÁËÕ ¹ Ç ໠¹à«¹µÔàÁµÃ áŠǹíÒÁÒáÊ´§·ÕèâÁ´ÙÅ LCD ¨Ò¡¹Ñé¹·íÒ¡ÒÃá»Å§¤ Ò·ÕèÍ Ò¹ä´ à» ¹¹ÔéÇ â´Â㪠¤ÇÒÁ ÊÑÁ¾Ñ¹¸ 1 ૹµÔàÁµÃ෠ҡѺ 0.3937 ¹ÔÇé à¾×Íè ãË ¡ÒÃáÊ´§¤ Òä´ ¼ÅÅѾ¸ ·ÅÕè ÐàÍÕ´¢Ö¹é ¤ÇÃãË ÅÐàÍÕ´ à» ¹ 0.1 ¹ÔÇé ¨Ö§µ ͧ¤Ù³´ Ç 3.937 á·¹ @ DEVICE PIC16F877,HS_OSC ' Use PIC16F877 and HS Oscilator DEFINE OSC 20 DEFINE LCD_DREG PORTD ' Set LCD Data port DEFINE LCD_DBIT 4 ' Set starting Data bit for 4-bit interface DEFINE LCD_RSREG PORTC ' Set LCD Register Select port DEFINE LCD_RSBIT 0 ' Set LCD Register Select bit DEFINE LCD_EREG PORTC ' Set LCD Enable port DEFINE LCD_EBIT 5 ' Set LCD Enable bit DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits) DEFINE LCD_LINES 2 ' Set number of lines on LCD DEFINE LCD_COMMANDUS 2000 ' Set command delay time in us DEFINE LCD_DATAUS 50 ' Set data delay time in us TRIGGER VAR PORTC.3 ECHO VAR PORTC.4 ' =====[ Variables ]====================================================== I VAR BYTE ' loop counter RESULT VAR WORD ' pulse width from sensor RAW VAR WORD ' filtered measurment CM VAR WORD ' centimeters INCH VAR WORD ' =====[ Initialization ]================================================== SETUP: LOW TRIGGER ' =====[ Program Code ]==================================================== MAIN: GOSUB GET_SONAR ' Take Sonar Reading CM = RAW /30 ' Convert to Centimeter LCDOUT $FE,$01,"CM = " , DEC CM , " CM" ' Show on LCD INCH = CM */ $03EF ' x 3.937 (to 0.1 inches) LCDOUT $FE,$C0,"INCH = ",DEC INCH/10,".",DEC1 INCH," INCH" ' Show on LCD GOTO MAIN END ' =====[ Subroutines ]==================================================== GET_SONAR: RAW = 0 ' Clear Measurement FOR I = 1 TO 5 ' Take 5 Samples PULSOUT TRIGGER,5 ' 10 uS Trigger Pulse PULSIN ECHO,1,RESULT ' Measure Pulse RAW = RAW + (RESULT / 5) ' Simple Digital Filter PAUSE 10 ' Minimum Period Between NEXT RETURN
ËÁÒÂà赯 : ¡Òäٳ¤ Ò´ ǵÑÇàÅ¢·Õèà» ¹·È¹ÔÂÁ ¨Ð㪠¤íÒÊÑ觤ٳàÅ¢áŠǹíÒàÍÒ¼ÅÅѾ¸ 16 ºÔµµÃ§¡ÅÒ§ÁÒ㪠¤ Ò 3.937 àÁ×Íè á»Å§à» ¹µÑÇàÅ¢°Ò¹ÊԺˡ¨ÐÁÕ¤Ò à· Ò¡Ñº 03EF â´Â 03 ¤×͵ÑÇàÅ¢ã¹ËÅѡ˹ ÇÂ Ê Ç¹ EF ¤×ͤ ÒµÑÇàÅ¢·È¹ÔÂÁ
â»Ãá¡ÃÁ·Õè 2 µÑÇÍ ҧâ»Ãá¡ÃÁÀÒÉÒàºÊÔ¡¢Í§ PIC16F877 ·Õãè ª PICBASIC PRO compiler ÊíÒËÃѺ µÃǨÊͺ¡Ò÷íÒ§Ò¹¢Í§ SRF05 âÁ´ÙŵÃǨ¨ÑºÇѵ¶Ø´Ç ¤Å×¹è ÍÑŵà Ò⫹ԡ
12
l
¡ÒÃ㪠§Ò¹âÁ´ÙÅÇÑ´ÃÐÂзҧ SRF05
3.3 à¢Õ¹â»Ãá¡ÃÁà¾×Íè Í Ò¹¤ Ò¨Ò¡âÁ´ÙÅ SRF05 㪠¡ÒõԴµ ÍẺ 2 ÊÒÂÊÑÒ³ ÊíÒËÃѺ i-Stamp (àºÊÔ¡áʵÁ» 2SX) áÅÐ i-Stamp2P (àºÊÔ¡áʵÁ» 2P) 1. µ Í¢Ò P0 ¢Í§ i-Stamp ËÃ×Í i-Stamp2P ࢠҡѺ¨Ø´µ Í ECHO 2. µ Í¢Ò P0 ¢Í§ i-Stamp ËÃ×Í i-Stamp2P ࢠҡѺ¨Ø´µ Í TRIGGER 3. µ ÍÊÒÂÊÑÒ³·Õ¨è Òí à» ¹ ´Ñ§ã¹Ç§¨ÃÃÙ»·Õè 8 â»Ãá¡ÃÁ·Õè 3 à» ¹â»Ãá¡ÃÁµÑÇÍ ҧ·Õãè ª ÍÒ ¹¤ ÒÃÐÂзҧ·ÕÇè ´Ñ ä´ ¨Ò¡ SRF05 ¹íÒä»áÊ´§·Õè ˹ Òµ Ò§ Debug Terminal ¢Í§â»Ãá¡ÃÁàºÊÔ¡áʵÁ» àÍ´ÔàµÍà â´Âã¹â»Ãá¡ÃÁ¹ÕÊé ÒÁÒÃ¶ãª ä´ ¡ºÑ ·Ñ§é i-Stamp (BS2SX : àºÊÔ¡áʵÁ» 2SX), i-Stamp2P (BS2P : àºÊÔ¡áʵÁ» 2P) áÅÐ BS2 (àºÊÔ¡ áʵÁ» 2 Ãع Áҵðҹ) â´Â¨Ðá¡´ ÇÂä´àÃ硵տ·Õ¡è Òí ˹´ã¹Ê ǹËÑǢͧâ»Ãá¡ÃÁ
0.1/50V x2
1 2 3 Tx Rx ATN
i-Stamp (BS2SX) i-Stamp2P (BS2P40)
+5V
P0 P1 GND
$ % &
K1 RS-232 (DB-9F)
4
S1 RESET
ECHO TRIGGER
+5V
RES
! " #
54. #
äÁ ÁÕ¡Òõ Í㪠§Ò¹·Õè¨Ø´àËÅ Ò¹Õé
ÃÙ»·Õè 8 ǧ¨Ã·´ÅͧµÔ´µ Í i-Stamp áÅÐ i-Stmp2P ¡Ñº SRF05 âÁ´ÙÅÇÑ´ÃÐÂзҧ
¡ÒÃ㪠§Ò¹âÁ´ÙÅÇÑ´ÃÐÂзҧ SRF05
l
13
' {$STAMP BS2sx} ' {$PBASIC 2.5} '*************************************************************************** ' SRF05 Ultra-Sonic Ranger demonstration code on BASIC Stamp 2,2e,2sx,2p,2pe,2px ' Using mode 1 (Mode pin leave no connect) ' Connect Trigger pin to transmit, Echo pin to receive '*************************************************************************** Trig_Pulse PIN 1 Echo PIN 0 Distance VAR Word LOW Trig_Pulse DO #IF ($STAMP = BS2SX) OR ($STAMP = BS2P) OR ($STAMP = BS2PX) #THEN PULSOUT Trig_Pulse,13 ' Pulse out 10.8 us PULSIN Echo,1,Distance ' Read positive pulse 0.8us per unit Distance = Distance */ $0161 ' Multiply by 1.379 convert unit as Millimeter DEBUG HOME,DEC5 Distance," mm.",CR PAUSE 100 #ELSE ' Case $Stamp BS2 , BS2E , BS2PE PULSOUT Trig_Pulse,5 ' Pulse out 10 us PULSIN Echo,1,Distance ' Read positive pulse 2us per unit IF Distance < 19000 THEN Distance = Distance */ $0373 ' Multiply by 3.448 convert unit as Millimeter DEBUG HOME,DEC5 Distance," mm.",CR ELSE Distance = Distance / 29 ' Divide by 29 convert unit as Centimeter DEBUG HOME,DEC5 Distance," cm.",CR ENDIF PAUSE 100 #ENDIF LOOP
â»Ãá¡ÃÁ·Õè 3 µÑÇÍ ҧâ»Ãá¡ÃÁÀÒÉÒ¾ÕàºÊÔ¡¢Í§ i-Stamp áÅÐ i-Stamp2P ÊíÒËÃѺµÃǨÊͺ¡Òà ·íÒ§Ò¹¢Í§ SRF05 âÁ´ÙÅÇÑ´ÃÐÂзҧ´ ǤÅ×¹è ÍÑŵà Ò⫹ԡã¹âËÁ´¡ÒõԴµ ÍẺ 2 ÊÒÂÊÑÒ³ ¡Ò÷íÒ§Ò¹àÃÔÁè ¨Ò¡¡íÒ˹´¢Ò¾Íà µ·Õãè ª µ´Ô µ ͡ѺâÁ´ÙÅ SRF05 ¨Ò¡¹Ñ¹é Ê §¾ÑÅÊ ¡Ãеع ÍÍ¡ä» ÂѧâÁ´ÙÅ SRF05 ¨Ò¡¹Ñ¹é Í Ò¹¤ ÒÊÑÒ³¾ÑÅÊ ¡ÅѺࢠÒÁÒ´ ǤíÒÊѧè PULSIN ÁÒà¡çºäÇ ·µÕè ÇÑ á»Ã Distance ·íÒ¡Òäíҹdz¤ ÒÃÐÂзҧã¹Ë¹ ÇÂÁÔÅÅÔàÁµÃÍÍ¡ÁÒ´ ǤíÒÊÑè§ Distance = Distance */ $0161 ¡Ã³Õ㪠¡ºÑ i-Stamp áÅÐ i-Stamp2P áÅ ÇãË áÊ´§ÍÍ¡ÁÒ·Õè˹ Òµ Ò§ Debug Terminal ¨Ò¡¹Ñ鹨зíÒ¡Òäíҹdzà¾×èÍáÊ´§¤ ÒÃÐÂÐ ·Ò§ÍÍ¡ÁÒã¹Ë¹ ÇÂૹµÔàÁµÃ ´ ǤíÒÊѧè Distance = Distance / 58 ¡Ã³Õ㪠¡ºÑ i-Stamp áÅÐ i-Stamp2P áÅ ÇãË áÊ´§ÍÍ¡ÁÒ·ÕËè ¹ Òµ Ò§ Debug Terminal ઠ¹¡Ñ¹ ¨Ò¡¹Ñ¹é ˹ ǧàÇÅÒ 100 ÁÔÅÅÔÇ¹Ô Ò·Õ ¡ ͹ǹ¡ÅѺä»Í Ò¹¤ ÒÍÕ¡¤ÃÑé§
14
l
¡ÒÃ㪠§Ò¹âÁ´ÙÅÇÑ´ÃÐÂзҧ SRF05
3.4 à¢Õ¹â»Ãá¡ÃÁà¾×Íè Í Ò¹¤ Ò¨Ò¡âÁ´ÙÅ SRF05 㪠¡ÒõԴµ ÍẺ 1 ÊÒÂÊÑÒ³ ÊíÒËÃѺ i-Stamp (àºÊÔ¡áʵÁ» 2SX) áÅÐ i-Stamp2P (àºÊÔ¡áʵÁ» 2P) 1. µ Í¢Ò P0 ¢Í§ i-Stamp ËÃ×Í i-Stamp2P ࢠҡѺ¨Ø´µ Í TRIGGER 2. µ ͨشµ Í MODE ¢Í§ SRF05 ŧ¡ÃÒÇ´ 3. µ ÍÊÒÂÊÑÒ³·Õ¨è Òí à» ¹ ´Ñ§ã¹Ç§¨ÃÃÙ»·Õè 9 â»Ãá¡ÃÁ·Õè 4 à» ¹â»Ãá¡ÃÁµÑÇÍÂ Ò§Í Ò¹¤ ÒÃÐÂзҧ·ÕÇè ´Ñ ä´ ¨Ò¡ SRF05 «Ö§è 㪠¡ÒõԴµ ÍẺ 1 ÊÒÂÊÑÒ³ ¹íÒä»áÊ´§·ÕËè ¹ Òµ Ò§ Debug Terminal ¢Í§â»Ãá¡ÃÁàºÊÔ¡áʵÁ» àÍ´ÔàµÍà â´Âã¹ â»Ãá¡ÃÁ¹ÕÊé ÒÁÒÃ¶ãª ä´ ¡ºÑ ·Ñ§é i-Stamp (BS2SX : àºÊÔ¡áʵÁ» 2SX), i-Stamp2P (BS2P : àºÊÔ¡ áʵÁ» 2P) áÅÐ BS2 (àºÊÔ¡áʵÁ» 2 Ãع Áҵðҹ) â´Â¨Ðá¡´ ÇÂä´àÃ硵տ·Õ¡è Òí ˹´ã¹Ê ǹËÑÇ ¢Í§â»Ãá¡ÃÁ
0.1/50V x2
1 2 3 Tx Rx ATN
i-Stamp (BS2SX) i-Stamp2P (BS2P40)
TRIGGER
+5V
P1 GND
$ % &
K1 RS-232 (DB-9F)
4
S1 RESET
MODE
+5V
RES
! " #
54. #
äÁ ÁÕ¡Òõ Í㪠§Ò¹·Õè¨Ø´àËÅ Ò¹Õé
ÃÙ»·Õè 9 ǧ¨Ã·´ÅͧµÔ´µ Í i-Stamp áÅÐ i-Stmp2P ¡Ñº SRF05 âÁ´ÙÅÇÑ´ÃÐÂзҧã¹áºº 1 ÊÒÂÊÑÒ³
¡ÒÃ㪠§Ò¹âÁ´ÙÅÇÑ´ÃÐÂзҧ SRF05
l
15
' {$STAMP BS2sx} '*************************************************************************** ' SRF05 Ultra-Sonic Ranger demonstration code on BASIC Stamp 2,2e,2sx,2p,2pe,2px ' Using mode 2 (Mode pin tied to GND) ' Connect Trigger pin both transmit and receive '*************************************************************************** Trig_Echo PIN 1 Distance VAR Word LOW Trig_Echo DO #IF ($STAMP = BS2SX) OR ($STAMP = BS2P) OR ($STAMP = BS2PX) #THEN PULSOUT Trig_Echo,13 ' Pulse out 10.8 us PULSIN Trig_Echo,1,Distance ' Read positive pulse 0.8us per unit Distance = Distance */ $0161 ' Multiply by 1.379 convert unit as Millimeter DEBUG HOME,DEC5 Distance," mm.",CR PAUSE 100 #ELSE ' Case $Stamp BS2 , BS2E , BS2PE PULSOUT Trig_Echo,5 ' Pulse out 10 us PULSIN Trig_Echo,1,Distance ' Read positive pulse 2us per unit IF Distance < 19000 THEN Distance = Distance */ $0373 ' Multiply by 3.448 convert unit as Millimeter DEBUG HOME,DEC5 Distance," mm.",CR ELSE Distance = Distance / 29 ' Divide by 29 convert unit as Centimeter DEBUG HOME,DEC5 Distance," cm.",CR ENDIF PAUSE 100 #ENDIF LOOP
â»Ãá¡ÃÁ·Õè 4 µÑÇÍ ҧâ»Ãá¡ÃÁÀÒÉÒ¾ÕàºÊÔ¡¢Í§ i-Stamp áÅÐ i-Stamp2P ÊíÒËÃѺµÃǨÊͺ¡Òà ·íÒ§Ò¹¢Í§ SRF05 âÁ´ÙÅÇÑ´ÃÐÂзҧ´ ǤÅ×¹è ÍÑŵà Ò⫹ԡã¹âËÁ´¡ÒõԴµ ÍẺ 1 ÊÒÂÊÑÒ³
16
l
¡ÒÃ㪠§Ò¹âÁ´ÙÅÇÑ´ÃÐÂзҧ SRF05
ºÃÔÉÑ· ÍÔ¹â¹àǵտ àÍç¡à¾ÍÃÔàÁ¹µ ¨íÒ¡Ñ´
3133/53 «.ÊØ¢ÁØ ÇÔ· 101/2 ¶. ÊØ¢ÁØ ÇÔ· á¢Ç§ºÒ§¹Ò ࢵºÒ§¹Ò ¡ÃØ§à·¾Ï 10260 â·ÃÈѾ· 0-2747-7001-4 â·ÃÊÒà 0-2747-7005
URL : www.inex.co.th
e-mail : tech@inex.co.th