当前位置:网站首页>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点亮,蜂鸣器报警
给传感器接入增添其他显示
边栏推荐
- 系统设计学习(二)Design a key-value cache to save the results of the most recent web server queries
- 阿里云微服务(四) Service Mesh综述以及实例Istio
- 系统设计学习(三)Design Amazon‘s sales rank by category feature
- ROS machine voice
- 4.30动态内存分配笔记
- Inheritance and polymorphism (I)
- Record: I accidentally wrote a recursion next time
- String类
- Record: newinstance() obsolete replacement method
- 2年经验总结,告诉你如何做好项目管理
猜你喜欢

10 minutes pour maîtriser complètement la rupture du cache, la pénétration du cache, l'avalanche du cache

System design learning (III) design Amazon's sales rank by category feature

Redis介绍与使用
![[algorithm] sword finger offer2 golang interview question 9: subarray with product less than k](/img/65/fc3fb5a217a3b44f506b695af53e2c.png)
[algorithm] sword finger offer2 golang interview question 9: subarray with product less than k

阿里云微服务(一)服务注册中心Nacos以及REST Template和Feign Client

MYSQL索引钟B-TREE ,B+TREE ,HASH索引之间的区别和应用场景

121 distributed interview questions and answers

2-year experience summary, tell you how to do a good job in project management

Common method signatures and meanings of Iterable, collection and list

TYUT太原理工大学2022数据库大题之概念模型设计
随机推荐
十分钟彻底掌握缓存击穿、缓存穿透、缓存雪崩
Network layer 7 protocol
[algorithm] sword finger offer2 golang interview question 3: the number of 1 in the binary form of the first n numbers
Iterable、Collection、List 的常见方法签名以及含义
Error: sorting and subscript out of bounds
MySQL backup -- common errors in xtrabackup backup
A brief introduction to the database of tyut Taiyuan University of technology in previous years
All in one 1405: sum and product of prime numbers
Answer to "software testing" exercise: Chapter 1
Voir ui plus version 1.3.1 pour améliorer l'expérience Typescript
TYUT太原理工大学2022“mao gai”必背
TYUT太原理工大学2022数据库大题之概念模型设计
[rtklib 2.4.3 B34] version update introduction I
分支语句和循环语句
Branch and loop statements
MySQL 30000 word essence summary + 100 interview questions, hanging the interviewer is more than enough (Collection Series
Small exercise of library management system
面渣逆袭:Redis连环五十二问,三万字+八十图详解。
【话题终结者】
Solution: warning:tensorflow:gradients do not exist for variables ['deny_1/kernel:0', 'deny_1/bias:0',