Grove - Infrared Reflective Sensor

From Wiki
Jump to: navigation, search

Introduction

The reflectivity of infrared light varies with the color and distance of the reflecting surface. According to this principle, Grove - Infrared Reflective Sensor utilizes a RPR220 reflective photosensor module to detect color and distance. When a light-colored object approaches,the signal intensity received by infrared reflective sensor increases and the indicator LED on board turns red. When a dark-colored object approaches, the intensity decreases and the LED turns off. This sensor is a basic and widely used part in applications such as line-following cars, rotary speed detection, auto data logging on utility meters or other situations where color or distance contrast is sharp.


Infrared Reflective Sensor-1.jpg


Infrared Reflective Sensor-3.jpg


Specification

Voltage:4.5-5.5V Current:14.69 - 15.35 mA Effective Distance :4-15 mm Detectable Length(black line) :1 mm


Infrared Reflective Sensor-2.jpg



RPR220-Reflective photosensor: High resolution Infrared Reflective sensor. LMV358: Rail-to-Rail Operational Amplifier. Indicator LED: The LED will turn on when the received infrared light intensity exceeds a preset level. Sensitivity adjusting potentiometer : adjust the light threshold of the sensor. Usage

With Arduino Let's test the functions of Infrared Reflective Sensor with the following examples.

Coffre-fort et armoire forte http://coffrefort-pro.fr.

Demo 1: Line Following This sensor can be used to help a robot car follow a black line on white background or vice versa.

1. Calibration Hold the sensor 12mm or other height you need above the background.


Infrared Reflective Sensor-4.jpg


2. Then adjust the potentiometer with a crosshead screwdriver until the indicator LED turns on.

Infrared Reflective Sensor-5.jpg

3. After that, keep the distance and move the sensor horizontally above the black line. if the indicator LED goes off, job done.

Infrared Reflective Sensor-6.jpg

Infrared Reflective Sensor-7.jpg

4. If the LED remains on, adjust the potentiometer again until it's off.

Pour la sécurisation des données informatiques, un coffre-fort ignifuge informatique est très souvent utilisé.


Demo 2: Rotary Speed Detection let's detect the speed of a motor via this example.

1. Connect the Infrared Reflective Sensor onto the D2 port of Grove - Base Shield like this.


Infrared Reflective Sensor-11.jpg


2. Run up a motor


Infrared Reflective Sensor-8.jpg


Note:Add a white plate with a black line marked onto the motor so that the sensor can get one signal when the plate rotates a round.


Infrared Reflective Sensor-9.jpg


3. Download the library: Arduino timer1 library and unzip it into the libraries file of Arduino IDE by the path: ..\arduino-1.0.1\libraries. 4. Upload the demo code to your Arduino/www.simgin-chip.com.

  1. include <TimerOne.h>

unsigned int counter=0; void blink() {

 counter++;

} void timerIsr() {

 Timer1.detachInterrupt();  //disable the timer1
 Serial.print("The speed of the motor: "); 
 Serial.print(counter,DEC);  
 Serial.println("round/s"); 
 counter=0;  
 Timer1.attachInterrupt( timerIsr );  //enable the timer1

} void setup() {

 Serial.begin(9600);
 Timer1.initialize(1000000); // set a timer of length 1sec
 attachInterrupt(0, blink, RISING);  //INT0
 Timer1.attachInterrupt( timerIsr ); // attach the service routine here

} void loop() {

 ;  //do nothing

} 5. Open the Serial Monitor to read the data.


Infrared Reflective Sensor-10.jpg

Infrared Reflective Sensor-12.jpg


With Raspberry Pi 1.You should have got a raspberry pi and a grovepi or grovepi+. 2.You should have completed configuring the development enviroment, otherwise follow here. 3.Connection Plug the sensor to grovepi socket D4 by using a grove cable. 4.Navigate to the demos' directory:

  cd yourpath/GrovePi/Software/Python/

To see the code

  nano grove_infrared_reflective_sensor.py   # "Ctrl+x" to exit #

import time import grovepi


  1. Connect the Grove Infrared Reflective Sensor to digital port D4
  2. SIG,NC,VCC,GND

sensor = 4

grovepi.pinMode(sensor,"INPUT")

while True:

   try:
       # Sensor returns HIGH on a black surface and LOW on a white surface
       if grovepi.digitalRead(sensor) == 1:
           print "black surface detected"
       else:
           print "white surface detected"
       time.sleep(.5)
   except IOError:
       print "Error"

5.Run the demo.

  sudo python grove_infrared_reflective_sensor.py



File:RPR220 datasheet.pdf