IR Array

The IR Array consists of 3 IR (Infrared) sensors. Look closely and you will see that each sensor has two ‘dots’, one blue and one black. The blue one is an IR LED and the black one is the actual IR sensor. When connected to power, the IR LED emits infrared light. You can not see it with your own eyes but if you have a camera in your mobile phone you can direct it towards the LED and on the mobile screen you will see the IR light very clearly.
When you hold the sensors close to a white surface, the white surface will reflect a lot of the IR light emitted by the LED, which will be detected by the IR sensor. If you hold it over a black surface, instead almost no IR light will be reflected. This is how it can distinguish black from white.

https://vimeo.com/93635860

Materials

  • 1 Arduino Uno board
  • 1 Education Shield
  • 1 IR Array
  • 5 jumper wires

Instructions


  1. Attach the shield onto the top of the Arduino board.
  2. Connect IR1 to A1, IR2 to A2 and IR3 to A3.
  3. Connect the IR Arrays GND to GND and 5V to 5V.
  4. Connect the board to the computer and upload example ‘IRArray’.

Code

Find the code in File>Examples>EducationShield>Help>IRArray

You should now open the serial monitor and move the IRArray over a black or white surface. If a sensor is over a black surface, a value around 330 should be printed, if over a white surface, the value should be around 400.

Commands

  • IRArray( IR1, IR2, IR3 ) – Creates an IRArray object
    • Parameters
      • (int) IR1 – the analog pin to which the first IR sensor is connected to.
      • (int) IR2 – the analog pin to which the second IR sensor is connected to.
      • (int) IR3 – the analog pin to which the third IR sensor is connected to.

  • test() – prints all the IR sensor readings to the serial monitor.

  • setThreshold(threshold) - Sets the threshold value between black and white. Use test() first to check the readings from black and white, then decide on a threshold value between those values. 
    • Parameters
      • (intthreshold - The threshold value between black and white. Default is 380.

Other commands:

  • readLine() – returns the direction of a black line on a white surface.
    • Return
      • (int) - Value between -100 to 100. When it is close to 0, the IR array is in middle of the black line. When it is close to -100 or 100, it is offset to the sides.

  • readBinary() – Returns the binary value combined from the individual IR sensor readings.
    • Return
      • (int) – A value between 0 and 7. See table below for the value representation.

Troubleshooting

  • Make sure the connections between the IR Array, wires and board are correct.
  • If you move IR1 from black to white but only the value of IR2 is changed, you need to either change the analog pins in the code or change the connections to the analog pins on the Arduino.