当前位置:网站首页>Zhihuijia - full furniture function

Zhihuijia - full furniture function

2022-06-26 01:03:00 Salted fish shell

 contain


Materials and wiring

MR Development board
 Insert picture description here
1.54LCD The screen
 Insert picture description here

Welcome home to connect

Ultrasonic ranging
 Insert picture description here
Tricolor RGB
 Insert picture description here

Development board Ultrasonic ranging
trigA6
echoA4
5vVCC
GNDGND
Development board RGB
GNDGND
BC0

Fire alarm

Flame sensor module
 Insert picture description here
Active buzzer
 Insert picture description here
Wiring instructions

Development board Flame sensor
DOB1
5vVCC
GNDGND
Development board Buzzer
DOB0
5vVCC
GNDGND

Out of office index reminder

PM2.5 5003 G5
 Insert picture description here
PM2.5 Adapter plate
Cough , It is more convenient to use the adapter board .
 Insert picture description here
Tricolor RGB
 Insert picture description here
connection

Development board PM2.5
A3(RX)TX
5vVCC
GNDGND
Development board RGB
GNDGND
RC7
GC6

Smart lights + Intimate curtain

Photoresistor sensor
 Insert picture description here

8MM Luminescence LED modular
 Insert picture description here
12V DC motor

 Insert picture description here

connection

Development board Photosensitive resistor
5VVCC
GNDGND
A0DO
Development board 8MMLED
5VVCC
GNDGND
A1OUT
Pin explain
C8 Only for high level , The motor will turn
B8PWM control A The motor
B12A0 # This time I used A The motor , It can be debugged on demand .
B13A1
B9PWM control B The motor
B14B0
B15B1

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

原网站

版权声明
本文为[Salted fish shell]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/177/202206252250263151.html