Go Down

Topic: BI-DIRECTIONAL PEOPLE SENSOR AND COUNTER USING ARDUINO BOARD (Read 18690 times) previous topic - next topic


Rob Gray aka the GRAYnomad www.robgray.com



I have done all I can and the only segments am getting lit are a,b,c and d, the rest are off and nothing sensible is coming out of my display.


You are not getting what I said.
The change I showed was a bit pattern that had one segment lit up for each of the numbers 0 to 7. If you display just one digit you should see just one segment lit up. Do not have the full code just display one digit at a time.
If you do not then you have not wired up your display like you say you have, you have something wrong with your hardware.

Anyway as that plan does not seem to be working:-
So try something simpler, you are trying to test if the wiring you have is correct. Write a small sketch that turns on only one transistor, and then goes through each segment one at a time and turns it on. Put a one second delay between each so you can see it come on. Turn off that segment before you turn the next one on.
You should see each segment a to g come on in turn. If you do not see this then you know it is physically wired up not like your diagram. Maybe you have misidentified the pins on the display or something. If it does work then we can tick that off with confidence and start looking at the software. But until you verify the hardware is correct it is pointless looking at anything else.

It is also a valuable lesson for you into how to find a fault.



I slept 5am this morning working on this, my hardware is perfect. My verbose 000--999 counting code I posted before works flawlessly
have even tried to do another simplified counting code and all counts perfectly. The problem is in the software(the code you sent to me)
No matter what I change 0 or ones the display stays the same all through.



Dec 17, 2012, 03:43 pm Last Edit: Dec 17, 2012, 04:14 pm by Graynomad Reason: 1
Here is the absolute simplest thing I can think of to test the bits along the lines of what Mike is saying.

Code: [Select]

byte digitPins[] = {25,26,27};
byte segmentPins[] = {30,31,32,33,34,35,36};

byte digitPatterns [] = {

B00000000, // 0
B10000000, // 1
B01000000, // 2
B00100000, // 3
B00010000, // 4
B00001000, // 5
B00000100, // 6
B00000010, // 7
B11111110, // 8
B11100110, // 9

void setup() {

for (int i = 0; i < 3; i++) {
digitalWrite (i, LOW);
pinMode(segmentPins[i], OUTPUT);

pinMode(25, OUTPUT);
digitalWrite(25, LOW);

PORTC = digitPatterns[1];  // <==== change this number to try all 7 possibilities


void loop () {}

Run that and see what segment lights up. Then play with the indicated number and record the results.

EDIT: I did notice one thing in your code though, you are writing to PORTA to set the segments, your displays are on PORTC are they not?

Rob Gray aka the GRAYnomad www.robgray.com


I don't know what you expect this code to do:-
Code: [Select]
void convert_to_digits (byte number) {
   for (int i = NDIGITS-1; i > -1; i--) {
      display_digits = number % 10;
      number /= 10;

It won't even compile the way you have defined the variables but anyway it is a loop that keeps writing over the value in the variable display_digits. As display_digits  is an array anyway should you not be using an array index with this anyway?

Then this bit:-
Code: [Select]
void show_next_digit () {
   digitalWrite (current_digit, LOW);
   PORTC = B11111110;
   PORTA = digitPatterns[display_digits[current_digit]];

You are using current_digit as an index into an array whose value can only range from 0 to 2, but you are also using the same variable to define a pin number to write a logic LOW to. So that is using pins 0 to 2 only. That does not tie up with your schematic.


Mike, Rob,

Wondering if you have had a look at the latest working 3 digit 7 segment display code I posted yesterday?
I am working on this with my ISR.



// Loop through each bit in the font mapped digit turning on and off segments as needed

This absolutely makes no sense, you have parallel access to the 7 segments, Just do a single write to PORTC.

Rob Gray aka the GRAYnomad www.robgray.com


I really can't see why you have to have all that interrupt code. For any given person you get 4 interrupts and every one of them can adjust the counter. I didn't follow the logic but the fact that you are getting double counts does not surprise me at all.

Did you try my code from post #23? If so what was the result?

Rob Gray aka the GRAYnomad www.robgray.com



Rob, mike

I will try your version on #23 to see how it goes. Do you mind doing a polled version instead of the ISR as you promised?
In the near future I will be looking on how to achieve time stamping with arduino and Real time clock.

Many thanks.


Let me first start off by stating I'm not a C developer, I'm a longtime VB developer.  That being said, I have been perusing the logic samples in this string of postings and I ended up perplexed.  Perhaps it is just my lack of experience with C, perhaps it is the choppy series of responses, or perhaps I'm just too old!

I figured I could simulate the events using VB since it is something near and dear to my heart.  In addition, the example code uses an "event recorder" to record the sequence of triggers.  In other words, "AB" means sensor "A" and sensor "B" were both triggered, which means someone came INTO the room.  "BA" means sensor "B" and sensor "A" were both triggered meaning someone "LEFT" the room.  In addition I have added code to handle "stale" or "incomplete" triggers.

My assumption is that this code can be converted to C and tweaked to add logic to increment/decrement a counter very easily.

Go Up