flash LED wirelessly .... please help :(
Zakariya
Posts: 3
hi every one
i am new for BS microcontroller
i work on project that flash LEDs wirelessly (xbee ) using IR sensor
to make my explaination simple see digram below
..................transmitter.........................................receiver.....................
IR sensor ==> BS2 ==> Xbee ................. Xbee ==> BS2 ==> LEDs
i built sketch for both the receiver and transmitter so :
when the sensor 1 detect ... led 1 will shutdown
when the sensor 2 detect ... led 2 will shutdown
________________________
the problem now is when both sensor detect one of the LED will shutdown only
i think the problem with sketch of the receiver......please help
this is my sketch for transmitter
*************
' {$STAMP BS2}
' {$PBASIC 2.5}
ir_detect VAR Byte
LOW 7
DO
DEBUG CLS
ir_detect = IN8
IF (IN8 = 0 ) THEN
DEBUG "Output 8 is high, no object detected." ,CR
ELSE
DEBUG "Output is 8 low, object is detected. " ,CR
SEROUT 14, 84, ["A"]
ENDIF
ir_detect = IN9
IF (IN9 = 0 ) THEN
DEBUG "Output 9 is high, no object detected." ,CR
ELSE
DEBUG "Output 9 is low, object is detected. " ,CR
SEROUT 14, 84, ["B"]
ENDIF
ir_detect = IN10
IF (IN10 = 0 ) THEN
DEBUG "Output 10 is high, no object detected." ,CR
ELSE
DEBUG "Output 10 is low, object is detected. " ,CR
SEROUT 14, 84, ["C"]
ENDIF
ir_detect = IN11
IF (IN11 = 0 ) THEN
DEBUG "Output 11 is high, no object detected." ,CR
ELSE
DEBUG "Output 11 is low, object is detected. " ,CR
SEROUT 14, 84, ["D"]
ENDIF
PAUSE 1000
LOOP
*************
............................................receiver............................................
******************
' {$STAMP BS2}
' {$PBASIC 2.5}
x VAR Byte
LOW 7
DO
SERIN 14, 84, [ x]
DEBUG ? x
IF (x= 65) THEN
LOW 8
ELSE
HIGH 8
ENDIF
IF (x= 66) THEN
LOW 9
ELSE
HIGH 9
ENDIF
IF (x= 67) THEN
LOW 10
ELSE
HIGH 10
ENDIF
IF (x= 68) THEN
LOW 11
ELSE
HIGH 11
ENDIF
PAUSE 250
LOOP
END
*******************
i am new for BS microcontroller
i work on project that flash LEDs wirelessly (xbee ) using IR sensor
to make my explaination simple see digram below
..................transmitter.........................................receiver.....................
IR sensor ==> BS2 ==> Xbee ................. Xbee ==> BS2 ==> LEDs
i built sketch for both the receiver and transmitter so :
when the sensor 1 detect ... led 1 will shutdown
when the sensor 2 detect ... led 2 will shutdown
________________________
the problem now is when both sensor detect one of the LED will shutdown only
i think the problem with sketch of the receiver......please help
this is my sketch for transmitter
*************
' {$STAMP BS2}
' {$PBASIC 2.5}
ir_detect VAR Byte
LOW 7
DO
DEBUG CLS
ir_detect = IN8
IF (IN8 = 0 ) THEN
DEBUG "Output 8 is high, no object detected." ,CR
ELSE
DEBUG "Output is 8 low, object is detected. " ,CR
SEROUT 14, 84, ["A"]
ENDIF
ir_detect = IN9
IF (IN9 = 0 ) THEN
DEBUG "Output 9 is high, no object detected." ,CR
ELSE
DEBUG "Output 9 is low, object is detected. " ,CR
SEROUT 14, 84, ["B"]
ENDIF
ir_detect = IN10
IF (IN10 = 0 ) THEN
DEBUG "Output 10 is high, no object detected." ,CR
ELSE
DEBUG "Output 10 is low, object is detected. " ,CR
SEROUT 14, 84, ["C"]
ENDIF
ir_detect = IN11
IF (IN11 = 0 ) THEN
DEBUG "Output 11 is high, no object detected." ,CR
ELSE
DEBUG "Output 11 is low, object is detected. " ,CR
SEROUT 14, 84, ["D"]
ENDIF
PAUSE 1000
LOOP
*************
............................................receiver............................................
******************
' {$STAMP BS2}
' {$PBASIC 2.5}
x VAR Byte
LOW 7
DO
SERIN 14, 84, [ x]
DEBUG ? x
IF (x= 65) THEN
LOW 8
ELSE
HIGH 8
ENDIF
IF (x= 66) THEN
LOW 9
ELSE
HIGH 9
ENDIF
IF (x= 67) THEN
LOW 10
ELSE
HIGH 10
ENDIF
IF (x= 68) THEN
LOW 11
ELSE
HIGH 11
ENDIF
PAUSE 250
LOOP
END
*******************
Comments
Assuming the transmitter program is behaving as you expect, you should be able to see the data activity lights on the XBee's as the data is sent from the transmitter to receiver.
On the receiver Stamp, there is no communication buffer so the SERIN must be occurring at the instant the data arrives from the transmitter. We can get around that problem by using the WAIT modifier in the SERIN command. This will force the SERIN to wait for some period of time as it executes so that there is a much better chance for the transmitted character to arrive. If you look at the Helpfile under SERIN, there is a detailed explanation of the modifiers available to use for serial communication.
Cheers,
.
thanks for replay
I check that before but I got error may be I misunderstand ........
actually I did some modification on program
for transmitter
' {$STAMP BS2}
' {$PBASIC 2.5}
ir_detect1 VAR Byte >>>>>>>'sensor 1>>>>>'LED1
ir_detect2 VAR Byte>>>>>>>'sensor 2>>>>>'LED2
ir_detect3 VAR Byte>>>>>>>'sensor 3>>>>>'LED3
ir_detect4 VAR Byte>>>>>>>'sensor 4>>>>>'LED4
LOW 7
DO
DEBUG CLS
ir_detect1 = IN1
IF (IN1 = 0 ) THEN
DEBUG "Output 1 is low, no object detected." ,CR
ELSE
DEBUG "Output is 1 high, object is detected. " ,CR
SEROUT 14, 84, ["A"]
ENDIF
ir_detect2 = IN5
IF (IN5 = 0 ) THEN
DEBUG "Output 5 is low, no object detected." ,CR
ELSE
DEBUG "Output 5 is high, object is detected. " ,CR
SEROUT 14, 84, ["B"]
ENDIF
ir_detect3 = IN8
IF (IN8 = 0 ) THEN
DEBUG "Output 7 is low, no object detected." ,CR
ELSE
DEBUG "Output 7 is high, object is detected. " ,CR
SEROUT 14, 84, ["C"]
ENDIF
ir_detect4 = IN10
IF (IN10 = 0 ) THEN
DEBUG "Output 10 is low, no object detected." ,CR
ELSE
DEBUG "Output 10 is high, object is detected. " ,CR
SEROUT 14, 84, ["D"]
ENDIF
PAUSE 1000
LOOP
****************************************************************for receiver**********************************************************
' {$STAMP BS2}
' {$PBASIC 2.5}
x1 VAR Byte >>>>>>>'sensor 1>>>>>'LED1
x2 VAR Byte >>>>>>>'sensor 2>>>>>'LED2
x3 VAR Byte >>>>>>>'sensor 3>>>>>'LED3
x4 VAR Byte >>>>>>>'sensor 4>>>>>'LED4
DO
SERIN 14, 84, [x4]
IF (x4= 65) THEN
HIGH 1
ELSE
LOW 1
DEBUG "active",CR
PAUSE 1000
ENDIF
SERIN 14, 84, [x1]
IF (x1= 66) THEN
HIGH 5
ELSE
LOW 5
DEBUG "active",CR
ENDIF
SERIN 14, 84, [x2]
IF (x2= 67) THEN
HIGH 7
ELSE
LOW 7
ENDIF
' SERIN 14, 84, [ x3]
'DEBUG ? x3
'IF (x3= 68) THEN
'HIGH 10
'ELSE
'LOW 10
'ENDIF
PAUSE 1000
LOOP
END
the output behavior now is
>>>>>>> when sensor 4 is detect..... LED 4 is off ( this is what I want for other sensors.... when they detect object ... the LED of sensor in receiver should go off )
>>>>>>> when sensor 3 is detect..... LED 4 and 3 is off
>>>>>>> when sensor 2 is detect..... LED 4 , 3 and 2 is off
>>>>>>> when sensor 1 is detect..... LED 4 , 3 ,2 ,1 is off
can any one tell me why outputs are coming like this??? ..... and how to fix the sketch what to add and what to remove?????
I am still beginner ):
In your transmitter/receiver program, things will be easier if you can consolidate the state of all the detectors into one byte.
For example... Then on the receive side, there is only one byte wait for, and the program there can decode it bit by bit.
thanks a lot Tracy for your replays ...... now it works ....... I will post the project after I finish to make clear for all the people who seek for the same solution
thanks a lot to Stamptrol too