Last active
May 7, 2024 01:00
-
-
Save kenedii/93648f5421f87e7526afce9163ce94e8 to your computer and use it in GitHub Desktop.
An Arduino elevator system that will service 3 floors, using the servo motor to represent the elevator being at various floors, and LED’s to indicate which floor you are on.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Servo.h> | |
// Made for final TEJ3M Culminating April 2021 | |
Servo myservo; // create servo object to control a servo | |
int pos = 0; //makes a position variable to easily write code for it | |
int green = 10; //sets the green LED on pin 10 | |
int yellow = 9; //sets the yellow LED on pin 9 | |
int red = 8; //sets the red LED on pin 8 | |
void setup() { | |
myservo.attach(0); //attaches the servo on pin 0 to the servo object | |
pinMode(green,OUTPUT); //makes the pin an output | |
pinMode(yellow,OUTPUT); //makes the pin an output | |
pinMode(red, OUTPUT); //makes the pin an output | |
} | |
void loop(){ | |
myservo.write(0); //puts the servo to 0 degrees to "reset" it | |
delay(5000); //waits 5 seconds | |
for (pos = 0; pos<= 10; pos += 1) {// goes from 0 degrees to 10 degrees (floor 1) | |
//in steps of 1 degree | |
myservo.write(pos); | |
delay(15); | |
} | |
digitalWrite(green, HIGH); //turns on the green LED to show floor 1 | |
delay(5000); //waits 5 seconds | |
digitalWrite(green, LOW); //turns off the green LED (leaving floor 1) | |
for (pos = 10; pos<= 50; pos += 1) {// goes from 10 degrees to 50 degrees | |
//in steps of 1 degree | |
myservo.write(pos); | |
delay(15); | |
} | |
digitalWrite(yellow, HIGH); //turns on the yellow LED to show floor 2 | |
delay(5000); //waits 5 seconds | |
digitalWrite(yellow, LOW); //turns off the yellow LED (leaving floor 2) | |
for (pos = 50; pos<= 170; pos += 1) {// goes from 50 degrees to 170 degrees | |
//in steps of 1 degree | |
myservo.write(pos); | |
delay(15); | |
} | |
digitalWrite(red, HIGH); //turns on the red LED to show floor 3 | |
delay(5000); //waits 5 seconds | |
//elevator goes back down | |
digitalWrite(red, LOW); //turns off the red LED (leaving floor 3) | |
for (pos = 170; pos >= 50; pos -= 1) {//goes from 170 degrees to 50 degrees | |
myservo.write(pos); | |
delay(15); | |
} | |
digitalWrite(yellow, HIGH); //turns on the yellow LED to show floor 2 | |
delay(5000); //waits 5 seconds | |
digitalWrite(yellow, LOW); //turns off the yellow LED (leaving floor 2) | |
for (pos = 50; pos >= 10; pos -= 1) {//goes from 50 degrees to 10 degrees | |
myservo.write(pos); | |
delay(15); | |
} | |
digitalWrite(green, HIGH); //turns on the green LED to show floor 1 | |
delay(5000); //waits 5 seconds | |
digitalWrite(green, LOW); //turns off the green LED before restarting loop | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment