IR (Infrared) obstacle avoidance Sensor module uses infrared reflection principle to detect obstacle. This sensor has a high precision components paired of infrared transmitter and receiver. The transmitter tubes emit a certain frequency of infrared when detecting a direction or obstacle or a reflector the infrared receiver tube receive a reflected signal came from the obstacle then the indicator output will turn to HIGH as you can see at the board there are two type of trimmer or potentiometer knob to adjust the distance from 2 to 40 cm. running at 3.3v or 5v dc.
Required Components
- Raspberry Pi / Banana Pi / Orange Pi (If your using Banana Pi or Orange See first the GPIO Pins)
- Obstacle Avoidance / Obstacle Sensor Module Board
- Solder Less Breadboard
- Jumper Wire / DuPont Wire
Wiring Diagram
CCode with WiringPi
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
/* 14CORE Test Code for: Obstacle Avoidance on C Code .:+osysso++:` `+yhs/-` `-+s+` `:/+++++++++` .:/++ooo++/-` .ooooooooooo+: :///////////- `odh/` `:y+` /ddhsooooooo+ /hddhsooooydddh sdddoooooosdddy` `////////////` -hds` `sy. +ddy` .ddd: sddy.dddo +ddd- .-----------` `hds :sssss/ -ossssso-yy` `hdd: oddy `ddd/oddd:......+dddo .++++++++++++ +dd` :sdddh` :ydddddddo +y/ .ddd+........ `hddy:.....:yddy.hdddddddddddy+. ```````````` ydy .hddd/+hdddhydddh/.+yo /hdddddddddd. :shddddddddhs/`+ddd:````-yddy- :ooooooooooo+ odh` sdddooyyyyyhddddyy.sy+ ` `......... ``.... ....` ```...` ` `` `` ` -dd+`::::` .:::- /yy. -oos+:-oos+--oos+: /o `+y o/: o:+/ h:`yos /+-`/+/+ s:y/y. /dd/ `+yy: +//+ +/:+ +/:+ -. `/ -:o.:/:`//+- + +:- :`-+:`://: +`o`+. -yds. `/yys- .`-.. .``` ```` .`` ` ` ``` ``-..` ` :ydy/.`````.-/oyhs: `+++oo+oo+:.+-++/-/ooo+o +:o/oo///:+/ .:oyhhhhhhhso:` `. ``` */ #include <wiringPi.h> #include <stdio.h> #define ObstaclePin 4 void myISR(void){ printf("14CORE | Obstacle Avoidance Sensor Test \n") printf(" DETECTED: There is an obstacle ahead") } int main(void) { if(wiringPiSetup() == -1){ // Wiringpi initialization failed print error printf(" Wiripin initialization failed!"); return 1; } if(wiringPiISR(ObstaclePin, INT_EDGE_FALLING, &myISR) < 0 ){ printf("14CORE | Obstacle Avoidance Sensor Test \n") printf("WARNING: Unable to setup ISR\n") return 1; } while(1){ ; } return 0; } |
Python Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# 14CORE Test Code for: Obstacle Avoidance Sensor with Python Test Code # .:+osysso++:` # `+yhs/-` `-+s+` `:/+++++++++` .:/++ooo++/-` .ooooooooooo+: :///////////- # `odh/` `:y+` /ddhsooooooo+ /hddhsooooydddh sdddoooooosdddy` `////////////` # -hds` `sy. +ddy` .ddd: sddy.dddo +ddd- .-----------` # `hds :sssss/ -ossssso-yy` `hdd: oddy `ddd/oddd:......+dddo .++++++++++++ # +dd` :sdddh` :ydddddddo +y/ .ddd+........ `hddy:.....:yddy.hdddddddddddy+. ```````````` # ydy .hddd/+hdddhydddh/.+yo /hdddddddddd. :shddddddddhs/`+ddd:````-yddy- :ooooooooooo+ # odh` sdddooyyyyyhddddyy.sy+ ` `......... ``.... ....` ```...` ` `` `` ` # -dd+`::::` .:::- /yy. -oos+:-oos+--oos+: /o `+y o/: o:+/ h:`yos /+-`/+/+ s:y/y. # /dd/ `+yy: +//+ +/:+ +/:+ -. `/ -:o.:/:`//+- + +:- :`-+:`://: +`o`+. # -yds. `/yys- .`-.. .``` ```` .`` ` ` ``` ``-..` ` # :ydy/.`````.-/oyhs: `+++oo+oo+:.+-++/-/ooo+o +:o/oo///:+/ # .:oyhhhhhhhso:` `. ``` #!/usr/bin/env python import RPi.GPIO as GPIO ObstaclePin = 24 def setup(): GPIO.setmode(GPIO.BOARD) # Set GPIO by numbers GPIO.setup(ObstaclePin, GPIO.IN, pull_up_down=GPIO.PUD_UP) def loop(): while True: if (0 == GPIO.input(ObstaclePin)): print "14CORE | Obstacle Avoidance Sensor Test \n" print " DETECTED: There is an obstacle ahead" def destroy(): GPIO.cleanup() # Release resource if __name__ == '__main__': # The Program start here setup() try: loop() except KeyboardInterrupt: # Control C is pressed, the child program destroy will be executed. destroy() |
Wiring IR (Infrared) Obstacle Avoidance Sensor with Raspberry Pi