Pages: [1]   Go Down
Author Topic: Measuring distance.  (Read 1020 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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.
Logged

Oregon, USA
Offline Offline
Edison Member
*
Karma: 68
Posts: 2268
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

"It seems to run on some form of electricity"

Offline Offline
Newbie
*
Karma: 3
Posts: 39
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi, did you measure the voltage from the phototransistor/input pin? With a multimeter, Oscilloscope etc?
Logged


0
Offline Offline
Shannon Member
****
Karma: 207
Posts: 12200
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


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
Logged

[ I won't respond to messages, use the forum please ]

Southeast US
Offline Offline
God Member
*****
Karma: 15
Posts: 683
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 627
Posts: 34234
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Faraday Member
**
Karma: 62
Posts: 3031
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 627
Posts: 34234
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Isn't a segway always the same distance from the ground ?
Depends on how you drive it.  smiley-grin  smiley-eek-blue
Logged

Pages: [1]   Go Up
Jump to: