Go Down

Topic: How can I count analog pulses. (Read 324 times) previous topic - next topic

amsnick

Hello!

I am using a photoresitor to detect an event.  The Arduino Uno R3 detects the event.  I know that the event lasts in the second range and the time between events is at least 250 milliseconds.  It would give a square wave and I am confined to the analog inputs.  I would like to count the events.  How would I program the event counter?

Thanks for your thoughts!

jremington

#1
Oct 02, 2016, 04:43 pm Last Edit: Oct 02, 2016, 04:44 pm by jremington
First, you have to decide how to identify an event. It could be that a value is greater than some maximum, perhaps for some period of time.

To count, each time you identify an event, add one to the total.

amsnick

I should have included that the pulse (time) varies significantly for both the pulse and the void between pulses.  That would imply, to me, that using a timer to capture the signal wouldn't work.  I think I was hoping that the analog inputs could detect a rising or falling signal, or maybe a significant change in signal.  I am getting close to full scale signal deflection.  Both rise and fall or change could be counted in both directions. 


Wawa

It would give a square wave and I am confined to the analog inputs.
The analogue inputs are digital inputs with the added functionality of analogue.

sensor = digitalRead(14); // reads a digital signal on pin A0

Leo..

ChrisTenone

I should have included that the pulse (time) varies significantly for both the pulse and the void between pulses.  That would imply, to me, that using a timer to capture the signal wouldn't work.  I think I was hoping that the analog inputs could detect a rising or falling signal, or maybe a significant change in signal.  I am getting close to full scale signal deflection.  Both rise and fall or change could be counted in both directions. 


Is it a 'things randomly blocking a beam' (people walking by, cars on a road, eggs on a conveyor, etc.) or 'sequential events' (opening/closing of a shutter or door, etc)? in the first case, events can overlap, and be obscured by simultaneous events, but in the second each event is discrete. Guess which one is easier to count.
Wubba lubba dub dub!

amsnick

Thanks for your responses.

Chris the cause of the beam blocking is model train cars.  It will only be discreet signals, no overlapping and pretty clean and definitely square.  It will be used to turn off lights at a complex grade crossing.

Wawa I've used the digital conversion and have either a 0 or a 1 to work with.  The next step is, because the train might be changing speed and the Arduino's sampling rate is fast, to capture the change of the signal from 1 to 0 as each car enters the sensor then from 0 to 1 as it leaves. 

I've got the programming pretty well solved but would appreciate some hints for a more elegant solution and/or a second opinion.

Programming a new scenario can be a long and tedious process!


Wawa

#6
Oct 03, 2016, 10:28 pm Last Edit: Oct 03, 2016, 10:39 pm by Wawa
Wawa I've used the digital conversion and have either a 0 or a 1 to work with.  The next step is, because the train might be changing speed and the Arduino's sampling rate is fast, to capture the change of the signal from 1 to 0 as each car enters the sensor then from 0 to 1 as it leaves. 

I've got the programming pretty well solved but would appreciate some hints for a more elegant solution and/or a second opinion.
Don't see what the problem is, and what speed of the Arduino has to do with this.
Just update a variable for that opto with every loop.
Then decide what to do with it.
Post your code (inside code tags) if you want help with it.
Leo..

edit
Just saw that you're using reflection sensors.
Maybe wise to use a short sketch that reads the analogue value of the sensors.
See if they output less than ~200 and more than ~750 when the train passes over them.
Only then can you be sure that they also work digitally.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy