There are few sensors that I've been considering to use in my installation. I'll test on the sensitivity and usability on different sensor. The sensor that I've been tested is knock sensor. I started with the tutorial in Arduino website. This is the basic arrangement of the knock sensor:
This is the code I've used to test on the knock sensor:
================================================================================
// 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 = 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
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 >= threshold) {
// 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("Knock!");
}
delay(100); // delay to avoid overloading the serial port buffer
}
================================================================================
I've followed all the instruction and arrangement as stated in the tutorial but I failed to make the knock sensor function. I've tested it over and over again but it react nothing. I thought that I might have burnt the knock sensor but it is quite impossible because the circuit is very simple and all installed as the image in tutorial. So I decided to try on the knock sensor which borrowed from my friend, Stefan. The experiment still show no result. I've tried with the different code from internet and there is still no improvement. So I just leave with the knock sensor first and test with other sensor. This experiment: FAILED!
No comments:
Post a Comment