Pages: [1]   Go Down
Author Topic: Pin will not go LOW after tone  (Read 695 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am getting a audible pulsing 1.2v - 1.6v and cannot figure out why the piezo pin will not go LOW.

Running a Piezo actuated by a PID.


// Motion Buzzer
#define PIEZO 3 // pin 3 PEZO output
#define MOTION 4 // pin 4 PIR input
void setup()
{
 pinMode(PIEZO, OUTPUT);
 pinMode(MOTION, INPUT);
}
void loop(){
  int val = digitalRead(MOTION); // read input value
  if (val == HIGH){   // check if the input is HIGH
  NOISE();}
  else {
    SENSOR();} 
}

void SENSOR(){ // This will be used later
  digitalWrite (PIEZO, LOW);
 
}
void NOISE(){
  for (int x=0; x < 10; x++){
    tone  (PIEZO, 19500);
    delay(2);
    tone(PIEZO, 19000);
    delay(2);
    tone(PIEZO, 18500);
    delay(2);
    tone(PIEZO, 18000);
    delay(2);
    tone(PIEZO, 17500);
    delay(2);
    tone(PIEZO, 17000);
    delay(2);
    tone(PIEZO, 16500);
    delay(2);
    tone(PIEZO, 16000);
    delay(2);
    tone(PIEZO, 15500);
    delay(2);
    tone(PIEZO, 15000);
    delay(2);
    tone(PIEZO, 14500);
    delay(2);
    tone(PIEZO, 14000);
    delay(2);
    tone(PIEZO, 13500);
    delay(2);
    tone(PIEZO, 13000);
    delay(2);
    tone(PIEZO, 12500);
    delay(2);
    tone(PIEZO, 12000);
    delay(2);
    tone(PIEZO, 11500);
    delay(2);
    tone(PIEZO, 11000);
    delay(2);
    tone(PIEZO, 10500);
    delay(2);
    tone(PIEZO, 10000);
    delay(2);
    tone(PIEZO, 9500);
    delay(2);
    tone(PIEZO, 9000);
    delay(2);
    tone(PIEZO, 8500);
    delay(2);
    tone(PIEZO, 8000);
    delay(2);
    tone(PIEZO, 7500);
    delay(2);
    tone(PIEZO, 7000);
    delay(2);
    tone(PIEZO, 6500);
    delay(2);
    tone(PIEZO, 6000);
    delay(2);
    tone(PIEZO, 5500);
    delay(2);
    tone(PIEZO, 5000);
    delay(2);
    tone(PIEZO, 4500);
    delay(2);
    tone(PIEZO, 4000);
    delay(2);
    tone(PIEZO, 3500);
    delay(2);
    tone(PIEZO, 3000);
    delay(2);
    tone(PIEZO, 2500);
    delay(2);
    tone(PIEZO, 2000);
    delay(2);
    tone(PIEZO, 1500);
    delay(2);
    tone(PIEZO, 1000);
    delay(2);
    tone(PIEZO, 500);
    delay(4);
    tone(PIEZO, 250);
    delay(4);
    tone(PIEZO, 175);
    delay(4);
    tone(PIEZO, 100);
    delay(4);
    tone(PIEZO, 50);
    delay(4);
    tone(PIEZO, 100);
    delay(4);
    tone(PIEZO, 175);
    delay(4);
    tone(PIEZO, 250);
    delay(4);
    tone(PIEZO, 500);
    delay(4);
    tone(PIEZO, 1000);
    delay(2);
    tone(PIEZO, 1500);
    delay(2);
    tone(PIEZO, 2000);
    delay(2);
    tone(PIEZO, 2500);
    delay(2);
    tone(PIEZO, 3000);
    delay(2);
    tone(PIEZO, 3500);
    delay(2);
    tone(PIEZO, 4000);
    delay(2);
    tone(PIEZO, 4500);
    delay(2);
    tone(PIEZO, 5000);
    delay(2);
    tone(PIEZO, 5500);
    delay(2);
    tone(PIEZO, 6000);
    delay(2);
    tone(PIEZO, 6500);
    delay(2);
    tone(PIEZO, 7000);
    delay(2);
    tone(PIEZO, 7500);
    delay(2);
    tone(PIEZO, 8000);
    delay(2);
    tone(PIEZO, 8500);
    delay(2);
    tone(PIEZO, 9000);
    delay(2);
    tone(PIEZO, 9500);
    delay(2);
    tone(PIEZO, 10000);
    delay(2);
    tone(PIEZO, 10500);
    delay(2);
    tone(PIEZO, 11000);
    delay(2);
    tone(PIEZO, 11500);
    delay(2);
    tone(PIEZO, 12000);
    delay(2);
    tone(PIEZO, 12500);
    delay(2);
    tone(PIEZO, 13000);
    delay(2);
    tone(PIEZO, 13500);
    delay(2);
    tone(PIEZO, 14000);
    delay(2);
    tone(PIEZO, 14500);
    delay(2);
    tone(PIEZO, 15000);
    delay(2);
    tone(PIEZO, 15500);
    delay(2);
    tone(PIEZO, 16000);
    delay(2);
    tone(PIEZO, 16500);
    delay(2);
    tone(PIEZO, 17000);
    delay(2);
    tone(PIEZO, 17500);
    delay(2);
    tone(PIEZO, 18000);
    delay(2);
    tone(PIEZO, 18500);
    delay(2);
    tone(PIEZO, 19000);
    delay(2);
    tone(PIEZO, 19500);
    delay(2);
    tone(PIEZO, 20000);
    delay(2);}
     
}
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 212
Posts: 13531
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Please use code tags...
Please press CTRL-T before copying code for the forum

a bit different and a lot shorter
Code:
void NOISE()
{
  for (int x=0; x < 10; x++)
  {
    for (int freq = 19500; freq > 100; freq = freq /(sqrt(2) / 12))
    {
       tone  (PIEZO, freq);
       delay(2);
    }
    for (int freq = 100; freq < 19500;  freq = freq * (sqrt(2) / 12))
    {
       tone  (PIEZO, freq);
       delay(2);
    }
  }
}

Quote
cannot figure out why the piezo pin will not go LOW.
maybe you should add a pull-down resistor.
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Global Moderator
Boston area, metrowest
Online Online
Brattain Member
*****
Karma: 524
Posts: 26427
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Isn't there a notone() command too?
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Pages: [1]   Go Up
Jump to: