powerpoint 프레젠테이션vulkan.co.kr/doc_arduino_02/004/아두이노_plc... · 2018-11-22 ·...
TRANSCRIPT
![Page 1: PowerPoint 프레젠테이션vulkan.co.kr/doc_arduino_02/004/아두이노_PLC... · 2018-11-22 · 디지털명령어 02 - 1 디지털명령어 2. 디지털센서값의처리 02 아두이노와plc를이용한iot](https://reader030.vdocuments.mx/reader030/viewer/2022040722/5e304cfe59b34447965f1a95/html5/thumbnails/1.jpg)
디지털 명령어
2-1 디지털명령어2-2 디지털부품연결하기2-3 LED 제어하기2-4 Setup 함수2-5 콘솔에값출력하기2-6 버튼으로 LED 제어하기2-7 토글스위치구현하기2-8 응용실습
02
![Page 2: PowerPoint 프레젠테이션vulkan.co.kr/doc_arduino_02/004/아두이노_PLC... · 2018-11-22 · 디지털명령어 02 - 1 디지털명령어 2. 디지털센서값의처리 02 아두이노와plc를이용한iot](https://reader030.vdocuments.mx/reader030/viewer/2022040722/5e304cfe59b34447965f1a95/html5/thumbnails/2.jpg)
디지털명령어
02 - 1 디지털명령어
1. 아두이노 명령어 규칙
02
아두이노와 PLC를 이용한 IoT 구현 실습
2
![Page 3: PowerPoint 프레젠테이션vulkan.co.kr/doc_arduino_02/004/아두이노_PLC... · 2018-11-22 · 디지털명령어 02 - 1 디지털명령어 2. 디지털센서값의처리 02 아두이노와plc를이용한iot](https://reader030.vdocuments.mx/reader030/viewer/2022040722/5e304cfe59b34447965f1a95/html5/thumbnails/3.jpg)
디지털명령어
02 - 1 디지털명령어
2. 디지털 센서 값의 처리
02
아두이노와 PLC를 이용한 IoT 구현 실습
3
디지털 센서의 출력 또는 입력
5V
0V
HIGH (1)
LOW (0)
아두이노 보드에서의디지털 센서값 처리
![Page 4: PowerPoint 프레젠테이션vulkan.co.kr/doc_arduino_02/004/아두이노_PLC... · 2018-11-22 · 디지털명령어 02 - 1 디지털명령어 2. 디지털센서값의처리 02 아두이노와plc를이용한iot](https://reader030.vdocuments.mx/reader030/viewer/2022040722/5e304cfe59b34447965f1a95/html5/thumbnails/4.jpg)
디지털명령어
02 - 1 디지털명령어
3. 디지털 명령어 예시
02
아두이노와 PLC를 이용한 IoT 구현 실습
4
아두이노에서 특별히 디지털 센서 값은 다음과 같이 예약어로사용됩니다.
5V
0V
HIGH 라는 단어를 사용합니다.
LOW 라는 단어를 사용합니다.
예) DigitalWrite(13, HIGH)
예) DigitalWrite(13, LOW)
![Page 5: PowerPoint 프레젠테이션vulkan.co.kr/doc_arduino_02/004/아두이노_PLC... · 2018-11-22 · 디지털명령어 02 - 1 디지털명령어 2. 디지털센서값의처리 02 아두이노와plc를이용한iot](https://reader030.vdocuments.mx/reader030/viewer/2022040722/5e304cfe59b34447965f1a95/html5/thumbnails/5.jpg)
디지털명령어
02 - 1 디지털명령어
4. 디지털 명령어 종류
02
아두이노와 PLC를 이용한 IoT 구현 실습
5
• 디지털 핀에 값을 쓸 때 사용하는 명령어
DigitalWrite (핀번호, 값)
• 디지털 핀에서 값을 읽어 올 때 사용하는 명령어
DigitalRead (핀번호)
![Page 6: PowerPoint 프레젠테이션vulkan.co.kr/doc_arduino_02/004/아두이노_PLC... · 2018-11-22 · 디지털명령어 02 - 1 디지털명령어 2. 디지털센서값의처리 02 아두이노와plc를이용한iot](https://reader030.vdocuments.mx/reader030/viewer/2022040722/5e304cfe59b34447965f1a95/html5/thumbnails/6.jpg)
디지털명령어
02 - 2 디지털부품 연결하기
1. 디지털 핀의 위치
02
아두이노와 PLC를 이용한 IoT 구현 실습
6
모터 2핀 x 2 아날로그 3핀
디지털 3핀I2C 4핀
시리얼 4핀
브래드 보드가 필요없는초보자용 아두이노 보드
![Page 7: PowerPoint 프레젠테이션vulkan.co.kr/doc_arduino_02/004/아두이노_PLC... · 2018-11-22 · 디지털명령어 02 - 1 디지털명령어 2. 디지털센서값의처리 02 아두이노와plc를이용한iot](https://reader030.vdocuments.mx/reader030/viewer/2022040722/5e304cfe59b34447965f1a95/html5/thumbnails/7.jpg)
디지털명령어
02 - 2 디지털부품 연결하기
2. 디지털 부품 연결하기
02
아두이노와 PLC를 이용한 IoT 구현 실습
7
디지털 부품은 디지털핀에 연결합니다.
디지털 핀에는2번 ~ 13번 까지번호가 표시되어 있습니다.(D2 ~ D13)
디지털 핀에 부품을 연결할때에는 핀 번호를 확인해야합니다.
![Page 8: PowerPoint 프레젠테이션vulkan.co.kr/doc_arduino_02/004/아두이노_PLC... · 2018-11-22 · 디지털명령어 02 - 1 디지털명령어 2. 디지털센서값의처리 02 아두이노와plc를이용한iot](https://reader030.vdocuments.mx/reader030/viewer/2022040722/5e304cfe59b34447965f1a95/html5/thumbnails/8.jpg)
디지털명령어
02 - 2 디지털부품 연결하기
2. 디지털 부품 연결하기
02
아두이노와 PLC를 이용한 IoT 구현 실습
8
디지털 센서는케이블이 녹색선으로표시되어 있습니다.
GND
VCC 또는 5V
디지털 데이터 선
![Page 9: PowerPoint 프레젠테이션vulkan.co.kr/doc_arduino_02/004/아두이노_PLC... · 2018-11-22 · 디지털명령어 02 - 1 디지털명령어 2. 디지털센서값의처리 02 아두이노와plc를이용한iot](https://reader030.vdocuments.mx/reader030/viewer/2022040722/5e304cfe59b34447965f1a95/html5/thumbnails/9.jpg)
디지털명령어
02 - 3 LED 제어하기
1. LED 소자 연결하기
02
아두이노와 PLC를 이용한 IoT 구현 실습
9
LED소자
디지털 13번에 연결합니다.
![Page 10: PowerPoint 프레젠테이션vulkan.co.kr/doc_arduino_02/004/아두이노_PLC... · 2018-11-22 · 디지털명령어 02 - 1 디지털명령어 2. 디지털센서값의처리 02 아두이노와plc를이용한iot](https://reader030.vdocuments.mx/reader030/viewer/2022040722/5e304cfe59b34447965f1a95/html5/thumbnails/10.jpg)
디지털명령어
02 - 3 LED 제어하기
1. LED 소자 연결하기
02
아두이노와 PLC를 이용한 IoT 구현 실습
10
디지털 13번에 연결합니다.
13번(D13)
![Page 11: PowerPoint 프레젠테이션vulkan.co.kr/doc_arduino_02/004/아두이노_PLC... · 2018-11-22 · 디지털명령어 02 - 1 디지털명령어 2. 디지털센서값의처리 02 아두이노와plc를이용한iot](https://reader030.vdocuments.mx/reader030/viewer/2022040722/5e304cfe59b34447965f1a95/html5/thumbnails/11.jpg)
디지털명령어
02 - 3 LED 제어하기
1. LED 소자 연결하기
02
아두이노와 PLC를 이용한 IoT 구현 실습
11
디지털 부품을연결할 때에는선의 색상(검정, 빨강, 초록)순서 및 핀 위치를확인하여 연결합니다.
왼쪽은 LED소자를디지털 13번 핀에 연결한예입니다.
![Page 12: PowerPoint 프레젠테이션vulkan.co.kr/doc_arduino_02/004/아두이노_PLC... · 2018-11-22 · 디지털명령어 02 - 1 디지털명령어 2. 디지털센서값의처리 02 아두이노와plc를이용한iot](https://reader030.vdocuments.mx/reader030/viewer/2022040722/5e304cfe59b34447965f1a95/html5/thumbnails/12.jpg)
디지털명령어
02 - 3 LED 제어하기
2. LED 점멸 시키기
02
아두이노와 PLC를 이용한 IoT 구현 실습
12
void setup(){}
void loop(){
DigitalWrite(13, HIGH)Delay(1000)DigitalWrite(13, LOW)Delay(1000)
}
![Page 13: PowerPoint 프레젠테이션vulkan.co.kr/doc_arduino_02/004/아두이노_PLC... · 2018-11-22 · 디지털명령어 02 - 1 디지털명령어 2. 디지털센서값의처리 02 아두이노와plc를이용한iot](https://reader030.vdocuments.mx/reader030/viewer/2022040722/5e304cfe59b34447965f1a95/html5/thumbnails/13.jpg)
디지털명령어
02 - 3 LED 제어하기
3. 프로그램 실행하기
02
아두이노와 PLC를 이용한 IoT 구현 실습
13
![Page 14: PowerPoint 프레젠테이션vulkan.co.kr/doc_arduino_02/004/아두이노_PLC... · 2018-11-22 · 디지털명령어 02 - 1 디지털명령어 2. 디지털센서값의처리 02 아두이노와plc를이용한iot](https://reader030.vdocuments.mx/reader030/viewer/2022040722/5e304cfe59b34447965f1a95/html5/thumbnails/14.jpg)
디지털명령어
02 - 3 LED 제어하기
4. LED 제어 응용 실습
02
아두이노와 PLC를 이용한 IoT 구현 실습
14
![Page 15: PowerPoint 프레젠테이션vulkan.co.kr/doc_arduino_02/004/아두이노_PLC... · 2018-11-22 · 디지털명령어 02 - 1 디지털명령어 2. 디지털센서값의처리 02 아두이노와plc를이용한iot](https://reader030.vdocuments.mx/reader030/viewer/2022040722/5e304cfe59b34447965f1a95/html5/thumbnails/15.jpg)
디지털명령어
02 - 4 Setup 함수
1. 아두이노 프로그램의 구조
02
아두이노와 PLC를 이용한 IoT 구현 실습
15
void setup(){
}
void loop(){
}
Setup 함수는 가장 먼저 실행되며한번만 실행됩니다.
Loop 함수는 Setup 함수 실행이 끝난 후 실행되며, 아두이노 보드에 전원이 공급되는 한 무한히 반복하여실행됩니다.
![Page 16: PowerPoint 프레젠테이션vulkan.co.kr/doc_arduino_02/004/아두이노_PLC... · 2018-11-22 · 디지털명령어 02 - 1 디지털명령어 2. 디지털센서값의처리 02 아두이노와plc를이용한iot](https://reader030.vdocuments.mx/reader030/viewer/2022040722/5e304cfe59b34447965f1a95/html5/thumbnails/16.jpg)
디지털명령어
02 - 4 Setup 함수
2. Setup 함수
02
아두이노와 PLC를 이용한 IoT 구현 실습
16
![Page 17: PowerPoint 프레젠테이션vulkan.co.kr/doc_arduino_02/004/아두이노_PLC... · 2018-11-22 · 디지털명령어 02 - 1 디지털명령어 2. 디지털센서값의처리 02 아두이노와plc를이용한iot](https://reader030.vdocuments.mx/reader030/viewer/2022040722/5e304cfe59b34447965f1a95/html5/thumbnails/17.jpg)
디지털명령어
02 - 4 Setup 함수
3. Loop 함수
02
아두이노와 PLC를 이용한 IoT 구현 실습
17
![Page 18: PowerPoint 프레젠테이션vulkan.co.kr/doc_arduino_02/004/아두이노_PLC... · 2018-11-22 · 디지털명령어 02 - 1 디지털명령어 2. 디지털센서값의처리 02 아두이노와plc를이용한iot](https://reader030.vdocuments.mx/reader030/viewer/2022040722/5e304cfe59b34447965f1a95/html5/thumbnails/18.jpg)
디지털명령어
02 - 4 Setup 함수
4. 실습
02
아두이노와 PLC를 이용한 IoT 구현 실습
18
디지털 13번 핀에 연결된 LED 소자를 0.5초간 3번 점멸 한 후, 항상 꺼져
있도록 기존 프로그램을 수정해 봅니다.
![Page 19: PowerPoint 프레젠테이션vulkan.co.kr/doc_arduino_02/004/아두이노_PLC... · 2018-11-22 · 디지털명령어 02 - 1 디지털명령어 2. 디지털센서값의처리 02 아두이노와plc를이용한iot](https://reader030.vdocuments.mx/reader030/viewer/2022040722/5e304cfe59b34447965f1a95/html5/thumbnails/19.jpg)
디지털명령어
02 - 4 Setup 함수
4. 실습
02
아두이노와 PLC를 이용한 IoT 구현 실습
19
void setup(){}
void loop(){
DigitalWrite(13, HIGH)Delay(1000)DigitalWrite(13, LOW)Delay(1000)
}
void setup(){
}
void loop(){
}
![Page 20: PowerPoint 프레젠테이션vulkan.co.kr/doc_arduino_02/004/아두이노_PLC... · 2018-11-22 · 디지털명령어 02 - 1 디지털명령어 2. 디지털센서값의처리 02 아두이노와plc를이용한iot](https://reader030.vdocuments.mx/reader030/viewer/2022040722/5e304cfe59b34447965f1a95/html5/thumbnails/20.jpg)
디지털명령어
02 - 5 콘솔에값 출력하기
1. 콘솔에 값을 출력하는 명령어
02
아두이노와 PLC를 이용한 IoT 구현 실습
20
Print(값)- 값을 이어서 출력합니다.
PrintLine(값)- 값을 출력한 후, 줄을 바꿉니다.
실제 스케치 코드는 Serial.println(값); 형태임
![Page 21: PowerPoint 프레젠테이션vulkan.co.kr/doc_arduino_02/004/아두이노_PLC... · 2018-11-22 · 디지털명령어 02 - 1 디지털명령어 2. 디지털센서값의처리 02 아두이노와plc를이용한iot](https://reader030.vdocuments.mx/reader030/viewer/2022040722/5e304cfe59b34447965f1a95/html5/thumbnails/21.jpg)
디지털명령어
02 - 5 콘솔에값 출력하기
2. 1초 간격으로 “Hello World” 한 줄씩 출력하기
02
아두이노와 PLC를 이용한 IoT 구현 실습
21
void setup(){
}
void loop(){
PrintLine(“Hello World”)Delay(1000)
}
![Page 22: PowerPoint 프레젠테이션vulkan.co.kr/doc_arduino_02/004/아두이노_PLC... · 2018-11-22 · 디지털명령어 02 - 1 디지털명령어 2. 디지털센서값의처리 02 아두이노와plc를이용한iot](https://reader030.vdocuments.mx/reader030/viewer/2022040722/5e304cfe59b34447965f1a95/html5/thumbnails/22.jpg)
디지털명령어
02 - 5 콘솔에값 출력하기
3. 문자열을 붙여서 출력하기 -> Print() 명령어
02
아두이노와 PLC를 이용한 IoT 구현 실습
22
void setup(){
}
void loop(){
Print(“Hi, “)PrintLine(“Hello World”)Delay(1000)
}
![Page 23: PowerPoint 프레젠테이션vulkan.co.kr/doc_arduino_02/004/아두이노_PLC... · 2018-11-22 · 디지털명령어 02 - 1 디지털명령어 2. 디지털센서값의처리 02 아두이노와plc를이용한iot](https://reader030.vdocuments.mx/reader030/viewer/2022040722/5e304cfe59b34447965f1a95/html5/thumbnails/23.jpg)
디지털명령어
02 - 6 버튼으로 LED 제어하기
1. 버튼 연결하기
02
아두이노와 PLC를 이용한 IoT 구현 실습
23
다음과 같이 디지털 13번에 LED, 디지털 2번에 버튼을 연결해 봅니다.
13번(D13)
2번(D02)
![Page 24: PowerPoint 프레젠테이션vulkan.co.kr/doc_arduino_02/004/아두이노_PLC... · 2018-11-22 · 디지털명령어 02 - 1 디지털명령어 2. 디지털센서값의처리 02 아두이노와plc를이용한iot](https://reader030.vdocuments.mx/reader030/viewer/2022040722/5e304cfe59b34447965f1a95/html5/thumbnails/24.jpg)
디지털명령어
02 - 6 버튼으로 LED 제어하기
1. 버튼 연결하기
02
아두이노와 PLC를 이용한 IoT 구현 실습
24
다음과 같이 디지털 13번에 LED, 디지털 2번에 버튼을 연결해 봅니다.
![Page 25: PowerPoint 프레젠테이션vulkan.co.kr/doc_arduino_02/004/아두이노_PLC... · 2018-11-22 · 디지털명령어 02 - 1 디지털명령어 2. 디지털센서값의처리 02 아두이노와plc를이용한iot](https://reader030.vdocuments.mx/reader030/viewer/2022040722/5e304cfe59b34447965f1a95/html5/thumbnails/25.jpg)
디지털명령어
02 - 6 버튼으로 LED 제어하기
2. 버튼값 콘솔창에 출력하기
02
아두이노와 PLC를 이용한 IoT 구현 실습
25
void setup(){
}
void loop(){
d = DigitalRead(2)PrintLine(d)Delay(100)
}
![Page 26: PowerPoint 프레젠테이션vulkan.co.kr/doc_arduino_02/004/아두이노_PLC... · 2018-11-22 · 디지털명령어 02 - 1 디지털명령어 2. 디지털센서값의처리 02 아두이노와plc를이용한iot](https://reader030.vdocuments.mx/reader030/viewer/2022040722/5e304cfe59b34447965f1a95/html5/thumbnails/26.jpg)
디지털명령어
02 - 6 버튼으로 LED 제어하기
3. 버튼값으로 LED 제어하기
02
아두이노와 PLC를 이용한 IoT 구현 실습
26
• 실습 목표
• 버튼을 누르고 있는 동안 LED가 켜지게 합니다.
• 실습 내용
• 디지털 버튼의 눌림 상태를 읽어 옵니다.
• 디지털 버튼의 상태에 따라 다음과 같이 LED를 제어합니다.
• 버튼이 눌려져 있으면 LED를 켭니다.
• 버튼이 눌려져 있지 않으면 LED를 끕니다.
![Page 27: PowerPoint 프레젠테이션vulkan.co.kr/doc_arduino_02/004/아두이노_PLC... · 2018-11-22 · 디지털명령어 02 - 1 디지털명령어 2. 디지털센서값의처리 02 아두이노와plc를이용한iot](https://reader030.vdocuments.mx/reader030/viewer/2022040722/5e304cfe59b34447965f1a95/html5/thumbnails/27.jpg)
디지털명령어
02 - 6 버튼으로 LED 제어하기
4. If 조건문 추가하기
02
아두이노와 PLC를 이용한 IoT 구현 실습
27
void loop(){
d = DigitalRead(2)PrintLine(d)
if (d == HIGH){
}else{
}Delay(100)
}
![Page 28: PowerPoint 프레젠테이션vulkan.co.kr/doc_arduino_02/004/아두이노_PLC... · 2018-11-22 · 디지털명령어 02 - 1 디지털명령어 2. 디지털센서값의처리 02 아두이노와plc를이용한iot](https://reader030.vdocuments.mx/reader030/viewer/2022040722/5e304cfe59b34447965f1a95/html5/thumbnails/28.jpg)
디지털명령어
02 - 6 버튼으로 LED 제어하기
5. LED 명령어 추가하기
02
아두이노와 PLC를 이용한 IoT 구현 실습
28
void loop(){
d = DigitalRead(2)PrintLine(d)
if (d == HIGH){
DigitalWrite(13, HIGH)}else{
DigitalWrite(13, LOW)}Delay(100)
}
![Page 29: PowerPoint 프레젠테이션vulkan.co.kr/doc_arduino_02/004/아두이노_PLC... · 2018-11-22 · 디지털명령어 02 - 1 디지털명령어 2. 디지털센서값의처리 02 아두이노와plc를이용한iot](https://reader030.vdocuments.mx/reader030/viewer/2022040722/5e304cfe59b34447965f1a95/html5/thumbnails/29.jpg)
디지털명령어
02 - 7 토글 스위치구현하기
1. LED 상태를 전역변수로 정의하기
02
아두이노와 PLC를 이용한 IoT 구현 실습
29
led_on = 0
void loop(){
d = DigitalRead(2)if (d == HIGH){
if (led_on == 1)led_on = 0
elseled_on = 1
}PrintLine(led_on)
if (led_on)DigitalWrite(13, HIGH)
elseDigitalWrite(13, LOW)
Delay(100)}
![Page 30: PowerPoint 프레젠테이션vulkan.co.kr/doc_arduino_02/004/아두이노_PLC... · 2018-11-22 · 디지털명령어 02 - 1 디지털명령어 2. 디지털센서값의처리 02 아두이노와plc를이용한iot](https://reader030.vdocuments.mx/reader030/viewer/2022040722/5e304cfe59b34447965f1a95/html5/thumbnails/30.jpg)
디지털명령어
02 - 7 토글 스위치구현하기
2. 중복눌림 방지 기능이 추가된 코드
02
아두이노와 PLC를 이용한 IoT 구현 실습
30
void loop(){
d = DigitalRead(2)if (d == HIGH){
if (pressed == 0){
if (led_on == 1)led_on = 0
elseled_on = 1
}
pressed = 1}else
pressed = 0
PrintLine(led_on)
if (led_on)DigitalWrite(13, HIGH)
elseDigitalWrite(13, LOW)
Delay(100)}
led_on = 0pressed = 0
전역변수
![Page 31: PowerPoint 프레젠테이션vulkan.co.kr/doc_arduino_02/004/아두이노_PLC... · 2018-11-22 · 디지털명령어 02 - 1 디지털명령어 2. 디지털센서값의처리 02 아두이노와plc를이용한iot](https://reader030.vdocuments.mx/reader030/viewer/2022040722/5e304cfe59b34447965f1a95/html5/thumbnails/31.jpg)
디지털명령어
02 - 8 응용 실습
1. 버튼으로 숫자 세기 (숫자 세는 카운터 장치 만들기)
02
아두이노와 PLC를 이용한 IoT 구현 실습
31
count = 0pressed = 0
void loop(){
d = DigitalRead(2)if (d == HIGH){
if (pressed == 0){
count = count + 1PrintLine(count)
}
pressed = 1}else
pressed = 0
Delay(100)}