강의자료 코딩클럽 아두이노 워크샵-2015.4.11
-
Upload
songsup-shin -
Category
Education
-
view
383 -
download
4
Transcript of 강의자료 코딩클럽 아두이노 워크샵-2015.4.11
코딩클럽신송섭 ([email protected])1
2015.4.10
코딩클럽 신송섭
왕초보!! 아두이노 따라잡기
2탄
E-mail : [email protected]
F.B : www.facebook.com/songsup.shin
코딩클럽신송섭 ([email protected])2
강사 소개
• 이 름 : 신 송 섭
• EMail : [email protected]
• FB : www.facebook.com/songsup.shin
코딩클럽신송섭 ([email protected])3
목차
• 따라해보기 #1 RGB LED 제어하기
• 따라해보기 #2 소리내기
• 따라해보기 #3 빛 감지하기
• 따라해보기 #4 온도측정하기
코딩클럽신송섭 ([email protected])9
실습 #1 - 사용함수
• pinMode();– 기능 : 디지털 입출력 핀을 입력 또는 출력으로 설정– Syntax
pinMode(pin, mode);
• digitalWrite();– 기능 : 디지털 핀에 HIGH or LOW를 쓴다.– Syntax
digitalWrite(pin,mode);– Parameter
pin : 디지털 핀 번호mode : HIGH or LOW(1 or 0)
• analogWrite();– 기능 : 디지털 핀에 PWM 신호 출력- Syntax
analogWrite(pin, value);- Parameter
pin : 핀번호value : duty cycle( 0 ~255)
0 : always off255 : always on
- PWM(Pulse Width Modulation)
코딩클럽신송섭 ([email protected])10
실습 #1 – RGB LED On/Off
330ohm
1. int redLed = 9;
2. int greenLed=10;
3. int blueLed=11;
4. void setup( ) {
5. pinMode(redLed, OUTPUT);
6. pinMode(greenLed, OUTPUT);
7. pinMode(blueLed, OUTPUT);
8. }
9. void loop( ) {
10. digitalWrite(redLed, HIGH);
11. digitalWrite(greenLed, HIGH);
12. digitalWrite(blueLed, HIGH);
13.}
코딩클럽신송섭 ([email protected])11
실습 #1 – RGB LED Fading
analogWrite();
- 기능 : 디지털 핀에 PWM 신호 출력
- Syntax
analogWrite(pin, value);
- Parameter
pin : 핀번호
value : duty cycle( 0 ~255)
0 : always off
255 : always on
- PWM(Pulse Width Modulation)
1. int redLed = 9;2. int greenLed=10; 3. int blueLed=11;
4. void setup( ) {5. pinMode(redLed, OUTPUT); 6. pinMode(greenLed, OUTPUT); 7. pinMode(blueLed, OUTPUT); 8. }
9. void loop( ) {
10. int i=0;
11. for(i=0;i<255;i++){12. analogWrite(redLed, i);13. delay(50);14. }15.16. for(i=0;i<255;i++){17. analogWrite(greenLed, i);18. delay(50);19. }20.21. for(i=0;i<255;i++){22. analogWrite(blueLed, i);23. delay(50);24. }25. }
코딩클럽신송섭 ([email protected])14
실습#2 – 회로연결하기
코딩클럽신송섭 ([email protected])15
실습 #2 - 사용함수
• tone()– 주파수에 해당하는 PWM 신호를 발생하는 함수
– Syntax
tone(pin, frequency);
tone(pin, frequency, duration);
– Parameter
• pin : 부저가 연결된 핀
• frequency : 출력 주파수
• duration : 톤이 유지되는 시간(milliseconds)
코딩클럽신송섭 ([email protected])16
실습 #2 – 부저 소리내기
1. int buzPin=6;
2. void setup( ) {
3. pinMode(buzPin, OUTPUT);
4. }
5. void loop( ) {
6. tone(buzPin, 1000, 200);
7. delay(300);
8. }
코딩클럽신송섭 ([email protected])17
실습 #2 – 계이름 소리내기
1. #define NOTE_C4 262
2. #define NOTE_CS4 277
3. #define NOTE_D4 294
4. #define NOTE_DS4 311
5. #define NOTE_E4 330
6. #define NOTE_F4 349
7. #define NOTE_FS4 370
8. #define NOTE_G4 392
9. #define NOTE_GS4 415
10. #define NOTE_A4 440
11. #define NOTE_AS4 466
12. #define NOTE_B4 494
13. #define NOTE_C5 523
1. int buzPin=6;
2. int noteDuration=500;
3. void setup( ) {
4. pinMode(buzPin, OUTPUT);
5. }
6. void loop( ) {
7. tone(buzPin, NOTE_C4, noteDuration);
8. delay(500);
9. tone(buzPin, NOTE_D4, noteDuration);
10. delay(500);
11. tone(buzPin, NOTE_E4, noteDuration);
12. delay(500);
13. tone(buzPin, NOTE_F4, noteDuration);
14. delay(500);
15. tone(buzPin, NOTE_G4, noteDuration);
16. delay(500);
17. tone(buzPin, NOTE_A4, noteDuration);
18. delay(500);
19. tone(buzPin, NOTE_B4, noteDuration);
20. delay(500);
21. tone(buzPin, NOTE_C5, noteDuration);
22. delay(500);
23. }
코딩클럽신송섭 ([email protected])19
실습 #3 – 빛 감지하기
Photocell, CdS cell, photoresistors, LDR(Light dependent resistor), 광도전 센서
10kohm
코딩클럽신송섭 ([email protected])20
실습 #3 - 사용함수
• analogRead();– 아날로그 센서의 값을 읽는 함수– Syntax
“sensorValue”=analogRead(pin);– Parameter
pin : 부저가 연결된 핀
• Serial.begin();– 기능 : 시리얼포트의 보드 레이트를 설정– Syntax
Serial.begin(baud_rate);– Parameter
baud_rate : 300, 600, 1200, 2400, 4800, 9600, 14440, 19200, 28800, 57600, 115200값으로 셋팅
• Serial.print(); and Serial.println();– 기능 : 시리얼 포트로 변수값을 출력– Sytax
Serial.print(val);Serial.print(val, format);
– Parameterval : 출력값 – 숫자, 문자, 문자열, 특수기호(\n,\t,\r, …)format : BIN, OCT, DEC, HEX, 소수점 자릿수,
- ExampleSerial.print(78);Serial.print(1.23456);Serial.print(‘N’);Serial.print(“Hello world”);Serial.print(“\n \r”);Serial.print(78, BIN);Serial.print(1.23456,3);
코딩클럽신송섭 ([email protected])21
실습 #3 – 빛의 세기에 따라 LED 밝기 변화시키기
1. int redLed = 9;
2. int greenLed = 10;
3. int blueLed = 11;
4. int sensorPin = A0;
5. int sensorValue = 0;
6. void setup() {
7. pinMode(redLed, OUTPUT);
8. pinMode(greenLed, OUTPUT);
9. pinMode(blueLed, OUTPUT);
10. Serial.begin(9600);
11. }
12. void loop() {
13. sensorValue = analogRead(sensorPin);
14. Serial.println(sensorValue);
15. analogWrite(redLed, map(sensorValue, 0,1023, 0, 255));
16. delay(sensorValue);
17. digitalWrite(redLed, LOW);
18. delay(sensorValue);
19. }
코딩클럽신송섭 ([email protected])23
실습 #4 - 온도센서
• 반도체 온도센서– 아날로그타입 : LM35, TMP36, …
– 디지털 타입 : 18B20, DHTX1, SHTX1, …
코딩클럽신송섭 ([email protected])25
실습 #4 – 온도센서 프로그램하기
1. int sensorPin = A1;2. float sensorValue = 0;
3. void setup()4. {5. Serial.begin(9600);6. }
7. void loop() {
8. int sensorValue = analogRead(sensorPin);
9. // 아날로그 측정-값을 전압값으로 변환10. float voltage = sensorValue * 5.0/1024;
11. // 전압값으로 표현12. Serial.print(voltage); Serial.println(" volts");13.14. // 전압값을 온도로 변환15. // TMP36은 0℃일때 500mV를 나타내며16. // 1 ℃ 변할 때 마다 10mV 변함17. //500 mV 오프셋,
18. float temperatureC = (voltage *1000 - 500) / 10 ;
19. Serial.print(temperatureC); Serial.println(" degrees C");
20. delay(1000);21. }
코딩클럽신송섭 ([email protected])26
시스템 구성
아두이노보드
온도센서
빛센서
터치센서
초음파센서
DC 모터
LED
LCD
부저
저장장치
네트워크(WiFi, BT, ZigBee,---)
초음파센서
초음파센서
코딩클럽신송섭 ([email protected])27
Arduino 개발방법
아디디어 구상
자료수집
부품구매
하드웨어
코딩
디버깅
• 회로도를 찾아보자• 부품에 해당되는 라이브러리가 있을까?• 없으면 라이브러리가 있는 부품을 구하자
• 온라인• Devicemart.co.kr• Eleparts.co.kr• Icbanq.co.kr• 오픈마켓(G마켓, 11번가, 옥션, …)• 알리바바, 알리익스프레스, 아마존,..
• 오프라인• 구로유통상가• 청계천• 안양유통상가
• 브래드보드에 회로를 구성한다.• PCB에 회로를 구성한다. <- 고수
• 라이브러리를 설치한다• 응용프로그램을 코딩한다.
• 현상보고 문제 예측하기• 소프트웨어 구성대로 하드웨어가 동작하는지?• 소프트웨어는 정확히 구성되어 있는가..?• 소프트웨어 검증방법은?• 소프트웨어에서 설정한대로 하드웨어가 연결되었는가?• 하드웨어 문제인가?• 왜?• 하드웨어 검증방법은? • 미궁에 빠지다• 열정과 노력이 필요함
코딩클럽신송섭 ([email protected])28
만들어보기
코딩클럽신송섭 ([email protected])29
• 온도 센서를 이용해서 특정한 온도가 되면 R, G, B LED를 켠다.
• 레이저 커터를 이용해서 모양을 만들고 RGB LED를 이용해서 액자를 만들어본다.
• 온도에 따라 LED 색이 변하는 액자를 만들어 본다.
• 빛의 밝기에 따라 LED 색이 변하는 액자를 만들어 본다.
코딩클럽신송섭 ([email protected])30
감사합니다.