Hi everyone,
I'm working on a movie poster with moving eyes. Im using a small servo for the eyes and I have two parallax PING))) ultrasonic range finders. I want to put the two sonars on either edge of the frame so when someone walks by the two range finders cause the servo to turn to move the eyes toward the person walking by.
I figure it's just a servo being manipulated by two sonars, can't be too hard right?
My question is, is this even possible using the arduino? I can't seem to wrap my head around how something like this would be coded.
This is a hard problem to solve due to the way the sensors work. These are active devices, so will need to be constantly scanning for a target. Unlike a PIR sensor or similar that simply reacts to the change in IR activity, a sonar detector fires off a beam that is then reflected back to a receiver. This beam returns nothing more than the time taken for an echo response to be returned, i.e. you will need to orient the sensors yourself. You'll need to determine the frequency of scanning as well as figuring out how best to determine the position of the target. A simple approach might be to take a baseline reading for each sensor and compare each periodic echo response to this baseline.
Add in the fact that you may have multiple targets walking past at any time, from any direction, at many different velocities (speed with a direction component relative to the sensor placement), and you'll find that you'll have to make a lot of assumptions about any potential target.
Any solution with active scanning of this sort is likely to have high power requirements as well.
That said, you could probably make a device that assumes a single target and reacts to that, in which case you could use the afore-mentioned PIR sensor, though you'll have to forego the 'eyeball tracking' feature in this case.
Further thinking about this has led me to conclude that you may arrive at an acceptable solution by simply tracking the eyes towards the sensor that triggers first, in which case, something like the following may help:
Setup: obtain and store baseline readings for left (L) and right (R) sensor.
1. Check L sensor.
2. If L reading is less than L-baseline, turn servo appropriately.
3. Otherwise:
4. Check R sensor
5. If R reading is less than R-baseline, turn servo appropriately.
6. Wait a bit for person walking by to react.
7. Re-centre servo if desired.
8. Go to 1.
This obviously has a left bias, and doesn't have the full tracking feature, but may be acceptable to you nonetheless.