#include <LiquidCrystal.h> LiquidCrystal lcd(8, 9, 4, 5, 6, 7); //LCD Key Shield의 pin 설정 int lcd_key = 0; int adc_key_in = 0; #define DC_N 13 //DC Motor의 pin 설정 #define DC_P 12 #define DC_En 11 #define PSD A1 //PSD Sensor #define CDS A5 //CdS Sensor #define LED 22 //LED #define SWITCH 23 //스위치 int distance = 15; //15cm 이하의 거리에 물체가 접근하면 PSD Sensor로 문을 개폐 void setup() { lcd.begin(16, 2); // LCD Key Shield의 행수, 열수 지정 pinMode(10,OUTPUT); // 백라이트 digitalWrite(10, 1); Serial.begin(9600); //시리얼 모니터로 거리값을 출력 pinMode(DC_N, OUTPUT); //Setting OUTPUT mode pinMode(DC_P, OUTPUT); //Setting OUTPUT mode pinMode(DC_En, OUTPUT); //Setting OUTPUT mode pinMode(CDS, INPUT); pinMode(LED, OUTPUT); pinMode(SWITCH, INPUT_PULLUP); IdleScreen(); } void loop() { float Dist = 0; float Read = 0; Read = ((float)analogRead(PSD))*5/1023; Dist = 1/(Read * 0.0434 - 0.0046); if(Dist > 80) Dist = 80; //Max.Distance if(Dist < 15) Dist = 15; //Min.Distance Serial.print("Distance : "); Serial.println(Dist); if(digitalRead(SWITCH)==0) //수동개폐 { OpenDoor(); } else if(Dist<=distance) //센서 인식 { OpenDoor(); } else { MotorStop(); } } void Direction_rotation(int Mode, int Speed) { if(Mode) { digitalWrite(DC_N, LOW); digitalWrite(DC_P, HIGH); analogWrite(DC_En, Speed); //Motor Speed } else { digitalWrite(DC_N, HIGH); digitalWrite(DC_P, LOW); analogWrite(DC_En, Speed); //Motor Speed } } void MotorStop() { digitalWrite(DC_N, HIGH); digitalWrite(DC_P, HIGH); } void NameScreen() { lcd.clear(); lcd.setCursor(0,0); lcd.print("JNUECE 151807"); } void IdleScreen() //아무 동작도 없을 시 LCD Key Shield 에 표시할 적절한 대기 화면 { lcd.clear(); lcd.setCursor(0,0); lcd.print("Automatic Door"); lcd.setCursor(0,1); lcd.print("JNUECE 151807"); } void DeveloperInfo() { lcd.clear(); lcd.setCursor(0,0); lcd.print("Jung Hoe Hyeong"); lcd.setCursor(0,1); lcd.print("commania.kr"); } void LightOn() { if(analogRead(CDS)>=330) digitalWrite(LED, LOW); else digitalWrite(LED, HIGH); delay(100); } void OpenDoor() //문 열기 { LightOn(); NameScreen(); Direction_rotation(1, 70); lcd.setCursor(0,1); lcd.print("Door Opened"); delay(1000); MotorStop(); delay(5000); Direction_rotation(0, 70); lcd.setCursor(0,1); lcd.print("Door Closed"); delay(1000); MotorStop(); delay(2000); DeveloperInfo(); delay(2000); IdleScreen(); digitalWrite(LED, LOW); } long Distance(long time, int flag){ long distance; if(flag) distance = time / 29 / 2; else distance = time / 74 / 2; return distance; }
2015년 2학기 아두이노 프로젝트 - 자동문
This post is licensed under
CC BY 4.0
by the author.
Comments powered by Disqus.