当前位置:网站首页>Zhihuijia - full furniture function
Zhihuijia - full furniture function
2022-06-26 01:03:00 【Salted fish shell】
Smart home —— Full furniture function
Materials and wiring
MR Development board
1.54LCD The screen
Welcome home to connect
Ultrasonic ranging
Tricolor RGB
Development board | Ultrasonic ranging |
---|---|
trig | A6 |
echo | A4 |
5v | VCC |
GND | GND |
Development board | RGB |
---|---|
GND | GND |
B | C0 |
Fire alarm
Flame sensor module
Active buzzer
Wiring instructions
Development board | Flame sensor |
---|---|
DO | B1 |
5v | VCC |
GND | GND |
Development board | Buzzer |
---|---|
DO | B0 |
5v | VCC |
GND | GND |
Out of office index reminder
PM2.5 5003 G5
PM2.5 Adapter plate
Cough , It is more convenient to use the adapter board .
Tricolor RGB
connection
Development board | PM2.5 |
---|---|
A3(RX) | TX |
5v | VCC |
GND | GND |
Development board | RGB |
---|---|
GND | GND |
R | C7 |
G | C6 |
Smart lights + Intimate curtain
Photoresistor sensor
8MM Luminescence LED modular
12V DC motor
connection
Development board | Photosensitive resistor |
---|---|
5V | VCC |
GND | GND |
A0 | DO |
Development board | 8MMLED |
---|---|
5V | VCC |
GND | GND |
A1 | OUT |
Pin | explain |
---|---|
C8 | Only for high level , The motor will turn |
B8 | PWM control A The motor |
B12 | A0 # This time I used A The motor , It can be debugged on demand . |
B13 | A1 |
B9 | PWM control B The motor |
B14 | B0 |
B15 | B1 |
The sample program
from pyb import UART,Pin,delay,Timer
import time
from HCSR04 import HCSR04
from machine import Pin
import lcd
# The screen
lcd = lcd.LCD()
#PM2.5
u2 = UART(2, baudrate=9600,bits=8, parity=None, stop=1, timeout=100) # Initialize serial port
# 3 color Red and green +PM2.5 Blue + ultrasonic
p_Rout = Pin("C7",Pin.OUT_PP) # Red
p_Gout = Pin("C6",Pin.OUT_PP) # green
p_Bout = Pin("C0",Pin.OUT_PP) # Blue
# flame
fire=Pin('B1',Pin.IN)
# Buzzer
beep=Pin('B0',Pin.OUT_PP)
# —————— The motor ——————
cs = Pin('C8',Pin.OUT_PP) #C8 Set the output pin to output high level
cs(1)
ch1 =None
ch2 =None
trig = Pin("A6",Pin.OUT)
echo = Pin("A4",Pin.IN)
HC=HCSR04(trig,echo)
#A Motor forward and reverse s---
p2 = Pin('B8')
tim2 = Timer(10, freq=120)
ch2 = tim2.channel(1, Timer.PWM, pin=p2)
A0 = Pin('B12',Pin.OUT_PP)
A1 = Pin('B13',Pin.OUT_PP)
def z(speed): # Positive rotation
ch2.pulse_width_percent(speed)
A0(1)
A1(0)
def f(speed): # reverse
ch2.pulse_width_percent(speed)
A0(0)
A1(1)
#—————— The motor end
# photosensitive
Do = Pin("A0",Pin.IN)
# 8MM Linear lightening
p1 = Pin('A1')
tim1 = Timer(2, freq=100)
ch1 = tim1.channel(2, Timer.PWM, pin=p1)
while True:
time.sleep(1)
# ----PM2.5-----
if u2.any():
upp=u2.read() # Reading is enough
PM2_5= upp[6]*256+upp[7] # 6,7 Bit calculation pm2.5
PM10 = upp[8]*256+upp[9] # 8,9 Bit calculation PM10
#print("PM2.5 by :",int(PM2_5),"um") # The unit is MCG / Cubic meters
#print("PM10 by :",int(PM10),"um") # The unit is MCG / Cubic meters
if PM2_5 >= 50: # PM2.5 by 80um Above, the red light will be on Don't go out !
p_Rout(1)
p_Gout(0)
p_Bout(0)
else:
p_Rout(0)
p_Gout(1)
p_Bout(0)
# ---— ultrasonic -----
Distance = HC.getDm() # Measuring distance
print(Distance)
if Distance <10:
p_Rout(0)
p_Gout(0)
p_Bout(1)
else:
p_Bout(0)
# Screen display PM2.5
lcd.chars('PM2_5:'+str(PM2_5)+" ",40, 90)# Space to prevent exceeding the display limit
# Light sense + The motor + Light emitting module
if Do.value()==0: #yougguang
ch1.pulse_width_percent(0) # The light is not bright
f(30) # The motor reverses Here the status should be judged I didn't write , Pay attention to the
else:
for i in range(100):
ch1.pulse_width_percent(i) # The light is linear
delay(50)
z(10) # The motor is turning forward ( Close the curtains )
# Fire alarm
if fire.value()==1:
beep(1) # High level trigger , Detect the flame , Call the police
else:
beep(0)
from pyb import Pin,delay
fire=Pin('B0',Pin.IN)
beep=Pin('B1',Pin.OUT_PP)
while True:
delay(1000)
print(fire.value())
if fire.value()==1:
beep(1) # High level trigger , Detect the flame , Call the police
else:
beep(0)
Please download the full code by yourself : Basic functions of smart home competition
边栏推荐
- Mpu6050 reads the ID incorrectly and 0xd1 occurs (the correct ID should be 0x68 or 0x69). Solution.
- Kylin
- The cache page stores the initial parameters after the route jump under the react + router framework
- [learn FPGA programming from scratch -44]: vision chapter - integrated circuit helps high-quality development in the digital era -1- main forms of integrated circuit chips
- Music spectrum display toy -- implementation and application of FFT in stm32
- Implementation notes of least square fitting conic in stm32
- [从零开始学习FPGA编程-44]:视野篇 - 集成电路助力数字化时代高质量发展-1-集成电路芯片主要形态
- Learn to identify follow-up questions in dialogue Q & A
- Leetcode 513. Find the value in the lower left corner of the tree
- 关于EF翻页查询数据库
猜你喜欢
Summary of push-pull output and open drain output of STM32 and failure of analog IIC driving mlx90615
模板引擎——FreeMarker初体验
Establish a j-link GDB cross debugging environment for Px4
Endnote IEEE Transactions on industrial electronics/tie/tpel reference format template
Redis strings command
CXF
下载安装Flume
C IO stream (II) extension class_ Packer
Mpu6050 reads the ID incorrectly and 0xd1 occurs (the correct ID should be 0x68 or 0x69). Solution.
Computer network knowledge summary (interview)
随机推荐
Compiler Telegram Desktop end (tdesktop) en utilisant vs2022
Modelsim simulation FFT core cannot be simulated solution (qsys)
同花顺软件买股票进行交易安全吗?怎么开户买股票
Px4 system terminal for pixhawk
Comment promouvoir efficacement les produits
Error 65:access violation at 0x58024400: no 'read' permission
FreeRTOS+STM32L+ESP8266+MQTT协议传输温湿度数据到腾讯云物联网平台
Installation and configuration of gradle environment
WordPress
ciscn_2019_en_2
Megacli common command collation
智慧家——全家具功能
mysql cluster
How to effectively promote products
PHP performance optimization
Idea kotlin version upgrade
多接口调用,使用Promise.all、Promise.race和Promise.any
. Net using access 2010 database
Flex & bison start
Redis strings command