The other is just a tiny speaker that I pulled from an old digital camera. I'd be surprised if it wasn't a piezo, as the kit it came with allegedly came with a piezo and it's the only thing that fits the description. The small black one has a "+" on one side, and "HXD®" on the other which I'm assuming is a brand name. I'm attaching a (somewhat blurry) photo of my piezos. I can even get 16 force sensors to work fine through my Analog multiplexer. I even tried with no resistor and was extra careful not to overload the input. I've also tried all possible setups too(there aren't that many) and tried different analog inputs also. I've tried several different resistors and still nothing. I've got my current setup on a breadboard, so the resistor stays in place but shouldn't be doing anything because it completes no circuit(?). When I disconnect the piezo, I'm only pulling out the jumper that goes from + on the piezo to analog input 0. The speaker had a red and black wire coming out of it which I've verified as standard +. The piezo from the kit is clearly labeled with a "+" on one side along with a long leg. One came with an assortment of sensors and stuff that came with arduino from makershed, and the other is a small salvaged speaker from an old digital camera. I don't have data sheets for the piezos that I have. send the string "Knock!" back to the computer, followed by newlineĭelay(100) // delay to avoid overloading the serial port buffer if the sensor reading is greater than the threshold: read the sensor and store it in the variable sensorReading: Serial.begin(9600) // use the serial port PinMode(ledPin, OUTPUT) // declare the ledPin as as OUTPUT Int ledState = LOW // variable used to store the last LED status, to toggle the light Int sensorReading = 0 // variable to store the value read from the sensor pin * 1-megohm resistor attached from analog in 0 to groundĬonst int ledPin = 13 // led connected to digital pin 13Ĭonst int knockSensor = 5 // the piezo is connected to analog pin 0Ĭonst int threshold = 100 // threshold value to decide when the detected sound is a knock or not * - connection of the piezo attached to ground * + connection of the piezo attached to analog in 0 "knock" to the serial port, and toggles the LED on pin 13. If the result is greater than the threshold, it writes It reads an analog pin and compares the result to a set threshold. This sketch reads a piezo element to detect a knocking sound. I'll place the code below for reference: /* Knock Sensor Guess not.Īny idea what could be wrong and/or how to fix it? And I am using the recommended 1 mega ohm resistor in parallel with the ground.Īnd that's about it. Only when I disconnect the wire to Analog 0 do I begin to get random values in the Serial.Ī few notes: Yes, I do have the piezo element oriented correctly in terms of +/- (it works fine in playing simple tunes for other sketches). However, it always reads "0" despite any amount of knocking I do. Anyway, I'm using the code provided and I've added the line: Serial.println(analogRead(knockSensor)) which should print out the sensor value regardless of whether or not it's hit the threshold. I'm fairly new to arduino, but I feel like this should not be an issue whatsoever. (had to break up the urls because it wouldn't let me post them on my first post) Alternate wiring diagrams for breadboard and info here: fritzing org/projects/knock/. I'm following tutorial and code found at arduino cc/en/Tutorial/Knock which is also included with the arduino software. I'm trying to make a very simple knock sensor out of a piezo and it just wont give me anything.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |