BASIC4MCU | 질문게시판 | 아두이노 스텝모터관련 문의 드립니다(꼭 봐주세요 ㅠㅠ)
페이지 정보
작성자 융추 작성일2018-12-07 23:37 조회3,416회 댓글0건본문
#define TRIG_PIN 2
#define ECHO_PIN 3
int i=1; // the value represents where elevator stay ( fisrt time elevator start in the first floor
int motorPin1 = 10; //스텝모터 신호핀 설정
int motorPin2 = 11;
int motorPin3 = 12;
int motorPin4 = 13;
//스텝모터의 스텝설정
const byte numbers[16] = {
0b11111100,
0b01100000,
0b11011010,
0b11110010,
0b01100110,
0b10110110,
0b10111110,
0b11100000,
0b11111110,
0b11100110,
0b11101110,
0b00111110,
0b10011100,
0b01111010,
0b10011110,
0b10001110
};
void setup() {
pinMode(TRIG_PIN, OUTPUT);
pinMode(ECHO_PIN, INPUT);
pinMode(motorPin1, OUTPUT);
pinMode(motorPin2, OUTPUT);
pinMode(motorPin3, OUTPUT);
pinMode(motorPin4, OUTPUT);
int delayTime = 50;
Serial.begin(9600);
}
void loop() {
// Serial.println("You are on the i st floor");
long duration;
digitalWrite(TRIG_PIN, LOW);
delayMicroseconds(2);
digitalWrite(TRIG_PIN, HIGH);
delayMicroseconds(5);
digitalWrite(TRIG_PIN,LOW);
duration=pulseIn(ECHO_PIN,HIGH);
long value = duration/29/0.2;
for(int j=0;j<=3;j++){
Serial.print("duration = ");
Serial.print(value);
Serial.println("mm");
if(value <= 30){
i++;
up();
Serial.print(i);
delay(1000);
}
else if(value>30){
delay(1000);
}
}
}
// ------- up function which is for to go up elevator
void up() { // each floor distance where it works to up
for(int b=0; b<450; b++){
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, LOW);
digitalWrite(motorPin3, LOW);
digitalWrite(motorPin4, HIGH);
delay(3);
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, LOW);
digitalWrite(motorPin3, HIGH);
digitalWrite(motorPin4, LOW);
delay(3);
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, HIGH);
digitalWrite(motorPin3, LOW);
digitalWrite(motorPin4, LOW);
delay(3);
digitalWrite(motorPin1, HIGH);
digitalWrite(motorPin2, LOW);
digitalWrite(motorPin3, LOW);
digitalWrite(motorPin4, LOW);
delay(3);
}
}
void down() { // each floor distance where it works to down
for(int a=0;a<450;a++){
digitalWrite(motorPin1, HIGH);
digitalWrite(motorPin2, LOW);
digitalWrite(motorPin3, LOW);
digitalWrite(motorPin4, LOW);
delay(3);
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, HIGH);
digitalWrite(motorPin3, LOW);
digitalWrite(motorPin4, LOW);
delay(3);
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, LOW);
digitalWrite(motorPin3, HIGH);
digitalWrite(motorPin4, LOW);
delay(3);
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, LOW);
digitalWrite(motorPin3, LOW);
digitalWrite(motorPin4, HIGH);
delay(3);
}
}
엘레베이터 소스 코드에 초음파 센서 소스를 더한 코드입니다. 차가 엘레베이터에 탑승하면 바닥면의 초음파 센서가 차를 인식하고 센서값을 받으면 엘레베이터가 일층에서 이층으로 그리고 이층에서 다시 내리고 다시 타면 이층에서 삼층으로 그리고 삼층에서 내리면 엘레베이터는 지하 일층으로 내려가게 되고 지하일층에서 다시 차가 타면 일층으로 가서 마무리가 되는 그런 코드입니다. 하지만 무슨이유인지 센서값에 의해서 자꾸 올라가기만 하지 내려가거나 멈추지를 않습니다. 삼일간 고민하다가 자문을 구할 곳이 없어 이렇게 자문을 구합니다 ㅠㅠ 제발 조금의 의견이나 코멘트라도 남겨주세요ㅠㅠㅠ
댓글 0
조회수 3,416등록된 댓글이 없습니다.