Micropython学习交流群 学习QQ群:786510434 提供多种固件下载和学习交流。

Micropython-扇贝物联 QQ群:31324057 扇贝物联是一个让你与智能设备沟通更方便的物联网云平台

Micropython学习交流群 学习QQ群:468985481 学习交流ESP8266、ESP32、ESP8285、wifi模块开发交流、物联网。

Micropython老哥俩的IT农场分享QQ群:929132891 为喜欢科创制作的小白们分享一些自制的计算机软硬件免费公益课程,由两位多年从事IT研发的中年大叔发起。

Micropython ESP频道

Micropython ESP32 C3连接人体红外感应模块HC-SR505


Micropython ESP32 C3连接人体红外感应模块HC-SR505

 ESP32 C3和SR505模块接线方法:

652ba0d841d34e0ea92f368c1f2bf397.png

from machine import Pin,UART
import time
 
# 定义led灯对象
led = Pin(12,Pin.OUT)
# 定义SR505人体感应器对象
sr505 = Pin(4,Pin.IN,Pin.PULL_DOWN)
# 创建串口对象
uart = UART(1,baudrate = 9600,tx = 0,rx = 1)
 
# 命令
on = bytearray(b'\x7e\xff\x06\x03\x00\x00\x01\xfe\xf7\xef')  # 开启
off = bytearray(b'\x7e\xff\x06\x03\x00\x00\x02\xfe\xf6\xef')  # 关闭
 
# 创建SR505对象
def SR505():
    if sr5.value() == True:
        time.sleep(0.05)
        if sr5.value() == True:
            led.value(not led.value())
            if led.value():
                uart.write(on)
            else:
                uart.write(of)
                
            while not sr5.value():
                None
                
        time.sleep(10)
        
def main():
    #uart.write(on)
    while True:
        SR505()
 
 
if __name__ == "__main__":
    main()

来源:https://blog.csdn.net/zhusongziye/article/details/131315109


推荐分享
图文皆来源于网络,内容仅做公益性分享,版权归原作者所有,如有侵权请告知删除!
 

Copyright © 2014 ESP56.com All Rights Reserved

执行时间: 0.0098919868469238 seconds