Exercise 17 - Connecting an infrared obstacle detector module

1.      INTRODUCTION

An infrared obstacle detector is composed by two LED diode the first one emit in infrared spectre and the second one receive the rebound emissions. If this received rebound is enough, the module sends HIGH state by OUTPUT terminal.

The detection distance can be regulated by the potentiometer soldered to the module.


2.      HOW TO CONNECT?

This module has three terminals (OUT, GND, VCC) which are connected to pin4, Ground and 5V respectively. Also you can connect a led to pin 13 to test the sensor.

EXERCISE_A (Testing the sensor)

 

Materials:

·         Arduino UNO board

·         Protoboard

·         Some wire Jumpers

·         IR obstacle sensor

·         LED

·         220 ohms resitor


3.      PROGRAMMING

 

This program tests Infrared LED obstacle sensor turning on a LED when an obstacle is detected.

int led=13;

int sensor=4;

void setup(){

  pinMode(led,OUTPUT);

  pinMode(sensor,INPUT);

}

 

Loop is written with standard digital sensor test code.

 

void loop(){

  //On "if" condition sensor is read, whether it is in LOW state

  //led turn on

  if(digitalRead(sensor)==LOW){

    digitalWrite(led,HIGH);

  }

  else{

    digitalWrite(led,LOW);

  }

}


Última modificación: Tuesday, 21 de January de 2020, 10:29