Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Python how to DIY Intelligent temperature Control small Fan

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

In this article, the editor introduces in detail "python how to DIY intelligent temperature control small fan", the content is detailed, the steps are clear, and the details are handled properly. I hope this "python how to DIY intelligent temperature control small fan" article can help you solve your doubts.

two。 Required components

TPYBoard board

A DC motor

A piece of bread

A data line

18b20 temperature sensor

Triode 9014 (NPN) one

DuPont line several (radish discipline programming education tpyboard. Com)

3. Learn the wiring method of DS18B20 and detect the current temperature

First, take a look at the meaning of DS18B20 pins, as shown in the figure above:

The corresponding relationship between the pins of TPYBoard and those of DS18B20 is as follows:

TPYBoard DS18B20

-

# 3V3 or any Pin = > VDD

# any Pin = > DO

# GND = > GND

If you still don't understand, just put the pin number on it.

TPYBoard DS18B20

-

3.3v = > VDD

GND = > GND

Y10 = > DO

After connecting to ok, in the source directory of MicroPython, go to the drivers\ onewire\ directory, and then copy the files ds18x20.py and onewire.py in the directory to the root directory of the PYBFLASH disk. Copy the file to safely exit the disk, and then re-access, otherwise can not find the file, you can run the main.py file, print temperature, you can use Putty to see the current temperature. (radish programming education tpyboard. Com)

Main.py source code:

# main.pyimport pybfrom pyb import Pinfrom ds18x20 import DS18X20Pin ("Y11", Pin.OUT_PP). Low () # GNDPin ("Y9", Pin.OUT_PP). High () # VCCpyb.delay (100) DQ=DS18X20 (Pin ('Y10')) # DQwhile True: tem = DQ.read_temp () print (tem) pyb.delay (1000)

4. The principle of Triode

Here we use the switching and amplification function of the transistor to control the current on and off of the DC motor at different levels of the base in order to control the rotation of the motor. according to the characteristics of the transistor, we connect the collector to the 3.3v of TPYBoard, the emitter to one pole of the motor, and the motor to the GND of TPYboard. The temperature is detected by the temperature sensor 18B20. When the temperature reaches the specified temperature, the level of the Triode base is controlled by TPYBoard. Drive DC motor to rotate.

5. source code

After we follow the above steps, then turn on the power and write the main.py file, we can control the rotation of the fan through the temperature. The specific code is as follows:

# main.pyimport pybfrom pyb import Pinfrom ds18x20 import DS18X20Pin ("Y9", Pin.OUT_PP). High () # VCCPin ("Y11", Pin.OUT_PP). Low () # GNDx1 = Pin ('X1, Pin.OUT_PP) pyb.delay (100) DQ=DS18X20 (Pin ('Y10')) # DQwhile 1: tem = DQ.read_temp () if tem > 18: x1.value (1) else: x1.value (0) This article "python how to DIY Intelligent temperature Control small Fan" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself. If you want to know more about related articles, welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report