사운드샌서모듈
Makerist
센서기초
0
806
2024.03.17 04:06
// 사운드 센서의 아날로그 핀 const int soundSensorPin = A0; // 임계값 설정 (소리가 이 값 이상이면 감지됨) const int threshold = 500; void setup() { // 시리얼 통신 시작 Serial.begin(9600); } void loop() { // 사운드 센서 값 읽기 int soundValue = analogRead(soundSensorPin); // 소리가 임계값을 초과하는지 확인 if (soundValue > threshold) { Serial.println("소리 감지됨!"); // 소리가 감지되면 일부 동작을 수행할 수 있음 // 여기에 릴레이를 랜덤하게 활성화하는 코드를 추가할 수 있음 } // 잠시 대기 delay(100); }