Back to Arduino Step By Step Course

Lesson 72: Obstacle detection using laser transmitter and receiver with Arduino

If you don't like to see ads while video is being played you can purchase this course for $200 from Udemy or purchase YouTube premium Here

Part 7: Obstacle Avoidance with Arduino

This video shows you how to use Laser Transmitter (TX) module and Laser Receiver (RX) module to detect obastacle using Arduino. The code and methods have been explained in the video.

  * Lesson 77: How to use Laser Transmitter and Receiver 
  to detect obstacle using Arduino

 Written by Ahmad Shamshiri for
 on Feb 02, 2018 at 18:24 in Ajax, Ontario, Canada

 * Original library:
 * Watch Video instrution for this code:
 * Full explanation of this code and wiring diagram is available at
 * my Arduino Course at here:

 * Written by Ahmad Shamshiri on Feb 03, 2018 at 07:34
 * in Ajax, Ontario, Canada.

If you found this tutorial helpful, please support me so I can continue creating 
content like this make donation using PayPal

 *  * This code is "AS IS" without warranty or liability. Free to be used as long as you keep this note intact.* 
 * This code has been download from
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <>.


#define DETECT 2 // pin 2 for  sensor
#define ACTION 8 // pin 8 for action to do someting

void setup() {
  Serial.println(" Laser Module Test");
  pinMode(DETECT, INPUT);//define detect input pin
  pinMode(ACTION, OUTPUT);//define ACTION output pin

  // Laser sensor code for


void loop() {
     // Laser Sensor code for

  int detected = digitalRead(DETECT);// read Laser sensor
  if( detected == HIGH)
    digitalWrite(ACTION,HIGH);// set the buzzer ON

    digitalWrite(ACTION,LOW); // Set the buzzer OFF
    Serial.println("No laser");
     // Laser Sensor code for



The least I expect from you is to thumb up the video and subscribe to my channel. I appriciate that. .I have spent months making these lectures and writing code. You don't lose anything by subscribging to my channel. Your subscription is stamp of approval to my videos and more people can find them and in it turn it helps me. Thank you

If you found this tutorial helpful, please support me so I can continue creating content like this. support me via PayPal

**** AFFILIATE PROGRAM **** We are a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for us to earn fees by linking to and affiliated sites.