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

Arduino Project 013 - Piezo Knock Sensor

RonWang4个月前 (08-13)电子编程63

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.donstudio.cn/?id=263

标签: Arduino

相关文章

Arduino Project 008 - RGB LED Mood Lamp

Arduino Project 008 - RGB LED Mood Lamp

In the last project, you learned how to adjust the brightness of an LED using the PWM capabilities o...

Arduino Project 022 - LED Dot Matrix Display - Pong Game

Arduino Project 022 - LED Dot Matrix Display - Pong Game

This project was hard going and a lot to take in. So, for Project 22 you are going to create a simpl...

Arduino Project 011 - Piezo Sounder Alarm

Arduino Project 011 - Piezo Sounder Alarm

Arduino project - sounder and sensors : Include project 11 Piezo Sounder Alarm ,Project piezo sounde...

Arduino Project 036 - DTH Temperature and Humid Sensor

Arduino Project 036 - DTH Temperature and Humid Sensor

The DHT11 Temperature and Humidity Sensor senses, measures and regularly reports the relative humidi...

Arduino Project 014 - Light Sensor

Arduino Project 014 - Light Sensor

This project introduces a new component known as a Light Dependent Resistor, or LDR. As the name imp...

Arduino Project 030B - MX1508 H-Driver Motor

Arduino Project 030B - MX1508 H-Driver Motor

MX1508 H-BridgeDual Motor DriverThe driver can drive up to two motors. The H-Bridge dual motor drive...

发表评论

访客

看不清,换一张

◎欢迎参与讨论,请在这里发表您的看法和观点。