Use Laser Emitter Module sending Morse signals

Background

Laser is widely used in medical treatment, military, and other fields due to its good directivity and energy concentration.

Project Principle

A laser is a device that emits light through a process of optical amplification based on the stimulated emission of electromagnetic radiation. Lasers differ from other sources of light because they emit light coherently.
Spatial coherence allows a laser to be focused to a tight spot, enabling applications like laser cutting and lithography, and a laser beam to stay narrow over long distances (collimation), enabling applications like laser pointers. Lasers can also have high temporal coherence which allows them to have a very narrow spectrum, i.e., they only emit light of a single color. And its temporal coherence can be used to produce pulses of light—as short as a femtosecond.
The schematic diagram of the module is as shown below:

What you need

  • -1 * Raspberry Pi
  • – 1 * Breadboard
  • – 4 * Jumper wires (Male to Male, 2 red and 2 black)
  • – 1 * Network cable (or USB wireless network adapter)
  • – 1 * Laser Emitter module
  • – 1 * 2-Pin anti-reverse cable

Step 1: Connect the circuit

Raspberry Pi T-Cobbler Laser Emitter Module
5V 5V0 VCC
GPIO0 GPIO17 SIG

Step 2: Run the C/Python programm

Create or upload the C programm to your Raspberry Pi and enter the path, Please refer the below C source code for reference.

In our case, I create the C file as 05_laser at /home/pi/projects/ 05_laser/
cd /home/pi/projects/05_laser/

Compile it,
gcc laser.c -o laser –lwiringPi -lpthread

Run it,
sudo ./laser

For the Python program, you dont need complie it, but just run it. below steps,

Enter the directory which stored your python code, please refere the attached python source code for your reference.
cd /home/pi/projects/05_laser/

Run the Python code,
sudo python 05_laser.py

Application Show

Now you can see the module send out Morse signals.

Note: Do NOT look directly at the laser head. It can cause great harm to your eyes. You can point the laser beam to the table and see the light spot flashing on the table.

Appendix

C source code: laser.c

#include <wiringPi.h>
#include <stdio.h>

#define LaserPin    0

int main(void)
{
	if(wiringPiSetup() == -1){ //when initialize wiring failed,print messageto screen
		printf("setup wiringPi failed !");
		return 1; 
	}
	//printf("linker LedPin : GPIO %d(wiringPi pin)\n",LedPin); //when initialize wiring successfully,print message to screen

	pinMode(LaserPin, OUTPUT);

	while(1){
		digitalWrite(LaserPin, HIGH);
		delay(500);
		digitalWrite(LaserPin, LOW);
		delay(500);
	}

	return 0;
}

Python source code: 05_laser.py

#!/usr/bin/env python
#####################################################
#
#	DO NOT WATCH THE LASER DERECTELY IN THE EYE!
#
#####################################################
import RPi.GPIO as GPIO
import time

LedPin = 11    # pin11

def setup():
	GPIO.setmode(GPIO.BOARD)       # Numbers GPIOs by physical location
	GPIO.setup(LedPin, GPIO.OUT)   # Set LedPin's mode is output
	GPIO.output(LedPin, GPIO.HIGH) # Set LedPin high(+3.3V) to off led

def loop():
	while True:
		print '...Laser on'
		GPIO.output(LedPin, GPIO.LOW)  # led on
		time.sleep(0.5)
		print 'Laser off...'
		GPIO.output(LedPin, GPIO.HIGH) # led off
		time.sleep(0.5)

def destroy():
	GPIO.output(LedPin, GPIO.HIGH)     # led off
	GPIO.cleanup()                     # Release resource

if __name__ == '__main__':     # Program start from here
	setup()
	try:
		loop()
	except KeyboardInterrupt:  # When 'Ctrl+C' is pressed, the child program destroy() will be  executed.
		destroy()

About the author

Leave a Reply

Your email address will not be published. Required fields are marked *