First-Arduino-Project

by Makavelii in Circuits > Arduino

37 Views, 0 Favorites, 0 Comments

First-Arduino-Project

20240701_041205.jpg

My initial idea was to create a mask with a visor that could open at the press of a button, accompanied by a light turning on when the visor was raised. I aimed to blend functionality with aesthetics, envisioning a piece that was both practical and visually appealing. However, as I worked on the project, I decided to tweak my concept slightly.

Instead of a wearable mask, I crafted a box-like structure that retains the same mechanical features. While not wearable, it still opens the visor with a button press and activates a light when the visor lifts.

I found the idea of creating not just a functional item but also a decoration for my room intriguing. This project became an opportunity to explore both my creativity and technical skills

Supplies

Naamloze presentatie.png
20240630_171939.jpg

Tools:

  • Soldering iron
  • Solder
  • Cable cutter
  • Cable stripper (optional)
  • Screwdriver

Other:

  • Wooden plank
  • Screws
  • The second image shows a corner support used to connect two components. While this is one way to achieve the connection, it's not the only method. There are other components available that can accomplish the same goal.

I initially cut the right pieces from the wooden plank on a laser cut machine. It doesn't have to be cut by a laser cut machine so any other way is also possible

Create the Design

Screenshot 2024-06-29 172934.png
Screenshot 2024-07-01 052824.png

Before anything else, I started by creating a sketch design to ensure I knew where to place everything, such as the button. This gave me a clear picture of how my design would look. As a result, I had a better understanding of what I needed and was able to keep the design realistic and feasible.

Make the Circuit Design

tinkercad.png

After creating the sketch design, I knew what kind of mechanism I wanted for my project. I envisioned a mechanism where you press a button, and the visor goes up, activating the LED light. When the visor goes down again, the LED light turns off. To achieve this, I first created the circuit design on Tinkercad. This helped me understand how the mechanism works.

Test 1

WhatsApp Image 2024-06-29 at 19.51.22_39de7a47.jpg
Iteration 1

After designing the circuit on Tinkercad, my next step was to create a proof of concept to check if it would actually work. I used the same materials that I planned to use for the final product, but without the final design elements, to test if everything functioned correctly.

Laser Cut

Naamloze presentatie(1).png

After successfully testing the proof of concept, I proceeded to create the design using wooden planks. I used laser cutting to ensure precise dimensions and shapes for the design. Additionally, I incorporated holes in strategic locations for efficient cable management

Building the Design Part 1: Case

20240628_232549.jpg
20240628_232452.jpg
20240628_234644.jpg
20240630_171834.jpg
20240630_191757.jpg
20240630_183723.jpg
20240630_183715.jpg

I began assembling the design to get a quick preview of where I would place the Arduino and breadboard. Despite having a sketch of the design, I wanted to confirm the placement to ensure everything fit perfectly.

Building the Design Part 2: Solder

20240629_210801.jpg
Arduino_Input - Rotated.jpg
Arduino_Input_2_Painted.jpg
Arduino_Input_Painted.jpg
Breadboard_1_Painted.jpg
Breadboard_2_Painted.jpg
Button_1.jpg
Button_2.jpg
Light_1.jpg
Servo_1.jpg
Servo_2.jpg
20240629_063501.jpg

Once I determined the placement for everything, including cables, I proceeded with soldering the cables onto the breadboard, LED light, and button. I positioned the Arduino and breadboard in their designated spots and began organizing the cables for efficient management.

Input configuration for the Arduino:

  • Button: connected to pin 2
  • LED Light: connected to pin 13
  • Servo Motor: connected to pin ~9

Test 2: Test After Solder

Test 2 1
Test 2 2

After soldering everything onto the breadboard and ensuring all cables were securely attached, I conducted another test to verify that everything was still functioning correctly.

Building the Design Part 3: Finished

video
CableManagement.jpg
20240701_041212.jpg
20240701_041205.jpg

To enhance the design's appeal and make it less mundane, I painted the structure and completed the cable management. Additionally, I captured a video showcasing the finished design.

Code

#include <Servo.h>


// Constants

const int buttonPin = 2;      // Pin for the pushbutton

const int ledPin = 13;        // Pin for the LED

const int servoPin = 9;       // Pin for the servo


// Variables

int buttonPressCount = 0;     // Counter to track button presses

bool isServoMoving = false;   // Flag to indicate if the servo is moving

int targetServoAngle = 0;     // Desired angle of the servo

int currentServoAngle = 0;    // Current angle of the servo

const int maxServoAngle = 100; // Maximum angle for the servo

const int startServoAngle = 0; // Start angle for the servo


Servo myServo; // Create a Servo object


void setup() {

 pinMode(ledPin, OUTPUT);          // Set LED pin as an output

 pinMode(buttonPin, INPUT_PULLUP); // Set button pin as an input with an internal pull-up resistor

 myServo.attach(servoPin, 500, 2500); // Attach the servo to the pin with min and max pulse widths


 myServo.write(startServoAngle);   // Move servo to the start angle

 currentServoAngle = 0;            // Initialize the current angle

 digitalWrite(ledPin, LOW);        // Turn off the LED

}


void loop() {

 // Read the state of the pushbutton

 if (digitalRead(buttonPin) == LOW) {

   // Wait for the button to be released

   while (digitalRead(buttonPin) == LOW) {

     delay(10); // Small delay to debounce the button

   }


   // Toggle the buttonPressCount variable and set the target angle

   buttonPressCount++;

   if (buttonPressCount % 2 == 1) {

     targetServoAngle = maxServoAngle; // If buttonPressCount is odd, set target angle to max angle

   } else {

     targetServoAngle = 0;            // If buttonPressCount is even, set target angle to 0

   }

   isServoMoving = true; // Set the moving flag to true


   // Debounce delay

   delay(100); // Small delay to debounce the button

 }


 // Move the servo towards the target angle if it's moving

 if (isServoMoving) {

   if (currentServoAngle < targetServoAngle) {

     currentServoAngle++; // Increment the current angle

     if (currentServoAngle >= targetServoAngle) {

       currentServoAngle = targetServoAngle; // Ensure the current angle does not exceed the target

       isServoMoving = false; // Stop moving once the target is reached

     }

     myServo.write(currentServoAngle); // Move the servo to the current angle

   } else if (currentServoAngle > targetServoAngle) {

     currentServoAngle--; // Decrement the current angle

     if (currentServoAngle <= targetServoAngle) {

       currentServoAngle = targetServoAngle; // Ensure the current angle does not go below the target

       isServoMoving = false; // Stop moving once the target is reached

     }

     myServo.write(currentServoAngle); // Move the servo to the current angle

   }

 }


 int actualServoAngle = myServo.read(); // Read the current angle of the servo


 if (actualServoAngle == maxServoAngle) {

   digitalWrite(ledPin, HIGH); // Turn on the LED if the servo is at the max angle

 } else if (actualServoAngle == startServoAngle) {

   digitalWrite(ledPin, LOW); // Turn off the LED if the servo is at the start angle

 }


 delay(15); // Small delay for smoother movement

}

Problems

Although the overall design wasn't particularly difficult, I did encounter some challenges when designing the mechanism for the visor. Initially, I expected the mechanism to be more complicated, but it still presented some unexpected difficulties.

I also want to mention that balancing the visor was challenging with just one servo. Eventually, I found a solution by adding a long screw on the other side to act as a pivot mechanism. This allowed me to achieve the movement I needed, although it made it difficult to keep the visor perfectly straight.

Reflection

I started this project with no prior knowledge of Arduino, but I was excited because I had experience building and configuring gaming PCs, which involved connecting cables to the right inputs—similar to Arduino. I had some soldering experience, so that part went smoothly. Despite appearances, I did face challenges in designing the project. I had to carefully consider the engineering aspects and watched tutorial videos to understand how others approached similar tasks.

Although the engineering aspects of my design weren't overly complex, I still needed to learn from others' experiences. Through this project, I gained a deep understanding of Arduino, learned how to create various mechanisms, and improved my circuitry skills by combining different components to achieve specific goals. It also opened my eyes to the possibilities of using Arduino in game development.

I enjoyed the hands-on crafting aspect, which is quite different from coding, and found immense satisfaction in seeing the finished design come together. Overall, I feel like I've learned a lot and am eager to tackle another Arduino project in the future.