KY-038 Microphone sound sensor module

From SensorKit X40 Wiki

Revision as of 10:15, 27 February 2017 by Webmaster Wiki (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Picture

none

Technical data / Short description

Digital Out: You can use a potentiometer to configure an extreme value for the sonic. IF the value exceeds the extreme value it will send a signal via digital out.

Analog Out: Direct microphone signal as voltage value 


LED1: Shows that the sensor is supplied with voltage 

LED2: Shows that a magnetic field was detected

Pinout

none

Functionality of the sensor

The sensor has 3 main components on its circuit board. First the sensor unit at the front of the module which measures the area physically and sends an analog signal to the second unit, the amplifier. The amplifier amplifies the signal according to the resistant value of the potentiometer and than sends the signal to the analog output of the module.


Please notice: The Signal will be inverted; that means, if you measure a high value , it will be shown as a low voltage value at the analog output. The third component is a comparator which switchs the digital out and the LED if the signal falls under a specific value. You can control the sensitivity via potentiometer.


none


This sensor doesn't show absolute values (like exact temperature in °C or magneticfield strenght in mT), it is a relative measurement: you define a extreme value to a given normal environment situation and a signal will be sended if the measurement exceeds the extreme value.


It is perfect for temperature control (KY-028), proximity switch (KY-024, KY-025, KY-036), detecting alarms (KY-037, KY-038) or rotary encoder (KY-026).

Code example Arduino

The program reads the current voltage value which will be measured at the output pin and shows it via serial interface.


Additional to that, the status of the digital pin will be shown at the terminal which means if the extreme value was exceeded or not.

// Declaration and initialization of the input pin
int Analog_Eingang = A0; // X-axis-signal
int Digital_Eingang = 3; // Button
 
void setup ()
{
  pinMode (Analog_Eingang, INPUT);
  pinMode (Digital_Eingang, INPUT);
      
  Serial.begin (9600); // Serial output with 9600 bps
}
 
// The program reads the current value of the input pins
// and outputs it via serial out
void loop ()
{
  float Analog;
  int Digital;
   
  // Current value will be read and converted to voltage 
  Analog = analogRead (Analog_Eingang) * (5.0 / 1023.0); 
  Digital = digitalRead (Digital_Eingang);
   
  //... and outputted here
  Serial.print ("Analog voltage value:"); Serial.print (Analog, 4);  Serial.print ("V, ");
  Serial.print ("Extreme value:");
 
  if(Digital==1)
  {
      Serial.println (" reached");
  }
  else
  {
      Serial.println (" not reached yet");
  }
  Serial.println ("----------------------------------------------------------------");
  delay (200);
}

Connections Arduino:

digital Signal = [Pin 3]
+V = [Pin 5V]
GND = [Pin GND]
analog Signal = [Pin 0]

Example program download 

Ard_Analoger_Sensor.zip

Codebeispiel Raspberry Pi

!! Attention !! Analog sensor  !! Attention !!

Unlike the Arduino, the Raspberry Pi dont provide an ADC ( analog digital converter ) on its chip. This gives the Raspberry Pi limits if you want to use a non digital sensor [ voltage value exceeded -> digital ON | voltage value deceeded -> digital OFF | example : button pushed [ON] button released [OFF]], but rather its a continous changeable value ( example: potentiometer -> other position = other voltage value).

To evade this, use our Sensorkit X40 with the KY-053 module which provides a 16 Bit ADC, which can be used  with the Raspberry Pi, to upgrade it with 4 additional analog input pins. This will be connected via I2C from the Raspberry Pi, it takes the analog measurment and gives the digital value to the Raspberry Pi.

So we recommend for analog sensors from this set, to interpose the KY-053 module with the ADC. For more information please look at the infosite: KY-053   Analog Digital Converter

!! Attention !! Analog sensor  !! Attention !!

The program uses the specific ADS1x15 and I2C python-libraries from the company Adafruit to control the ADS1115 ADC. You will find these on the link: [https://github.com/adafruit/Adafruit-Raspberry-Pi-Python-Code] published under the BSD-License [Link]. You can find the needed libraries in the download package below.

The program reads the current values of the input pins and outputs it at the terminal in [mV].

Additional to that, the status of the digital pin will be shown at the terminal to show if the extreme value was exceeded or not.

#
#!/usr/bin/python
# coding=utf-8

#############################################################################################################
### Copyright by Joy-IT
### Published under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
### Commercial use only after permission is requested and granted
###
### Analog Sensor + ADS1115 ADC - Raspberry Pi Python Code Example
###
#############################################################################################################


# This code is using the ADS1115 and the I2C python libraries for the Raspberry Pi 
# It is published by BSD License under the following link
# [https://github.com/adafruit/Adafruit-Raspberry-Pi-Python-Code]
from Adafruit_ADS1x15 import ADS1x15
from time import sleep

# Additional needed modules will be imported and configured 
import time, signal, sys, os
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)

# Used variables will be initialized 
delayTime = 0.2

# Address allocation ADS1x15 ADC

ADS1015 = 0x00  # 12-bit ADC
ADS1115 = 0x01  # 16-bit

# Amplification (Gain) will be picked
gain = 4096  # +/- 4.096V
# gain = 2048  # +/- 2.048V
# gain = 1024  # +/- 1.024V
# gain = 512   # +/- 0.512V
# gain = 256   # +/- 0.256V

# Sample rate of the ADC (SampleRate) will be picked 
# sps = 8    # 8 Samples per second 
# sps = 16   # 16 Samples per second 
# sps = 32   # 32 Samples per second 
sps = 64   # 64 Samples per second 
# sps = 128  # 128 Samples per second 
# sps = 250  # 250 Samples per second 
# sps = 475  # 475 Samples per second 
# sps = 860  # 860 Samples per second 

# ADC-Channel (1-4) will be picked
adc_channel = 0    # Channel 0
# adc_channel = 1    # Channel 1
# adc_channel = 2    # Channel 2
# adc_channel = 3    # Channel 3

# Here, the ADC will be initialized - the ADC which is used by the KY-053 is an ADS1115 chipset
adc = ADS1x15(ic=ADS1115)

# Input pin for the digital signal will be picked here
Digital_PIN = 24
GPIO.setup(Digital_PIN, GPIO.IN, pull_up_down = GPIO.PUD_OFF)

#############################################################################################################

# ########
# main program loop
# ########
# The program reads the current value of the input pin
# and shows it at the terminal 

try:
        while True:
                # Current values will be recorded 
                analog = adc.readADCSingleEnded(adc_channel, gain, sps)

                # Output via terminal 
                if GPIO.input(Digital_PIN) == False:
                        print "Analog voltage value:", analog,"mV, ","Extreme value: not reached yet"
                else:
                        print "Analog voltage value:", analog, "mV, ", "Extreme value: reached"
                print "---------------------------------------"

                # Reset + Delay
                button_pressed = False
                time.sleep(delayTime)



except KeyboardInterrupt:
        GPIO.cleanup()

Connections Raspberry Pi:

Sensor

digital signal = GPIO 24 [Pin 18 (RPi)]
+V = 3,3V [Pin 1 (RPi)]
GND = GND [Pin 06 (RPi)]
analog signal = Analog 0 [Pin A0 (ADS1115 - KY-053)]

ADS1115 - KY-053:

VDD = 3,3V [Pin 01]
GND = GND [Pin 09]
SCL = GPIO03 / SCL [Pin 05]
SDA = GPIO02 / SDA [Pin 03]
A0 = look above [Sensor: analog signal]

Example program download

RPi_AnalogSensor.zip


To start with the command:

sudo python RPi_AnalogSensor.py