Experiment 7- Optical Sensors I

In this experiment, we want to use IR sensor and check its performance


Materials: Two 470 ohm resistor, two battery holder, IR sensor, BC 557 Transistor, two different buzzers, two 9 V batteries, IR emitter LED, a remote control



Task:

For using an IR sensor we should make the following circuit. For making this circuit, we should make the following connections:



  1. Connect the battery to the sensor according to the picture.
  2. Connect the positive port of sensor to the emitter and GND port of sensor to the negative terminal of the buzzer.
  3. Connect the positive terminal of the buzzer to the transistor collector.
  4. Connect one end of the resistor to the base of the transistor and another end of the resistor to the outport of sensor.

Now you can use your IR sensor. Bring your hand near to the infrared signal receiver of the sensor. You will hear a sound from the buzzer.


Check the infrared signal transmitter of the sensor

For this check, you can bend the signal transmitter. Now when you move your hand near the signal receiver, it does not make a sound. Make your hand in a way that the receiver makes a noise.


Check with infrared lights

Now turn on the flashlight of your mobile device. When you move it near the infrared light receiver, what will happen?

Again check this experiment with one remote control device.


Check with IR emitter LED

Make the following circuit

 

 

In this circuit, the LED will emit the IR light. So, if you move it near the sensor it should make a noise.


Check the Movement Direction with Buzzers and IR Sensors

Sometimes you need to check the movement direction of your product in a production line but you cannot watch it. What can you do?

For this problem, you can use two IR sensors with two different buzzers. The circuit for using the IR sensor and buzzer is same as previous one. Just you need to put them in a certain distance together. According to the direction of movement you can hear two different sounds and by using them you can find the movement direction.




Distance measurement

In this experiment, we are using TCRT5000 sensor for measuring distance and detecting an object

Materials: One TCRT5000 IR sensor, one breadboard, some cables, one Arduino

The sensor has four terminals. Connect GND and VCC to GND and 5v ports of Arduino. Connect A0 and D0 to A0 and pin8 of Arduino.

Run the following code.

In the serial monitor, you can see the analog output and digital output (when it detects an object the digital output will be zero and when it does not detect any object it will be one).


const int pinIRd=8;

const int pinIRa=A0;


int IRvalueA=0;

int IRvalueD=0;

void setup() {

  // put your setup code here, to run once:

Serial.begin(9600);

pinMode(pinIRd,INPUT);

pinMode(pinIRa,INPUT);


}


void loop() {

  // put your main code here, to run repeatedly:

Serial.print("Analog Reading:");

Serial.print(IRvalueA);

Serial.print("\t Digital Reading:");

Serial.println(IRvalueD);


delay(500);

IRvalueA= analogRead(pinIRa);

IRvalueD= digitalRead(pinIRd);

}




Counting system

In this experiment, we want to make a counting system

Materials: One  TCRT5000, IR sensor, one breadboard, some cables, one Arduino


We can use the same circuit as the previous experiment, but just using the digital output of the sensor. By using the following code in Arduino we can count the number of objects which come in front of the sensor.


const int pinIrd = 8;

int IRvalued = 0;

int TotalNo = 0;

void setup() {

  // put your setup code here, to run once:

Serial.begin(9600);

pinMode(pinIrd,INPUT);

}


void loop() {

  // put your main code here, to run repeatedly:

IRvalued = digitalRead(pinIrd);

if (IRvalued == 0) {

    Serial.println("another object is detected");

    TotalNo = TotalNo + 1;

    delay(1000);

    Serial.println(TotalNo);

}}


Direction detection


In this experiment, we want to detect the movement direction of an object.

Materials: Two  TCRT5000 IR sensor, one breadboard, some cables, one Arduino, Two LEDs


The sensor has four terminals. Connect GND and VCC to GND and 5v ports of Arduino. Connects A0 and D0 to A0 and pin8 of Arduino. Connect LEDs’ Cathode to GND of Arduino and Anode to Port4 and 5.

Run the following code.


const int pinIr1p = 8;

const int pinIr2p = 12;

int ledOne=5;

int ledTwo=4;

int IRvalue1p = 0;

int IRvalue2p = 0;

int IRvalue1pdiff = 0;

int IRvalue1plast = 0;

int IRvalue2pdiff = 0;

int IRvalue2plast = 0;


void setup() {

  // put your setup code here, to run once:

Serial.begin(9600);

  pinMode(pinIr2p,INPUT);

  pinMode(pinIr1p,INPUT);

  pinMode(ledTwo,OUTPUT);

  pinMode(ledOne,OUTPUT);

}


void loop() {

  // put your main code here, to run repeatedly:

IRvalue1p = digitalRead(pinIr1p);

IRvalue2p = digitalRead(pinIr2p);

IRvalue2p = 1- IRvalue2p;

IRvalue1p = 1- IRvalue1p;

IRvalue1pdiff=IRvalue1p-IRvalue1plast;

IRvalue2pdiff=IRvalue2p-IRvalue2plast;


if (IRvalue1pdiff > 0) {

  if (IRvalue2p == 1) {

    Serial.println("object is moving from sensor two to one");

    digitalWrite(ledTwo,HIGH);

    delay(100);

  }

  else if (IRvalue2p == 0) {

    Serial.println("object is moving from sensor one to two");

    digitalWrite(ledOne,HIGH);

    delay(100);

  }}

else if (IRvalue1pdiff < 0) {

  if (IRvalue2p == 1) {

    Serial.println("object is moving from sensor one to two");

    digitalWrite(ledOne,HIGH);

    delay(100);

  }

  else if (IRvalue2p == 0) {

    Serial.println("object is moving from sensor two to one");

    digitalWrite(ledTwo,HIGH);

    delay(100);

  }}

   else{

    Serial.println("no change in sensor one state");

    digitalWrite(ledOne,LOW);

    digitalWrite(ledTwo,LOW);

}

    delay(200);

    IRvalue2plast=IRvalue2p;

    IRvalue1plast=IRvalue1p;

    Serial.println(IRvalue1p);

    Serial.println(IRvalue2p);

}


In the serial monitor, you can see the movement direction of the object and when the right LED is on it means that the object is moving from right to left and vice versa.


Institut für Mechatronik im Maschinenbau (iMEK), Eißendorfer Straße 38, 21073 Hamburg