Arduino Code and Video Transmitter and Laser Sensor

Arduino Code and Video Transmitter and Laser Sensor

In this tutorial, we will learn how to use a laser transmitter and receiver to detect a laser beam and trigger a buzzer or another action. This setup can be utilized in various applications, including automation and robotics. By the end of the tutorial, you'll understand how to wire the components and write the Arduino code to make everything work seamlessly.

Laster RX or receiver module
Laster TX or transmitter module

Throughout the tutorial, we will discuss the key components involved in this project, including how to wire them correctly and how the code operates. Watch the video for a detailed walkthrough (in video at 02:00).

Hardware Explained

The main components of this project include a laser transmitter, a laser receiver, and a buzzer. The laser transmitter emits a beam of light, while the receiver detects this beam. When the beam is interrupted, the receiver sends a signal to the Arduino, which can then activate the buzzer or perform another action.

The transmitter module operates at 5 volts and includes a resistor to limit current. The receiver module can be connected to an external wire for flexibility in placement. The buzzer is also powered by 5 volts and has two pins: one for positive and one for ground.

Datasheet Details

ManufacturerUnknown
Part numberLaser Transmitter/Receiver Module
Operating Voltage5 V
Current Consumption5 mA typ.
Output TypeDigital Signal
Detection RangeVaries with environment
SizeTransmitter: 14.8 mm x 18.8 mm, Receiver: 15.4 mm x 23.4 mm

  • Ensure proper voltage supply to prevent damage.
  • Use short wires to minimize signal loss.
  • Keep the receiver aligned with the transmitter for reliable detection.
  • Test the setup in different lighting conditions.
  • Be cautious with reflections that may trigger false detections.

Wiring Instructions

Arduion wiring laser Transmitter and receiver
Arduion wiring laser Transmitter and receiver

To wire the laser transmitter, connect its ground pin to the Arduino GND and the positive pin to the Arduino 5V. The middle pin of the transmitter is not used. For the laser receiver, connect its ground pin to GND, the positive pin to 5V, and the output pin to Arduino pin 2. This output pin will read the signal from the laser receiver.

Next, connect the buzzer: its longer pin (positive) should be connected to Arduino pin 8, while the shorter pin (ground) connects to GND. Make sure all connections are secure to avoid intermittent issues during operation.

Code Examples & Walkthrough

The Arduino code begins by defining the pins for the laser sensor and the action (buzzer) using the identifiers DETECT and ACTION. The code initializes the serial communication for debugging and sets the pin modes in the setup() function.

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

void setup() {
  Serial.begin(9600);
  pinMode(DETECT, INPUT); // define detect input pin
  pinMode(ACTION, OUTPUT); // define ACTION output pin
}

This snippet shows how to configure the pins for input and output, which is crucial for the functionality of the setup. The Serial.begin(9600) command allows for communication with the serial monitor, enabling us to see debug messages.

In the loop() function, the code continuously checks the state of the laser sensor. If the laser beam is detected, it activates the buzzer and prints "Detected!" to the serial monitor.

void loop() {
  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");
  }
  delay(200); // wait 200 milliseconds
}

This excerpt demonstrates the core logic of the program. The variable detected stores the output of the digitalRead() function, which checks if the laser beam is present. Depending on the state, the buzzer is turned on or off.

Demonstration / What to Expect

When the setup is correctly wired and the code is uploaded, the system should function as expected. The serial monitor will indicate "Detected!" when the laser beam hits the receiver, and the buzzer will sound. If the beam is interrupted or not detected, it will display "No laser" and the buzzer will turn off.

It is essential to ensure that the laser beam is properly aligned with the receiver for reliable operation. Be aware of potential reflections that may trigger false positives, as discussed in the video (in video at 08:00).

Video Timestamps

  • 00:00 - Introduction
  • 02:00 - Hardware Explanation
  • 04:30 - Wiring Instructions
  • 06:15 - Code Explanation
  • 08:00 - Demonstration

Images

Laster RX or receiver module
Laster RX or receiver module
Laster RX or receiver module
Laster RX or receiver module
Laster TX or transmitter module
Laster TX or transmitter module
Laster TX or transmitter module
Laster TX or transmitter module
Laster TX or transmitter module
Laster TX or transmitter module
Arduion wiring laser Transmitter and receiver
Arduion wiring laser Transmitter and receiver
67-This is the Arduino code and video for a laser sensor module.
Language: C++
Copied!

Things you might need

Resources & references

No resources yet.

Files📁

No files available.