当前位置:首页 > 科学研究 > 电子编程 > 正文内容

Arduino Project 013 - Piezo Knock Sensor

RonWang9个月前 (08-13)电子编程216

A piezo disc works when an electric current is passed over the ceramic material in the disc, causing it to change shape and hence make a sound (a click). The disc also works in reverse: when the disc is knocked or squeezed, the force on the material causes the generation of an electric current. You can read that current using the Arduino and you are going to do that now by making a Knock Sensor.

项目Project 13  Piezo Knock Sensor 压电振动传感器

/* Coding Ron Wang
   Aug.13rd 2024
   Autaba support for coding hardware
 */
// Project 13 - Piezo Knock Sensor
int ledPin = 9; // LED on Digital Pin 9
int piezoPin = 5; // Piezo on Analog Pin 5
int threshold = 120; // The sensor value to reach before activation
int sensorValue = 0; // A variable to store the value read from the sensor
float ledValue = 0; // The brightness of the LED
void setup() {
 pinMode(ledPin, OUTPUT); // Set the ledPin to an OUTPUT
 // Flash the LED twice to show the program has started
 digitalWrite(ledPin, HIGH); delay(150); digitalWrite(ledPin, LOW); delay(150);
 digitalWrite(ledPin, HIGH); delay(150); digitalWrite(ledPin, LOW); delay(150);
}
void loop() {
 sensorValue = analogRead(piezoPin); // Read the value from the sensor
 if (sensorValue >= threshold) { // If knock detected set brightness to max
 ledValue = 255;
 }
 analogWrite(ledPin, int(ledValue) ); // Write brightness value to LED
 ledValue = ledValue - 0.05; // Dim the LED slowly
 if (ledValue <= 0) { ledValue = 0;} // Make sure value does not go below zero
}

arduino Pieizo Knock Sensor Circuit

arduino Pieizo Knock Sensor Schematic

版权声明:本文为原创文章,版权归donstudio所有,欢迎分享本文,转载请保留出处!

本文链接:http://www.parentscn.com/?id=263

标签: Arduino

相关文章

C语言调试运行环境Pelles C的安装

C语言调试运行环境Pelles C的安装

C语言调试运行环境之TurboC一文介绍了在32位Windows系统下安装C语言运行环境之TubroC,但是由于TurobC只能在32位系统下运行,导致现在很多Windows10和Windows 11...

Arduino Project 042 - SD Card Information Basic

Arduino Project 042 - SD Card Information Basic

Arduino Programming Basic -- Reading and Writing to an SD CardProject 42A SD Card InformationArduino...

Arduino Project 007 - Pulsating Lamp

Arduino Project 007 - Pulsating Lamp

You are now going try a more advanced method of controlling LEDs. So far, you have simply turned the...

Arduino Programming Basic - Input and Outpput

Arduino Programming Basic - Input and Outpput

The pins on the Arduino can be configured as either inputs or outputs. This document explains the fu...

Arduino UNO Mp3音乐播放代码

Arduino UNO Mp3音乐播放代码

Arduino UNO Mp3音乐播放代码今天我们将使用Arduino UNO 和SD卡制作音乐播放器。这个播放器不需要添加多余的模块,只需要SD读卡器和Arduino UNO开发板就可以播放音频文件...

Arduino Project 002 - LED SOS Morse Code Singal

Arduino Project 002 - LED SOS Morse Code Singal

Arduino 电子编程--灯项目及控制,主要使用Arduino编程控制LED灯,实现基本控制Project 2 LED闪烁S.O.S信号。项目2 Project 2 S.O.S...