Arduino Program Problems

2 posts in this topic

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){
  val = digitalRead(light_1);
  if ((val==HIGH) && (old_val==LOW)){
    state = 1 - state;
  old_val = val;
  if (state == 1) {
  } else {

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


Share this post

Link to post
Share on other sites

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.


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now