From b77c1c826a06752229db4e95134a568c4ed69561 Mon Sep 17 00:00:00 2001 From: DavidShapiro313 <102691518+DavidShapiro313@users.noreply.github.com> Date: Thu, 5 Jun 2025 11:12:15 -0700 Subject: [PATCH 1/5] Create Controlling a Servo with Joystick - David Shapiro Mini Project 3 --- ...th Joystick - David Shapiro Mini Project 3 | 94 +++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 content/tutorials/Controlling a Servo with Joystick - David Shapiro Mini Project 3 diff --git a/content/tutorials/Controlling a Servo with Joystick - David Shapiro Mini Project 3 b/content/tutorials/Controlling a Servo with Joystick - David Shapiro Mini Project 3 new file mode 100644 index 00000000..b14ea942 --- /dev/null +++ b/content/tutorials/Controlling a Servo with Joystick - David Shapiro Mini Project 3 @@ -0,0 +1,94 @@ +# Arduino Mega 2560 Servo Control with Joystick Tutorial + +Note: While this tutorial uses the Arduino Mega 2560 (as my ESP32 was being used for the final project), the principles remain very similar. ESP32 code is provided at the end for reference. + +## Learning Objectives + +- Understanding basic servo motor control +- Reading analog input from a joystick module +- Programming the Arduino Mega for motor control applications +- Working with Arduino libraries + +## Required Components + +- 1x Arduino Mega 2560 board +- 1x Servo motor (SG90 or similar) +- 1x Analog joystick module +- Jumper wires +- Breadboard +- USB cable for programming + +## Required Libraries + +In the Arduino IDE, you only need the standard Servo library (included with Arduino IDE) + +## Circuit Connections + +Connect the components as follows: + +### Joystick Module: + +- VCC → 5V +- GND → GND +- VRx (X-axis) → A1 + +### Servo Motor: + +- Red wire (Power) → 5V +- Brown/Black wire (Ground) → GND +- Orange/Yellow wire (Signal) → Pin 50 + +## Arduino Mega Code + +``` +#include + +// Create servo object +Servo myservo; + +// Define pins +const int joystickXPin = A1; // Joystick X-axis +const int servoPin = 50; // Servo control pin + +// Variables +int joystickValue; +int servoAngle; + +void setup() { + // Initialize serial communication + Serial.begin(9600); + + // Attach servo to pin + myservo.attach(servoPin); +} + +void loop() { + // Read joystick value (0-1023) + joystickValue = analogRead(joystickXPin); + + // Map joystick value to servo angle (0-180) + servoAngle = map(joystickValue, 0, 1023, 0, 180); + + // Control servo + myservo.write(servoAngle); + + // Debug output + Serial.print("Joystick Value: "); + Serial.print(joystickValue); + Serial.print(" Servo Angle: "); + Serial.println(servoAngle); + + // Small delay for stability + delay(15); +} +``` + +## Important Notes for Arduino Mega + +- The Arduino Mega's ADC has 10-bit resolution (0-1023 values) +- The standard Servo library is simpler to use than the ESP32 version +- 5V power is more stable for servos compared to ESP32's 3.3V logic + +## Troubleshooting + +- If movement is reversed, adjust the map() function values From 7826afa334c00480c80ce98e15ceba2b3a0a5a6e Mon Sep 17 00:00:00 2001 From: DavidShapiro313 <102691518+DavidShapiro313@users.noreply.github.com> Date: Thu, 5 Jun 2025 11:16:20 -0700 Subject: [PATCH 2/5] Update Controlling a Servo with Joystick - David Shapiro Mini Project 3 --- ...th Joystick - David Shapiro Mini Project 3 | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/content/tutorials/Controlling a Servo with Joystick - David Shapiro Mini Project 3 b/content/tutorials/Controlling a Servo with Joystick - David Shapiro Mini Project 3 index b14ea942..7a30bbf5 100644 --- a/content/tutorials/Controlling a Servo with Joystick - David Shapiro Mini Project 3 +++ b/content/tutorials/Controlling a Servo with Joystick - David Shapiro Mini Project 3 @@ -92,3 +92,48 @@ void loop() { ## Troubleshooting - If movement is reversed, adjust the map() function values + +## ESP32 Code(Not fully Tested) +-Slight modifications to the circuit must be made, Changing the pins for Joystick and Servo. + +#include + +// Create servo object +Servo myservo; + +// Define pins +const int joystickXPin = 1; // Joystick X-axis +const int servoPin = 46; // Servo control pin + +// Variables +int joystickValue; +int servoAngle; + +void setup() { + // Initialize serial communication + Serial.begin(115200); + + + // Attach servo to pin + myservo.attach(servoPin, 500, 2400); +} + +void loop() { + // Read joystick value (0-4095) + joystickValue = analogRead(joystickXPin); + + // Map joystick value to servo angle (0-180) + servoAngle = map(joystickValue, 0, 1023, 0, 180); + + // Control servo + myservo.write(servoAngle); + + // Debug output + Serial.print("Joystick Value: "); + Serial.print(joystickValue); + Serial.print(" Servo Angle: "); + Serial.println(servoAngle); + + // Small delay for stability + delay(15); +} From 467b24fa482aa13ae909c146f1e8627cdfc0ae80 Mon Sep 17 00:00:00 2001 From: DavidShapiro313 <102691518+DavidShapiro313@users.noreply.github.com> Date: Thu, 5 Jun 2025 11:23:15 -0700 Subject: [PATCH 3/5] Rename Controlling a Servo with Joystick - David Shapiro Mini Project 3 to Controlling a Servo with Joystick - David Shapiro Mini Project 3.md --- ...lling a Servo with Joystick - David Shapiro Mini Project 3.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename content/tutorials/{Controlling a Servo with Joystick - David Shapiro Mini Project 3 => Controlling a Servo with Joystick - David Shapiro Mini Project 3.md} (100%) diff --git a/content/tutorials/Controlling a Servo with Joystick - David Shapiro Mini Project 3 b/content/tutorials/Controlling a Servo with Joystick - David Shapiro Mini Project 3.md similarity index 100% rename from content/tutorials/Controlling a Servo with Joystick - David Shapiro Mini Project 3 rename to content/tutorials/Controlling a Servo with Joystick - David Shapiro Mini Project 3.md From dcdee01506ac956b75a4ce7c7e217a779d3392a4 Mon Sep 17 00:00:00 2001 From: DavidShapiro313 <102691518+DavidShapiro313@users.noreply.github.com> Date: Thu, 5 Jun 2025 11:24:33 -0700 Subject: [PATCH 4/5] Update Controlling a Servo with Joystick - David Shapiro Mini Project 3.md --- ...ing a Servo with Joystick - David Shapiro Mini Project 3.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/content/tutorials/Controlling a Servo with Joystick - David Shapiro Mini Project 3.md b/content/tutorials/Controlling a Servo with Joystick - David Shapiro Mini Project 3.md index 7a30bbf5..5f51418f 100644 --- a/content/tutorials/Controlling a Servo with Joystick - David Shapiro Mini Project 3.md +++ b/content/tutorials/Controlling a Servo with Joystick - David Shapiro Mini Project 3.md @@ -95,7 +95,7 @@ void loop() { ## ESP32 Code(Not fully Tested) -Slight modifications to the circuit must be made, Changing the pins for Joystick and Servo. - +``` #include // Create servo object @@ -137,3 +137,4 @@ void loop() { // Small delay for stability delay(15); } +``` From 9fc8bc6c9efa8dabaf2aeff43aa7ca6fd07e560c Mon Sep 17 00:00:00 2001 From: DavidShapiro313 <102691518+DavidShapiro313@users.noreply.github.com> Date: Fri, 6 Jun 2025 15:14:01 -0700 Subject: [PATCH 5/5] Update Controlling a Servo with Joystick - David Shapiro Mini Project 3.md --- ...g a Servo with Joystick - David Shapiro Mini Project 3.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/content/tutorials/Controlling a Servo with Joystick - David Shapiro Mini Project 3.md b/content/tutorials/Controlling a Servo with Joystick - David Shapiro Mini Project 3.md index 5f51418f..8ddfc9c4 100644 --- a/content/tutorials/Controlling a Servo with Joystick - David Shapiro Mini Project 3.md +++ b/content/tutorials/Controlling a Servo with Joystick - David Shapiro Mini Project 3.md @@ -1,4 +1,7 @@ -# Arduino Mega 2560 Servo Control with Joystick Tutorial +# Title: Arduino Mega 2560 Servo Control with Joystick Tutorial +date: 2025-06-06 +authors: +  - name: David Shapiro Note: While this tutorial uses the Arduino Mega 2560 (as my ESP32 was being used for the final project), the principles remain very similar. ESP32 code is provided at the end for reference.