Lesson 72: Obstacle Detection Using a Laser Transmitter and Receiver with Arduino
454-Lesson 72: Obstacle detection using a laser transmitter and receiver with Arduino
Language: C++
/*
* Lesson 77: How to use a Laser Transmitter and Receiver
to detect obstacles using Arduino
Written by Ahmad Shamshiri for Robojax.com
on February 2, 2018 at 18:24 in Ajax, Ontario, Canada
* Original library: https://github.com/guillaume-rico/SharpIR
* Watch Video instruction 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 February 3, 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 a 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 downloaded 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 something
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);
}
Resources & references
No resources yet.
Files📁
No files available.