Beginner Arduino Question.

Discussion in 'Embedded Systems and Microcontrollers' started by mbohuntr, Nov 26, 2012.

  1. mbohuntr

    Thread Starter Active Member

    Apr 6, 2009
    413
    32
    I decided to go with an Arduino Uno because it seemed a little easier to learn. I got it up and running, even wrote a sequential LED program from scratch. Now the question... I'm looking into building a simple motion detector/alarm circuit, but do not know enough about the language to work it out.
    In Assembly, you would scan the motion sensor, if the bit has changed (alarm), you would wait 15 seconds, scan the disable bit, and either sound the alarm, or loop to the previous step. It is easier to loop to specific points in assembly. I cannot find the concept in the library, nor can I find a reference to a disable or sleep mode. Any hints or ideas would be greatly appreciated! (keep in mind, I'm a real noob with this program...)

    Thanks!!
     
  2. mbohuntr

    Thread Starter Active Member

    Apr 6, 2009
    413
    32
    I was thinking of "if" the sensor bit "and" the enable bit were high, "then alarm output high, wait (time) then loop. but do all loops go to the beginning? This method has many loops...:confused: I also have to learn about number keypads, do you use the output to enable a bit?, or a mask?
     
  3. mcgyvr

    AAC Fanatic!

    Oct 15, 2009
    4,771
    971
    There is already SOOOOOOOOOOO much information/projects/completed code all over the internet for Arduinos I suggest you simply google "arduino motion detector" and go from there..
     
  4. mbohuntr

    Thread Starter Active Member

    Apr 6, 2009
    413
    32
    Well... duh.... I was looking at everything else from interrupts, sleep, masks, that I never considered the obvious! Thanks! Sometimes a good slap in the back of the head is what I needed! :D There were lots of examples and code! Thanks again!
     
  5. mbohuntr

    Thread Starter Active Member

    Apr 6, 2009
    413
    32
    I was unable to find the exact combination of peripherals (PIRs and number keypad) , so I have to wing it... How does this sequence sound? any advice is welcome...
    Pir as input
    keypad as input
    red led as output
    green led as output
    alarm as output

    scan keypad (digitalread)
    if high (disabled)
    digitalwrite green led low
    digitalwrite red led high
    loop
    else
    digitalwrite green led high
    digitalwrite red led low
    scan pir (digitalread)
    if high,
    digitalwrite alarm high
    delay 10000
    loop
    else loop

    I do not know if you can arm/disarm the system from inside the door without setting off the alarm. maybe aim the pir further into the room?
     
  6. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    6,357
    718
    Alarm systems typically notice the fault, such as sensor switch, PIR sensor, etc, immediately, then allow 20 seconds for a user to enter the arm/disarm code before sounding the alarm.

    Do you have specs for your PIR sensor? Is the output logic high/low, analog, or a bus of some sort?

    I'm assuming you have the keypad operating correctly? A test program with just the LEDs and keypad could do this, by blinking an LED once the code has been entered. This would allow you to narrow the problem down to the single issue you are having problems with.

    The other option is to search Google to find code somebody has already written in the same application to get ideas.
     
  7. mbohuntr

    Thread Starter Active Member

    Apr 6, 2009
    413
    32
    I'm working on the pir's, having some difficulty with stability(low end canadian(hong Kong)) units., keypad is in the mail. I was going that route(first alarm, then keypad), but was unsure of using multiple loops. Then I tried it backward to see if it flowed any better... That's why I'm looking for a path that flows. The if/else idea might work, but maybe there is a disable/enable command that works better...
     
Loading...