마스터님께(창문소스코드 의문점)
페이지 정보
작성자 wait 작성일19-05-23 16:59 조회4,806회 댓글0건본문
#include <Stepper.h>
const int TMP36_pin = A1; //온도
const int stepsPerRevolution = 200; //회전수 200/한바퀴
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);
int ENA=2;
int ENB=5;
int ondo1 = 30;
int ondo2 = 28;
int gas1 = 200;
int gas2 = 150;
boolean window = false; //false -> 닫혀있는상태
//true -> 열려있는상태
const int gasPin = A0; // 가스
void setup()
{
pinMode(ENA,OUTPUT); //
pinMode(ENB,OUTPUT);//
digitalWrite(ENA,HIGH);//
digitalWrite(ENB,HIGH);//
myStepper.setSpeed(10);
}
void loop()
{
int sensorValue = analogRead(TMP36_pin);
float mVoltage = sensorValue * 5000.0/1024.0;
float temperatureC = (mVoltage - 500) / 10.0;
int value = digitalRead(2);
Serial.print("Now : ");
Serial.print(temperatureC);
Serial.println(" C");
Serial.println();
Serial.print("current gas : ");
Serial.println(analogRead(gasPin));
Serial.println();
Serial.print("Rain : ");
Serial.println(value);
Serial.print("Window : ");
if(window==false) Serial.println("Close");
else if(window==true) Serial.println("Open");
Serial.println("=============================================== ");
Serial.println();
if(window == false && value==1) //창문이 닫혀있고 비가 안오는 상태
{
if(temperatureC<=ondo2 && analogRead(gasPin)>=gas1)
{
sensor_open();
}
else if(temperatureC>=ondo1 && analogRead(gasPin)>=gas1)
{
sensor_open();
}
else if(temperatureC<=ondo2 && analogRead(gasPin)<=gas2)
{
// 동작안함
}
else if(temperatureC>=ondo1 && analogRead(gasPin)<=gas2)
{
sensor_open();
}
}
else if(window == false && value==0) //창문이 닫혀있고 비가 오는 상태
{
if(temperatureC<=ondo2 && analogRead(gasPin)>=gas1)
{
sensor_open();
}
else if(temperatureC>=ondo1 && analogRead(gasPin)>=gas1)
{
sensor_open();
}
else if(temperatureC<=ondo2 && analogRead(gasPin)<=gas2)
{
// 동작안함
}
else if(temperatureC>=ondo1 && analogRead(gasPin)<=gas2)
{
//동작안함
}
else
{
//동작안함
}
}
else if(window == true && value==1) //창문이열려있고 비가 안오는 상태
{
if(temperatureC<=ondo2 && analogRead(gasPin)>=gas1)
{
//동작안함
}
else if(temperatureC>=ondo1 && analogRead(gasPin)>=gas1)
{
//동작안함
}
else if(temperatureC<=ondo2 && analogRead(gasPin)<=gas2)
{
sensor_close();
}
else if(temperatureC>=ondo1 && analogRead(gasPin)<=gas2)
{
//동작안함
}
}
else if(window == true && value==0) //창문이열려있고 비가 오는 상태
{
if(temperatureC<=ondo2 && analogRead(gasPin)>=gas1)
{
//동작안함
}
else if(temperatureC>=ondo1 && analogRead(gasPin)>=gas1)
{
//동작안함
}
else if(temperatureC<=ondo2 && analogRead(gasPin)<=gas2)
{
sensor_close();
}
else if(temperatureC>=ondo1 && analogRead(gasPin)<=gas2)
{
sensor_close();
}
else
{
sensor_close();
}
}
delay(5000);
}
void sensor_open(){
Serial.println("open");
myStepper.step(stepsPerRevolution);
Serial.println("stop");
window = true;
Serial.print("Window Status : ");
Serial.println(window);
Serial.println();
}
void sensor_close()
{
Serial.println("Close");
myStepper.step(-stepsPerRevolution);
window = false;
Serial.print("Window Status : ");
Serial.println(window);
Serial.println();
}
이 코드입니다.
그런데 온도가 자꾸 35~40도 사이로 뜨는 것도 있으며 , 넘어가도 코드가 open으로 작동을 하지 않습니다.
아래 링크를 작동해보려하는데
int ENA=8;
int ENB=5;
int enablePin = 11;
int in1Pin = 10;
int in2Pin = 9;
여기서 enblePin는 무엇인지 잘 모르겠고 in1Pin in2Pin은 이미 89에 연결되있는 상태아닌가요?
댓글 : 0
조회수 : 4,806
등록된 댓글이 없습니다.