Problem differentiating wall, staircase and obstacles.

Hi. Can you please help me to improve my coding's. I Am new to ardunio and my project is about differentiating the obstacles, wall and staircase. I'm using aurdunio uno and ultrasonic sensor HC-SR04. I wrote codes that gives distance and I made LED to glow in particular range. But I don't know how to write or how to start to differentiate them as wall or staircase or obstacles. Can anyone improve my codes or tell me instructions how to write codes to find them.

#define trigPin 3
#define echoPin 2
#define led1 13
#define led2 7
void setup() {
  Serial.begin (9600);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
 }

void loop() {
 int duration, distance;
 digitalWrite(trigPin, HIGH);
 delayMicroseconds(100);
 digitalWrite(trigPin,LOW);
 duration=pulseIn(echoPin, HIGH);
 distance=(duration/2)/29.1;
 Serial.print (distance);
 Serial.println("cm");
 if (distance<50)
 {
 digitalWrite(led1, HIGH);
 digitalWrite(led2, LOW);
}
if (distance>=50 && distance <100)
{
  digitalWrite(led1, LOW);
  digitalWrite(led2, HIGH);
}
if (distance >=100)
{
  digitalWrite(led1, LOW);
  digitalWrite(led2, LOW);
}
delay(500);
}

Do you have any ideas on how to differentiate between those obstacles, using an HC-SR04?

No. I don't have any ideas. That's why I'm seeking help here. Can you please help me with this?

No one can help unless you provide some data.
How does the HC-SR04 respond when you point it at different obstacles?
If there is no difference in the responses, there is nothing you can do.

the above is my code. It will find the distance of the obstacle and tell whether the obstacle is too close or close. And I want to know how can I improve my code such that it will say that the detected obstacle is a wall or staircase, or simply an obstacle.

And I want to know how can I improve my code such that it will say that the detected obstacle is a wall or staircase, or simply an obstacle.

See response #3.

Why do you need to detect one of those three conditions? What - in your mind - is the difference between the three, and what actions do you intend the robot to take - if it could identify such?

For instance - to me, I can only think of one reason you'd want to detect stairs - to either know to go up them in some manner (?) or to prevent falling down the stairs (?) or to prepare to go down the stairs (?).

But - a wall vs an obstacle to me would seem to be the same thing - something in the way that needs to be maneuvered around. So - why the differentiation between those two?

Finally - unless you want to get into computer vision and/or other non-trivial methods (SLAM, etc) - you are likely not going to be able to tell the difference between a wall, a staircase, and other objects - not with a single sensor.

Instead - what you are going to need to do is what is known as "sensor fusion" - use multiple sensors taking readings, then using that data in total to figure out what it all means. Maybe by adding an infrared distance sensor (ie - SharpIR) would help? Maybe some touch sensors, too. To detect a dropoff - maybe some kind of downward facing sensor, or maybe a switch to detect a "cliff" (look up "cliff sensor" for ideas). Maybe you add a barcode reader and mount stickers on the walls, objects, and stairways to detect them? Maybe you add short-distance RFID tags or something, and read those when you are nearby?

Actually I'm going to use this sensor in walking stick. So it will be useful for the blind person to know the obstacle in front of them. As you said if it is a staircase the person will intend to go up or come down. If my sensor blindly says its an obstacle then the person would not get any benefit from it. He may turn back. He needs to identify the staircase in order to use them. Can you now help me?

And if I am using multiple sensors how can I take readings with them. I'm new to this aurdino. My code will give only distance. Is it possible to make a threshold for different types of obstacles? If so, how can I do it?

Is it possible to make a threshold for different types of obstacles?

Yes, if the sensor responds differently (in a repeatable manner) to different obstacles.

Anje:
Actually I'm going to use this sensor in walking stick.

I assumed it was for a robot because...well...you posted this question in the Robotics forum...

Next time, you might want to post in the Sensors forum.

Anje:
So it will be useful for the blind person to know the obstacle in front of them. As you said if it is a staircase the person will intend to go up or come down. If my sensor blindly says its an obstacle then the person would not get any benefit from it. He may turn back. He needs to identify the staircase in order to use them. Can you now help me?

Ok - since it is a person using the system - then maybe sensor fusion could still be done? Perhaps by using both a Sharp-IR module and an ultrasonic module (so that for some things, the IR module will work better, whereas for others, the ultrasonic module might be better) - mounted close together (or maybe even multiple sensors of each?) - so that as the user waves the stick - they get back different levels - and that could be translated into sound, or vibration - that the user could learn to interpret?

I know this has been done in a similar manner using a video camera - where what the camera sees is translated in various ways (audio and other methods) which over time, the user adapts to and learns to "see" with.

Maybe you could do something similar - using the Nootropic Video Experimenter kit?

jremington:
Yes, if the sensor responds differently (in a repeatable manner) to different obstacles.

My code only gives distance. how can i monitor different response with that. Can you suggest any linkor codes to do so.