BASIC4MCU | 질문게시판 | 스텝모터 질문
페이지 정보
작성자 에딘 작성일2022-11-15 21:08 조회928회 댓글1건
https://www.basic4mcu.com/bbs/board.php?bo_table=gac&wr_id=21609
본문
전에 스텝모터 글 쓴 사람입니다..
스텝모터를 작동할 수 있는 코드를 짜서 업로드 해보니 스텝모터가 돌아가더라고요.
제가 빗방울 감지 센서에 물을 떨어트리면 스텝모터가 돌아가서 문이 닫히는 그런 걸 만들고 잇는데
이 스텝모터를 돌아가게 하는 코드를 if문에 넣으니 안됩니다..(if if else 부분)
if문 자체가 작동이 안되는 걸까 하면서 조건을 맞춰보니(window == true && value<500)
시리얼 모니터에 글이 써지긴 하는데 모터는 돌아가지 않습니다. 아래 흰색 글씨들이 스텝모터를 돌리는 코드입니다..
digitalWrite(dirPin,HIGH); // Enables the motor to move in a particular direction// Makes 200 pulses for making one full cycle rotation, 200펄스-> 1회전for(int x = 0; x < 4; x++) {digitalWrite(stepPin,HIGH);delayMicroseconds(500); // 모터 구동 속도 결정digitalWrite(stepPin,LOW);delayMicroseconds(500);}int Raindrops_pin = A0;boolean window = false;const int stepPin = 8; // 5 -> 8const int dirPin = 7; // 2 -> 7const int enPin = 6; // 8 -> 6void setup(){Serial.begin(9600);pinMode(A0, INPUT);pinMode(stepPin,OUTPUT);pinMode(dirPin,OUTPUT);pinMode(enPin,OUTPUT);digitalWrite(enPin,LOW);}void loop(){int value = analogRead(Raindrops_pin);Serial.print("Now : ");Serial.print("Rain : ");Serial.println(value);Serial.print("Window : ");if(window==0) Serial.println("Close");else if(window==1) Serial.println("Open");Serial.println("=============================================== ");Serial.println();if(window == false && value> 500) //창문이 닫혀있고 비가 안오는 상태{Serial.println("open");digitalWrite(dirPin,LOW); //Changes the rotations direction// Makes 400 pulses for making two full cycle rotationfor(int x = 0; x < 4; x++) {digitalWrite(stepPin,HIGH);delayMicroseconds(500);digitalWrite(stepPin,LOW);delayMicroseconds(500);}Serial.println("stop");window = true;Serial.print("Window Status : ");Serial.println(window);Serial.println();}else if(window == false && value<500) //창문이 닫혀있고 비가 오는 상태{//동작안함}else if(window == true && value>500) //창문이열려있고 비가 안오는 상태{//동작안함}else if(window == true && value<500) //창문이열려있고 비가 오는 상태{Serial.println("Close");digitalWrite(dirPin,HIGH); // Enables the motor to move in a particular direction// Makes 200 pulses for making one full cycle rotation, 200펄스-> 1회전for(int x = 0; x < 4; x++) {digitalWrite(stepPin,HIGH);delayMicroseconds(500); // 모터 구동 속도 결정digitalWrite(stepPin,LOW);delayMicroseconds(500);}window = false;Serial.print("Window Status : ");Serial.println(window);Serial.println();}delay(5000);}
댓글 1
조회수 928에딘님의 댓글
에딘 작성일아 고쳤어요!!!! ㅠㅠㅠㅠㅠㅠㅠㅠㅠㅠ