电子发烧友App

硬声App

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

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

3天内不再提示
电子发烧友网>电子资料下载>电子资料>Arduino洗手定时器

Arduino洗手定时器

2023-06-29 | zip | 0.04 MB | 次下载 | 免费

资料介绍

描述

背景

我创建这个项目只是为了确保我的家人受到保护并且他们洗手的时间适当。它使用超声波传感器检测手,并使用 16x2 液晶显示器显示剩余时间。整个项目基于 arduino pro micro。

它是如何工作的?

该项目使用 HC-SR04 超声波传感器来检测人的手部。传感器的工作原理是发出 40kHz 的声波,并等待查看是否有任何声波反弹回来。如果任何声波确实反弹回来,传感器就会向 Arduino 发送一个信号(见下图)。

pYYBAGN3LmaAQf1BAABfPVtJ_kw94.jpeg
HC-SR04 超声波传感器的工作原理
 

Arduino 从超声波传感器获取输入,然后计算物体的距离。

 

它是如何结合在一起的?

有关更详细的视图,请参见示意图。

超声波传感器引脚:

VCC:5V

触发:引脚 D9

回声:引脚 D10

接地:接地

LCD 引脚排列:

VSS:接地

VDD:5V

VO:带 1k 电阻的 Gnd(你真的应该在这里使用电位器来更好地调节对比度,这个电阻只是为了更紧凑)

RS:引脚 D13

RW:接地

E:引脚 D12

(跳过 D0-D3)

D4:引脚 D5

D5:引脚 D4

D6:引脚 D3

D7:引脚 D2

A:D7脚(背光电源开关)

K:接地

代码如何工作

这包括所有需要的库

#include 
#include "pitches.h"

这设置了所有的变量和音调数组

#define screenPower 7 //define screen power pin (to automatically turn lcd backlight on and off)
// defines HC-SR04 pin numbers
const int trigPin = 9;
const int echoPin = 10;
//variables for HC-SR04
long duration; 
int distance;
// Create an LCD object. Parameters: (RS, E, D4, D5, D6, D7):
LiquidCrystal lcd = LiquidCrystal(13, 12, 5, 4, 3, 2);
int timeLeft = 20; //variable for displaying time left
int speakerPin = 11;
int toneDuration = 100;
int tickDuration = 25;
//array of notes for done tone
int doneTone[] = {
 NOTE_C4, NOTE_D4, NOTE_E4, NOTE_F4, NOTE_G4, NOTE_A4, NOTE_B4, NOTE_C5
};
//note of the ticking sound
int tick[] = {
 NOTE_C5
};

这将设置 LCD 并启动超声波传感器

void setup() {
 pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
 pinMode(echoPin, INPUT); // Sets the echoPin as an Input
 Serial.begin(9600); // Starts the serial communication
 //Setup LCD rows and columns:
 pinMode(screenPower, OUTPUT);
 digitalWrite(screenPower, HIGH);
 delay(200);
 lcd.begin(16, 2);
 lcd.setCursor(0, 0);
 lcd.print("Hand Wash Timer");
 lcd.setCursor(0, 1);
 lcd.print("By:Danny Pashkow");
 delay(3000);
 lcd.clear();
 lcd.setCursor(0, 0);
 digitalWrite(screenPower, LOW);
}

这是每秒循环以检查对象的内容

void loop() {
 // Clears the trigPin
 digitalWrite(trigPin, LOW);
 delayMicroseconds(2);
 // Sets the trigPin on HIGH state for 10 micro seconds
 digitalWrite(trigPin, HIGH);
 delayMicroseconds(10);
 digitalWrite(trigPin, LOW);
 // Reads the echoPin, returns the sound wave travel time in microseconds
 duration = pulseIn(echoPin, HIGH);
 // Calculating the distance
 distance = duration * 0.034 / 2;
 // Prints the distance on the Serial Monitor
 Serial.print("Distance: ");
 Serial.println(distance);
 if (distance < 10) {
   Serial.println("Hand detected");
   isHand = true;
 }
 if (isHand == true) {
   handDetected();
 }
 if (timeLeft < 0) {
   noTimeLeft();
 }
}

此代码在 20 秒结束时运行

void noTimeLeft() {
 lcd.clear();
 lcd.setCursor(6, 0);
 lcd.print("Done!");
 for (int thisNote = 0; thisNote < 8; thisNote++) {
   tone(11, doneTone[thisNote], toneDuration);
   delay(100);
 }
 delay(5000);
 lcd.clear();
 digitalWrite(screenPower, LOW);
 timeLeft = 20;
 isHand = false;
 lcd.setCursor(0, 0);
}

当超声波传感器检测到一个物体时,这段代码就会运行

void handDetected() {
 digitalWrite(screenPower, HIGH);
 lcd.clear();
 lcd.setCursor(0, 0);
 lcd.print("Time Remaining: ");
 lcd.setCursor(0, 1);
 lcd.print(timeLeft);
 lcd.print(" seconds");
 timeLeft -= 1;
 for (int thisTick = 0; thisTick < 3; thisTick++) {
   tone(speakerPin, tick[thisTick], tickDuration);
 }
 delay(1000);
}

STL 文件

为了完全完成这个项目并在防水方面有所帮助,一台 3d 打印机(或从 Protolabs 等网站订购)。这弄乱了所有的接线,因此也弄乱了代码,所以我更新了 Nano 上面的代码和原理图。如果您仍在使用 Pro Micro,这里有一个指南


下载该资料的人也在下载 下载该资料的人还在阅读
更多 >

评论

查看更多

下载排行

本周

  1. 1储能电源市场分析
  2. 7.99 MB  |  8次下载  |  免费
  3. 2储能电源市场分析报告
  4. 2.61 MB   |  6次下载  |  免费
  5. 3磁环电感定制时应该注意什么
  6. 0.32 MB   |  2次下载  |  免费
  7. 4labview文档教程资料(一)
  8. 24.29 MB   |  2次下载  |  免费
  9. 5轻触三功能+常按 SOS 功能手筒LED驱动ICSD3302数据手册
  10. 0.60 MB   |  1次下载  |  2 积分
  11. 6英集芯IP5353 QFN32 规格书pdf
  12. 2.70 MB  |  1次下载  |  免费
  13. 7NCV78763R1DAGEVB子板数据手册
  14. 533.41 KB   |  次下载  |  免费
  15. 8500mA,高效 MicroSiP™ 降压转换器TPS8269xSIP数据表
  16. 918.92KB   |  次下载  |  免费

本月

  1. 1ES9038PRO解码芯片的电路原理图介绍
  2. 0.25 MB   |  35次下载  |  5 积分
  3. 2STM32国内外发展现状
  4. 1.15 MB   |  13次下载  |  免费
  5. 3传感芯片选型指南
  6. 3.60 MB   |  11次下载  |  免费
  7. 4ATmega8芯片中文手册
  8. 2.45 MB   |  8次下载  |  1 积分
  9. 5储能电源市场分析
  10. 7.99 MB  |  8次下载  |  免费
  11. 6TDK电容器产品指南
  12. 11.88 MB   |  7次下载  |  1 积分
  13. 72A多电池高效开关充电器AN_SY6912A中文资料规格书
  14. 1.43 MB   |  7次下载  |  免费
  15. 8储能电源市场分析报告
  16. 2.61 MB   |  6次下载  |  免费

总榜

  1. 1matlab软件下载入口
  2. 未知  |  935086次下载  |  免费
  3. 2开源硬件-PMP21529.1-4 开关降压/升压双向直流/直流转换器 PCB layout 设计
  4. 1.48MB  |  420050次下载  |  免费
  5. 3Altium DXP2002下载入口
  6. 未知  |  233068次下载  |  免费
  7. 4电路仿真软件multisim 10.0免费下载
  8. 340992  |  191317次下载  |  免费
  9. 5十天学会AVR单片机与C语言视频教程 下载
  10. 158M  |  183316次下载  |  免费
  11. 6labview8.5下载
  12. 未知  |  81567次下载  |  免费
  13. 7Keil工具MDK-Arm免费下载
  14. 0.02 MB  |  73788次下载  |  免费
  15. 8NI LabVIEW中实现3D视觉的工具和技术
  16. 未知  |  70088次下载  |  免费