Go Down

Topic: Measuring distance. (Read 1 time) previous topic - next topic

cedric100

Hi, I want to create a segway that knows about the distance of the ground using light sensors. I have been trying to use IR phototransistor and IR led in order to measure the intensity of the light that goes back to the phototransistor.

I used IR because I do not want the surrounding light to disturb the signal.

First, I wanted to see what the Phototransistor measures in front of a LED. I have weird values. (Either 0 or 1023, which means either everything or nothing, it is not quite analogic).

Connections. It is the basic:
- Resistor of 220 Ohms connected in serie to the LED to produce light feeded to the 5V.
- Same resistor connected to the phototransistor, same connection, and the analog input connected between resistor and phototransistor.

Coding:
Code: [Select]
int led = 5;
int ledState = HIGH;
int LDR = 3;
long previousMillis = 0;
long interval = 1000;

// the setup routine runs once when you press reset:
void setup() {               
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);
  pinMode(LDR, INPUT);
  Serial.begin(9600);
}

// the loop routine runs over and over again forever:
void loop() {
     // turn the LED on (HIGH is the voltage level)

  unsigned long currentMillis = millis();

  if(currentMillis - previousMillis > interval)
  {
    // save the last time you blinked the LED
    previousMillis = currentMillis;   

    // if the LED is off turn it on and vice-versa:
    if (ledState == LOW)
      ledState = HIGH;
    else
      ledState = LOW;

    // set the LED with the ledState of the variable:
    digitalWrite(led, ledState);
  }
  Serial.println(analogRead(LDR));
}


I do not know what went wrong. I would like the transistor to return normal values varying on the intensity it senses.

Can anyone help me understanding what went wrong ?

PS: I cannot test anymore, one of the LED pin is missing. I could on Monday, UK time.

Thank you by advance.

Kind regards.

jremington

You will be much better off using commercially available IR distance sensors. They are reliable and cheap.
Here is a collection: http://www.pololu.com/category/79/optical-range-finders

Robert Getzner

Hi, did you measure the voltage from the phototransistor/input pin? With a multimeter, Oscilloscope etc?
http://robertgetzner.com/PersonalWordpress/category/computer/arduino/

MarkT



I used IR because I do not want the surrounding light to disturb the signal.



But sunlight and tungsten lighting do have near IR - silicon LEDs are only just
beyond the visible at 850--900nm or so.   Make sure your phototransistor has an IR filter
to reduce the amount of visible it picks up (they respond to all shorter wavelengths
otherwise).  You will need to shade your system to get meaningful results I think.

http://www.coilgun.info/theory/phototransistors.htm
[ I won't respond to messages, use the forum please ]

mirith

Have you tried using ultrasonics?  My experience with IR sensors (And this is anecdotal, so I could be quite wrong), is that they tend to only really work REALLY close to the ground, and tend to be better for digital rather than analog signals.  The times I've used them were to detect the edges of table, so there was a sudden and drastic change in reflected light.

Grumpy_Mike

Quote
I want to create a segway that knows about the distance of the ground using light sensors.

The readings you get back will depend on the reflection properties of the ground as well as the distance. I can't see this working.

michinyon

Isn't a segway always the same distance from the ground ?

Grumpy_Mike


Isn't a segway always the same distance from the ground ?

Depends on how you drive it.  :D  :smiley-eek-blue:

Go Up