Jump to content


Photo
- - - - -

Arduino Program Problems

arduino program arduino debug

  • Please log in to reply
1 reply to this topic

#1 Ptolemy

Ptolemy

    Will I break 10 posts?

  • Members
  • 4 posts
  • Country:
  • Gender:Male

Posted 19 March 2013 - 09:59 AM

Hi all. I am trying to make an Arduino program to make a noise when my cat jumps onto the counter (a regular problem).  I got the code for the PIR motion sensor I have (parallax #910-28027).  I tried to get an LED to light first so that I could test my code. It didn't work. Here is the code:

 

 

const int motion_1 = 2;
const int light_1 = 13;
const int LED = 10;
int val = 0;
int old_val = 0;
int state = 0;
void setup(){
  pinMode (motion_1,INPUT);
  pinMode (light_1, OUTPUT);
}
 
void loop (){
  digitalWrite (light_1,LOW);
  delay(1000); //this delay is to let the sensor settle down before taking a reading
  int sensor_1 = digitalRead(motion_1);\
  if (sensor_1 == HIGH){
    digitalWrite(light_1,HIGH);
    delay(500);
    digitalWrite(light_1,LOW);
    delay(500);
   
  }
 
  val = digitalRead(light_1);
  if ((val==HIGH) && (old_val==LOW)){
    state = 1 - state;
    delay(10);
  }
  old_val = val;
  if (state == 1) {
    digitalWrite(LED,HIGH);
  } else {
    digitalWrite(LED,LOW);
  }
}
 

Can you give me a bit of help? Thanks in advanced.



#2 systems_glitch

systems_glitch

    Dangerous free thinker

  • Moderating Team
  • 1,642 posts
  • Gender:Male

Posted 19 March 2013 - 10:16 AM

The Parallax PIR sensor I have is a few years old, but just has a "detected something" output. You should be able to drive whatever makes noise through a transistor driver directly from that output. IIRC it's TTL compatible.






BinRev is hosted by the great people at Lunarpages!