当前位置:首页 > 科学研究 > 电子编程 > 正文内容

Arduino Project 027 - Joystick Servo Control

RonWang6个月前 (11-15)电子编程200

In this tutorial, we are going to learn how to use Arduino and a joystick to control two servo motors or a pan-tilt kit with servos.

Project 27  Joystick Servo Control

/* Coding Ron Wang
   Nov.15th 2024
   Autaba support for coding hardware
   Project 27  Joystick Servo Control
 */

#include <Servo.h>
Servo servo1; // Create a servo object
Servo servo2; // Create a second servo object
int pot1, pot2;
void setup()
{
 servo1.attach(5); // Attaches the servo on pin 5 to the servo1 object
 servo2.attach(6); // Attaches the servo on pin 6 to the servo2 object
 servo1.write(90); // Put servo1 at home position
 servo2.write(90); // Put servo2 at home postion
}
void loop()
{
 pot1 = analogRead(3); // Read the X-Axis
 pot2 = analogRead(4); // Read the Y-Axis
 pot1 = map(pot1,0,1023,0,180);
 pot2=map(pot2,0,1023,0,180);
 servo1.write(pot1);
 servo2.write(pot2);
 delay(15);
}

Arduino Joystick Servo Control Circuit

Arduino Joystick Servo Control Schematic

版权声明:本文为原创文章,版权归donstudio所有,欢迎分享本文,转载请保留出处!

本文链接:http://www.parentscn.com/?id=281

标签: Arduino

相关文章

 Arduino Project 037 - 18B20 Temperature Sensor

Arduino Project 037 - 18B20 Temperature Sensor

The DS18B20 Temperature Sensor is a digital temperature sensor capable of measuring temperatures wit...

Arduino Project 015 - Simple Motor Control

Arduino Project 015 - Simple Motor Control

First, you’re going to simply control the speed of a DC motor in one direction, using a power transi...

C语言调试运行环境Pelles C的安装

C语言调试运行环境Pelles C的安装

C语言调试运行环境之TurboC一文介绍了在32位Windows系统下安装C语言运行环境之TubroC,但是由于TurobC只能在32位系统下运行,导致现在很多Windows10和Windows 11...

Arduino Project 039 - Ultrasonic Distance Display

Arduino Project 039 - Ultrasonic Distance Display

Ultrasonic sensors measure distance by sending and receiving the ultrasonic wave. The ultrasonic sen...

Arduino Project 014 - Light Sensor

Arduino Project 014 - Light Sensor

This project introduces a new component known as a Light Dependent Resistor, or LDR. As the name imp...

Arduino Project 030 - Line Following Robot

Arduino Project 030 - Line Following Robot

Project 30 Line Following RobotUse L298P Driver Line Following Robot Line o...