Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino Nano Controlled Servomotor with Joystick Interface

View and Edit Project In Cirkit DesignerImage of Arduino Nano Controlled Servomotor with Joystick Interface

Circuit Documentation

Summary

This circuit is designed to control a Servomotor SG90 using an Arduino Nano microcontroller, which receives input from a KY-023 Dual Axis Joystick Module. The Breadboard Power Module supplies power to the system, providing both 3.3V and 5V as required. The joystick's X and Y axis movements are read by the Arduino Nano and translated into servo motor position commands, allowing for precise control of the servo's angle.

Component List

Breadboard Power Module (3.3/5V)

Servomotor SG90

KY-023 Dual Axis Joystick Module

Arduino Nano

Wiring Details

Breadboard Power Module (3.3/5V)

Servomotor SG90

KY-023 Dual Axis Joystick Module

Arduino Nano

Documented Code

#include <Servo.h>

Servo myServo;  // Create servo object

// Joystick and servo pins
const int joyXPin = A0;  // Joystick X-axis pin
const int joyYPin = A1;  // Joystick Y-axis pin
const int servoPin = 9;  // Servo control pin

// Variables to store joystick values
int joyXValue;
int joyYValue;

void setup() {
  // Start serial communication (optional)
  Serial.begin(9600);

  // Attach servo to specified pin
  myServo.attach(servoPin);
}

void loop() {
  // Read values from the joystick
  joyXValue = analogRead(joyXPin);  // Read X-axis
  joyYValue = analogRead(joyYPin);  // Read Y-axis

  // Map joystick values (0-1023) to servo angles (0-180)
  int servoAngleX = map(joyXValue, 0, 1023, 0, 180);
  int servoAngleY = map(joyYValue, 0, 1023, 0, 180);

  // Move servo based on joystick values
  myServo.write(servoAngleX);  // Move servo according to X-axis

  // Display joystick values and servo angle on Serial Monitor (optional)
  Serial.print("Joystick X: ");
  Serial.print(joyXValue);
  Serial.print(" | Servo Angle X: ");
  Serial.println(servoAngleX);

  // Delay for stability
  delay(15);
}

This code snippet is responsible for reading the analog values from the joystick's X and Y axes, mapping these values to a range suitable for servo control, and then adjusting the servo's position accordingly. The serial communication lines, which are optional, allow for monitoring the joystick's position and the corresponding servo angle through the Serial Monitor in the Arduino IDE.