Sound Sensor

Wiring diagram for sound sensor

Below is the basic code usage for the sound sensor.

# Imports

import LocoIOT

import LocoIOT_Communicator as MSG

import time



# USB Port Address

usb_str = "COM452"


def main():


# Create Class Instances

loco_iot = LocoIOT.LocoIOT()

msg = MSG.IOT_Codes()


# Connect to Controller Through USB Connection

loco_iot.connect(usb_str)


# Enable Microphone Sensor Hardware Configuration

loco_iot.enable(msg.SUBTYPE_MIC)


# Send Start Flag

loco_iot.start()


# Loop for an Arbitrary Duration

start_time = time.time()

while (time.time() - start_time) < 5:

# Request Microphone Data

data = [msg.MIC_ANALOG]

mic_dig_dict = loco_iot.getData(msg.SUBTYPE_MIC, data)

# Print Microphone Dictionary

print(mic_dig_dict)

# Short Arbitrary Delay

time.sleep(0.25)



# Loop for an Arbitrary Duration

start_time = time.time()

while (time.time() - start_time) < 5:

# Request Microphone Data

data = [msg.MIC_DIGITAL]

mic_dig_dict = loco_iot.getData(msg.SUBTYPE_MIC, data)

# Print Microphone Dictionary

print(mic_dig_dict)

# Short Arbitrary Delay

time.sleep(0.25)


# Close USB Connection to Controller

loco_iot.close()



# Run Main Function

main()