Go Down

Topic: serious guidance required for a motion sensor (sort of) device (Read 3648 times) previous topic - next topic

radman

If counter < 3600 you are going to be flashing pin 7 on and off.
As soon as counter gets to 3600 you set it to 0 so it will, more or less instantly start flashing pin 7 on and off.

whitepanda

#16
Dec 11, 2011, 01:49 am Last Edit: Dec 11, 2011, 01:54 am by whitepanda Reason: 1
Since I am not the best to explain stuff, so i draw the flow chart


the system is kind of a motion sensor, it will monitor movement using a vibration switch (very very sensitive), and taking data probably every 1 second and give feedback with Green LED and red led at the same time, Green mean yes there is movement, Red mean no. After an hour it will give an overall feedback. e.g. lets say there were 3600 data in an hour, and if the number of YES(s) are 1800 or more it will turn LED off and repeat the program over again. otherwise red led will flash for few times and repeat the program

in the flowchart the digitalread(0) should be digitalread(2)>0


radman

Flowcharts are a good idea. Look at the bottom of yours, counter will almost always be less than 3600 so the program will almost always be going up the right hand side and flashing the red LED. When counter get to 3600 it will go up the left hand side once and zero counter, then start going up the right hand side again. It is always going to look like the red LED is flashing.

wildbill

The design seems odd - what is the delay(3600-counter) for? Also, it seems as though if you're not watching the device very closely,  you will miss the hourly led flashing report. Would it make sense to have another led to indicate whether there was activity detected on more than half the sensor reads in the hour? Or in other words - what is this device supposed to be used for?

GoForSmoke

With all those delays your system is mostly ignoring the vibration switch. Is that your goal?

If your goal is to detect vibration then you need to re-think your flowchart.

Nick Gammon on multitasking Arduinos:
1) http://gammon.com.au/blink
2) http://gammon.com.au/serial
3) http://gammon.com.au/interrupts

radman

Maybe if you thought along these lines things would start to become clearer.
Use three counters

  • Count the total number of times you go round the loop

  • Count the number of times you go down the green leg

  • Count the number of times you go down the red leg



At the bottom of your program have some logic that does things based on total number of times you have been round the loop.
I agree with WildBill that you probably want to use more LEDs otherwise you will miss what happens when the total times round the loop is 3600 or 1800. GoForSmoke is also correct that you are hardly ever reading you switch.

whitepanda

I have changed the delay much 10 - 20 so i will not miss any events.
loop should go around forever, and give feedback every hour ( in this testing case, scale down to 1 min)

whitepanda

the device is used for detecting leg movement (due to cost and component available, i was only given a vibration switch which will only have simple on and off) and if there wasn't enough movement over an hour, it will warn the user

GoForSmoke

You might want to live-test your switch on a leg as fast as it can run just to see what you get. You can then say definite things about the switch and leg setup.

Like for all of loop() {
  if the switch is on, turn off the red led and light the green led, else turn green off and light red
}

Then see what you get when you don't move your leg on purpose. Maybe you get flashing lights always and need to modify your setup. It's best to find that through unadjusted data.

From your goal I get the idea you want to track non-movement. Don't make any delays longer than half of what you can afford to miss catching a change.

Nick Gammon on multitasking Arduinos:
1) http://gammon.com.au/blink
2) http://gammon.com.au/serial
3) http://gammon.com.au/interrupts

radman

Quote
the device is used for detecting leg movement (due to cost and component available, i was only given a vibration switch which will only have simple on and off) and if there wasn't enough movement over an hour, it will warn the user

Quote
it will monitor movement using a vibration switch (very very sensitive)


You should be able to do what you want with the components you have available, but it might be worth taking a step back and clearly stating your objectives.

You are trying to warn somebody that they have not moved their leg sufficiently is that correct?
Is the purpose to ensure they maintain circulation to the limb?

How long  can the person leave their leg without circulation, I would suggest 10min max.
Therefore there is no point in warning the person after an hour, that is way too long.
Also you describe the vibration sensor as "very very sensitive", will it react to levels of movement less than that required for circulation in the leg i.e. general upper body movement/vibration such as breathing (this should be easy to test just strap it your leg, keep your leg still but breath, move your arms etc.). If the sensor reacts to movement other than just the leg then you will need to be smart in how you use it to ensure circulation is being maintained.

This might be going off at a tangent but have you considered applying appropriate, safe, voltage to the leg muscles to make them contract/relax.

Yet another silly though, I don't suppose the sensor is sensitive enough to detect a pulse

wildbill

So from a user's perspective, what do they care about the red and green led as they are set up now? Useful to you in debugging, but doesn't tell them anything. How about having red yellow & green and light them to indicate whether the user has too little movement, some movement & enough. Check the sensor every time round loop and see if movement is detected in the last second. Keep count of elapsed seconds and the count for those in which movement was detected. Do a little math & light the leds accordingly. No need to use delay at all.

whitepanda

You are trying to warn somebody that they have not moved their leg sufficiently is that correct? Yes, it is used to reduce the risk of deep vein thrombosis. 10 mins seems too short as most people can sit and not move i would say at most 1 hour and a bit more without problem. so we choose 1 hour. in the prototype the sensor will be placed on the socks around the calf.

windbill: this was something we had in mind, but we want it to give overall feedback every hour, as well as instant feedback.
instant feedback like every 1 or few sec. it light up red or green to tell you no movement or there is movement.
and overall feedback based on not enough movement over an hour. as we wanted to make sure the program does work first (where the most mark will be given on working prototype) the value of accuracy may not be in play, as we need to present it in a trade show, which i don't think lecturer will be interesting to watch us playing with it and wait for an hour to see if it work or not.

radman

Quote
most people can sit and not move i would say at most 1 hour and a bit more without problem

I know pandas are sedentary but an hour is  a long time :D

I thought you might have had in mind somebody who had lost feeling in their legs and the device was to warn them to move.
If the problem is deep vein thrombosis then maybe you should try to see if the sensor can be used to detect a pulse in the ankle.


whitepanda

i don't exactly mean actual NOT moving like panda just chew bamboo, at least very very limted movement for about an hour... even our lecturer give us lecture from 2pm till 5pm with no break in between, and just sit n listening  :smiley-sad-blue:

Go Up