基于Arduino UNO设计一个温控制系统
设置智能控制系统自动调节温度 #生活常识# #生活建议# #节能技巧# #建筑节能设计#
目录
概述
1 硬件结构
1.1 整体硬件介绍
1.2 硬件连接结构
2 软件设计
2.1 软件功能介绍
2.2 关于Arduino的一些知识点
2.2.1 定时器
2.2.2 PWM
2.3 代码实现
2.3.1 编译工具
2.3.2 详细代码
3 测试
3.1 温度数据监控
3.2 温控测试
概述
本文介绍如何使用Arduino UNO作为主控制板,设计一个智能温控系统,其实现功能如下:当环境温度达到一定的门限值时,开始风扇,当环境温度低于该门限值则关闭风扇。系统使用DS18B20采集环境温度,L298N驱动电机,OLED显示当前环境温度。软件设计上使用Arduino自带的定时器中断功能,用于控制时间间隔。还使用了PWM技术,以控制电机的转速。
1 硬件结构
1.1 整体硬件介绍
1)Arduino UNO: 主控板卡
2)控制L298N:用于控制电机系统
3)控制OLED模块:用于显示当前温度数据
4)控制DS18B20:获取环境温度数据
5)直流电机:驱动扇叶
1.2 硬件连接结构
模块引脚与Arduino UNO主板之间关系:
Arduino UNO IO应用模块IO注释PIN-2DS18B20 DQPIN-5L298N in-1用于电机控制PIN-6L298N in-2用于电机控制SCLOLED-sclSDAOLED-sda2 软件设计
2.1 软件功能介绍
软件主要实现功能如下:
1) 控制DS18B20,读取该传感器采集到的温度值
2) 在OLED显示温度数据
3)通过串口打印调试信息
4)根据门限值,控制电机转速(PWM)
2.2 关于Arduino的一些知识点
2.2.1 定时器在Arduino中使用定时器,必须要包含该头文件 <MsTimer2.h>,然后调用如下函数启动定时器,并且还要实现一个中断回调函数。
void startTime()
{
MsTimer2::set(500, timer_irq);
MsTimer2::start();
}
void timer_irq()
{
}
2.2.2 PWM在Arduino UNO板卡中使用PWM功能,其能使用的引脚为pin( 3, 5, 6, 9, 10, 11),使用方法如下:
1) 配置端口为模拟引脚
2)使用analogWrite( pin, cycle )函数来配置占空比参数含义如下:
pin - 引脚号;
cycle - 占空比(范围: 0 ~ 255 )
一个使用案例:
const int output1 = 5;
const int output2 = 6;
void setup()
{
pinMode(output1, OUTPUT);
pinMode(output2, OUTPUT);
}
void pwmCycle()
{
analogWrite(output1, 150);
analogWrite(output2, 0);
}
2.3 代码实现
2.3.1 编译工具#include <MsTimer2.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
const int output1 = 5;
const int output2 = 6;
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);
unsigned int cnt = 0;
int pwmcycle = 0;
void timer_irq();
void setup() {
Serial.begin(9600);
pinMode(output1, OUTPUT);
pinMode(output2, OUTPUT);
analogWrite(output1, 0);
analogWrite(output2, 0);
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.display();
display.clearDisplay();
MsTimer2::set(500, timer_irq);
MsTimer2::start();
}
void loop() {
int tempPwmCycle = 0;
if( cnt%2 == 0 )
{
sensors.requestTemperatures();
if( cnt%3 == 0 )
{
display.clearDisplay();
Serial.print("Temperature for the device 1 (index 0) is: ");
Serial.println(sensors.getTempCByIndex(0));
display.setTextSize(1);
display.setCursor(0,0);
display.println(F("Current temp: "));
display.setTextSize(2);
display.setTextColor(SSD1306_WHITE);
display.setCursor(25,15);
display.println(sensors.getTempCByIndex(0));
display.display();
}
}
if( sensors.getTempCByIndex(0) >= 20 )
{
tempPwmCycle = 100;
}
else
{
tempPwmCycle = 0;
}
if( pwmcycle != tempPwmCycle )
{
pwmcycle = tempPwmCycle;
analogWrite(output1, pwmcycle);
analogWrite(output2, 0);
}
}
void timer_irq()
{
cnt++;
}
3 测试
3.1 温度数据监控
采集和打印温度数据信息:
3.2 温控测试
温度值 Value > 20 ℃ ,开启风扇
网址:基于Arduino UNO设计一个温控制系统 https://www.yuejiaxmz.com/news/view/434593
相关内容
如何使用Arduino UNO和YK04构建远程控制家庭自动化系统基于Arduino的智能家居系统设计与实现
基于Arduino智能家居控制系统
基于Arduino的智能环境监测与反馈系统
基于Arduino的智能家居控制系统的设计与实现
基于Arduino的智能家居系统设计
基于ESP32的智能家居控制系统设计
基于arduino的智能家居系统
基于物联网的智能厨房安全监测系统
家庭自动化系统开源构建