Experiment 17: Laser Sensor Experiment
From Diustou Wiki
Revision as of 15:54, 12 February 2025 by Yousimaier17 (talk | contribs) (Created page with "*Basic Experiment Kits For Arduino *Basic Experiment Kits For Raspberry Pi == Arduino == === Experimental Phenomenon === * The module emits a laser beam every 1 second...")
Contents
Arduino
Experimental Phenomenon
- The module emits a laser beam every 1 second.
Circuit Connection
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
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.
- Main parameters:
- For more commands, please refer to the gpiozero documentation