4687 views|38 replies

3386

Posts

0

Resources
The OP
 

MicroPython Hands-on (18) - Sound and light sensor on the control board [Copy link]

 
 

Microphone, light sensor
The control board has a microphone onboard, which can be used to sense changes in the sound of the surrounding environment.
The control board has a light sensor onboard, which can be used to sense changes in the light of the surrounding environment.
The detection range is 0-4095.


This content was originally created by eagler8 , a user on the EEWORLD forum. If you need to reprint or use it for commercial purposes, you must obtain the author's consent and indicate the source

 
 

3386

Posts

0

Resources
2
 

1. Microphone
The scientific name is microphone, which is translated from the English word microphone. It is also called microphone or micro-phone. Microphone is an energy conversion device that converts sound signals into electrical signals. There are dynamic, condenser, electret and the recently emerging silicon micro-microphones. There are also liquid microphones and laser microphones. Most microphones are electret capacitor microphones, which work by using a polymer material vibration membrane with permanent charge isolation.

Most microphones are electret condenser microphones (ECM), a technology that has been around for decades. The working principle of ECM is to use a polymer diaphragm with permanent charge isolation. Compared with the polymer diaphragm of ECM, the performance of MEMS microphones is very stable at different temperatures and is not affected by temperature, vibration, humidity and time. Due to its strong heat resistance, MEMS microphones can withstand high-temperature reflow soldering at 260°C without any change in performance. Since the sensitivity change before and after assembly is small, this can even save audio debugging costs during the manufacturing process. At present, integrated circuit technology is being increasingly used in the manufacture of sensor and sensor interface integrated circuits. This micro-manufacturing process has the advantages of precision, design flexibility, miniaturization, integration with signal processing circuits, low cost and large-scale production. Early micro-microphones were based on the piezoresistive effect. Research reports have produced microphones with (1×1) cm2 and 2μm thick polysilicon films as sensitive films. However, in the absence of stress in the sensitive film, the first-order resonance frequency of such a large and thin polysilicon film will be lower than 300Hz. The first-order resonant frequency in such a low frequency range will cause the frequency response of the microphone in the auditory frequency range to be extremely uneven (the sensitivity variation is greater than 40dB), which is unacceptable for microphone applications. When there is tensile stress in the sensitive film, its resonant frequency will increase, but at the expense of sensitivity. Of course, a higher first-order resonant frequency can be obtained by adjusting the size of the sensitive film, but this will still reduce the sensitivity. It can be seen that the piezoresistive solution is not suitable for the manufacture of miniature microphones.

One possible solution is to use a capacitive solution to manufacture micro-microphones. The advantage of this method is that all materials used in the integrated circuit manufacturing process can be used to manufacture sensors. However, it is quite difficult to manufacture micro-microphones using a single-chip process because the air medium between the two capacitor plates can only have a small gap. In addition, due to size limitations, it is difficult to meet the bias voltage in some applications. Based on the above problems, research on capacitive microphones has never stopped.

 
 
 

3386

Posts

0

Resources
3
 

2. Photoelectric sensor
It is a device that converts light signals into electrical signals. Its working principle is based on the photoelectric effect. The photoelectric effect refers to the phenomenon that when light shines on certain substances, the electrons of the substance absorb the energy of photons and produce corresponding electrical effects. According to the different photoelectric effect phenomena, the photoelectric effect is divided into three categories: external photoelectric effect, internal photoelectric effect and photovoltaic effect. Photoelectric devices include phototubes, photomultiplier tubes, photoresistors, photodiodes, phototransistors, photocells, etc. The performance and characteristic curves of photoelectric devices are analyzed.

Photoelectric sensors generally consist of two parts: a processing path and a processing element. Its basic principle is based on the photoelectric effect, which converts the measured changes into changes in light signals, and then uses photoelectric elements to further convert non-electrical signals into electrical signals. The photoelectric effect refers to the use of light to illuminate an object, which can be regarded as a series of photons with a certain energy bombarding the object. At this time, the photon energy is transferred to electrons, and the entire energy of a photon is absorbed by an electron at one time. After the electron obtains the energy transferred by the photon, its state will change, thereby causing the object illuminated by light to produce a corresponding electrical effect. The photoelectric effect is usually divided into three categories: (1) The phenomenon that electrons can escape from the surface of an object under the action of light is called the external photoelectric effect, such as phototubes, photomultiplier tubes, etc.; (2) The phenomenon that the resistivity of an object can change under the action of light is called the internal photoelectric effect, such as photoresistors, phototransistors, etc.; (3) The phenomenon that an object generates an electromotive force in a certain direction under the action of light is called the photovoltaic effect, such as photocells, etc.

The photoelectric detection method has the advantages of high precision, fast response, and non-contact. It can measure many parameters, the sensor has a simple structure, and the form is flexible and diverse. Therefore, photoelectric sensors are widely used in detection and control.

 
 
 

3386

Posts

0

Resources
4
 

3. OLED displays light and sound values

#MicroPython动手做(18)——掌控板之声光传感器
#OLED显示光线与声音数值

from mpython import *

import time
while True:
    oled.fill(0)
    oled.DispChar('声音值为', 40, 11, 1)
    oled.DispChar((str(sound.read())), 55, 22, 1)
    oled.DispChar('光线值为', 40, 33, 1)
    oled.DispChar((str(light.read())), 53, 44, 1)
    oled.show()
    time.sleep(1)

Before use, import the mpython module
from mpython import *

We use sound.read() to get the data from the microphone
.

Note:
The microphone uses the read() function to read data. The returned value is 12-bit ADC sampling data, that is, the maximum value is decimal 4095.

Use the light object to get the light sensor data:
light.read()

Notes
The light sensor uses the read() function to read data. The returned value is 12-bit ADC sampling data, that is, the maximum value is decimal 4095.

 
 
 

3386

Posts

0

Resources
5
 

mPython Graphics Programming

 
 
 

3386

Posts

0

Resources
6
 

 
 
 

3386

Posts

0

Resources
7
 

4. Light-controlled switch (the red light turns on when the light value is less than 300)

#MicroPython动手做(18)——掌控板之声光传感器
#光控开关(光线值小于300红灯亮)

from mpython import *

import time
while True:
    oled.fill(0)
    oled.DispChar('光线值', 46, 22, 1)
    oled.DispChar((str(light.read())), 55, 33, 1)
    oled.show()
    time.sleep_ms(100)
    if light.read() < 300:
        rgb.fill( (int(120), int(0), int(0)) )
        rgb.write()
        time.sleep_ms(1)
        time.sleep_ms(100)
    else:
        rgb.fill( (int(0), int(100), int(0)) )
        rgb.write()
        time.sleep_ms(1)
        time.sleep_ms(100)

 
 
 

3386

Posts

0

Resources
8
 

mPython Graphics Programming

 
 
 

3386

Posts

0

Resources
9
 

 
 
 

3386

Posts

0

Resources
10
 

5. Simple light intensity measuring instrument

#MicroPython动手做(18)——掌控板之声光传感器
#简易光强度测量仪

from mpython import *

myUI = UI(oled)
while True:
    oled.fill(0)
    i = ((100 - 0) / (4095 - 0)) * (light.read() - 0) + 0
    oled.DispChar('光强度', 25, 10, 1)
    oled.DispChar((str(light.read())), 73, 10, 1)
    myUI.stripBar(10, 32, 105, 10, i, 1, 1)
    oled.show()

 
 
 

3386

Posts

0

Resources
11
 

mPython Graphics Programming

 
 
 

3386

Posts

0

Resources
12
 

 
 
 

3386

Posts

0

Resources
13
 

 
 
 

3386

Posts

0

Resources
14
 
This post was last edited by eagler8 on 2020-4-26 16:45

6. Noise alarm

Noise
is a type of sound that annoys people or is too loud and harmful to human health. From the perspective of environmental protection: any sound that interferes with people's normal rest, study and work, and any sound that interferes with the sound people want to hear, is considered noise. From the perspective of physics: noise is the sound produced by a sound-emitting body when it vibrates irregularly.

Volume level (analog):
190 decibels can cause death;
150 decibels are the sound of rockets and missiles being launched;
140 decibels are the highest critical point for complete hearing loss as defined by the European Union;
140 decibels are the sound of a jet taking off;
139 decibels are the shouts of World Cup fans;
130 decibels are the sound of propeller planes taking off and the sound of rock concerts;
120 decibels are temporary deafness if you stay in this environment for more than one minute;
120 decibels are the sound of a ball mill working;
110 decibels are the sound of an electric saw working;
105 decibels are permanent hearing damage;
100 decibels are the sound of a pneumatic drill and the sound of a compression hammer hitting a heavy object; 100 decibels are
the sound of a tractor starting;
90 decibels are the sound of a noisy bar environment and the sound of an electric saw cutting wood;
90 decibels are the sound of a noisy office and the sound on the highway;
85 decibels and below will not damage the hair cells in the cochlea;
80 decibels are the sound of a street environment and the sound of ordinary vehicles driving;
75 decibels is the upper limit of human ear comfort;
70 decibels is the sound of loud talking;
60 decibels is the sound of normal conversation;
50 decibels is the sound of office;
40 decibels is the sound of library reading room;
30 decibels is the sound of bedroom;
20 decibels is the sound of whispering;
10 decibels is the rustling of fallen leaves in the wind;
0 decibels is the sound that just causes hearing.

 
 
 

3386

Posts

0

Resources
15
 
#MicroPython动手做(18)——掌控板之声光传感器
#噪音报警器

from mpython import *

import time

myUI = UI(oled)
while True:
    oled.fill(0)
    i = ((100 - 0) / (2000 - 0)) * (sound.read() - 0) + 0
    oled.DispChar('麦克风', 30, 10, 1)
    oled.DispChar((str(sound.read())), 73, 10, 1)
    myUI.ProgressBar(10, 30, 105, 10, i)
    oled.show()
    if i > 20:
        if i >= 20:
            rgb[0] = (int(255), int(0), int(0))
            rgb.write()
            time.sleep_ms(1)
        if i >= 50:
            rgb[0] = (int(255), int(0), int(0))
            rgb.write()
            time.sleep_ms(1)
            rgb[1] = (int(255), int(0), int(0))
            rgb.write()
            time.sleep_ms(1)
        if i >= 80:
            rgb.fill((int(255), int(0), int(0)))
            rgb.write()
            time.sleep_ms(1)
    else:
        rgb.fill( (0, 0, 0) )
        rgb.write()
        time.sleep_ms(1)

 
 
 

3386

Posts

0

Resources
16
 

mPython Graphics Programming

 
 
 

3386

Posts

0

Resources
17
 

 
 
 

3386

Posts

0

Resources
18
 

7. Sound and light control of corridor lights

The operating principle of the corridor light: when the light value of the surrounding environment becomes darker, the light value detected by the light sensor attached to the corridor light will also decrease. At this time, if someone passes by and makes a sound, the value detected by the sound sensor on the corridor light will increase (when the light value is less than the set value and the sound value is greater than the set value, the bulb will be lit for a period of time), illuminating the stairs for pedestrians to pass through, and then turning off.

Here, the light value is set to less than 180 and the sound value is set to greater than 500, which is the on/off value of the corridor light switch.

#MicroPython动手做(18)——掌控板之声光传感器
#声光控制楼道灯

from mpython import *

import time
while True:
    if light.read() < 180 and sound.read() > 500:
        rgb.fill((int(255), int(255), int(0)))
        rgb.write()
        time.sleep_ms(1)
        oled.fill(0)
        oled.DispChar('楼道灯 开', 36, 25, 1)
        oled.show()
        time.sleep(10)
    else:
        rgb.fill( (0, 0, 0) )
        rgb.write()
        time.sleep_ms(1)
    oled.fill(0)
    oled.DispChar('光线——', 26, 10, 1)
    oled.DispChar((str(light.read())), 73, 10, 1)
    oled.DispChar('声音——', 26, 26, 1)
    oled.DispChar((str(sound.read())), 73, 26, 1)
    oled.show()

 
 
 

3386

Posts

0

Resources
19
 

mPython Graphics Programming

 
 
 

3386

Posts

0

Resources
20
 

 
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list