During the COVID-19 pandemic, touchless solutions have become increasingly important. So I want to make an elevator system that can be controlled using a smartphone instead of pressing buttons.
So The idea is for the user to connect to the elevator via Bluetooth when they enter and control the elevator directly from their phone.
SOFTWARE
Simulation Software
Arduino Software
COMPONENTS
Thinking about what components make this function and idea (7_Segment, Servo motor, Bluetooth module, voltage regulator 5v)
Searching how to connect these components with an Arduino board.
Coding:
Thinking about how I can make the code to perform the idea🤔.
I will send Arduino numbers from my phone and if the number:
'1' (Automatic Mode): Displays numbers from 9 to 1 with delays, then opens the door.
'2': Turns off the display and closes the door.
'3': Opens the door.
'4': Closes the door.
'5' (Manual Mode by using switch case): Cycles through numbers 1 to 9 each time the command is received, then resets the counter.
#include <Servo.h>
Servo myservo;
int OpenDoor = 160;
int ClosedDoor = 20;
int a = 2;
int b = 3;
int c = 4;
int d = 5;
int e = 6;
int f = 7;
int g = 8;
char InComingData = '0';
int counter = 1;
void setup() {
Serial.begin(9600);
myservo.attach(9);
myservo.write(20);
pinMode(a, OUTPUT);
pinMode(b, OUTPUT);
pinMode(c, OUTPUT);
pinMode(d, OUTPUT);
pinMode(e, OUTPUT);
pinMode(f, OUTPUT);
pinMode(g, OUTPUT);
}
void loop() {
while(Serial.available() == 0);
InComingData = Serial.read();
if (InComingData == '1'){ //Automatic mode
Num9();
delay(1000);
Num8();
delay(1000);
Num7();
delay(1000);
Num6();
delay(1000);
Num5();
delay(1000);
Num4();
delay(1000);
Num3();
delay(1000);
Num2();
delay(1000);
Num1();
delay(1000);
myservo.write(OpenDoor);
} else if (InComingData == '2'){
Off();
myservo.write(ClosedDoor);
} else if (InComingData == '3'){
myservo.write(OpenDoor);
} else if (InComingData == '4'){
myservo.write(ClosedDoor);
} else if (InComingData == '5'){
switch(counter){
case 1:{
Num1();
counter++;
break;
}
case 2:{
Num2();
counter++;
break;
}
case 3:{
Num3();
counter++;
break;
}
case 4:{
Num4();
counter++;
break;
}
case 5:{
Num5();
counter++;
break;
}
case 6:{
Num6();
counter++;
break;
}
case 7:{
Num7();
counter++;
break;
}
case 8:{
Num8();
counter++;
break;
}
case 9:{
Num9();
counter = 1;
break;
}
}
}
}
void Num9(){
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
digitalWrite(6, LOW);
digitalWrite(7, HIGH);
digitalWrite(8, HIGH);
}
void Num8(){
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
digitalWrite(6, HIGH);
digitalWrite(7, HIGH);
digitalWrite(8, HIGH);
}
void Num7(){
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
digitalWrite(7, LOW);
digitalWrite(8, LOW);
}
void Num6(){
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
digitalWrite(6, HIGH);
digitalWrite(7, HIGH);
digitalWrite(8, HIGH);
}
void Num5(){
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
digitalWrite(6, LOW);
digitalWrite(7, HIGH);
digitalWrite(8, HIGH);
}
void Num4(){
digitalWrite(2, LOW);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
digitalWrite(7, HIGH);
digitalWrite(8, HIGH);
}
void Num3(){
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
digitalWrite(6, LOW);
digitalWrite(7, LOW);
digitalWrite(8, HIGH);
}
void Num2(){
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, LOW);
digitalWrite(5, HIGH);
digitalWrite(6, HIGH);
digitalWrite(7, LOW);
digitalWrite(8, HIGH);
}
void Num1(){
digitalWrite(2, LOW);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
digitalWrite(7, LOW);
digitalWrite(8, LOW);
}
void Off(){
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
digitalWrite(7, LOW);
digitalWrite(8, LOW);
}
First, testing each component to make sure that all works well.
Adapter 9v --> connecting the +ve & -ve to positive and negative lines on the breadboard.
Voltage Regulator :
INPUT terminal (left) --> to +ve line on breadboard.
GND terminal (middle) --> to -ve line on breadboard.
OUTPUT terminal (Right) --> to the VCC of the Servo.
Arduino :
V_IN --> to +ve line on breadboard.
GND --> to -ve line on breadboard.
Servo Motor :
VCC --> to the output of the voltage regulator.
GND --> to the -ve line on the breadboard.
Signal --> to PIN 9 on Arduino.
Bluetooth Module :
VCC --> to the 5v PIN on Arduino.
GND --> to the -ve line on the breadboard.
TX --> to RX on Arduino (PIN 0)
RX --> to TX on Arduino (PIN 1)
7_Segment --> Every terminal to digital PIN on Arduino from PIN 2: 8 as shown in the figure.
Finally, connected the Arduino Jake to the laptop, and from Arduino IDE I chose the correct port and then uploaded the code on Arduino.
==> HINT: Don't forget to remove the RX &TX while uploading the code.
I encountered several challenges with the code, where the seven-segment display only showed the number 1.
Solution
To troubleshoot, I used the Serial Monitor to print debug statements within each if function to identify the issue. I discovered that the counter was resetting to 1 with each iteration, which occurred because I hadn't initialized the counter outside the void loop.