Picaxe IR LED

krogerssolar

Senior Member
Hi all I have code for a IR Railroad track side signal indicator control the code below is for two led's and two Ir Receivers I'm Building a switch yard and was wondering if i could have each picaxe say 4 or 5. I would like any of the picaxe's to trigger the red led code on each Pixace so when the Ir is tripped on one picaxe it will trigger on the others until the Ir beam is restored. Is this Idea Possible.

Code:
#PICAXE 14M2

; define the IO pin assignments
SYMBOL GreenLight = b.1
SYMBOL RedLight   = b.2
SYMBOL IRIN1     = pinc.3 ; The IR input to detect train presence
SYMBOL IRIN2     = pinc.2 ; The IR input to detect train presence

;Define the variables
SYMBOL flasher    = b6  ; used to count number of cycles in yellow/amber flash mode
;Define the constants
SYMBOL Red_Off_Delay        = 8000 ; milliseconds


Initialise:
	LOW GreenLight	   ; Green LED on
	HIGH RedLight	   ; Red LED off



MAIN:
 
DO 
     IF IRIN1 =1 or IRIN2 =1 THEN  ; IR beam is broken
 	HIGH GreenLight		   ; Green LED off
  	LOW  RedLight		   ; Red LED on

Wait_Till_clear:
    IF IRIN1 =1 or IRIN2 =1 THEN Wait_Till_clear
    
	PAUSE Red_off_Delay	   ; wait for the red phase period to end
	HIGH RedLight		   ; Red LED off
	LOW GreenLight		   ; Green LED on
	
  ELSE ; IR beam is received
	LOW GreenLight	   ; Green LED on
	HIGH RedLight	   ; Red LED off
  ENDIF
LOOP
 

inglewoodpete

Senior Member
There are a couple of possible solutions. One would be to have serial communications between each of the PICAXEs but the coding required would be quite complicated.

A simpler solution would be to have a single wire "state" bus connected in an "wired diode or" arrangement. The wire has a single pull-up resistor and each PICAXE has an output pin connected via a blocking diode to the bus. Each PICAXE monitors the state of the wire with a second pin. Code is written to pull the output low when one PICAXE wants to assert the 'busy' state while every PICAXE will monitor and respond to this indication.
 

erco

Senior Member
Do you really need full SIRC protocol for your IR signal? You'll need a timeout on your IRIN function. Is your IR source a switchable, multifunction remote control you're using (TV remote or a PICAXE using IROUT) or just a fixed signal?

I often use IR sources flashing at slightly different frequencies as beacons. The IR receiver picks these signals up and the Picaxe uses COUNT to determine which beacon it sees. You can use a Picaxe as the beacon or a 556 timer, and you can adjust the signal strength by voltage and series resistor on the IR LED.

Even though most IR receivers are not continuous signal compatible, many will work over a narrow modulation frequency range generated by the attached schematic by varying R between 8K and 15K.

 

Attachments

krogerssolar

Senior Member
Thanks For the info.

Erco I'm using another 14m2 power IR LEDs with the code below.

Code:
rem sends 38 kHz pulse to IR LED - constant on

symbol irled1 = b.2		'IR LED is connected to output pin out2
symbol irled2 = b.4		'IR LED is connected to output pin out3
symbol irled3 = c.2		'IR LED is connected to output pin out4
symbol irled4 = c.0		'IR LED is connected to output pin out5
symbol LED = b.1		'red LED is connected to output pin out1

main:
low LED			'turn on red LED
pause 1000
high LED
pwmout irled1, 25, 52 	'PWM on for 26 usec period 38.4kHz
pwmout irled2, 25, 52 	'PWM on for 26 usec period 38.4kHz
pwmout irled3, 25, 52 	'PWM on for 26 usec period 38.4kHz
pwmout irled4, 25, 52 	'PWM on for 26 usec period 38.4kHz
low LED
goto main			'go to start and do it again

Then I have other Picaxes with there own codes waiting for the beams to break when the IR receiver Voltage drops just wondering on the other ones if they could all talk to each other to trigger there LED triggers like this code on say 4 other picaxe tide together.

Code:
#PICAXE 14M2

; define the IO pin assignments
SYMBOL GreenLight = b.1
SYMBOL RedLight   = b.2
SYMBOL IRIN1     = pinc.3 ; The IR input to detect train presence
SYMBOL IRIN2     = pinc.2 ; The IR input to detect train presence

;Define the variables
SYMBOL flasher    = b6  ; used to count number of cycles in yellow/amber flash mode
;Define the constants
SYMBOL Red_Off_Delay        = 8000 ; milliseconds


Initialise:
	LOW GreenLight	   ; Green LED on
	HIGH RedLight	   ; Red LED off



MAIN:
 
DO 
     IF IRIN1 =1 or IRIN2 =1 THEN  ; IR beam is broken
 	HIGH GreenLight		   ; Green LED off
  	LOW  RedLight		   ; Red LED on

Wait_Till_clear:
    IF IRIN1 =1 or IRIN2 =1 THEN Wait_Till_clear
    
	PAUSE Red_off_Delay	   ; wait for the red phase period to end
	HIGH RedLight		   ; Red LED off
	LOW GreenLight		   ; Green LED on
	
  ELSE ; IR beam is received
	LOW GreenLight	   ; Green LED on
	HIGH RedLight	   ; Red LED off
  ENDIF
LOOP
 
Top