Arduino, Laser Obstacle Detection / Proximity Sensing / Line Counter

Introduction: Arduino, Laser Obstacle Detection / Proximity Sensing / Line Counter


The laser proximity sensor is used for detecting objects, by passing the laser light on the object and detecting the reflected laser. This proximity sensor (obstacle / object detector) will detect, very small size objects too with in the detection range. This is because the laser light ray is much focused and almost have no divergence over small distances. Laser proximity sensor module provides the digital output signal, which is connected to the Arduino digital IO pin. Software will read the digital IO pin value and displayed on the connected MAX7219 seven segment display (Obstacle / Free indication / Obstructed count), also prints via the serial port for further analysis.

Parts and components

Arduino Uno board = 1 No

Laser Proximity Sensor = 1 No

MAX7219 Seven Segment Display Module = 1 No

Step 1: Schematic

The laser proximity sensor is used for detecting objects, by passing the laser light on the object and detecting the reflected laser.

The Sensor includes laser source (transmitter), laser detector (receiver) and signal amplification (conditioning circuit).

The transmitter is an oscillating tube can generate a shockwave in a frequency of 180KHz. After amplified by a transistor, the shockwave is applied to the laser tube for exciting.

The receiver, in the receiving tube, matching to the oscillating tube, can receive the reflected light.

Since the laser sensor adopts modulation processing technology, the receiving tube can only receive the reflected light in a same frequency, efficiently preventing from the visible light.

Sensor effective distance of measurement is 0.8 meters to 1.5 meters.

Can be used for obstacle detection, pipeline counting and proximity detection.

The laser proximity sensor has three signals:- VCC, GND and DOUT.

Sensor Dout pin is connected to D5 digital IO pin of Arduino.

The MAX7219 display module provides a 3-wire serial (SPI) interface to drive 7-segment LED displays (common-cathode type) up to 8 digits.

The on-chip includes a BCD decoder, multiplex scan circuitry, segment and digit drivers, and an 8×8 static RAM to store the digit values.

The DIN, LOAD and CLOCK pins of MAX7219 is connected with 4,2 and 3 digital IO pins of Arduino.

Step 2: Software

The Arduino LedControl library is used for displaying alphanumeric digits on MAX7219.

Software will detect the obstacle and shows on connected MAX7219 seven segment display (Obstacle / Free).

Also the “number of times obstructed” (three digit counter) will be displayed, when “Free” is shown at connected display.

Once count value reaches to 999, then the software will reset it to zero.

When debug flag is enabled at compile time, then the software will sends the debug information to serial port.

// Demonstrates the use of Laser obstacle detection.

// The Arduino circuit connection for 7219: // MAX7219 DIN pin to Arduino digital pin 4 // MAX7219 LOAD pin to Arduino digital pin 3 // MAX7219 CLOCK pin to Arduino digital pin 2

// Laser Module digital output to Arduino digital pin 5 // Name:- M.Pugazhendi // Date:- 24thAug2016 // Version:- V0.1 // e-mail:-


#define AA B01110111 #define BB B00011111 #define CC B00001101 #define EE B01101111 #define FF B01000111 #define LL B00001110 #define OO B00011101 #define RR B00000101 #define SS B01011011 #define TT B00001111

//We always have to include the library #include "LedControl.h"

unsigned int count = 0x00; unsigned int count_one = 0x00; unsigned int previous = 0x00;

int detect_obstacle=5;

LedControl myDisplay=LedControl(4,2,3,1);

void setup() { pinMode(detect_obstacle,INPUT); //The MAX7219 is in power-saving mode on startup, we have to do a wakeup call myDisplay.shutdown(0,false); //Set the brightness to a medium values myDisplay.setIntensity(0,8); //Clear the display myDisplay.clearDisplay(0); #ifdef DEBUG_PRINT Serial.begin(9600); Serial.println("Laser Obstacle detection / counter"); // 2 Second delay delay(2000); #endif } void loop() { if(digitalRead(detect_obstacle)==LOW) { if(previous == count) { #ifdef DEBUG_PRINT Serial.println("Obstruct"); #endif count++; //Reset the counter if(count >= 1000) { count = 0; } myDisplay.clearDisplay(0); //Show the finding on 7 Segment display myDisplay.setRow(0,7,OO); myDisplay.setRow(0,6,BB); myDisplay.setRow(0,5,SS); myDisplay.setRow(0,4,TT); myDisplay.setRow(0,3,AA); myDisplay.setRow(0,2,CC); myDisplay.setRow(0,1,LL); myDisplay.setRow(0,0,EE); } } else { if(previous != count) { #ifdef DEBUG_PRINT Serial.println("Free"); //print the counted value Serial.print("Count ="); Serial.println(count); #endif myDisplay.clearDisplay(0); //Show the finding on 7 Segment display myDisplay.setRow(0,7,FF); myDisplay.setRow(0,6,RR); myDisplay.setRow(0,5,EE); myDisplay.setRow(0,4,EE); count_one = HexToBCD(count); myDisplay.setDigit(0, 2, ((count_one>>8)&0x0F), false); myDisplay.setDigit(0, 1, ((count_one>>4)&0x0F), false); myDisplay.setDigit(0, 0, (count_one&0x0F), false); previous = count; } } delay(100); }

/**************************************************************************/ /*! * \brief Coverts hex into BCD * * This function will coverts hex into BCD * * \param[in] byte * \param[out] byte * \return Nill * */ /**************************************************************************/ unsigned int HexToBCD(unsigned int number) { unsigned char i=0; unsigned int k = 0;

while(number) { k = ( k ) | ((number%10) << i*4); number = number / 10; i++; }

return(k); }

Step 3: Conclusion

The project is successfully completed with Arduino UNO, Laser Proximity Sensor module and Max7219 Seven segment display module.

The laser module will generate the laser, and whenever the laser light is interrupted, then writes a high level on its digital pin.

The obstacle detection, line count will be shown on connected display, as well as serial port print message.

Be the First to Share


    • Mason Jar Speed Challenge

      Mason Jar Speed Challenge
    • Bikes Challenge

      Bikes Challenge
    • Remix Contest

      Remix Contest

    2 Discussions


    4 years ago

    Do you have a model / part number of your proximity sensor?


    Reply 4 years ago

    Please find in attached html page