Go Down

Topic: arduino + piezo sensor (once again ;) (Read 706 times) previous topic - next topic

slash

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

Code: [Select]

#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
}

slash

#1
Dec 08, 2010, 03:15 pm Last Edit: Dec 08, 2010, 03:17 pm by slash Reason: 1
a picture of our setting - we tried to combine ten 10kOhm resistors in series to replace one 1mOhm resistor.


Groove

Ten 10kohm resistors in series is 100kohm, not 1 milliohm.
That's a huge difference.
Per Arduino ad Astra

slash

#3
Dec 08, 2010, 03:22 pm Last Edit: Dec 08, 2010, 03:24 pm by slash Reason: 1
ahhhh. nooooo. thanks a lot groove! so we need to get a 1mOhm resistor. or is there a possibility to get more ot of ten 10kOhm resistors ;) ?

Bobnova

If you need a megaohm resistor you'll need 100 of the 10kOhm flavor.  I'd hit radioshack or somesuch and pick up the proper resistor, personally.

Go Up