Loading...
Pages: [1]   Go Down
Author Topic: Help a newb out  (Read 210 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 138
Posts: 19067
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Is there anything useful over at the Playground_
Logged

Pete, it's a fool looks for logic in the chambers of the human heart.

Offline Offline
Sr. Member
****
Karma: 1
Posts: 478
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
#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 smiley i know what you mean by example. needed the same thing when i was more of a newb.
Logged

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

{NEW} Getting Started, Learning, Reference + FAQ PDF!!:
http://arduino.cc/forum/index.php/topic,79026

UK
Offline Offline
Tesla Member
***
Karma: 89
Posts: 6406
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

how to wire the piezo to the arduino

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

Offline Offline
Sr. Member
****
Karma: 1
Posts: 478
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

the megaohm resistor...
Logged

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

{NEW} Getting Started, Learning, Reference + FAQ PDF!!:
http://arduino.cc/forum/index.php/topic,79026

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Holy crap, Thanks so much!!
Logged

Pages: [1]   Go Up
Print
 
Jump to: