Which would be a most suitable sensor ultrasonic or infra-red and what should the output be analog or digital?
I'd think that 15 minutes with a web browser and a search engine and you'd know how each sensor works. Then, without embarrassing yourself, you'd KNOW the answer.
The sensor manufacturer will tell you what kind of output the sensor produces.
I don't think visible light is going to interfere with a sound-based sensor. Do you?
Yeah, I was kind of thinking the same thing... this is a very general problem and a lot of solutions would solve it... just not sure what'd work best for their problem. Digital will work... go/no-go style. If you trigger high, you're about to fall off the edge and need to turn around. Analog would work too (see the ultrasonic example below).
But on the ultrasonic question, "...can you hear an edge?" Heck yeah you can. If you hang an ultrasonic sensor over the front bumper x number of inches above the table and that sensor comes up with anything larger than x, then you know you're about to drive over an edge.
I guess we kind of need more information. How big is your robot? What's your budget? What other sensors are on the robot? How good are you at writing code?
In the end, I decided to to IR, mainly due to cost. I got hold of the Sharp Analog sensors.
I'll estimate the robot would be within a 300x300mm, but I think the length would be close to 250mm. Apart from detecting edges, it also needs to carry some load.
There are no other sensors on it.
How good am I at coding? Bad, since I have no experience whatsoever with C/C++.
But I have worked with MATLAB and quite comfortable with it.
Well it looks like the only limit you might have is how hard the code is to write so I'd say a simple IR sensor set to (fake) digital output seems like a great fit. If the distance is too far (meaning it's hanging over the edge of the table) then trigger high and if your trigger is high then turn the robot away from the edge it's about to fall off of. Good luck and keep us posted!
remember, many ultrasonic rangefinders have a minimum range, within which they will report things as being outside their maximum range. This is caused by their blanking period.