Recent Posts
printf("ho_tari\n");
<프로젝트> 스마트 주차장 본문
<Flow Chart>
<회로도>
<사용 센서>
<주차 출입 및 주차 유도 센서 코드>
#include <Servo.h>
Servo myservo;
#define ir_enter 2
#define ir_back 3
#define ir_car1 5
#define ir_car2 6
#define ir_car3 7
#define ir_car4 8
#define redPin1 9
#define greenPin1 10
#define bluePin1 A3
#define redPin2 11
#define greenPin2 12
#define bluePin2 A3
#define redPin3 13
#define greenPin3 A0
#define bluePin3 A3
#define redPin4 A2
#define greenPin4 A1
#define bluePin4 A3
#define buzzerPin A4
int flag1 = 0, flag2 = 0;
int tmp1 = 2000;
int tmp2 = 2000;
int tmp3, tmp4, tmp5, tmp6;
int pos = 0;
int buzzerFlag = 0;
void setup() {
Serial.begin(9600);
pinMode(ir_car1, INPUT);
pinMode(ir_car2, INPUT);
pinMode(ir_car3, INPUT);
pinMode(ir_car4, INPUT);
pinMode(ir_enter, INPUT);
pinMode(ir_back, INPUT);
pinMode(redPin1, OUTPUT);
pinMode(greenPin1, OUTPUT);
pinMode(bluePin1, OUTPUT);
digitalWrite(greenPin1, HIGH);
pinMode(redPin2, OUTPUT);
pinMode(greenPin2, OUTPUT);
pinMode(bluePin2, OUTPUT);
digitalWrite(greenPin2, HIGH);
pinMode(redPin3, OUTPUT);
pinMode(greenPin3, OUTPUT);
pinMode(bluePin3, OUTPUT);
digitalWrite(greenPin3, HIGH);
pinMode(redPin4, OUTPUT);
pinMode(greenPin4, OUTPUT);
pinMode(bluePin4, OUTPUT);
digitalWrite(greenPin4, HIGH);
myservo.attach(4);
myservo.write(0);
pinMode(buzzerPin, OUTPUT);
}
void loop() {
if (Serial.available() >= 2) {
tmp1 = Serial.parseInt();
tmp2 = Serial.parseInt();
Serial.print("tmp1: ");
Serial.println(tmp1);
Serial.print("tmp2: ");
Serial.println(tmp2);
if (tmp1 == 0 || tmp2 == 0) {
for(pos = 0; pos <= 90; pos += 1) {
myservo.write(pos);
flag1 = 1;
flag2 = 1;
delay(15);
}
}
else if (flag1 == 1 && flag2 == 1) {
for(pos = 90; pos >= 0; pos -= 1) {
myservo.write(pos);
flag1 = 0;
flag2 = 0;
delay(15);
}
}
}
if (pos != 0 && !buzzerFlag) {
tone(buzzerPin, 1000);
delay(500);
buzzerFlag = 1;
}
else if (pos == 0) {
noTone(buzzerPin);
buzzerFlag = 0;
}
if (Serial.available() >= 4) {
tmp3 = Serial.parseInt();
tmp4 = Serial.parseInt();
tmp5 = Serial.parseInt();
tmp6 = Serial.parseInt();
Serial.print("tmp3: ");
Serial.println(tmp3);
Serial.print("tmp4: ");
Serial.println(tmp4);
Serial.print("tmp5: ");
Serial.println(tmp5);
Serial.print("tmp6: ");
Serial.println(tmp6);
if (tmp3 == 0) {
digitalWrite(redPin1, HIGH);
digitalWrite(greenPin1, LOW);
digitalWrite(bluePin1, LOW);
} else if(tmp3 == 1) {
digitalWrite(redPin1, LOW);
digitalWrite(greenPin1, HIGH);
digitalWrite(bluePin1, LOW);
}
if (tmp4 == 0) {
digitalWrite(redPin2, HIGH);
digitalWrite(greenPin2, LOW);
digitalWrite(bluePin2, LOW);
} else if(tmp4 == 1) {
digitalWrite(redPin2, LOW);
digitalWrite(greenPin2, HIGH);
digitalWrite(bluePin2, LOW);
}
if (tmp5 == 0) {
digitalWrite(redPin3, HIGH);
digitalWrite(greenPin3, LOW);
digitalWrite(bluePin3, LOW);
} else if(tmp5 == 1) {
digitalWrite(redPin3, LOW);
digitalWrite(greenPin3, HIGH);
digitalWrite(bluePin3, LOW);
}
if (tmp6 == 0) {
digitalWrite(redPin4, HIGH);
digitalWrite(greenPin4, LOW);
digitalWrite(bluePin4, LOW);
} else if(tmp6 == 1) {
digitalWrite(redPin4, LOW);
digitalWrite(greenPin4, HIGH);
digitalWrite(bluePin4, LOW);
}
}
delay(100);
}
<LCD에 주차 현황 출력 코드>
<입출차 시 경고음 및 경고등>
const int ir_sensor_pin = 12;
const int buzzer_pin = 13;
const int redpin1 = 6; // Replace with your red LED pin number
const int greenpin1 = 7;
const int bluepin1 = 8; // Replace with your blue LED pin number
const int redpin2 = 9;
const int greenpin2 = 10;
const int bluepin2 = 11;
void setup() {
pinMode(ir_sensor_pin, INPUT);
pinMode(buzzer_pin, OUTPUT);
pinMode(redpin1, OUTPUT);
pinMode(greenpin1, OUTPUT);
pinMode(bluepin1, OUTPUT);
pinMode(redpin2, OUTPUT);
pinMode(greenpin2, OUTPUT);
pinMode(bluepin2, OUTPUT);
digitalWrite(buzzer_pin, LOW);
}
void loop() {
int ir_value = digitalRead(ir_sensor_pin);
if (ir_value == LOW) {
tone(buzzer_pin, 700);
digitalWrite(redpin1, HIGH); // Turn on the red LED
delay(500);
noTone(buzzer_pin);
digitalWrite(redpin1, LOW); // Turn off the red LED
tone(buzzer_pin, 500);
digitalWrite(bluepin2, HIGH); // Turn on the blue LED
delay(500);
noTone(buzzer_pin);
digitalWrite(bluepin2, LOW); // Turn off the blue LED
tone(buzzer_pin, 700);
digitalWrite(redpin1, HIGH); // Turn on the red LED
delay(500);
noTone(buzzer_pin);
digitalWrite(redpin1, LOW); // Turn off the red LED
tone(buzzer_pin, 500);
digitalWrite(bluepin2, HIGH); // Turn on the blue LED
delay(500);
noTone(buzzer_pin);
digitalWrite(bluepin2, LOW); // Turn off the blue LED
tone(buzzer_pin, 700);
digitalWrite(redpin1, HIGH); // Turn on the red LED
delay(500);
noTone(buzzer_pin);
digitalWrite(redpin1, LOW); // Turn off the red LED
tone(buzzer_pin, 500);
digitalWrite(bluepin2, HIGH); // Turn on the blue LED
delay(500);
noTone(buzzer_pin);
digitalWrite(bluepin2, LOW); // Turn off the blue LED
}
delay(100);
}
<결과물>
<영상>
'Arduino' 카테고리의 다른 글
EX03_Binary_LED_Interrupt (0) | 2023.09.02 |
---|---|
EX02_DC_MOTOR (0) | 2023.09.02 |
EX01_Binary_LED (0) | 2023.09.02 |
17_Multi_Task (0) | 2023.09.02 |
16_Keypad_4x4 (0) | 2023.09.02 |