This Python code allows you to control a robot using a Raspberry Pi and various components such as motors, LEDs, and an ultrasonic sensor. The code utilizes the RPi.GPIO library for GPIO control.
This code is still a work in progress and is being updated. Additional features and improvements are planned for future updates.
- Autonomous Mode: The robot can operate autonomously using the ultrasonic sensor to detect obstacles and adjust its movement accordingly.
- Manual Mode: You can manually control the robot's movement by selecting the desired direction from the menu.
- Ultrasonic Sensor: Connected to GPIO pins Echo (pin 23) and Trig (pin 24). It measures the distance to obstacles using sound waves.
- LEDs: A red LED connected to GPIO pin 18. It indicates the presence of obstacles when the distance measured by the ultrasonic sensor is below a certain threshold.
- Motors: Four motors connected to GPIO pins MotorLF (pin 26), MotorRF (pin 20), MotorLB (pin 19), and MotorRB (pin 21). They control the robot's movement in different directions.
- Connect the required components (ultrasonic sensor, LEDs, and motors) to the appropriate GPIO pins on the Raspberry Pi.
- Run the Python code on the Raspberry Pi.
- Select the desired driving mode (autonomous or manual) from the menu.
- If in manual mode, choose the direction (forward, backward, left, right) for the robot to move.
- In autonomous mode, the robot will move and adjust its direction based on the obstacle detection by the ultrasonic sensor.
- The distance measured by the ultrasonic sensor and the status of the LED indicator will be displayed.
Feel free to modify and adapt the code according to your specific robot configuration and requirements.
- Raspberry Pi board
- RPi.GPIO library
- Ultrasonic sensor
- LEDs
- Motors