Sketches: Obstacle Avoidance Sensor Module

HCMODU0006_800_600_NEW
IR Distance Sensing Module

 

Items you will need:

Arduino development board, like this one

Male to female dupont cables

Obstacle avoidance sensor

 

What does it do?

This module allows for sensing of solid objects within a fixed range (adjustable with on-board potentiometer). Ideal for robotic applications. This is a simple example of how to use the Hobby Components obstacle avoidance sensor module (HCMODU0006). It is a very simple module that requires only one DIO pin (defined as an input) to operate. When the sensor detects a reflective object in close proximity it will pull a connected DIO pin LOW. A non reflective or no object in close proximity will cause the DIO pin to go high.

Pinout:

PIN 1: GND
PIN 2: +5V
PIN 3: DATA OUT
PIN 4: ENABLE (NOT CONNECTED)

Code:

/* FILE:    ARD_Obstacle_Avoidance_Sensor_Module_HMODU0006_Example
DATE:    04/06/13
VERSION: 0.1

You may copy, alter and reuse this code in any way you like, but please leave reference to HobbyComponents.com in your comments if you redistribute this code. This software may not be used directly for the purpose of selling products that
directly compete with Hobby Components Ltd's own range of products.

THIS SOFTWARE IS PROVIDED "AS IS". HOBBY COMPONENTS MAKES NO WARRANTIES, WHETHER
EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ACCURACY OR LACK OF NEGLIGENCE.
HOBBY COMPONENTS SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR ANY DAMAGES,
INCLUDING, BUT NOT LIMITED TO, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY
REASON WHATSOEVER.

*/

/* Define the DIO pin that will be used to communicate with the sensor */
#define SENS_DIO 2

/* Initialise serial and DIO */
void setup()
{
/* Setup the serial port for displaying the status of the sensor */
Serial.begin(9600);

/* Configure the DIO pin the sensor will be connected to as an input */
pinMode(SENS_DIO, INPUT);
}

/* Main program loop */
void loop()
{
/* If the DIO pin is pulled low then an object has been detected */
if (!digitalRead(SENS_DIO))
Serial.println("Object detected !");

}

Add a Comment

Your email address will not be published.