Experiment 33: DC Motor Driver Experiment
From Diustou Wiki
Contents
Arduino
Experimental Phenomenon
- The motor runs at full speed after power-on.
Notes
- DC motors are the most common type of motors. A DC motor typically has only two leads, one positive and one negative. If these two leads are directly connected to a battery, the motor will rotate. If the leads are switched, the motor will rotate in the opposite direction.
- Do not drive the motor directly from the Arduino board pins. This could damage the circuit board. Use a driver circuit or IC.
Circuit Connection
Reference Program
#define Motor 5 void setup() { pinMode(Motor,OUTPUT); } void loop() { analogWrite(Motor,150); }
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
- Set the DIP switch on the ULN2003 driver module to the ON position
- Download the Raspberry Pi reference example, unzip the file, copy it to the user directory, and run it:
cd raspberrypi/33/python_gpiozero python motor.py
- You can see the Raspberry Pi running the program correctly. To exit, press ctrl+C.
- Command description: gpiozero.OutputDevice(pin, pwm, active_high, initial_value)
- Main parameters:
- pin: GPIO pin number
- active_high: Internal pull-up/pull-down resistor setting
- When set to True (default), on() sets the pin to High and off() sets the pin to LOW.
- When set to False, on() sets the pin to LOW and off() sets the pin to High.
- initial_value:
- If False (default), all LEDs are initially off.
- If None, the initial state of all LEDs is unstable.
- If True, all LEDs are initially on.
- Main parameters:
- For more commands, please refer to the gpiozero documentation