Go Down

Topic: Help a newb out (Read 500 times) previous topic - next topic

connington

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!

AWOL

Is there anything useful over at the Playground_
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

sirbow2

Code: [Select]
#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 :) i know what you mean by example. needed the same thing when i was more of a newb.
http://dduino.blogspot.com all my Arduino/electronic projects!!!

{NEW} Getting Started, Learning, Reference + FAQ PDF!!:
[url]http://ar

PeterH


how to wire the piezo to the arduino


How do you ensure that the piezo output voltage never exceeds 5V?
I only provide help via the forum - please do not contact me for private consultancy.

sirbow2

the megaohm resistor...
http://dduino.blogspot.com all my Arduino/electronic projects!!!

{NEW} Getting Started, Learning, Reference + FAQ PDF!!:
[url]http://ar

connington

Holy crap, Thanks so much!!

Go Up