![]() * Arduino Interface Shield or into an Analog Protoboard Adapter * Plug the sensor into the Analog 1 port on the Vernier * 4) or wire it to the DCU screw terminal. * labeled "Servo" (black lead to GND, white or yellow lead to * Connect the servo motor to the 3-pin connector on the DCU * to the voltage from a Vernier analog (BTA)) sensor. * This sketch controls the arm on a servo motor in response An external power supply, such as the LabQuest Power Supply, is required to power the servo motor. Plug the sensor and DCU into the Analog 1 and Digital 2 ports, respectively, on the Vernier Arduino Interface Shield or into Analog and Digital Protoboard Adapters wired as explained in the Connecting Vernier Sensors to the Arduino Using a Breadboard section. Servo 5V (red wire) to DCU line XP (power).Servo Control line (white or yellow wire) to DCU line D4.If your servo motor does not have a 3-pin plug, you can wire it to the DCU screw terminal using the wiring diagram below. If you are using a servo motor with a standard 3-pin plug, you can connect it directly to the 3 pins on the Vernier DCU labeled “Servo.” Be sure to verify that the orientation of the servo connector is correct (black lead to GND and white or yellow lead to 4). You will need to include the servo.h library at the beginning of your sketch. The sample sketch, VernierTutorialDCUServo, controls the position of a servo arm in response to raw voltage from any Vernier Analog (BTA) sensor. A standard servo is small, but strong, and energy-efficient, because it draws power proportional to its load. Servo motors are popular with many Arduino users, because they allow for precise control of angular position. Vernier.DCUPWM(PWMSetting) //turn on motor to PWM levelĭelay(30) //wait 30 milliseconds to see timing effectĭelay(1000) //wait 1 sec before repeating demononstrate PWM by fade in from 0 to max in increments of 5 pointsįor(int PWMSetting = 0 PWMSetting = 0 PWMSetting -=5) ![]() Int PWMSetting //create global variable for level of PWM VernierLib Vernier //create an instance of the VernierLib library #include "VernierLib.h" //include Vernier functions in this sketch * Interface Shield or into a Digital Protoboard Adapter wired * Plug the DCU into the Digital 2 port on the Vernier Arduino * then slowly decrease its speed from max to 0. * motor will slowly increase its speed from 0 to max and * the speed of a DC motor connected to a Vernier DCU. * This sketch uses pulse-width modulation (PWM) to control Plug the DCU into the Digital 2 port on the Vernier Arduino Interface Shield or a Digital Protoboard Adapter wired to Arduino pins 6, 7, 8, and 9 as explained in the Connecting Vernier Sensors to the Arduino section. ![]() Connect the DC motor to lines D4 and GND on a Vernier DCU. The sample sketch, VernierLibTutorialDCUPWM, uses PWM to gradually speed up and slow down a DC motor. If it is HIGH twice as long as it is LOW, then it is effectively outputting a voltage two-thirds max. If it switches equally between max and zero, the output voltage is effectively one-half the max. In order to output a voltage midrange between max and zero, a microcontroller can alternate between the HIGH and LOW output settings very quickly. This process is called pulse-width modulation (PWM). There is an indirect method however, that allows you to output a voltage some place between max and zero. ![]() You can set an output line HIGH (max voltage) or LOW (zero voltage), but you can’t directly output a voltage in between. One limitation with many microcontrollers, like the Arduino, is that it only offers digital lines for output. Switch the leads and it spins in the opposite direction. Apply a greater voltage and it spins faster. Apply a voltage across the two leads and the motor spins. DC motors are simple electronic components.
0 Comments
Leave a Reply. |