当前位置:网站首页>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点亮,蜂鸣器报警
给传感器接入增添其他显示
边栏推荐
- Redis介绍与使用
- Rt-ppp test using rtknavi
- Code example of MATLAB reading GNSS observation value o file
- 2022 National Games RE1 baby_ tree
- Interview Essentials: talk about the various implementations of distributed locks!
- Summary of multiple choice questions in the 2022 database of tyut Taiyuan University of Technology
- Shortest Hamilton path (pressure DP)
- Record: the solution of MySQL denial of access when CMD starts for the first time
- Share a website to improve your Aesthetics
- 2年经验总结,告诉你如何做好项目管理
猜你喜欢
View UI plus released version 1.2.0 and added image, skeleton and typography components
《软件测试》习题答案:第一章
Application architecture of large live broadcast platform
几道高频的JVM面试题
[algorithm] sword finger offer2 golang interview question 13: sum of numbers of two-dimensional submatrix
The port is occupied because the service is not shut down normally
[GNSS data processing] Helmert variance component estimation analysis and code implementation
RTKLIB: demo5 b34f. 1 vs b33
TYUT太原理工大学2022数据库大题之数据库操作
Edit distance (multi-source BFS)
随机推荐
Interview Essentials: talk about the various implementations of distributed locks!
Heap sort [handwritten small root heap]
First acquaintance with C language (Part 2)
Alibaba cloud microservices (I) service registry Nacos, rest template and feign client
初识C语言(下)
几道高频的JVM面试题
Role movement in the first person perspective
记录:newInstance()过时的代替方法
165. Compare version number - string
《软件测试》习题答案:第一章
[algorithm] sword finger offer2 golang interview question 4: numbers that appear only once
Fairygui bar subfamily (scroll bar, slider, progress bar)
十分钟彻底掌握缓存击穿、缓存穿透、缓存雪崩
记录:下一不小心写了个递归
Quickly generate illustrations
Answer to "software testing" exercise: Chapter 1
Counter attack of flour dregs: redis series 52 questions, 30000 words + 80 pictures in detail.
Realization of the code for calculating the mean square error of GPS Height Fitting
[untitled]
Chromatic judgement bipartite graph