Connect with us

Sensor signal frequency counter in arduino

Discussion in 'Microcontrollers, Programming and IoT' started by ram, Apr 17, 2014.

Scroll to continue with content
  1. ram


    Feb 7, 2010
    I used IR as my sensor and my task is depends on my IR sensors number of signals with in 1 min my output ill vary...
    ex: if IR signal is 1 my output 1 ill execute if IR signal is 2 my output 2 ill execute....
    i did this task by the help of loops without using counters & timers of controller... my question s how to use counters&timers for this task.......
  2. Harald Kapp

    Harald Kapp Moderator Moderator

    Nov 17, 2011
    Welcome to our forum, ram.

    One way of using counters and timers is like this (Pseudocode, you'll have to write the correct code for teh arduino yourself):
    Initialise a counter to increment by 1 for each signal from the IR sensor (e.g. trigger counter on rising edge of the signal).
    Set the counter to 0
    Initialise timer for 1 minute interval
    Set up an interrupt routine that will be triggered by the timer after the 1 minute count-down.
    Start the timer
    Go to main routine - counting and setting the port pins will be handled by the timer interrupt roputine, see below.

    This is what the timer interrupt routine does:
    read counter and activate the port pin corresponding to the value of the counter (you should include some checks to avoid e.g. illegal values).
    reset counter to 0
    reset timer to initial value (so it will again count down 1 minute)

Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day