임베디드 보드/아두이노

아두이노 사운드 레벨 감지 센서

ZEROWIN.TECH 2021. 12. 31. 15:06
728x90

SOUND LEVEL SENSOR

 

보드의 가변저장으로 감도 조절
VCC : 3.3 V or 5V
GND : 
DO : TTL OUTPUT

 

 

 

아두이노

아두이노를 이용하여 감지된 소음데이터를 아두이노 시리얼 플로터를 이용하여 그래프로 표시

 

테스트

저가형 사운드 레벨센서를 이용하여 아두이노로 간단하게 소음 감지

 

 

소스코드

 

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
}

#define MAX_LEN 100
int array[MAX_LEN]; // 1sec

int timeout = 0;
void loop() {
  // put your main code here, to run repeatedly:
  int value = analogRead(A0);
  memcpy(array, &array[1], sizeof(array) - sizeof(int));
  array[MAX_LEN-1] =  value;

  timeout += 1;

  if(timeout % 10 == 0) {
  
    double total = 0;
    for(int i = 0; i < MAX_LEN; i++) {
      total += array[i];
    }
    total /= MAX_LEN;
    Serial.print(total); Serial.print(',');
    Serial.println(value/4);
  }
  
  

  delay(1);
}