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 Robojax.com
on Feb 02, 2018 at 18:24 in Ajax, Ontario, Canada
* Original library: https://github.com/guillaume-rico/SharpIR
* Watch Video instrution for this code: https://youtu.be/ggrSmv99Cxs
*
* Full explanation of this code and wiring diagram is available at
* my Arduino Course at Udemy.com here: http://robojax.com/L/?id=62
* Written by Ahmad Shamshiri on Feb 03, 2018 at 07:34
* in Ajax, Ontario, Canada. www.robojax.com
*
If you found this tutorial helpful, please support me so I can continue creating
content like this make donation using PayPal http://robojax.com/L/?id=64
* * 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 Robojax.com
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
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
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 <https://www.gnu.org/licenses/>.
*/
#define DETECT 2 // pin 2 for sensor
#define ACTION 8 // pin 8 for action to do someting
void setup() {
Serial.begin(9600);
Serial.println("Robojax.com Laser Module Test");
pinMode(DETECT, INPUT);//define detect input pin
pinMode(ACTION, OUTPUT);//define ACTION output pin
// Laser sensor code for Robojax.com
}
void loop() {
// Laser Sensor code for Robojax.com
int detected = digitalRead(DETECT);// read Laser sensor
if( detected == HIGH)
{
digitalWrite(ACTION,HIGH);// set the buzzer ON
Serial.println("Detected!");
}else{
digitalWrite(ACTION,LOW); // Set the buzzer OFF
Serial.println("No laser");
// Laser Sensor code for Robojax.com
}
delay(200);
}