빵빵한아두이노센서키트 총 40 개의모듈과 40 핀케이블이포함되어있습니다. Version 1.1 릴리즈 2013 년 09 월 10 일 메카솔루션 1
Intro... 빵빵한센서키트는 40개의센서로이루어진패키지로아두이노초보자들을위해고안되었습니다. 초보자들이사용하기쉽도록납땜이필요없이간단히케이블을이용하여아두이노와연결할수있으며각각의센서에대한개괄적인설명및아두이노코드를제공함으로써센서를보다쉽게동작하고응용할수있습니다. 본매뉴얼에서다루게될센서는다음과같습니다. 1. 초음파거리센서모듈 2. 적외선인체감지센서모듈 3. 아날로그가속도센서모듈 4. 디지털온도센서모듈 5. 진동센서모듈 6. 홀자기센서모듈 7. 리셋버튼모듈 8. 적외선발광모듈 9. 수동부저모듈 10. 레이져발광모듈 11. RGB SMD LED 모듈 12. 포토인터럽트모듈 13. 듀얼컬러 LED 모듈 3mm ( 커먼캐소드 ) 14. 피에조버저모듈 15. 아날로그온도센서모듈 16. DHT11 디지털온도습도센서모듈 17. RGB 컬러 LED 모듈 18. 수은기울기스위칭센서모듈 19. 조도센서모듈 20. 5V 릴레이모듈 2
21. 기울기센서모듈 22. 소형리드스위치모듈 23. 적외선리모트컨트롤모듈 24. PS2 게임조이스틱모듈 25. 리니어홀자기센서모듈 26. 리드스위치모듈 27. 불꽃감지센서모듈 28. 매직라이트컵모듈 29. 디지털온도센서모듈 30. 듀얼컬러 LED 모듈 5mm ( 커먼캐소드 ) 31. 노크센서모듈 32. 적외선장애물감지센서모듈 33. 7 컬러플래시 LED 모듈 34. 아날로그홀자기센서모듈 35. 터치센서모듈 36. 고감도사운드센서모듈 37. 마이크로폰사운드감지센서모듈 38. 심박센서모듈 39. 트랙킹센서모듈 40. 로터리인코더모듈 3
1. 초음파거리센서모듈 - 기본정보 초음파를이용한거리센서 유효측정거리 : 2~500cm 입력전압 : 5V 4
- 핀연결 센서핀 vcc Trig Echo GND 아두이노핀 5V D12 D13 GND - Arduino 소스코드 #define trigpin 12 #define echopin 13 void setup() Serial.begin (9600); pinmode(trigpin, OUTPUT); pinmode(echopin, INPUT); void loop() int duration, distance; digitalwrite(trigpin, HIGH); delaymicroseconds(1000); digitalwrite(trigpin, LOW); duration = pulsein(echopin, HIGH); distance = (duration/2) / 29.1; if (distance >= 200 distance <= 0) Serial.println("Out of range"); else Serial.print(distance); Serial.println(" cm"); delay(500); (1000); // delay one second 5
2. 적외선인체감지센서모듈 - 기본정보 유효감지거리 : 7m 감지각도 : 120 작동전압 : 5V - 20V PCB Dimension: 32mm*24mm 6
- 핀연결 센서핀 GND OUT VCC 아두이노핀 GND D2 5V - Arduino 소스코드 int motion_1 = 2; int light_1 = 13; void setup() pinmode (motion_1,input); pinmode (light_1, OUTPUT); void loop () digitalwrite (light_1,low); delay(1000); //this delay is to let the sensor settle down before taking a reading int sensor_1 = digitalread(motion_1); if (sensor_1 == HIGH) digitalwrite(light_1,high); delay(500); digitalwrite(light_1,low); delay(500); 7
3. 아날로그가속도센서모듈 - 기본정보 손쉽게사용가능한아날로그출력형 3 축가속센서보드로 +3/-3g 측정영역의초절전저노이즈형제품으로안정된성능을제공. X, Y, Z 값을이용하여 Pitch 와 Roll 의값을구할수있음. Pitch = tan 1 x acc y 2 acc +z2 acc Roll = tan 1 y acc - 핀연결 x 2 acc +z2 acc 센서핀 아두이노핀 VCC 3.3V X_OUT A1 Y_OUT A2 Z_OUT A3 GND GND 8
- Arduino 소스코드 const int xpin = A1; const int ypin = A2; const int zpin = A3; // x-axis of the accelerometer // y-axis // z-axis (only on 3-axis models) int sampledelay = 500; //number of milliseconds between readings void setup() // initialize the serial communications: Serial.begin(9600); //Make sure the analog-to-digital converter takes its reference voltage from // the AREF pin analogreference(external); pinmode(xpin, INPUT); pinmode(ypin, INPUT); pinmode(zpin, INPUT); void loop() int x = analogread(xpin); //add a small delay between pin readings. I read that you should //do this but haven't tested the importance delay(1); int y = analogread(ypin); //add a small delay between pin readings. I read that you should //do this but haven't tested the importance delay(1); int z = analogread(zpin); //zero_g is the reading we expect from the sensor when it detects //no acceleration. Subtract this value from the sensor reading to //get a shifted sensor reading. float zero_g = 512.0; //scale is the number of units we expect the sensor reading to //change when the acceleration along an axis changes by 1G. //Divide the shifted sensor reading by scale to get acceleration in Gs. 9
float scale = 102.3; Serial.print(((float)x - zero_g)/scale); Serial.print("\t"); Serial.print(((float)y - zero_g)/scale); Serial.print("\t"); Serial.print(((float)z - zero_g)/scale); Serial.print("\n"); // delay before next reading: delay(sampledelay); 10
4. 디지털온도센서모듈 - 기본정보 DS18B20을사용 -55 ~ +125, 정확도 ±0.5 (-10 ~ +85 내 ) 센서의 + 는가운데핀으로 와 S핀사이에있음. - 핀연결 센서핀아두이노핀 - GND + 5V S D10 - Arduino 소스코드 #include <OneWire.h> 11
OneWire ds(10); // 디지털 10 번핀에연결 void setup(void) Serial.begin(9600); void loop(void) byte i; byte present = 0; byte data[12]; byte addr[8]; int Temp; if (!ds.search(addr)) ds.reset_search(); return; Serial.print("R="); for( i = 0; i < 8; i++) Serial.print(addr[i], HEX); Serial.print(" "); if ( OneWire::crc8( addr, 7)!= addr[7]) Serial.print("CRC is not valid!n"); return; if ( addr[0]!= 0x28) Serial.print("Device is not a DS18S20 family device.n"); return; ds.reset(); ds.select(addr); ds.write(0x44,1); // start conversion, with parasite power on at the end delay(1000); // maybe 750ms is enough, maybe not present = ds.reset(); ds.select(addr); ds.write(0xbe); // Read Scratchpad 12
Serial.print("P="); Serial.print(present,HEX); Serial.print(" "); for ( i = 0; i < 9; i++) // we need 9 bytes data[i] = ds.read(); Serial.print(data[i], HEX); Serial.print(" "); Temp=(data[1]<<8)+data[0];//take the two bytes from the response relating to temperature Temp=Temp>>4;//divide by 16 to get pure celcius readout //next line is Fahrenheit conversion Temp=Temp*1.8+32; // comment this line out to get celcius Serial.print("T=");//output the temperature to serial port Serial.print(Temp); Serial.print(" "); Serial.print(" CRC="); Serial.print( OneWire::crc8( data, 8), HEX); Serial.println(); 13
5. 진동센서모듈 - 기본정보 SW-18015P을사용 터치, 진동, 충격등의물리적인움직임을감지함 Maximum 12V, 20mA current 14
- 핀연결 센서핀아두이노핀 - GND + 5V S D3 - Arduino 소스코드 int Led=13;//define LED interface int Shock=3;//define vibration sensor interface int val;//define digital varible val void setup() pinmode(led,output);//define LED as output pinmode(shock,input);//define shock as input void loop() val=digitalread(shock);// if(val==high)// digitalwrite(led,low); else 15
digitalwrite(led,high); 16
6. 홀자기센서모듈 - 기본정보 3144EUA-S 홀자기센서사용 홀자기센서는자기장의세기에따라전압이변하는소자로서펄스변조, 유량및유속감지, 자동차속도측정등다양한분야에사용됨 BLDC 모터에서회전체의회전수를감지하기위해서도사용됨 - 핀연결 센서핀아두이노핀 - GND + 5V S D3 - Arduino 소스코드 int Led=13; int SENSOR=3; 17
int val; void setup() pinmode(led,output); pinmode(sensor,input); void loop() val=digitalread(sensor); if(val==high) digitalwrite(led, HIGH); else digitalwrite(led, LOW); 18
7. 리셋버튼모듈 - 기본정보 일반적으로널리사용되는리셋버튼스위치를이용하여디지털핀입력에대한학습을할수있음. 버튼이눌림에따른 LED 점등변화확인. - 핀연결 - Arduino 소스코드 센서핀아두이노핀 - GND + 5V S D3 int Led=13; int BUTTONPIN=3; int val; void setup() 19
pinmode(led,output); pinmode(buttonpin,input); void loop() val=digitalread(buttonpin); if(val==high) digitalwrite(led, HIGH); else digitalwrite(led, LOW); 20
8. 적외선발광모듈 - 기본정보 IRremote.h 는메카솔루션홈페이지에서다운로드가능 7 컬러플래시 LED 모듈과모양이비슷하여혼돈할수있음 7 컬러플래시는 CNT5, DHT11 이기판에적혀있고, 적외선발광모듈은 - 핀연결 기판에홀이많이있음 센서핀아두이노핀 - GND + 5V S D3 - Arduino 소스코드 #include <IRremote.h> IRsend irsend; 21
void setup () Serial.begin (9600); void loop () for (int i = 0; i <50; i++) irsend.sendsony (0xa90, 12); // Sony TV power code delay (40); 22
9. 수동부저모듈 - 기본정보 버저는소리신호알림장치이며기계, 전자기계, 압전방식으로되어있음. 전기적신호를소리신호로변경함. 출력 : 95dBA 주파수영역 : 2048Hz - 핀연결 센서핀아두이노핀 - GND + 5V S D11 - Arduino 소스코드 int buzzer=11; void setup() 23
pinmode(buzzer,output); void loop() unsigned char i,j; while(1) for(i=0;i<80;i++)//output sound of one frequency digitalwrite(buzzer,high);//make a sound delay(1);//delay 1ms digitalwrite(buzzer,low);//silient delay(1);//delay 1ms for(i=0;i<500;i++)//output sound of another frequency digitalwrite(buzzer,high);//make a sound delay(2);//delay 2ms digitalwrite(buzzer,low);//silient delay(2);//delay 2ms 24
10. 레이저발광모듈 - 기본정보 650nm 레이저다이오드 - 핀연결 센서핀아두이노핀 - GND + 5V S D10 - Arduino 소스코드 void setup () pinmode (10, OUTPUT); void loop () digitalwrite (10, HIGH); // open the laser head delay (1000); // delay one second 25
digitalwrite (10, LOW); // turn off the laser head delay (1000); // delay one second 26
11. RGB SMD LED 모듈 - 기본정보 풀컬러 RGB LED - 핀연결센서핀아두이노핀 - GND R D11 G D10 B D9 - Arduino 소스코드 int redpin = 11; int bluepin =10; int yellowpin =9; int val; void setup() 27
pinmode(redpin, OUTPUT); pinmode(bluepin, OUTPUT); pinmode(yellowpin, OUTPUT); Serial.begin(9600); void loop() for(val=255; val>0; val--) analogwrite(11, val); analogwrite(10, 255-val); analogwrite(9, 128-val); delay(1); for(val=0; val<255; val++) analogwrite(11, val); analogwrite(10, 255-val); analogwrite(9, 128-val); delay(1); Serial.println(val, DEC); 28
12. 포토인터럽트모듈 - 기본정보 기판의 U 자형홈에사물혹은조그만시편을지나가게하면이를센싱함 - 핀연결 센서핀아두이노핀 - GND + 5V S D3 - Arduino 소스코드 int Led = 13;// define LED Interface int buttonpin = 3; // define the photo interrupter sensor interface int val; // define numeric variables val void setup () pinmode (Led, OUTPUT);// define LED as output interface pinmode (buttonpin, INPUT);// define the photo interrupter sensor output interface 29
void loop () val = digitalread (buttonpin);// digital interface will be assigned a value of 3 to read val if (val == HIGH) // When the light sensor detects a signal is interrupted, LED flashes digitalwrite (Led, HIGH); else digitalwrite (Led, LOW); 30
13. 듀얼컬러 LED 모듈 3mm ( 커먼캐소드 ) - 기본정보 3mm와 5mm LED 중 3mm LED. - 핀연결센서핀아두이노핀 - GND G D11 R D10 - Arduino 소스코드 int redpin = 10; // select the pin for the red LED int greenpin = 11; // select the pin for the blueled int val; void setup () pinmode (redpin, OUTPUT); pinmode (greenpin, OUTPUT); 31
Serial.begin (9600); void loop () for (val = 255; val> 0; val --) analogwrite (11, val); analogwrite (10, 255-val); delay (15); for (val = 0; val <255; val ++) analogwrite (11, val); analogwrite (10, 255-val); delay (15); Serial.println (val, DEC); 32
14. 피에조버저모듈 - 기본정보 간혹, - 와 + 가바뀌어있는경우가있음. 스티커를제거하였을경우버저의 - 핀연결 + 가 3 핀쪽으로오면 3 핀의 와 + 가반대로연결되어있기에다음처럼핀 연결을함. 만약, 버저위의 + 가 3 핀의반대방향을향하면센서핀의 는 아두이노의 GND 에, 센서핀의 + 는아두이노의 5V 에정상적으로연결함. 센서핀아두이노핀 - 5V + GND S D8 - Arduino 소스코드 int speakerpin = 8; byte song_table [] = 30, 30, 30, 40, 50, 60, 70, 80, 90, 100,110, 120, 130, 140, 150, 160, 170, 180, 190, 200, 210, 220, 230, 240, 250, 250, 240, 230, 220, 210, 33
200, 190, 180, 170, 160, 150, 140, 130, 120, 110, 100, 90, 80, 70, 60, 50, 40, 30, 30, 30; int MAX = 50; int count = 0; void setup () pinmode (speakerpin, OUTPUT); void loop () analogwrite (speakerpin, song_table [count]); count ++; if (count> MAX) count = 0; delay (50); 34
15. 아날로그온도센서모듈 - 기본정보 써미스터를이용한온도측정 테스트결과 와 + 극이반대로되어있음을확인 ( 주의요망 ) Steinhart-Hart Thermistor equation 을이용하여온도를측정 - 핀연결 센서핀아두이노핀 - 5V + GND S A0 - Arduino 소스코드 #include <math.h> int sensorpin = A0; int ledpin = 13; // select the input pin for the potentiometer // select the pin for the LED 35
int sensorvalue = 0; // variable to store the value coming from the sensor void setup() pinmode(ledpin, OUTPUT); Serial.begin(9600); void loop() sensorvalue = analogread(sensorpin); digitalwrite(ledpin, HIGH); delay(sensorvalue); digitalwrite(ledpin, LOW); delay(sensorvalue); Serial.println(Thermister(sensorValue), DEC); double Thermister (int RawADC) double Temp; Temp = log (((10240000/RawADC) - 10000)); Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp)) * Temp); Temp = Temp - 273.15; // Convert Kelvin to Celcius return Temp; 36
16. DHT11 디지털온도습도센서모듈 - 기본정보 DHT11 를이용한온도와습도측정 습도측정범위 : 20-90% (5% 오차 ) 온도측정범위 : 0-50 (2 오차 ) - 핀연결 센서핀아두이노핀 - 5V + GND S A0 - Arduino 소스코드 #define dht_dpin A0 byte bglobalerr; byte dht_dat[5]; void setup() InitDHT(); 37
Serial.begin(9600); delay(300); Serial.println("Humidity and temperaturenn"); delay(700); void loop() ReadDHT(); switch (bglobalerr) case 0: Serial.print("Current humdity = "); Serial.print(dht_dat[0], DEC); Serial.print("."); Serial.print(dht_dat[1], DEC); Serial.print("% "); Serial.print("temperature = "); Serial.print(dht_dat[2], DEC); Serial.print("."); Serial.print(dht_dat[3], DEC); Serial.println("C "); break; case 1: Serial.println("Error 1: DHT start condition 1 not met."); break; case 2: Serial.println("Error 2: DHT start condition 2 not met."); break; case 3: Serial.println("Error 3: DHT checksum error."); break; default: Serial.println("Error: Unrecognized code encountered."); break; delay(800); void InitDHT() pinmode(dht_dpin,output); digitalwrite(dht_dpin,high); void ReadDHT() bglobalerr=0; byte dht_in; byte i; digitalwrite(dht_dpin,low); delay(20); 38
digitalwrite(dht_dpin,high); delaymicroseconds(40); pinmode(dht_dpin,input); //delaymicroseconds(40); dht_in=digitalread(dht_dpin); if(dht_in) bglobalerr=1; return; delaymicroseconds(80); dht_in=digitalread(dht_dpin); if(!dht_in) bglobalerr=2; return; delaymicroseconds(80); for (i=0; i<5; i++) dht_dat[i] = read_dht_dat(); pinmode(dht_dpin,output); digitalwrite(dht_dpin,high); byte dht_check_sum = dht_dat[0]+dht_dat[1]+dht_dat[2]+dht_dat[3]; if(dht_dat[4]!= dht_check_sum) bglobalerr=3; ; byte read_dht_dat() byte i = 0; byte result=0; for(i=0; i< 8; i++) while(digitalread(dht_dpin)==low); delaymicroseconds(30); if (digitalread(dht_dpin)==high) result =(1<<(7-i)); while (digitalread(dht_dpin)==high); return result; 39
17. RGB 컬러 LED 모듈 - 기본정보 RGB 컬러 LED (5mm) - 핀연결센서핀아두이노핀 - GND R D11 G D10 B D9 - Arduino 소스코드 int redpin = 11; int bluepin =10; int yellowpin =9; int val; 40
void setup() pinmode(redpin, OUTPUT); pinmode(bluepin, OUTPUT); pinmode(yellowpin, OUTPUT); Serial.begin(9600); void loop() for(val=255; val>0; val--) analogwrite(11, val); analogwrite(10, 255-val); analogwrite(9, 128-val); delay(1); for(val=0; val<255; val++) analogwrite(11, val); analogwrite(10, 255-val); analogwrite(9, 128-val); delay(1); Serial.println(val, DEC); 41
18. 수은기울기스위칭센서모듈 - 기본정보 유리관속의수은이기울기에따라움직이며 LED 를스위칭하는동작 - 핀연결 센서핀아두이노핀 - GND + 5V S D2 - Arduino 소스코드 const int S = 2; // the number of the pushbutton pin const int ledpin = 13; // the number of the LED pin int sensorstate = 0; // variable for reading the pushbutton status void setup() pinmode(ledpin, OUTPUT); pinmode(s, INPUT); 42
void loop() sensorstate = digitalread(s); if (sensorstate == HIGH) // turn LED on: digitalwrite(ledpin, HIGH); else // turn LED off: digitalwrite(ledpin, LOW); 43
19. 조도센서모듈 - 기본정보 빛의밝기에따라저항값이변하는특성을이용한센서 광센서, 포토셀, 혹은조도센서라불림. - 핀연결 센서핀아두이노핀 - GND + 5V S A0 - Arduino 소스코드 int sensorpin = A0; // select the input pin for the potentiometer int ledpin = 13; // select the pin for the LED int sensorvalue = 0; // variable to store the value coming from the sensor 44
void setup() pinmode(ledpin, OUTPUT); Serial.begin(9600); void loop() sensorvalue = analogread(sensorpin); Serial.println(sensorValue, DEC); delay(50); 45
20. 5V 릴레이모듈 - 기본정보 릴레이는전기적으로구동되는스위치로서많은릴레이는전자석으로스위칭하는구조를가지고있음. 릴레이에신호를가하면딸깍하는소리가나며 NO, NC, 그리고 COM의출력을갖는다. 예를들어, 두개의신호선을스위칭할경우, 한쪽은 NO (Normally Opened) 에그리고다른하나는 COM에연결하면릴레이에신호를가하지않을때까지두신호선은열려있다. 그리고, 릴레이에신호가가해지면 NO와 COM은연결되어두신호선은닫히게된다. 46
- 핀연결 센서핀아두이노핀 - GND + 5V S D10 - Arduino 소스코드 int relay = 10; // relay turns trigger signal - active high; void setup () pinmode (relay, OUTPUT); // Define port attribute is output; void loop () digitalwrite (relay, HIGH); // relay conduction; delay (1000); digitalwrite (relay, LOW); // relay switch is turned off; delay (1000); 47
21. 기울기센서모듈 - 기본정보 센서내부의금속이기울기에따라움직이며아두이노의 LED 를스위칭하는 동작 - 핀연결 센서핀아두이노핀 - GND + 5V S D2 - Arduino 소스코드 const int S = 2; // the number of the pushbutton pin const int ledpin = 13; // the number of the LED pin int sensorstate = 0; // variable for reading the pushbutton status void setup() pinmode(ledpin, OUTPUT); pinmode(s, INPUT); 48
void loop() sensorstate = digitalread(s); if (sensorstate == HIGH) // turn LED on: digitalwrite(ledpin, HIGH); else // turn LED off: digitalwrite(ledpin, LOW); 49
22. 소형리드스위치모듈 - 기본정보 리드스위치는자석을가까이가져갔을때연결이되고자석을떼었을때 - 핀연결 단락이되는성질을이용한센서입니다. 센서핀아두이노핀 - GND + 5V S D2 - Arduino 소스코드 const int S = 2; // the number of the pushbutton pin const int ledpin = 13; // the number of the LED pin int sensorstate = 0; // variable for reading the pushbutton status void setup() pinmode(ledpin, OUTPUT); 50
pinmode(s, INPUT); void loop() sensorstate = digitalread(s); if (sensorstate == HIGH) // turn LED on: digitalwrite(ledpin, HIGH); else // turn LED off: digitalwrite(ledpin, LOW); 51
23. 적외선리모트컨트롤모듈 - 기본정보 IRremote.h 라이브러리는메카솔루션홈페이지에서다운로드가능 - 핀연결 센서핀아두이노핀 - GND + 5V S D11 - Arduino 소스코드 #include <IRremote.h> int RECV_PIN = 11; // define input pin on Arduino IRrecv irrecv (RECV_PIN); decode_results results; void setup () Serial.begin (9600); 52
irrecv.enableirin (); // Start the receiver void loop () if (irrecv.decode (& results)) Serial.println (results.value, HEX); irrecv.resume (); // Receive the next value 53
24. PS2 게임조이스틱모듈 - 기본정보 로봇제어및모터제어에사용되는조이스틱으로아날로그출력방식의조이스틱으로 Arduino에연결하여쉽게제어를할수있는제품 2축조이스틱 (X,Y, 푸쉬버튼기능 ) - 핀연결센서핀아두이노핀 GND GND +5V 5V VRx A0 VRy A1 SW D3 - Arduino 소스코드 int JoyStick_X = 0; / / x int JoyStick_Y = 1; / / y 54
int JoyStick_Z = 3; / / key void setup () pinmode (JoyStick_X, INPUT); pinmode (JoyStick_Y, INPUT); pinmode (JoyStick_Z, INPUT); Serial.begin (9600); / / 9600 bps void loop () int x, y, z; x = analogread (JoyStick_X); y = analogread (JoyStick_Y); z = digitalread (JoyStick_Z); Serial.print (x, DEC); Serial.print (","); Serial.print (y, DEC); Serial.print (","); Serial.println (z, DEC); delay (100); 55
25. 리니어홀자기센서모듈 - 기본정보 리드센서와마찬가지로자석에반응하는센서 아날로그 (AO) 와디지털 (DO) 신호모두검출가능 - 핀연결센서핀아두이노핀 DO D2 + 5V G GND AO A0 - Arduino 소스코드 const int S = 2; // the number of the pushbutton pin const int ledpin = 13; // the number of the LED pin int sensorstate = 0; // variable for reading the pushbutton status 56
void setup() pinmode(ledpin, OUTPUT); pinmode(s, INPUT); void loop() sensorstate = digitalread(s); if (sensorstate == HIGH) // turn LED on: digitalwrite(ledpin, HIGH); else // turn LED off: digitalwrite(ledpin, LOW); 57
26. 리드스위치모듈 - 기본정보 홀자기센서와마찬가지로자석에반응하는센서 아날로그 (AO) 와디지털 (DO) 신호모두검출가능 - 핀연결센서핀아두이노핀 DO D2 + 5V G GND AO A0 - Arduino 소스코드 const int S = 2; // the number of the pushbutton pin const int ledpin = 13; // the number of the LED pin int sensorstate = 0; // variable for reading the pushbutton status 58
void setup() pinmode(ledpin, OUTPUT); pinmode(s, INPUT); void loop() sensorstate = digitalread(s); if (sensorstate == HIGH) // turn LED on: digitalwrite(ledpin, HIGH); else // turn LED off: digitalwrite(ledpin, LOW); 59
27. 불꽃감지센서모듈 - 기본정보 불꽃감지센서 아날로그 (AO) 와디지털 (DO) 신호모두검출가능 - 핀연결센서핀아두이노핀 DO D2 + 5V G GND AO A0 - Arduino 소스코드 const int S = 2; // the number of the pushbutton pin const int ledpin = 13; // the number of the LED pin int sensorstate = 0; // variable for reading the pushbutton status 60
void setup() pinmode(ledpin, OUTPUT); pinmode(s, INPUT); void loop() sensorstate = digitalread(s); if (sensorstate == HIGH) // turn LED on: digitalwrite(ledpin, HIGH); else // turn LED off: digitalwrite(ledpin, LOW); 61
28. 매직라이트컵모듈 - 기본정보 두개가하나의세트 하나의모듈에 LED 불이들어왔다가두개를동시에기울이면다른쪽으로 - 핀연결 LED 불빛이전달되는현상 센서A 핀 아두이노핀 센서B 핀 아두이노핀 G GND G GND + 5V + 5V S D7 S D4 L D5 L D6 - Arduino 소스코드 int LedPinA = 5; int LedPinB = 6; int SPinA = 7; int SPinB = 4; 62
int buttonstatea = 0; int buttonstateb = 0; int brightness = 0; void setup() pinmode(ledpina, OUTPUT); pinmode(ledpinb, OUTPUT); pinmode(spina, INPUT); pinmode(spinb, INPUT); void loop() buttonstatea = digitalread(spina); if (buttonstatea == HIGH && brightness!= 255) brightness ++; buttonstateb = digitalread(spinb); if (buttonstateb == HIGH && brightness!= 0) brightness --; analogwrite(ledpina, brightness); // A will turn off gradually analogwrite(ledpinb, 255 - brightness); // B will turn on gradually delay(25); 63
29. 디지털온도센서모듈 - 기본정보 디지털온도센서모듈이지만, 아날로그센서로도사용가능. 아날로그 (AO) 와디지털 (DO) 신호모두검출가능 - 핀연결센서핀아두이노핀 DO D2 + 5V G GND AO A0 - Arduino 소스코드 const int S = 2; // the number of the pushbutton pin const int ledpin = 13; // the number of the LED pin int sensorstate = 0; // variable for reading the pushbutton status 64
void setup() pinmode(ledpin, OUTPUT); pinmode(s, INPUT); void loop() sensorstate = digitalread(s); if (sensorstate == HIGH) // turn LED on: digitalwrite(ledpin, HIGH); else // turn LED off: digitalwrite(ledpin, LOW); 65
30. 듀얼컬러 LED 모듈 5mm ( 커먼캐소드 ) - 기본정보 5mm 사이즈의 Red, Green 듀얼컬러 LED 66
- 핀연결 센서핀 아두이노핀 - GND + ( 레드 ) D11 S ( 그린 ) D10 - Arduino 소스코드 int redpin = 11; // select the pin for the red LED int greenpin = 10; // select the pin for the greenled int val; void setup () pinmode (redpin, OUTPUT); pinmode (greenpin, OUTPUT); Serial.begin (9600); void loop () for (val = 255; val> 0; val --) analogwrite (11, val); analogwrite (10, 255-val); delay (15); for (val = 0; val <255; val ++) analogwrite (11, val); analogwrite (10, 255-val); delay (15); Serial.println (val, DEC); 67
31. 노크센서모듈 - 기본정보 플라스틱케이스안의금속이진동및충격을감지하여출력. - 핀연결 센서핀아두이노핀 - GND + 5V S D3 - Arduino 소스코드 int Led=13;//define LED interface int Shock=3;//define vibration sensor interface int val;//define digital varible val void setup() pinmode(led,output);//define LED as output 68
pinmode(shock,input);//define shock as input void loop() val=digitalread(shock);// if(val==high)// digitalwrite(led,low); else digitalwrite(led,high); 69
32. 적외선장애물감지센서모듈 - 기본정보 적외선이장애물에의해반사되면 LED를깜빡임. LED 발광다이오드를통해출력된빛이장애물에의해반사되고이를포토트렌지스터를통해읽음. - 핀연결센서핀아두이노핀 GND GND + 5V out D3 EN X 연결안함 - Arduino 소스코드 int Led = 13 ;// define LED Interface int buttonpin = 3; // define the obstacle avoidance sensor interface int val ;// define numeric variables val 70
void setup () pinmode (Led, OUTPUT) ;// define LED as output interface pinmode (buttonpin, INPUT) ;// define the obstacle avoidance sensor output interface void loop () val = digitalread (buttonpin) ;// digital interface will be assigned a value of 3 to read val if (val == HIGH) // When the obstacle avoidance sensor detects a signal, LED flashes digitalwrite (Led, HIGH); else digitalwrite (Led, LOW); 71
33. 7 컬러플래시 LED 모듈 - 기본정보 3 개의핀중가운데핀은연결하지않도록한다 ( 주의 ) - 핀연결 센서핀아두이노핀 - GND + X ( 연결안함 ) S D12 - Arduino 소스코드 void setup() pinmode(12, OUTPUT); void loop() digitalwrite(12, HIGH); // set the LED on 72
delay(1000); digitalwrite(12, LOW); delay(1000); // wait for a second // set the LED off // wait for a second 73
34. 아날로그홀자기센서모듈 - 기본정보 자기력에의해값이변함 - 핀연결 센서핀아두이노핀 - GND + 5V S A0 - Arduino 소스코드 int sensorpin = A0; int ledpin = 13; // select the pin for the LED int sensorvalue = 0; // variable to store the value coming from the sensor void setup() pinmode(ledpin, OUTPUT); Serial.begin(9600); 74
void loop() sensorvalue = analogread(sensorpin); Serial.println(sensorValue, DEC); delay(50); 75
35. 터치센서모듈 - 기본정보 터치감지센서 아날로그 (AO) 와디지털 (DO) 신호모두검출가능 - 핀연결센서핀아두이노핀 DO D2 + 5V G GND AO A0 - Arduino 소스코드 const int S = 2; // the number of the pushbutton pin const int ledpin = 13; // the number of the LED pin int sensorstate = 0; // variable for reading the pushbutton status void setup() 76
pinmode(ledpin, OUTPUT); pinmode(s, INPUT); void loop() sensorstate = digitalread(s); if (sensorstate == HIGH) // turn LED on: digitalwrite(ledpin, HIGH); else // turn LED off: digitalwrite(ledpin, LOW); 77
36. 고감도사운드센서모듈 - 기본정보 고감도사운드감지센서 아날로그 (AO) 와디지털 (DO) 신호모두검출가능 - 핀연결센서핀아두이노핀 DO D2 + 5V G GND AO A0 - Arduino 소스코드 const int S = 2; // the number of the pushbutton pin const int ledpin = 13; // the number of the LED pin int sensorstate = 0; // variable for reading the pushbutton status void setup() 78
pinmode(ledpin, OUTPUT); pinmode(s, INPUT); void loop() sensorstate = digitalread(s); if (sensorstate == HIGH) // turn LED on: digitalwrite(ledpin, HIGH); else // turn LED off: digitalwrite(ledpin, LOW); 79
37. 마이크로폰사운드감지센서모듈 - 기본정보 사운드감지센서 아날로그 (AO) 와디지털 (DO) 신호모두검출가능 - 핀연결센서핀아두이노핀 DO D2 + 5V G GND AO A0 - Arduino 소스코드 const int S = 2; // the number of the pushbutton pin const int ledpin = 13; // the number of the LED pin int sensorstate = 0; // variable for reading the pushbutton status void setup() 80
pinmode(ledpin, OUTPUT); pinmode(s, INPUT); void loop() sensorstate = digitalread(s); if (sensorstate == HIGH) // turn LED on: digitalwrite(ledpin, HIGH); else // turn LED off: digitalwrite(ledpin, LOW); 81
38. 심박센서모듈 - 기본정보 손가락을두개의다이오드사이에넣으면적외선이손가락을투과하여 - 핀연결 심박을측정한다. 센서핀아두이노핀 - GND + 5V S A0 - Arduino 소스코드 int ledpin = 13; int sensorpin = 0; double alpha = 0.75; int period = 20; double change = 0.0; void setup () 82
pinmode (ledpin, OUTPUT); Serial.begin (115200); void loop () static double oldvalue = 0; static double oldchange = 0; int rawvalue = analogread (sensorpin); double value = alpha * oldvalue + (1 - alpha) * rawvalue; Serial.print (rawvalue); Serial.print (","); Serial.println (value); oldvalue = value; delay (period); 83
39. 트랙킹센서모듈 - 기본정보 가변저항을돌려주면서감도 (Sensitivity) 를조절할수있다. - 핀연결 센서핀아두이노핀 - GND + 5V S D3 - Arduino 소스코드 int Led=13;//define LED interface int Shock=3;//define vibration sensor interface int val;//define digital varible val void setup() pinmode(led,output);//define LED as output pinmode(shock,input);//define shock as input 84
void loop() val=digitalread(shock);// if(val==high)// digitalwrite(led,low); else digitalwrite(led,high); 85
40. 로터리인코더모듈 - 기본정보 로터리인코더를돌리면서회전정도를측정. - 핀연결센서핀아두이노핀 GND GND + 5V SW D2 DT D3 CLK D4 - Arduino 소스코드 int apin = 3; int bpin = 4; int buttonpin = 2; 86
int temp; int temprotation = 100; int rotation = 100; void setup() pinmode(apin, INPUT); pinmode(bpin, INPUT); pinmode(buttonpin, INPUT); Serial.begin(9600); void loop() int change = getencoderturn(); if(change!=temp) rotation = rotation + change; if(rotation!= temprotation) Serial.println(rotation); temprotation = rotation; temp = change; delay(1); int getencoderturn() // return -1, 0, or +1 static int olda = LOW; static int oldb = LOW; int result = 0; int newa = digitalread(apin); int newb = digitalread(bpin); if (newa!= olda newb!= oldb) if (olda == LOW && newa == HIGH) result = -(oldb * 2-1); olda = newa; 87
oldb = newb; return result; 88