Pages: [1]   Go Down
Author Topic: Help a newb out  (Read 481 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: 309
Posts: 26509
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." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Sr. Member
****
Karma: 1
Posts: 486
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!!:
[url]http://ar

UK
Offline Offline
Shannon Member
****
Karma: 223
Posts: 12630
-
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

I only provide help via the forum - please do not contact me for private consultancy.

Offline Offline
Sr. Member
****
Karma: 1
Posts: 486
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!!:
[url]http://ar

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
Jump to: