Example Code for OpenMV-Analog Sound Sensor

How to set up and use an OpenMV Cam M7 with a Gravity Analog Sound Sensor for sound measurement. It covers hardware and software preparations, wiring instructions, and provides sample code to read sound levels using Python, showing how values change with sound fluctuations.

Hardware Preparation

Software Preparation

Wiring Diagram

As shown below,connect the sensor to the P6 port of the expansion shield.

Openmv_sound_wire.jpg

Other Preparation Work

When put the expansion shield on the OpenMV motherboard, please pay attention to the direction. The USB port of the expansion shield should be on the same side as the USB port of the OpenMV motherboard.

Sample Code

# Analog sound sensor is used to measure the sound.
# Hardware : analog sound sensor, OpenMV
# connect:
#     Sensor    OpenMV
#     VCC       3V3
#     GND       GND
#     data      P6
from pyb import ADC,Pin
import time
adc=ADC(Pin('P6'))  # Must always be "P6".
while True:
  val=adc.read()    # Read the analog value
  print(val)
  time.sleep(100)

Result

Copy the sample code in the OpenMV IDE and click the start button. As shown in the picture below, when there is sound, the value will increase significantly.

Openmv_sound_result.jpg

Was this article helpful?

TOP