050 - Light Sensing Command

Syntax:

50, BYTE2, BYTE3, BYTE4

Where:
BYTE1: = 50 (The Command)


BYTE2: = Limits for triggering the LED display (see description below)


BYTE3: 01 = Decimal Output
BYTE3: 02 = Ascii Output
BYTE3: 03 = Ascii Delimited Output


BYTE4: 0= one shot command
BYTE4: 255 = continuous
Response from IRCF360:

Depending on the value of BYTE3 the IRCF360 will respond as follows 

Decimal Output : 
[Reading from Right Sensor], [Reading from Left Sensor]  (the output is in WORD format i.e. 2 bytes per sensor)

Ascii Output:
RAW1= [Reading from Right Sensor]  RAW2=[Reading from Left Sensor] CR

ASCII Delimited Output:
[Reading from Right Sensor] ;  [Reading from Left Sensor] CR

Circular Display Feedback:
Based on the value of the BYTE 2 the circular display will illuminate. It has been assumed that the North LED is facing the forward direction. The LED's on either side of the N LED will will illuminated according to the magnitude of the difference between the Right and Left light sensor readings. For example if the light on the left light sensor is higher than the right sensor then the left LEDs will illuminate and visa versa.

The number of left or right LEDs illuminated will depend on the difference between the light sensor right and left readings. The North LED will illuminate if the difference between the two light sensors is less than 5. If the difference is > 5 and greater than BYTE2 then the NW or NE LED will also illuminate. If the difference is 2x the value of SBYTE 2 then the E or W LEDs will also illuminate. If the difference is 3x the value of SBYTE 2 then the SE or SW LEDs will also illuminate. If the difference is 4x the value of SBYTE 2 then the S LEDs will also illuminate.  (See videos)   

Description:
At the front of the IRC360 are two connectors were ambient light sensors can be fitted. The light sensors fitted to this robot are described -> here

The IRCF360 take 10 rapid light readings from the 10bit analogue to digital converter on the right and left sensors.

The value of the light readings are then averaged and the results sent to the RS232 interface for robot controller to act or to log the values in a spreadsheet on a PC.

The circular LED display acts as a visual feedback and flash the LED's depending on the light intensity recorded. It also indicates on which side of the robot the most light currently is shining. The sensitivity of the LED scale's is influenced by the value of BYTE2. In the video below the value was set to 70 and the sensor was pointing towards a window.

Experimentation of different values can be set-up. Setting BYTE2 as 0 will turn off the display.

This is a demo of the command 50 and the visual feedback of the light sensor functionality.

It's really easy to get up and running with building your own robots and saves a lot of time as the sensor interfaces direction with your programmable controller (arduino, basic stamp, picaxe, pololu, etc)
Describe where this command could be useful -
  • Build a Photovore - a light eating robot. Your robot will be able to detect which direction light is coming from, enabling your robot to head towards light (photovore) so re-charging can take place. Light = food - could be particular relevant for robots that have photocells to charge batteries
  • Build a Photophobe robot - A robot that is shy of light and will 'hide' in the shadows (photophobe). This offers many new 'artificial life' experiments and other exciting robot gaming dimensions
  • Additional proximity sensing - Can be used to detect sudden changes in light readings meaning that an obstacle is ahead. This can be particular useful for detecting black objects as this is invisible to Infrared Proximity Sensing.
  • Extend the light sensors and point towards the ground to follow a back line. 
  • Use light as a beacon for guide robots through a maze. Great for maze runner competitions

Technical Features

Two Vishay TEPT4400 Ambient Light Sensors are included within the IRCF360 sensor. These are silicon NPN epitaxial planar phototransistor in a T-1 package. It is sensitive to visible light much like the human eye and has peak sensitivity at 570 nm. Alternatives could be Cadmium Sulphide (CdS) photocells.


The IRCF360 takes 10 rapid light readings from the two 10-bit analogue-to-digital (A2D) converters on the right and left sensors. The values are then sorted using a bubble sort routine. 

Here is an example of a bubble sort routine written in Proton Basic for the Amicus:

Bubble Sort Demo

BUBBLE_SORT: 
Repeat
SWAP_OCCURED = 0 ' Clear flag that indicates swap. 
INDEX = 0
    Repeat ' For each cell of the array...
     If SAMPLE[INDEX] > SAMPLE[INDEX + 1] Then   ' Move larger values up. 
SWAPTMP = SAMPLE[INDEX] ' ..by swapping them. 
SAMPLE[INDEX] = SAMPLE[INDEX + 1]
SAMPLE[INDEX + 1] = SWAPTMP
SWAP_OCCURED = 1' Set bit if swap occurred.  
EndIf
Inc INDEX
    Until INDEX = SAMPLES_TO_TAKE ' Check next cell of the array. 
Until SWAP_OCCURED = 0 ' Keep sorting until no more swaps. 
Return

After sorting, the average reading for left and right light sensors are transimitted via the of RS232 port as a 10 bit data. Don't forget the results from the A2D converter are 10 bits - so either use 4bytes (two bytes for each left / right reading) or 2 words (1 word for each left / right reading) as the variable to receive the information. 

Example Code:
The following command was used to instruct the sensor to continuously monitor the light levels: 

Example code for light sensing - Video 1

SEROUT b.2,T9600_8, (50 ,70,0,255)

Example code for Light tracking - Video 2

IRCF360 Command 050 - Ambient Light Reading Example Code

Note: in this example 4 variable were used to read the 10bit light reading. On this example only the Highbyte1 and Highbyte2 variables were used to compare the values.

LIGHT_READING: SEROUT b.2,T9600_8, (50,25,1,0) SERIN 2,T9600_8, b12 IF b12 <> 50 THEN GOTO Light_Reading SERIN 2,T9600_8, Highbyte1,Lowbyte1,Highbyte2,Lowbyte2 PAUSE 50 RETURN



Videos:


IRCF360 - Command 50 - Ambient Light Sensing




IRCF360 - Command 050 . Ambient Light Sensing 2