当前位置:网站首页>arduino+水位传感器+led显示+蜂鸣器报警
arduino+水位传感器+led显示+蜂鸣器报警
2022-07-06 09:19:00 【麓南的风】
实验准备:
arduino mega2560(uno、Nano及其他型号同理)
led(黄、绿、红)
电阻x3(本次选用680Ω电阻1/4w金属膜电阻,避免led灯烧坏注意电阻值不要太小)
蜂鸣器(这里我用的有源高电平触发)
水位传感器(如下)
water sensor
接线情况(后边根据提供程序接线即可)
实验程序
#define water_sensorspin A1
#define led_yellow 2
#define led_green 3
#define led_red 4
#define buzzpin 7
float ad_value=0; //深度模拟值
float deepcm=0; //实际深度
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(led_yellow,OUTPUT); //设置引脚状态
pinMode(led_green,OUTPUT);
pinMode(led_red,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
ad_value=analogRead(water_sensorspin); //A1引脚获取模拟值赋予变量
Serial.println("Water level monitoring ready");
delay(20);
Serial.println(ad_value); //打印观察模拟值变化
deepcm=(ad_value/702)*4; //经过测量,最深时模拟值约为702,测量深度4cm
Serial.print("此时水的深度为:");
Serial.print(deepcm);
Serial.println("cm");
if(deepcm<1.5) //水位低于1.5cm时
{
delay(20);
digitalWrite(led_yellow,HIGH);
digitalWrite(led_green,LOW);
digitalWrite(led_red,LOW);
digitalWrite(buzzpin,LOW);
}
else if(deepcm<3)
{
delay(20);
digitalWrite(led_yellow,LOW);
digitalWrite(led_green,HIGH);
digitalWrite(led_red,LOW);
digitalWrite(buzzpin,LOW);
}
else if(deepcm>3)
{
delay(20);
digitalWrite(led_yellow,LOW);
digitalWrite(led_green,LOW);
digitalWrite(led_red,HIGH);
digitalWrite(buzzpin,HIGH);
Serial.println("水位太高了,注意!");
}
delay(2000); //延时堵塞稍微长一些,串口刷新太快看不清
}
实验现象
水位传感器插入水中(注意最大深度不得超过4cm)
深度较浅时
适中深度
深度较深时
视频
水位led显示
蜂鸣器报警
基础:led点亮,蜂鸣器报警
给传感器接入增添其他显示
边栏推荐
- Interview Essentials: talk about the various implementations of distributed locks!
- 架构师怎样绘制系统架构蓝图?
- [untitled]
- C code implementation of robust estimation in rtklib's pntpos function (standard single point positioning spp)
- Alibaba cloud microservices (I) service registry Nacos, rest template and feign client
- [algorithm] sword finger offer2 golang interview question 3: the number of 1 in the binary form of the first n numbers
- 记录:下一不小心写了个递归
- Tyut Taiyuan University of technology 2022 introduction to software engineering summary
- Small exercise of library management system
- 系统设计学习(三)Design Amazon‘s sales rank by category feature
猜你喜欢
121道分布式面试题和答案
国企秋招经验总结
继承和多态(下)
MySQL 30000 word essence summary + 100 interview questions, hanging the interviewer is more than enough (Collection Series
System design learning (I) design pastebin com (or Bit.ly)
[algorithm] sword finger offer2 golang interview question 4: numbers that appear only once
《软件测试》习题答案:第一章
Design a key value cache to save the results of the most recent Web server queries
What are the advantages of using SQL in Excel VBA
架构师怎样绘制系统架构蓝图?
随机推荐
Summary of multiple choice questions in the 2022 database of tyut Taiyuan University of Technology
Smart classroom solution and mobile teaching concept description
系统设计学习(二)Design a key-value cache to save the results of the most recent web server queries
String类
Design a key value cache to save the results of the most recent Web server queries
Error: sorting and subscript out of bounds
[untitled]
记录:下一不小心写了个递归
Fgui project packaging and Publishing & importing unity & the way to display the UI
Small exercise of library management system
String class
RTKLIB: demo5 b34f. 1 vs b33
TYUT太原理工大学2022数据库考试题型大纲
系统设计学习(一)Design Pastebin.com (or Bit.ly)
Alibaba cloud microservices (I) service registry Nacos, rest template and feign client
ROS machine voice
TYUT太原理工大学2022数据库大题之数据库操作
MySQL 三万字精华总结 + 面试100 问,吊打面试官绰绰有余(收藏系列
View UI Plus 发布 1.3.1 版本,增强 TypeScript 使用体验
TYUT太原理工大学2022软工导论考试题型大纲