우선 LED에 전류제한용 저항(보통 200 ~ 500옴정도)을 꼭 연결해주셔야합니다.
현재상태로는 보드에 무리가 가서 고장의 원인이 될 수 있습니다.
threshold값은 임의의 값을 주는것이 아니고 테스트로 값을 구한 후 적절하게 배정하셔야합니다.
이를 위해서 아두이노 기본예제중에서 아날로그입력값을 시리얼통신으로 PC에서 확인할 수 있는 예제를 활용하여 소리에 따라 출력값이 어떻게 변화하는지 확인하신 후 적절한 값을 배정해주시면 됩니다.
더불어 if 구문에 중괄호가 없습니다. (의도하신건가요?) 조건 참/거짓 여부에 따라 정확히 처리되도록 C언어 관련 구문을 다시 학습하실것을 권장드립니다.
---------- Original Message ----------
const int ledPin = 12; // the number of the LED pin
const int thresholdvalue=400;//The threshold to turn the led on
void setup() {
pinMode(ledPin, OUTPUT);
}
void loop() {
int sensorValue = analogRead(A0);//use A0 to read the electrical signal
if(sensorValue>thresholdvalue)
digitalWrite(ledPin,HIGH);//if the value read from A0 is larger than 400,then light the LED
delay(200);
digitalWrite(ledPin,LOW);
회원에게만 댓글 작성 권한이 있습니다.