MANE 3351 - Manufacturing Engineering Analysis
Laboratory Three Assignment
Assigned: September 24, 2025
Due: October 1, 2025 before 9:30 AM
Utilize an Arduino to control a servo that rotates from 0 degrees to 180 degrees and back to zero degrees. A switch will cause the servo to change the direction of rotation. An LED is lit when the servo is traveling from 0 to 180 degrees.
Equipment Needed
The following items are required to complete the third laboratory assignment. Note that this is the total equipment required for lab three; you already have many of the items from completing the first two labs.
- 1 Arduino Uno
- 1 USB printer cable
- 1 breadboard
- 1 servo (new)
- 8 male-to male (mm) jumper cable
- LED
- Switch
Assignment
Step One
Construct the circuit shown below on a breadboard. Do not connect to the Arduino Uno until after the sketch is uploaded.

Step Two
Open the Arduino IDE and enter the code for the sketch shown below. Verify the code and upload to your Arduino Uno. Do not forget to add documentation to the top of the program code.
#include <Servo.h>
//
// Pins
//
const int SERVO_PIN = 9; // Servo signal
const int BUTTON_PIN = 2; // Button to GND, uses INPUT_PULLUP
const int LED_PIN = 6; // Direction indicator
//
// Sweep settings
//
const unsigned long STEP_INTERVAL_MS = 15; // time between 1° steps (smaller = faster)
const int STEP_SIZE_DEG = 1; // degrees per step
//
// Button debounce
//
const unsigned long DEBOUNCE_MS = 25;
bool lastButtonReading = HIGH; // INPUT_PULLUP idle = HIGH
bool buttonState = HIGH;
unsigned long lastDebounceTime = 0;
//
// Motion state
//
Servo myServo;
int angle = 0; // current angle (0..180)
int direction = +1; // +1 = up (0→180), -1 = down (180→0)
unsigned long lastStepTime = 0;
void setLedForDirection() {
// LED ON while moving 0→180, OFF while moving 180→0
digitalWrite(LED_PIN, (direction > 0) ? HIGH : LOW);
}
void flipDirection() {
direction = -direction;
setLedForDirection();
}
void setup() {
myServo.attach(SERVO_PIN);
pinMode(BUTTON_PIN, INPUT_PULLUP);
pinMode(LED_PIN, OUTPUT);
// Start at 0°, moving upward
angle = 0;
direction = +1;
myServo.write(angle);
setLedForDirection();
}
void loop() {
// ---- Read & debounce button (active LOW) ----
bool reading = digitalRead(BUTTON_PIN);
if (reading != lastButtonReading) {
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > DEBOUNCE_MS) {
if (reading != buttonState) {
buttonState = reading;
if (buttonState == LOW) { // just pressed
flipDirection();
}
}
}
lastButtonReading = reading;
// ---- Sweep motion (non-blocking) ----
unsigned long now = millis();
if (now - lastStepTime >= STEP_INTERVAL_MS) {
lastStepTime = now;
// advance angle
angle += direction * STEP_SIZE_DEG;
// clamp and auto-reverse at ends
if (angle >= 180) {
angle = 180;
direction = -1;
setLedForDirection();
} else if (angle <= 0) {
angle = 0;
direction = +1;
setLedForDirection();
}
myServo.write(angle);
}
}
Step Three
Connect your breadboard to the Arduino and ensure that the program is working properly.
Step Four
Save and run the Python program. Hopefully, there will be no errors in the circuit and code and it will run immediately. Debug the schematic and code until everything works. Meet with Dr. Timmer in his office before the deadline (October 1, 2025 at 9:30 AM) and demonstrate your working laboratory three project.
Hints
The servo contains three wires and will accept male jumpers. Please ensure that the following connections are made:
- Servo brown wire to ground
- Servo red wire to +5V
- Servo orange wire to signal (D10)
Credit
This lab was largely generated by ChatGPT using the following prompt: "create an arduino project that rotates a servo 0 to 180, and then 180 to 0. incorporate a button switch to change directions when pressed. The switch should change directions and light an led. include a sketch, circuit and fritzing diagram in your solution". Dr.Timmer created the Fritzing diagram based upon the ChatGPT output.