Invalid code for Piezo Vibration Sensor

edited November 2013 in Arduino

This is the code provided on "learningaboutelectronics.com" that utilizes a Piezo Vibration Sensor in conjunction with Arduino to detect vibrations that will in turn light up an LED. The link to the project is here: http://www.learningaboutelectronics.com/Articles/Vibration-detector-circuit.php.

I believe I have the circuitry connected correctly, but I had to solder the piezo sensor (which is supposed to be able to do that). Ignoring all the potential problems with the circuit, when I tried to run this code, I ran into two problems:

  1. There is an issue in the calibrate() block. for (int=0; i { is incomplete?
  2. When I change for (int=0; i { to for (int:0) the next error is "Cannot find anything named A0." What does this mean? Is it the code or is it me?

Code Below.

//defines the pin connections
int GroundPin= A0;
int sensePin= 1;
int LEDpin= 8;

//defines normal and threshold voltage levels
int normalReading= 0;
int threshold= 10;

//sets GroundPin and LEDPin as output pins, with GroundPin being set to LOW
void setup()
{
pinMode(GroundPin, OUTPUT);
digitalWrite(GroundPin, LOW);
pinMode(LEDPin, OUTPUT);
normalReading= calibrate(); }

//if the reading is higher than the threshold value, then the LED is turned on
void loop()
{
int reading= analogRead(sensePin);
if (reading > normalReading + threshold)
{
digitalWrite(LEDPin, HIGH);
}
}

//this function returns the average reading of the sensePin when no large vibration is detected
int calibrate()
{
int n= 100;
long total=0;
for (int i=0; i {
total= total + analogRead(sensePin);
delay(1);
}
return total/n;
}
Tagged:

Answers

  • The line

    for (int i=0; i {

    doesn't make sense, indeed, it looks like it is incomplete. See the for entry in the reference page.

    Note: this appear to be Arduino code, not Processing code...

Sign In or Register to comment.