当前位置:网站首页>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
边栏推荐
- Download and install flume
- Idea kotlin version upgrade
- Unified gateway
- Music spectrum display toy -- implementation and application of FFT in stm32
- Stream data
- 如何有效地推廣產品
- [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
- . user. PHP website installation problems caused by INI files
- 马斯克 VS 乔布斯,谁是21世纪最伟大的创业家
- 下载安装Flume
猜你喜欢

Openresty chapter 01 introduction and installation configuration

Analyze the five root causes of product development failure

Endnote IEEE Transactions on industrial electronics/tie/tpel reference format template

Anaconda beginner's notes

Idea kotlin version upgrade

The maze of God's perspective in robot vision

Web学习之TypeScript

Typescript for Web Learning

Leetcode 513. Find the value in the lower left corner of the tree

Px4 system terminal for pixhawk
随机推荐
Megacli common command collation
The maze of God's perspective in robot vision
About the use of hc-12 radio frequency module
Casually painted
案例:绘制Matplotlib动态图
Recognize map
sqlserver 区分字符串中字母大小写
213. house raiding II
Permission design = function permission + Data permission
Chapter V exercises (124, 678, 15, 19, 22) [microcomputer principles] [exercises]
Px4 system terminal for pixhawk
Installation and startup of redis
Installation and configuration of gradle environment
Analyze the five root causes of product development failure
统一网关Gateway
Qt之自定义带游标的QSlider
同花顺软件买股票进行交易安全吗?怎么开户买股票
Summary of push-pull output and open drain output of STM32 and failure of analog IIC driving mlx90615
Inheritance -- holy grail mode
关于EF翻页查询数据库
