Help a newb out

I'm very new to arduino, and I would like a little help with coding techniques:
I'm trying to build a conceptual circuit that will light an LED when a piezo speaker reads a certain amount of noise. How would I set up the variables, like the pins that the LED and speaker are hooked up to? Could someone please write a piece of code that would accomplish this? I'd love some help understanding the way arduino works better. Thanks!

Is there anything useful over at the Playground_

#define piezoPin A5    // select the input pin -- analog 5
int ledPin = 13;   // select the pin for the speaker
int val = 0; //store value from piezo

void setup() {
  pinMode(ledPin, OUTPUT);  // declare the ledPin as an OUTPUT
  Serial.begin(9600);
}

void loop() {
  val = analogRead(piezoPin); //read value from piezo
 
  if (val > 500) //you need to find the value for this
  {
    digitalWrite(ledPin, HIGH);
    delay(100); //about how long the LED will stay on.
  }
  else
  {
    digitalWrite(ledPin, LOW); //turn off if value isn't high enough
  }
  Serial.println(val); //debug
}

how to wire the piezo to the arduino

basic, but should work :slight_smile: i know what you mean by example. needed the same thing when i was more of a newb.

sirbow2:
how to wire the piezo to the arduino

How do you ensure that the piezo output voltage never exceeds 5V?

the megaohm resistor...

Holy crap, Thanks so much!!