myRaspberry

Mes aventures en Raspberry et Arduino

IR detecteur

Posted on 5 mars 2016  in Composants

J’ai testé le détecteur infra rouge IR-08H V02.45.DC

14125853510

Le capteur dispose de 4  broches, cette de gauche n’est pas utilisée:

  • VCC
  • Signal de sortie numérique :(Black or no Obstacle = Logic HIGH, White or obstacle = Logic LOW)
  • GND

A la difference au détecteur détaillé dans cet article, la porte de ce détecteur est plus longue et peut atteindre 30cm.

  • Other : detective distance—2 cm to 30 cm
  • Supply voltage : DC 3V to 6V

Ci aprés une librairie Python pour vous simplifier la déclaration des IR.

Class-IR.zip (175 téléchargements)

########################################
#  C L A S S : IR
#
# HUB.BOSSEUR@GMAIL.COM
# http://aubonsurf.free.fr
#######################################
#!/usr/bin/env python
import RPi.GPIO as GPIO



class IR:
	
	# Declaration des E/S
	# Usage   : monIR=IR(PinUtiliser, ModeDeNumerotation)
	# exemple : monIR=IR(4, BCM)
	#			monIR.etatIR() return I/0
	#			monIR.close()
	#
	def __init__(self, pinIR,typeBoard):
		self.pin_IR=pinIR
		print ("LOG-Declaration IR sur PIN"+str(self.pin_IR))
		if typeBoard=='BCM':
			GPIO.setmode(GPIO.BCM) 
			print ("BCM")
		else:
			GPIO.setmode(GPIO.BOARD) 
			print ("BOARD")		
		GPIO.setup(self.pin_IR, GPIO.IN)

	def etatIR(self):
		return GPIO.input(self.pin_IR)
	

	
	
	def close(self):
		GPIO.cleanup() 
		
Class IR

 

J’utilise la bibliothèque passifBuzzer pour piloter le buzzer.

Mettre IR.py et passifBuzzer.py dans votre repertoire et testez:

Le programme de test

########################################
#  Programme de test IR
#
# HUB.BOSSEUR@GMAIL.COM
# http://aubonsurf.free.fr
#######################################
#!/usr/bin/env python
import IR
import time
import passifBuzzer

#NOTES
c3=763
d3=680
e3=606
f3=571
g3=510
a3=454
b3=404
c4=381
d4=340 
e4=303 
f4=286 
g4=255 
a4=227 
a4s=214
b4=202 
c5=191
d5=170
d5s=160
e5=151
f5=143
g5=127
a5=113
a5s=107
b5=101
c6=95
R=0

signalNote=[  f4,  f4, f4,  a4s]
signalTone=[  21,  21, 21,  128]
 
	
if __name__ == '__main__':     # Program start from here
	try:
		myIR=IR.IR(27,"BCM")
		myBuz=passifBuzzer.PassifBuzzer(17, 'BCM')
		myBuz.play(signalNote,signalTone)
		while True:
			time.sleep(1)
			if (myIR.etatIR()==0):
				myBuz.play(signalNote,signalTone)
				

	except KeyboardInterrupt:  # When 'Ctrl+C' is pressed, the child program destroy() will be  executed.
		myIR.close()
		buz.close()
Test IR

One Thought on “IR detecteur”

  1. Hello there, just became aware of your blog through Google, and found that it
    is really informative. I’m going to watch out for brussels.

    I’ll appreciate if you continue this in future. A lot of people
    will be benefited from your writing. Cheers!

Comments are closed.