Experiment 17: Laser Sensor Experiment

From Diustou Wiki

Arduino

Experimental Phenomenon

  • The module emits a laser beam every 1 second.

Circuit Connection

  • 实验十七:激光传感器实验 接线.png

Reference Program

#define SEN 2

void setup() 
{                
pinMode(SEN, OUTPUT); 
}

void loop() 
{
  digitalWrite(SEN, HIGH);   
  delay(1000);              
  digitalWrite(SEN, LOW);    
  delay(1000);              
}

Raspberry Pi

Circuit Connection

  • 实验十七:激光传感器实验 接线1.png

Program Execution

Python

  • Install the gpiozero library
    • You can use the following command to install the library:
sudo apt update
sudo apt install python3-gpiozero
  • For other systems on the Raspberry Pi, you can use the following command to install the library:
sudo pip3 install gpiozero
  • Run the following command to view the GPIO pin definitions on the Raspberry Pi:
pinout
  • Download the Raspberry Pi reference example, unzip the file, copy it to the user directory, and run it:
cd raspberrypi/17/python_gpiozero
python laser.py
  • At this point, you can see the Raspberry Pi running the program correctly. To exit, press ctrl+C.
  • Command explanation: gpiozero.LED(pin, pwm, active_high, initial_value)
    • Main parameters:
      • pin: GPIO pin number,
      • active_high:
        • When set to True (default), connect the negative lead of the LED to GND and the other end to the GPIO pin.
        • When set to False, connect the negative lead of the LED to the GPIO pin and the other end to the 3.3V pin.
      • initial_value:
        • If False (default), the LED is initially off.
        • If None, the LED pin is in an unstable state.
        • If True, the LED is initially on.
  • For more commands, please refer to the gpiozero documentation

Example Download

Related Examples

Basic Experiment Kits and Examples for Arduino and Raspberry Pi
教程名2
  • 列表2
教程名3
  • 列表3
教程名4
  • 列表4
教程名5
  • 列表5
教程名6
  • 列表6