120 likes | 268 Vues
This project demonstrates how to control the angle of a servo motor using two buttons: one to increase and one to decrease the angle. Both buttons will also light up an LED to indicate action. The system utilizes analog signals, enabling you to read the voltage and current through an analog pin with the analogRead() function. You'll learn how voltage represents the push of a charge and how to understand current flow, along with a basic overview of converting analog signals to digital to manage servo positions from 0 to 180 degrees.
E N D
Control Angle via Button Pushes One button increases angle. Other decreasesangle.Both light LED.
Servo Control Using Analog Signal Obtain “analog” input using analogRead().
Voltage, V • Voltage tells us how hard a positive charge ispushedbetween two different points. • Something, such as a battery, is needed to createa voltage. Current, I • Current tells us the amount of chargeflowing throughsomething (similar to gallons per minute). • Current must have a path through which to flow. I = V / R Resistor: R V = 5, R = 5, I = ?
What Is the Measure Voltage? 5V 4V 3V 2V 1V 0V
Potentiometer • Voltage at wiper depends onposition along the resistor. • Voltage varies between ground(0V) and the supplied voltage(5V in this case). • Voltage various continuously(analog “signal”). WIPER
Conversion of Analog to Digital • Obtain “analog” input using analogRead(). • analogRead()returns a value between 0 (if pin at ground) and 1023 (if pin at 3.3 V). • Argument of analogRead()is the pin to read(only pins labeled ANALOGIN can be used). • Servo position varies between 0 and 180.Therefore, must divide analogRead()whatreturns by 5.68333 (1023 / 5.68333 = 180).
Control Angle via Button Pushes One button increases angle. Other decreasesangle.Both light LED.