hi all.
im very new to this. Pretty good DIY'er. The hardware part of this kind of thing shouldn't be a problem for me but the code stuff will take some practice. I think i have about 4 books to read before i get a decent handle on it.
The project im working on is the whole reason i got the arduino. The concept is simple and the fact that i could find code already mostly done for me made it that much better.
Basically, Vibration sensor momentarily lights led. (Bullet hits steal--> led lights on impact--> led goes out.)
I used the example code for the Knock sensor using the piezo speaker however im using a MEAS vibration sensor and multiple led's instead.
My problem is def. in the code. It works as it should for the most part but for what ever reason the led stays lit from time to time. I need it to always go out after the sensor quits reading vibration.
this is the code im using
// these constants won't change:
const int ledPin = 13;// led connected to digital pin 13
const int knockSensor = A0; // the piezo is connected to analog pin 0
const int threshold = 100; // threshold value to decide when the detected sound is a knock or not
// these variables will change:
int sensorReading = 10 ; // 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
Serial.begin(9600); // use the serial port
}
void loop() {
// read the sensor and store it in the variable sensorReading:
sensorReading = analogRead(knockSensor);
// if the sensor reading is greater than the threshold:
if (sensorReading >= 10) {
// toggle the status of the ledPin:
ledState = !ledState;
// update the LED pin itself:
digitalWrite(ledPin, ledState);
// send the string "Knock!" back to the computer, followed by newline
Serial.println("HIT!");
}
delay(10); // delay to avoid overloading the serial port buffer
}
I have tried changing some of the variables but didnt really notice a difference.
Dont really care about the serial print stuff. wont be using that right now.
any help would be appreciated
thank you