[Diao Ye learns programming] Arduino hands-on (164)---Futaba S3003 servo module 3

The reference to 37 sensors and modules has been widely circulated on the Internet. In fact, there must be more than 37 sensor modules compatible with Arduino. In view of the fact that I have accumulated some sensor and actuator modules on hand, according to the concept of true knowledge (must be hands-on), for the purpose of learning and communication, here I am going to try and do more experiments one by one.

[Arduino] 168 kinds of sensor module series experiments (data code + simulation programming + graphics programming)
Experiment 164: Futaba S3003 steering gear 180 degrees 3.5KG vehicle and ship model 38 grams robot camera pan tilt

insert image description here

[Arduino] 168 sensor module series experiments (data code + simulation programming + graphics programming)

Experiment 164: Futaba S3003 steering gear 180 degrees 3.5KG vehicle and ship model 38 grams robot camera head

Project: Use 10K potentiometer module to control RC servo motor position

insert image description here

Arduino experiment open source code

/*
 【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
  实验一百六十四:Futaba S3003舵机 180度3.5KG车船模型38克 机器人摄像头云台
  项目:使用10K电位器模块控制 RC 伺服电机位置
*/

#include <Servo.h>
Servo myservo; // create servo object to control a servo
int potpin = 0; // analog pin used to connect the potentiometer
int val; // variable to read the value from the analog pin
 
  
 
void setup(){
    
    
         myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop(){
    
    
         val = analogRead(potpin); // reads the value of the potentiometer (value // between 0 and 1023)
         val = map(val, 0, 1023, 0, 179); // scale it to use it with the servo (value
                                                        // between 0 and 180)
         myservo.write(val); // sets the servo position according to the
                                      // scaled value
         delay(15); // waits for the servo to get there
}

Project: Use 10K potentiometer module to control the position of RC servo motor
Arduino experiment scene diagram

insert image description here
code result

The analog value is read from the 10K potentiometer module connected to pin A0, stored in a variable, value = map(val, 0, 1023, since the ADC inside the Arduino is a 0-bit ADC, the analog reads from 179 to 10, but the RC servo motor can only rotate 0- so the function map must scale the scale from 1023-1 to 180-0, and then store it in val myservo.write(val); When 1023-0 is lowered to 179-0, the servo motor is then instructed to rotate to the val delay variable (1023); a delay of 0 milliseconds, thus allowing the degree of servo motor to be adjusted by rotating the potentiometer.

insert image description here

Experimental open source simulation programming (Linkboy V5.33)

Item: Servo 30°, 60°, -30°, -60° cycle swing

insert image description here
Item: Servo 30°, 60°, -30°, -60° cycle swing

Experimental scene dynamic diagram

insert image description here
[Arduino] 168 sensor module series experiments (data code + simulation programming + graphics programming)

Experiment 164: Futaba S3003 steering gear 180 degrees 3.5KG vehicle and ship model 38 grams robot camera head

Installation library: PS2X_lib, download link:

https://github.com/simondlevy/PS2X_lib

insert image description here

Project: Serial port printing servo pos value

Arduino experiment open source code

/*
 【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
  实验一百六十四:Futaba S3003舵机 180度3.5KG车船模型38克 机器人摄像头云台
  项目:串口打印舵机pos的值
*/

#include <PS2X_lib.h>
#include <Servo.h>

Servo myservo;  // 创建Servo对象用以控制伺服电机

int pos = 0;    // 存储伺服电机角度信息的变量

void setup() {
    
    
  myservo.attach(9);  // Servo对象连接在9号引脚
  Serial.begin(9600);
}

void loop() {
    
    
  for (pos = 0; pos <= 180; pos += 1) {
    
     // 0°转到180°
    // 每一步增加1°
    myservo.write(pos);              // 告诉伺服电机达到‘pos’变量的角度
    Serial.println(pos);             //串口打印pos的值
    delay(15);                       // 等待15毫秒以确保伺服电机达到了目标角度
  }
  for (pos = 180; pos >= 0; pos -= 1) {
    
     // 180°转到 0°
    myservo.write(pos);              // 告诉伺服电机达到‘pos’变量的角度
    Serial.println(pos);             //串口打印pos的值
    delay(15);                       //等待15毫秒以确保伺服电机达到了目标角度
  }
}

[Arduino] 168 sensor module series experiments (data code + simulation programming + graphics programming)

Experiment 164: Futaba S3003 steering gear 180 degrees 3.5KG vehicle and ship model 38 grams robot camera head

Project: Serial port printing servo pos value

Arduino experiment scene diagram

insert image description here

Guess you like

Origin blog.csdn.net/weixin_41659040/article/details/131816304
Recommended