当前位置:网站首页>智慧家——全家具功能
智慧家——全家具功能
2022-06-25 22:50:00 【咸鱼箘】
材料及接线
MR开发板
1.54LCD屏幕
欢迎回家接线
超声波测距
三色RGB
| 开发板 | 超声波测距 |
|---|---|
| trig | A6 |
| echo | A4 |
| 5v | VCC |
| GND | GND |
| 开发板 | RGB |
|---|---|
| GND | GND |
| B | C0 |
火灾报警
火焰传感器模块
有源蜂鸣器
接线说明
| 开发板 | 火焰传感器 |
|---|---|
| DO | B1 |
| 5v | VCC |
| GND | GND |
| 开发板 | 蜂鸣器 |
|---|---|
| DO | B0 |
| 5v | VCC |
| GND | GND |
外出指数提醒
PM2.5 5003 G5
PM2.5 转接板
咳咳,还是用转接板方便一些。
三色RGB
接线
| 开发板 | PM2.5 |
|---|---|
| A3(RX) | TX |
| 5v | VCC |
| GND | GND |
| 开发板 | RGB |
|---|---|
| GND | GND |
| R | C7 |
| G | C6 |
聪明的灯光+贴心的窗帘
光敏电阻传感器
8MM发光LED模块
12V直流电机

接线
| 开发板 | 光敏电阻 |
|---|---|
| 5V | VCC |
| GND | GND |
| A0 | DO |
| 开发板 | 8MMLED |
|---|---|
| 5V | VCC |
| GND | GND |
| A1 | OUT |
| 引脚 | 说明 |
|---|---|
| C8 | 只有为高电平时,马达才会转 |
| B8 | PWM控制A电机 |
| B12 | A0 #本次使用了A电机,可以自己按需调试。 |
| B13 | A1 |
| B9 | PWM控制B电机 |
| B14 | B0 |
| B15 | B1 |
示例程序
from pyb import UART,Pin,delay,Timer
import time
from HCSR04 import HCSR04
from machine import Pin
import lcd
# 屏幕
lcd = lcd.LCD()
#PM2.5
u2 = UART(2, baudrate=9600,bits=8, parity=None, stop=1, timeout=100) #初始化串口
# 3色 红绿 +PM2.5 蓝色+超声波
p_Rout = Pin("C7",Pin.OUT_PP) # 红色
p_Gout = Pin("C6",Pin.OUT_PP) # 绿色
p_Bout = Pin("C0",Pin.OUT_PP) # 蓝色
# 火焰
fire=Pin('B1',Pin.IN)
# 蜂鸣器
beep=Pin('B0',Pin.OUT_PP)
# ——————电机——————
cs = Pin('C8',Pin.OUT_PP) #C8设置为输出引脚输出高电平
cs(1)
ch1 =None
ch2 =None
trig = Pin("A6",Pin.OUT)
echo = Pin("A4",Pin.IN)
HC=HCSR04(trig,echo)
#A电机正反转 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): #正转
ch2.pulse_width_percent(speed)
A0(1)
A1(0)
def f(speed): #反转
ch2.pulse_width_percent(speed)
A0(0)
A1(1)
#——————电机 end
#光敏
Do = Pin("A0",Pin.IN)
# 8MM 线性变亮
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() # 读数即可
PM2_5= upp[6]*256+upp[7] # 6,7位计算pm2.5
PM10 = upp[8]*256+upp[9] # 8,9位计算PM10
#print("PM2.5为:",int(PM2_5),"um") #单位是 微克/立方米
#print("PM10为:",int(PM10),"um") #单位是 微克/立方米
if PM2_5 >= 50: # PM2.5为80um以上的时候亮红灯 别出门啦!
p_Rout(1)
p_Gout(0)
p_Bout(0)
else:
p_Rout(0)
p_Gout(1)
p_Bout(0)
# ---— 超声波-----
Distance = HC.getDm() #测量距离
print(Distance)
if Distance <10:
p_Rout(0)
p_Gout(0)
p_Bout(1)
else:
p_Bout(0)
# 屏幕显示PM2.5
lcd.chars('PM2_5:'+str(PM2_5)+" ",40, 90)#空格以防超出显示限制补位使用
# 光感 + 电机+ 发光模块
if Do.value()==0: #yougguang
ch1.pulse_width_percent(0) # 灯不亮
f(30) # 电机反转 这里应该判断状态 我没写,注意一下
else:
for i in range(100):
ch1.pulse_width_percent(i) #灯线性亮
delay(50)
z(10) # 电机正转(关窗帘)
# 火焰报警
if fire.value()==1:
beep(1) #高电平触发,检测火焰,报警
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) #高电平触发,检测火焰,报警
else:
beep(0)
全代码请自行下载:智能家居竞赛基础功能
边栏推荐
- Methods of modifying elements in JS array
- Flink reports error: a JNI error has occurred, please check your installation and try again
- Ssl/tls, symmetric and asymmetric encryption, and tlsv1.3
- C another new class is ICO? And app Use of config
- Spark log analysis
- Phoenix index
- ASP. Net cache cache usage
- Installation and configuration of gradle environment
- Idea set the template of mapper mapping file
- 213. house raiding II
猜你喜欢

No executorfactory found to execute the application

jarvisoj_ level2_ x64

随便画画的

Compiler Telegram Desktop end (tdesktop) en utilisant vs2022

Why is it best to use equals for integer comparisons

Openresty chapter 01 introduction and installation configuration

Mining pit record of modified field information in Dameng database

1-11solutions to common problems of VMware virtual machine

Stream data

Idea set the template of mapper mapping file
随机推荐
1-11solutions to common problems of VMware virtual machine
Final review [machine learning]
1-10Vmware构建自定义的网络架构
Wireshark's analysis of IMAP packet capturing
C#使用MySql进行操作
213. house raiding II
C thread pool control semaphore
Flink报错:Error: A JNI error has occurred, please check your installation and try again
ciscn_ 2019_ en_ two
Modelsim simulation FFT core cannot be simulated solution (qsys)
Download and install flume
Electronic training.
Apache foundation officially announced Apache inlong as a top-level project
Redisson 3.17.4 发布
ASP.NET cache缓存的用法
flink报错:No ExecutorFactory found to execute the application
react + router 框架下的路由跳转后缓存页面存初始参数
The maze of God's perspective in robot vision
Performance leads the cloud native database market! Intel and Tencent jointly build cloud technology ecology
[system architecture] - what are MDA architecture, ADL and DSSA
