Arduino ile 3 Katlı asansör projesi

Katılım
1 Haz 2022
Mesajlar
1
Puanları
1
Yaş
14
3 katlı asansör projesi yapmaya çalışıyoruz. Haftaya çarşambaya yetişmesi lazım. Kodlarımızda sıkıntı çıktı. Kodlara ve devre şemasına bakarak yanlışı düzelte bilir misiniz?

Devre şeması
asansor-elektronik-devresi-1.jpg


Kodlar

#define switchFloor1 0
#define switchFloor2 2
#define switchFloor3 3

#define photocellFloor2 0
#define photocellFloor3 1

#define steps 520

#define stepperPin1 10
#define stepperPin2 11
#define stepperPin3 12
#define stepperPin4 13

#define delaytime 10
#define A 4 // (A = 11) Corresponding arduino pins for the segments on the 7 segment LED display
#define B 5 // (B = 7)
#define C 6 // (C = 4)
#define D 7 // (D = 2)
#define E 8 // (E = 1)
#define f 10 // Not used in the circuit
#define G 9 //(G = 5)
#define DP 11 // Not used in the circuit

#define CC4 1 // (CC4 = 13) Pin driving common cathodes


boolean firstRun = true;
int currentFloor = 1; // Used to save the current floor. This value is changed with the switches and with the readings done by the photocells
long debounceTime = 200; // The switch's debounce time
int secondFloorReading = 0; // The analog reading from the sensor divider (for floor 2 and 3)
int thirdFloorReading = 0;

byte numbers[3][8] = {{0,1,1,0,0,0,0,0},{1,1,0,1,1,0,1,0},{1,1,1,1,0,0,1,0}};

const int segments[8] = { A, B, C, D, E, f, G, DP }; // This defines an array that contains the arduino pins for each segment

void setup(){
Serial.begin(9600); // Initialize serial port

pinMode(A, OUTPUT); // Set anodes low to make sure all segments are off
digitalWrite(A,LOW);
pinMode(B, OUTPUT);
digitalWrite(B,LOW);
pinMode(C, OUTPUT);
digitalWrite(C,LOW);
pinMode(D, OUTPUT);
digitalWrite(D,LOW);
pinMode(E, OUTPUT);
digitalWrite(E,LOW);
pinMode(f, OUTPUT); // This pin will not be connected to the board
digitalWrite(f,LOW);
pinMode(G, OUTPUT);
digitalWrite(G,LOW);
pinMode(DP, OUTPUT); // This pin will not be connected to the board
digitalWrite(DP,LOW);

pinMode(CC4, OUTPUT); // Set catodes high to turn off digit
digitalWrite(CC4,HIGH);

pinMode(switchFloor1, INPUT); // Define the arduino pins for the swi tches as inputs
pinMode(switchFloor2, INPUT);
pinMode(switchFloor3, INPUT);

pinMode(stepperPin1, OUTPUT); // Define the the arduino pins for the stepper's coils as outputs
pinMode(stepperPin2, OUTPUT);
pinMode(stepperPin3, OUTPUT);
pinMode(stepperPin4, OUTPUT);
}

void loop(){

secondFloorReading = analogRead(photocellFloor2); // Get a reading from the photocells to verify the current floor
thirdFloorReading = analogRead(photocellFloor3);

Serial.print("Analog reading (Second floor) = ");
Serial.println(secondFloorReading); // the raw analog reading
Serial.print("Analog reading (Third floor) = ");
Serial.println(thirdFloorReading); // the raw analog reading
delay(1000);

if(secondFloorReading > 790 && thirdFloorReading > 790) // Check if the elevator is in the first floor
{
setSegments(0, CC4); // Turn on the segments that display the number 1
currentFloor = 1; // Set the current floor to 1
// The elevator is meant to start at the first floor
}
else if(secondFloorReading < 750) // Check if the elevator is in the second floor
{
setSegments(1, CC4); // Turn on the segments that display the number 2
currentFloor = 2;
}
else if(thirdFloorReading < 750) // Check if the elevator is in the third floor { setSegments(2, CC4); // Turn on the segments that display the number 3 currentFloor = 3; } // The following if statement will only allow the switch's input if the current floor is not already 1 // The coils in the stepper motor will go backwards if the elevator // is on either floor 2 or floor 3 // If it is on floor 3, it will go backwards twice the number of steps if(readSwitch(switchFloor1, debounceTime) == true && currentFloor != 1){ if(currentFloor == 2){ Serial.println("going down"); int numberOfSteps = steps+90; step_OFF(); // Turning all coils off while(numberOfSteps>0){
backward(); // Going backward
numberOfSteps -- ; // Counting down the number of steps
}
}
else if(currentFloor == 3){

Serial.println("going down");
int numberOfSteps = (steps*2)+80;
step_OFF(); // Turning all coils off

while(numberOfSteps>0){
backward(); // Going backward
numberOfSteps -- ; // Counting down the number of steps
}
}
currentFloor = 1; // Sets the currentFloor to 1 since the elevator is now at the first floor
delay(1000);
}

// The following if statement will only allow the switch's input if the current floor is not already 2
// The coils in the stepper motor will go forward or backwards if the elevator
// is on either floor 1 or floor 3, respectively
if(readSwitch(switchFloor2, debounceTime) == true && currentFloor != 2){

if(currentFloor == 1){
Serial.println("going up");
int numberOfSteps = steps+90;
step_OFF(); // Turning all coils off

while(numberOfSteps>0){
forward(); // Going forward
numberOfSteps -- ; // Counting down the number of steps
}
}
else if(currentFloor == 3){
Serial.println("going down");
int numberOfSteps = steps+5;
step_OFF(); // Turning all coils off

while(numberOfSteps>0){
backward(); // Going forward
numberOfSteps -- ; // Counting down the number of steps
}
}
currentFloor = 2; // Sets the currentFloor to 2 since the elevator is now at the second floor
delay(2000);
}


if(readSwitch(switchFloor3, debounceTime) == true && currentFloor != 3){ //
if(currentFloor == 1){
Serial.println("going up");
int numberOfSteps = (steps*2)+80; // Twice the number of steps to reach floor 3
step_OFF(); // Turning all coils off

while(numberOfSteps>0){
forward(); // Going forward
numberOfSteps -- ; // Counting down the number of steps
}
}
else if(currentFloor == 2){
Serial.println("going up");
int numberOfSteps = steps+5;
step_OFF(); // Turning all coils off

while(numberOfSteps>0){
forward(); // Going forward
numberOfSteps -- ; // Counting down the number of steps
}
}
currentFloor = 3; // Sets the currentFloor to 2 since the elevator is now at the second floor
delay(2000);
}
Serial.println(currentFloor);
}
bu kodları denedik ama hem motor yoktu hemde yüklerken hata veriyordu.


vppv3m.jpg


int in1=13;
int in2=12;
int e1=11;

int a=10;
int b=9;
int c=8;
int d=7;
int e=6;
int f=5;
int g=4;

int kat1=17;
int kat2=18;
int kat3=19;

int sensor1=14;
int sensor2=15;
int sensor3=16;

int katdurum1;
int katdurum2;
int katdurum3;

int sensordurum1;
int sensordurum2;
int sensordurum3;

void setup() {
Serial.begin(9600);
pinMode(in1,OUTPUT);
pinMode(in2,OUTPUT);
pinMode(e1,OUTPUT);

pinMode(a,OUTPUT);
pinMode(b,OUTPUT);
pinMode(c,OUTPUT);
pinMode(d,OUTPUT);
pinMode(e,OUTPUT);
pinMode(f,OUTPUT);
pinMode(g,OUTPUT);

pinMode(kat1,INPUT);
pinMode(kat2,INPUT);
pinMode(kat3,INPUT);

pinMode(sensor1,INPUT);
pinMode(sensor2,INPUT);
pinMode(sensor3,INPUT);
}

void loop() {
katdurum1=digitalRead(kat1);
katdurum2=digitalRead(kat2);
katdurum3=digitalRead(kat3);

sensordurum1=digitalRead(sensor1);
sensordurum2=digitalRead(sensor2);
sensordurum3=digitalRead(sensor3);

//Serial.println(katdurum1);
//Serial.println(katdurum2);
Serial.println(katdurum3);
//Serial.println(sensordurum1);
//Serial.println(sensordurum2);
//Serial.println(sensordurum3);


if(katdurum1==HIGH)
{
digitalWrite(in1,LOW);
digitalWrite(in2,HIGH);
analogWrite(e1,75);

if(sensordurum1==HIGH)
{
digitalWrite(in1,LOW);
digitalWrite(in2,LOW);

digitalWrite(a,LOW);
digitalWrite(b,HIGH);
digitalWrite(c,HIGH);
digitalWrite(d,LOW);
digitalWrite(e,LOW);
digitalWrite(f,LOW);
digitalWrite(g,LOW);
}
else digitalWrite(2,LOW);
}

if(katdurum2==HIGH)
{
if(sensordurum1==HIGH)
{
digitalWrite(in1,HIGH);
digitalWrite(in2,LOW);
analogWrite(e1,75);
}
else if(sensordurum2==HIGH)
{
digitalWrite(in1,LOW);
digitalWrite(in2,LOW);

digitalWrite(a,HIGH);
digitalWrite(b,HIGH);
digitalWrite(c,LOW);
digitalWrite(d,HIGH);
digitalWrite(e,HIGH);
digitalWrite(f,LOW);
digitalWrite(g,HIGH);
}
else
{
digitalWrite(in1,LOW);
digitalWrite(in2,HIGH);
analogWrite(e1,75);
}
}

if(katdurum3==HIGH)
{
digitalWrite(in1,HIGH);
digitalWrite(in2,LOW);
analogWrite(e1,75);
if(sensordurum3==HIGH)
{
digitalWrite(in1,LOW);
digitalWrite(in2,LOW);

digitalWrite(a,HIGH);
digitalWrite(b,HIGH);
digitalWrite(c,HIGH);
digitalWrite(d,HIGH);
digitalWrite(e,LOW);
digitalWrite(f,LOW);
digitalWrite(g,HIGH);
}
else digitalWrite(2,LOW);
}


}



Ama 3 tane kullandığı yeşil parçadan kullanmadık
 
Son düzenleme:
Kat sensörlerini interup ile almayı deneyin ama çağırılan kat ile ilgili sensör den bilgi eşleşirse motoru durdurmaya çalışın

Birde butonları if döngüsünden hemen önce okuyuma yapmayı deneyin
Keşke çıkan sıkıntıyı açıklasaydınız
 

Forum istatistikleri

Konular
128,128
Mesajlar
915,259
Kullanıcılar
449,843
Son üye
hvncrblt

Yeni konular

Geri
Üst