Home Code IR obstacle avoidance sensor example

IR obstacle avoidance sensor example

by shedboy71
[lebox id="1"]

Another sensor and this one goes by the title of a Ky-032 Infrared Obstacle Avoidance Sensor Module

ky-032jpg

Basically its an IR emitter and receiver, the receiver detects when an obstacle has been placed in the beam of the IR emitter output this is then sent back as a logic low when an obstacle is present and a logic high when no obstacle is present, when connected to and Arduino you can perform an action, a common use would be in a robot where you wished to detect the presence of an object, lets say a wall and either stop or change direction, your robot may in fact have more than one of these.

Specifications

  • Working voltage: DC 3.3V-5V
  • Working current: ≥ 20mA
  • Operating temperature: -10 ℃ – +50 ℃
  • detection distance :2-40cm
  • IO Interface: 4-wire interfaces (- / + / S / EN)
  • Output signal: TTL level
  • Effective angle: 35 °

here are the connections I used

Sensor Wemos Mini
G GND
V+ 5v
S PIN 8
EN Not connected

Code

[codesyntax lang=”cpp”]

int detector = 8; // define the obstacle avoidance sensor interface
int val ;

void setup ()
{
  pinMode(13, OUTPUT);     // Built in Arduino LED
  digitalWrite (13, LOW);
  pinMode (detector, INPUT) ;// define the obstacle avoidance sensor output interface
}

void loop ()
{
  val = digitalRead (detector) ;
  if (val == HIGH) // When the obstacle avoidance sensor detects a signal, LED flashes
  {
    digitalWrite (13, HIGH);
    delay(100);
  }
  else
  {
    digitalWrite (13, LOW);
    delay(100);
  }
}

[/codesyntax]

 

Links

Under $1 for the individual sensor, the 37 sensor kit comes in at about $25 and is good value for the amount of experimenting you can do
IR Infrared Obstacle Avoidance Sensor Module for Arduino Smart Car Robot 3-wire Reflective Photoelectric New

37 in 1 box Sensor Kit For Arduino Starters brand in stock good quality low price

Share
[lebox id="2"]

You may also like