We are about to switch to a new forum software. Until then we have removed the registration on this forum.
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:
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;
}
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...