I want to make Arduino's sound sensor recognize clapping with Python, but there is a difficulty in the middle

Asked 2 years ago, Updated 2 years ago, 71 views

I'm coding so that the LED is turned on at Arduino with Python.

It's coded to respond to clapping at once, but the problem is that if you do this, it responds to other noises.

So I want to respond to a specific clap pattern (I'm going to clap easily), but it's unfamiliar and I don't have a clue. How should I do it?

from machine import Pin
from time import sleep

led = Pin(13, Pin.OUT)
sound = Pin(12, Pin.IN)

wait = 0.1
state = 0

while True:
    if sound.value() ==1:
        state = 1 - state

    print(sound.value(), state)
    led.value(state)
    sleep(wait)

It's a code that responds with one clap.

python arduino

2022-09-20 19:26

1 Answers

If the sensor has a sound value of 0 and 1,

// default wait status
//if (sound.value() == 1)
// As long as you want to clap, wait
//(ex, wait 0.5 seconds. If you don't do it in 1 second, break to the default wait;)
//if(sound.value() == 1)
// Desired behavior (ex, led on)

How about this?


2022-09-20 19:26

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.