21. Arduino learning notebook-- Experiment of controlling steering engine

21. Arduino learning notebook-- Experiment of controlling steering engine

Juvtmall ( a company supply PCB PrototypingPCBA service and sell kinds of components, modules and so on) ( Catduino has the same function of Arduino) 

Here use Arduino duemilanove to control the rotation of steering engine through a potentiometer.

Material preparation:
A arduino duemilanove
A 10K potentiometer
A steering engine
A breadboard
Some connected wires

It should be noted here, do not use the computer usb to supply power, because if the current demand is greater than 500ma, the usb may be burned, it is recommended to use the external power supply.

The left and right pins of the potentiometer are connected with 3.3V and GND respectively, the middle pin is connected with the analog port 0. Steering engine is connected with 5V and GND, the signal port is connected to the digital port 7.

The hardware connection diagram






Download the following code into the arduino, and Then connect the wiring, and use the battery when running.
ARDUINO CODE

1. int readPin = 0; // Used to connect the potentiometer
2. int servopin = 7; / / The interface of steering engine is connected with digital interface 7
3. 
4. void servopulse (int angle) / / Define a pulse function
5. {
6.    int pulsewidth = (angle * 11) +500; // Convert the angle to 500-2480 pulse width value
7.    digitalWrite (servopin, HIGH); // Set the steering engine interface to high
8.    delayMicroseconds (pulsewidth); //Delay the number of microseconds of the pulse width value
9.    digitalWrite (servopin, LOW); // Turn the steering engine interface low
10.    delayMicroseconds (20000-pulsewidth);
11. }
12. 
13. void setup ()
14. {
15.    pinMode (servopin, OUTPUT); / / set the steering engine interface as the output interface
16. }
17. 
18. void loop ()
19. {
20.    // Read the reading of the potentiometer (sensor) and receive a value of 3.3V, ranging from 0 to 660
21.    int readValue = analogRead (readPin);
22.    // Map the range of values to around 0 to 165
23.    int angle = readValue / 4;
24.    // Send 50 pulses
25.    for (int i = 0; i <50; i ++)
26.    {
27.      // reference pulse function
28.      servopulse
29.    }
30. }




评论

此博客中的热门博文

1. Arduino learning notebook -- Button experience (volume 2)

1. Arduino learning notebook -- Button experience (volume 1)

19.Arduino learning notebook--Atmega8 makes the minimum arduino system