当前位置:网站首页>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
边栏推荐
猜你喜欢

Casually painted

关于HC-12无线射频模块使用

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

Mpu6050 reads the ID incorrectly and 0xd1 occurs (the correct ID should be 0x68 or 0x69). Solution.

Web学习之TypeScript

Implementation notes of least square fitting conic in stm32

Stream data

Template engine - FreeMarker first experience

案例:绘制Matplotlib动态图

mtb13_ Perform extract_ blend_ Super{candidate (primaryalternate) \u unique (nullable filtering \foreign\index\granulati
随机推荐
[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
Penetration tool -burpsuite
Learn to identify follow-up questions in dialogue Q & A
How to effectively promote products
ciscn_2019_en_2
sqlserver 区分字符串中字母大小写
关于EF翻页查询数据库
C IO stream (II) extension class_ Packer
C#线程池控制Semaphore
Compile the telegraph desktop side (tdesktop) using vs2022
Inheritance -- holy grail mode
1-10vmware builds customized network architecture
.net使用Access 2010数据库
C another new class is ICO? And app Use of config
How to design the product roadmap?
ASP.NET cache缓存的用法
Chapter V exercises (124, 678, 15, 19, 22) [microcomputer principles] [exercises]
The cache page stores the initial parameters after the route jump under the react + router framework
Permission design = function permission + Data permission
213. house raiding II
