# Arduino Bidirectional Counter

Hey guys, I need some help with writing a code for a bidirectional counter using the Uno R2 or 3.

The goal is to have 2 infrared detectors that give a HIGH output when triggered by motion. These HIGH outputs are fed to the arduino input pins and the time in which the detectors are triggered is recorded in real time. Since they'll be some time interval between the triggering of both detectors, the recorded times are compared and if the difference is positive, the 7 segment display connected to the ADC output of the Arduino increases by 1 If the difference is negative, it decreases by 1.

This is the best algorithm I came up with. If you have a better or easier method, I will be very glad to learn. I will really appreciate if someone can help with writing a source code for my counter. Thanks

Yes, well:

http://whathaveyoutried.com

You write some code, and if you have problems with it, post it and we'll be happy to help.

Hey guys, I need some help with writing a code for a bidirectional counter using the Uno R2 or 3.

The goal is to have 2 infrared detectors that give a HIGH output when triggered by motion.

You and about 8000 other people this time of year. Here's some code to get you started:

``````// Add some declarations here

void setup()
{
}

void loop()
{
}
``````

Since they'll be some time interval between the triggering of both detectors, the recorded times are compared and if the difference is positive, the 7 segment display connected to the ADC output of the Arduino increases by 1 If the difference is negative, it decreases by 1.

This doesn't make sense. The bit about the interval is true, and the bit about the need to compare values is correct. The rest is rubbish. The ADC (analog to digital converter) has NOTHING to do with the 7 segment display, and the display is a stump stupid device. You have to tell it what to display. It does not count for you.

This is the best algorithm I came up with.

What is?

I will really appreciate if someone can help with writing a source code for my counter.

Head over to Gigs and Collaboration, and offer up some renumeration. Make sure whoever helps you gets credit when you are graded. You certainly shouldn't be getting any.

Does your problem look anything like this?

@ Nick: I will be uploading a code very shortly. My main concern is the increment/decrement of the 7 segment display. I spent a few hours studying tutorials but I couldn't really understand how to make the values increase or decrease on its own. It's my first time using the Arduino, I definitely need some practice with simple codes.

@AWOL: Thanks for providing the link, I will be going through it. I'm sure it will be very helpful for an Arduino newbie like myself.

I really appreciate the reply from both of you.

That's a very complicated scheme for a simple task.

If the sensors go high when motion is detected, all you need is a "motion detected" variable that is reset after a period of low signal from both sensors.

Otherwise: increment your count if 1) motion detected is set; and 2) back sensor is low when the front sensor goes high; decrement if 1) motion detected is et and 2) front sensor is low when the back sensor goes high.

deejay_biig: I spent a few hours studying tutorials but I couldn't really understand how to make the values increase or decrease on its own.

They are hardly going to increase "on their own". You want something like:

``````if (someCondition)
someVariable++;
``````

deejay_biig: It's my first time using the Arduino, I definitely need some practice with simple codes.

In that case may I humbly suggest you work through some of the tutorials? Trying to do your assignment without knowing the basics is like trying to write your end-of-year essay before you have learned how to use a pen.