반응형 광센서2 아두이노 빛의 세기에 따라 소리,LED밝기 조절 예제 ●빛의 세기에 따라 소리,LED밝기 조절 예제 const int ledPin = 6;const int buzzerPin = 3;const int lightPin = A0;int lightValue;int brightness; void setup() {} void loop() { lightValue = analogRead(lightPin); brightness = map(lightValue, 0,1023,0,255); analogWrite(ledPin,brightness); brightness = map(lightValue, 0,1023,100,1000); tone(buzzerPin,lightValue);} 2016. 1. 1. 아두이노 광센서, 온도센서 사용 예제 ●광센서- 빛에 노출되면 저항이 줄어드는 저항이다. ●빛 세기에 의해 LED밝기 조절하는 예제 const int ledPin = 3;const int lightPin = A0;int lightValue;int brightness; void setup() { Serial.begin(9600);} void loop() { lightValue = analogRead(lightPin); Serial.println(lightValue); //0~1023값을 0에서 255값으로 환산한다. brightness = map(lightValue, 0,1023,0,255); analogWrite(ledPin,brightness);} ●온도센서- 온도에 따라 저항값이 달라지는 저항이다. 아래 온도센서는 LM35DZ이다. 양쪽.. 2016. 1. 1. 이전 1 다음 반응형