hey guys,
we're trying to get the piezo sensor work correctly. we used the tutorial on the arduino website.
if we open the Serial Monitor, it looks like the value of the piezo sensor is counting down from 1000 to 0. if we hit it, it snaps to 400 for example and goes down slowly to 0 again.
can you give us a hint? would be great.
kind regards, lisa & tobi
#include <SoftwareServo.h>
int servoPin = A5; // the servos is connected to analog pin 5
int knockSensor = A0; // the piezo is connected to analog pin 0
int threshold = 700; // threshold value to decide when the detected sound is a knock or not
SoftwareServo servo1;
int ledPin = 13; // led connected to digital pin 13
// these variables will change:
int sensorReading = 0; // variable to store the value read from the sensor pin
int ledState = LOW; // variable used to store the last LED status, to toggle the light
void setup() {
pinMode(ledPin, OUTPUT); // declare the ledPin as as OUTPUT
pinMode(servoPin,OUTPUT);
servo1.attach(servoPin);
Serial.begin(9600); // use the serial port
Serial.print("los");
}
void loop() {
sensorReading = analogRead(knockSensor);
if (sensorReading >= threshold) {
digitalWrite(ledPin, HIGH);
Serial.println(sensorReading);
servo1.write(40);
} else {
servo1.write(0);
digitalWrite(ledPin, LOW);
}
SoftwareServo::refresh();
delay(100); // delay to avoid overloading the serial port buffer
}