/*
  Sharp GP2D12 IR ranger reader
  Language: Wiring/Arduino
  
  Reads the value from a Sharp GP2D12 IR ranger and sends 
  it out serially.
*/

int sensorPin = 0;     // Analog input pin 
int sensorValue = 0;   // value read from the pot


void setup() {
  // initialize serial communications at 9600 bps:
  Serial.begin(9600); 
}

void loop() {
  sensorValue = analogRead(sensorPin); // read the pot value

  // the sensor actually gives results that aren't linear.
  // this formula converts the results to a linear range.
  int range = (6787 / (sensorValue - 3)) - 4;
  
  Serial.println(range, DEC);    // print the sensor value     
  delay(10);                     // wait 10 milliseconds 
                                 // before the next loop
}

Sorry, the comment form is closed at this time.

   
© 2012 Making Things Talk Suffusion theme by Sayontan Sinha