KY-032 Obstacle-detect module

From SensorKit X40 Wiki

Jump to: navigation, search

Picture

ky-032.jpg

Technical data / Short description

If the sended infrared light hits an obstacle, the light will be reflected and detected by the photodiode.
The detection range can be configured by the 2 controllers.

The behaviour of this can be used for Controllers, for example to stop a robot automatically which drives straight to an obstacle.

Condition 1: There is no obstacle in front of the detector [LED on the module: Off] [Sensor signal= Digital On]

KY-032 OFF.jpg


Condition 2: Detector detects an obstacle [LED on the module: ON] [Sensor Signal= Digital Off]

 
KY-032 ON.jpg


This sensor allows you to activate and deactivate the obstacle detection by manipulating the enable-pin.
It is activated by default which means that the sensor is in detection mode by default.
If you don't want that, you need to remove the jumper with the label "EN" and put a control signal on the enable pin.


KY-032 Jumper.jpg

Code example Arduino

This program reads the status of the sensor pin and prints it to the serial terminal if an obstacle was detected.

int Sensor = 10; // Declaration of the sensor input pin
  
void setup ()
{
  Serial.begin(9600); // Initialization serial output
  pinMode (Sensor, INPUT) ; // Initialization sensor pin
}
  
// The program reads the current status of the sensor pin
// shows via serial console if the sensor detects a obstacle or not
void loop ()
{
  bool val = digitalRead (Sensor) ; // The current signal at the sensor will be read
  
  if (val == HIGH) // If a signal is detected, the LED will light up.
  {
    Serial.println("No obstacle");
  }
  else
  {
    Serial.println("Obstacle detected");
  }
  Serial.println("------------------------------------");
  delay(500); // Break of 500ms between each measurement
}

Connections Arduino:

Sensor enable = [N.C. (jumper plugged in)]
Sensor signal = [Pin 10]
Sensor +V = [Pin 5V]
Sensor GND = [Pin GND]

Example program download

KY-032_Obstacle-detection

Code example Raspberry Pi

# Needed modules will be imported and configured
import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)

# Declaration of the input pin which is connected with the sensor.
GPIO_PIN = 24
GPIO.setup(GPIO_PIN, GPIO.IN, pull_up_down = GPIO.PUD_UP)

# Break between the results will be defined here (in seconds)
delayTime = 0.5

print "Sensor-Test [press ctrl+c to end]"

# main program loop
try:
        while True:
            if GPIO.input(GPIO_PIN) == True:
                print "No obstacle"
            else:
                print "Obstacle detected"
            print "---------------------------------------"

            # Reset + Delay
            time.sleep(delayTime)

# Scavenging work after the end of the program
except KeyboardInterrupt:
        GPIO.cleanup()

Connections Raspberry Pi:

Enable = - [N.C. (jumper plugged in)]
Signal = GPIO24 [Pin 18]
+V = 3,3V [Pin 1]
GND = GND [Pin 6]

Example program download

KY-032_Obstacle-detection_RPi

To start, enter the command:

sudo python KY-032_Obstacle-detection_RPi.py