Back to Step by Step Course by Robojax

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

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 give the video a thumbs up and subscribe to my channel. I appreciate it. I have spent hundreds of hours making these lectures and writing code. You don't lose anything by subscribing to my channel. Your subscription is a stamp of approval for my videos, helping more people find them and, in turn, helping 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.

Right Side