This Arduino project utilizes a PID (Proportional-Integral-Derivative) controller to control a motor's speed based on the distance measured by an ultrasonic sensor. The project also includes an I2C LCD display for visual feedback. The PID values and setpoint are adjusted using a potentiometer.
- Arduino board
- Ultrasonic sensor (HC-SR04)
- Potentiometer
- Motor
- I2C LCD display (20x4)
- Motor driver (if needed)
- Connecting wires
- Connect the ultrasonic sensor to the specified pins on the Arduino.
- Connect the potentiometer to an analog pin on the Arduino.
- Connect the motor to a PWM pin on the Arduino.
- Connect the I2C LCD display to the SDA and SCL pins on the Arduino.
Ensure you have the required libraries installed:
getDistance()
: Measures the distance using the ultrasonic sensor.controlMotor()
: Implements PID control for motor speed based on distance.updateLCD()
: Updates the I2C LCD display with feedback information.
Kp
,Ki
, andKd
: Proportional, Integral, and Derivative gains for the PID controller.
The LCD display is updated in a separate function (updateLCD()
) with a customizable refresh interval to reduce flickering.
- Upload the code to your Arduino board.
- Ensure all components are correctly wired.
- Observe the feedback on the I2C LCD display and the Serial Monitor.
- Adjust the potentiometer to change the setpoint and observe motor response.
- Modify PID parameters (
Kp
,Ki
,Kd
) based on your requirements. - Adjust the setpoint range using the potentiometer.
- Customize the LCD refresh interval in the
updateLCD()
function.
This project is licensed under the MIT License.