Pages: [1]   Go Down
Author Topic: piezo and external interrupt  (Read 851 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 23
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi there, i want to use a piezo to wakeup an arduino when someone knock a door.. The documentation says that it's only possible catching LOW states on digital pin.. What is the circuit i need to add to have 0V when it detects the knock and 5V when there is no knock? btw, sorry about my low english skills...
Thank you very much and have a nice weekend!
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 23
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

after reading ATmega 1280 datasheet i see that using pin change interrupts i can do what i need by software.. i share here the piece of code i wrote (part of it is the ArduinoSleepCode example), if someone need it.. i have tested it a little and it seems to work ok... but if someone can explain me what are the components i need to do what i asked before(0V when it detects the knock and 5V when there is no knock), i will be very pleased...

#include <avr/interrupt.h>
int wakePin = 53;
void setup()
{
    pinMode(wakePin, INPUT);
   
    Serial.begin(9600);     // Debugging only
    Serial.println("setup");

     miattachinterrupt();

}
void miattachinterrupt()
{
  PCICR=0;
  PCMSK0=0;
  PCMSK1=0;
  PCMSK2=0;
 
  PCMSK0 |= (1 <<PCINT0);
  PCICR |= (1<<PCIE0);
 
  sei();
 
}
void midetachinterrupt()
{
  PCICR=0;
  PCMSK0=0;
  PCMSK1=0;
  PCMSK2=0;
 
  cli();

}
ISR(PCINT0_vect) //i dont do nothing
{

}
void sleepNow()         
{
   set_sleep_mode(SLEEP_MODE_PWR_DOWN);
    sleep_enable();         
    miattachinterrupt();
    sleep_mode();           
    sleep_disable();         
    midetachinterrupt();
}
int count = 0;
void loop()
{
  count++;
  Serial.print(",Awake for ");
  Serial.println(count);

  delay(100);
  if (count >= 50) {
      Serial.println("Timer: Entering Sleep mode");
      delay(100);
      count = 0;
      sleepNow();     // sleep function called here
  }
}

}
Logged

Pages: [1]   Go Up
Jump to: