0
  • 聊天消息
  • 系统消息
  • 评论与回复
登录后你可以
  • 下载海量资料
  • 学习在线课程
  • 观看技术视频
  • 写文章/发帖/加入社区
创作中心

完善资料让更多小伙伴认识你,还能领取20积分哦,立即完善>

3天内不再提示

怎样用Arduino制作水位指示器

454398 来源:工程师吴畏 2019-08-02 16:43 次阅读

Arduino水位指示器如何工作?

该Arduino水位指示器使用超声波传感器Ping传感器来确定水箱中的水位。 Ping传感器使用声纳测量距离。从该单元发射超声波(远高于人类听觉)脉冲,并且通过测量回波返回所需的时间来确定到目标的距离。 Ping传感器的输出是可变宽度脉冲,对应于到目标的距离。然后将其输入微控制器,确定水位并通过一系列LED显示。

以下项目可以是如果您有一个或直接连接到面板上的ATmega 328微控制器,则可以连接到Arduino板。您还可以查看Jeff的Maker Pro教程,了解如何将超声波传感器连接到Arduino。

Arduino水位指示器代码

将提供的草图复制粘贴到Arduino IDE中并找到“int d = 18;”行并将“18”更改为 坦克的深度,单位为厘米。

//Coded by MATHEW VARGHESE

//Note that the numbering of arduino pins are different from microcontroller pinout

int d = 18; //Enter depth of your tank here in centimeters

int trig = 11; // Attach Trig of ultrasonic sensor to pin 11

int echo = 10; // Attach Echo of ultrasonic sensor to pin 10

int pin1 = 2;//Highest level

int pin2 = 3;

int pin3 = 4;

int pin4 = 5;

int pin5 = 6;

int pin6 = 7;//Lowest evel

void setup() {

pinMode (pin1, OUTPUT);// Set pins to output for controlling I/O

pinMode (pin2, OUTPUT);

pinMode (pin3, OUTPUT);

pinMode (pin4, OUTPUT);

pinMode (pin5, OUTPUT);

pinMode (pin6, OUTPUT);

}

void loop()

{ digitalWrite(pin1, LOW);//Resetting the LEDs to off state

digitalWrite(pin2, LOW);

digitalWrite(pin3, LOW);

digitalWrite(pin4, LOW);

digitalWrite(pin5, LOW);

digitalWrite(pin5, LOW);

// Establish variables for duration of the ping,

// and the distance result in inches and centimeters:

long duration, in, cm; //‘in’ is inches and ‘cm’ is centimeter

// The PING is triggered by a HIGH pulse of 2 or more microseconds.

// Give a short LOW pulse beforehand to ensure a clean HIGH pulse:

pinMode(trig, OUTPUT);

digitalWrite(trig, LOW);

delayMicroseconds(2);

digitalWrite(trig, HIGH);

delayMicroseconds(5);

digitalWrite(trig, LOW);

// The same pin is used to read the signal from the PING: a HIGH

// pulse whose duration is the time (in microseconds) from the sending

// of the ping to the reception of its echo off of an object.

pinMode(echo, INPUT);

duration = pulseIn(echo, HIGH);

// Convert the time into a distance

in = microsecondsToInches(duration);

cm = microsecondsToCentimeters(duration);

delay(100);// To save battery,remove if felt inconvenient

if (in 《 6 * d / 7)// Else is included to light only one led at a level and thus save battery charge

digitalWrite(pin1, HIGH);

else if (in 《 5 * d / 6)

digitalWrite(pin2, HIGH);

else if (in 《 4 * d / 6)

digitalWrite(pin3, HIGH);

else if (in 《 3 * d / 6)

digitalWrite(pin4, HIGH);

else if (in 《 2 * d / 6)

digitalWrite(pin5, HIGH);

else if (in 《 1 * d / 6)

digitalWrite(pin5, HIGH);

}

long microsecondsToInches(long microseconds)

{

// According to Parallax‘s datasheet for the PING, there are

// 73.746 microseconds per inch (i.e. sound travels at 1130 feet per

// second)。 This gives the distance travelled by the ping, outbound

// and return, so we divide by 2 to get the distance of the obstacle.

// See: http://www.parallax.com/dl/docs/prod/acc/28015-PI.。.

return microseconds / 74 / 2;

}

long microsecondsToCentimeters(long microseconds)

{

// The speed of sound is 340 m/s or 29 microseconds per centimeter.

// The ping travels out and back, so to find the distance of the

// object we take half of the distance travelled.

return microseconds / 29 / 2;

}

建立连接

按照附带的Fritzing图表在PCB或面包板上填充电路。这是在运行Arduino的面包板上的ATMEga328。您可以按照Mayoogh Girish的教程在面包板上使用ATMega328制作您自己的Arduino板。如果您使用的是Arduino板,您可以按如下方式连接LED和超声波传感器。

上传代码

将Arduino水位指示器的代码直接刻录到Arduino板或ATMega328P微控制器上。

将超声波传感器连接到水箱上

固定Ping传感器,使其直接面向水箱中的水。带 指示LED的主控板可以在任何舒适的位置固定在家中。任何多芯 电缆(以太网电缆)都可用于连接Ping传感器和 电路的其余部分。请记住,不要增加组件之间的长度 超过20mts。

现在只需连接电池,您的非接触式Arduinowater水平指示器即可使用。

声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉
  • 指示器
    +关注

    关注

    0

    文章

    238

    浏览量

    37936
  • Arduino
    +关注

    关注

    184

    文章

    6427

    浏览量

    184826
收藏 人收藏

    评论

    相关推荐

    水位指示器电路图分享

    水位指示器是一种用于测量和显示容器内水位高度的装置。它广泛应用于各种场合,如工业生产、电力系统、水处理工程、农业灌溉等领域。
    的头像 发表于 02-20 15:25 1062次阅读
    <b class='flag-5'>水位</b><b class='flag-5'>指示器</b>电路图分享

    水位指示器电路图分享

    水位指示器是一种用于检测和指示水位的设备。它通常采用简单的机制来工作,如利用静压力原理将水位信号转换为电信号输出到控制仪表,以对被测介质的液
    的头像 发表于 02-12 09:29 1310次阅读
    <b class='flag-5'>水位</b><b class='flag-5'>指示器</b>电路图分享

    水位指示器电路图分享

    水位指示器是一种用于检测和指示水位的设备。它通常采用简单的机制来工作,如利用静压力原理将水位信号转换为电信号输出到控制仪表,以对被测介质的液
    的头像 发表于 02-12 09:20 589次阅读
    <b class='flag-5'>水位</b><b class='flag-5'>指示器</b>电路图分享

    电池电量指示器电路图分享

    电池电量指示器是一种装置,也被称为电眼,用于指示蓄电池的电量或充电程度。当电量指示器显示绿色时,表示电瓶电量充足,电瓶是完好的;当电量指示器显示黑色时,表示电瓶电量不足需要充电了;当电
    的头像 发表于 02-07 18:18 1673次阅读
    电池电量<b class='flag-5'>指示器</b>电路图分享

    对称电源平衡指示器电路原理图

    电源平衡指示器显示对称电源是否真正对称。利用 LM339N 四路比较器的两个比较器对,我们可以制作这样的指示器。一对驱动红色警告 LED3,另一对驱动黄色负极 (-) 和正极 (+)。
    的头像 发表于 12-05 17:22 389次阅读
    对称电源平衡<b class='flag-5'>指示器</b>电路原理图

    怎样用32单片机测电压?

    怎样用32单片机测电压
    发表于 10-31 07:09

    基于ULN2004的水位指示电路

    本ULN2004电子工程电路图设计是一个非常简单的水位指示电路工程。这种ULN2004水位指示器电路非常简单,需要很少的外部电子部件。
    的头像 发表于 10-15 10:51 1399次阅读
    基于ULN2004的<b class='flag-5'>水位</b><b class='flag-5'>指示</b>电路

    24v电量指示器

    指示器
    学习电子知识
    发布于 :2023年07月17日 20:21:39

    如何使用LM339N制作对称电源平衡指示器

    电源的平衡指示器显示对称电源是否真的对称。使用LM339N四通道比较器的两个比较器对,我们可以制作这样的指示器。一对驱动红色警告 LED3,另一对驱动黄色负极 (-) 和正极 (+)。该电路的电源
    的头像 发表于 07-15 17:11 779次阅读
    如何使用LM339N<b class='flag-5'>制作</b>对称电源平衡<b class='flag-5'>指示器</b>?

    分享一个水位指示器电路

    在他们使用高架水箱的地方,浪费水确实是一个问题。在这些地方,监测水位确实是一项艰巨的任务,还可能导致水和电力的浪费。上面的电路显示了一个简单的水位指示器系统,该系统基于Tranistors和LED
    的头像 发表于 07-02 09:47 569次阅读
    分享一个<b class='flag-5'>水位</b><b class='flag-5'>指示器</b>电路

    基于Arduino和超声波传感器构建一个简单的油箱液位指示器电路

    在这篇文章中,我们将学习如何使用 Arduino 和超声波传感器构建一个简单的油箱液位指示器电路。
    的头像 发表于 06-27 18:14 804次阅读
    基于<b class='flag-5'>Arduino</b>和超声波传感器构建一个简单的油箱液位<b class='flag-5'>指示器</b>电路

    使用运算放大器和传感器来制作一个简单的指示器

    湿度是空气中以气态形式存在的水含量的测量值。它应用于天气预报,空调,工业空间,通风等。您可能已经看到许多使用微控制器进行测量和指示的测量系统。在本电路中,我们将仅使用运算放大器和传感器来制作一个简单的指示器,该
    的头像 发表于 06-18 11:20 475次阅读
    使用运算放大器和传感器来<b class='flag-5'>制作</b>一个简单的<b class='flag-5'>指示器</b>

    使用两个晶体管制作简单的可听见水位指示器电路

    可能只需要两个晶体管就可以制作这个简单的可听见水位指示器电路。当指示的探头与水接触时,电流会流向 BC547 的底座并触发其打开。这反过来又会打开 PNP 2N2907。
    的头像 发表于 06-10 17:49 428次阅读
    使用两个晶体管<b class='flag-5'>制作</b>简单的可听见<b class='flag-5'>水位</b><b class='flag-5'>指示器</b>电路

    监视线路电压的指示器要用什么硬件搭建?

    请问我有这样一种应用,要用什么元件实现? 在4~20毫安模拟信号回路上经常因一些元器件开路、短路等导致信号中断,引起设备动作等。现要在线路上做一个线路电压指示器(暂用二极管LED指示),意思是当线路
    发表于 06-06 12:36

    分享一个液位报警指示器电路

    该电路基本上是一个液位报警指示器,用于提醒视障人士注意杯子、玻璃或碗等容器中的液位。
    的头像 发表于 06-04 15:13 670次阅读
    分享一个液位报警<b class='flag-5'>指示器</b>电路