How to connect a Sharp 2Y0A710F distance sensor to Arduino
Sharp 2Y0A710F is a distance measuring sensor unit, composed of an integrated combination of PSD (position sensitive detector) , IRED (infrared emitting diode) and signal processing circuit. The variety of the reflectivity of the object, the environmental temperature and the operating duration are not influenced easily to the distance detection because of adopting the triangulation method. The sensor outputs the voltage corresponding to the detection distance. So it can also be used as a proximity sensor. In order to get readings you have to connect it to an analog pin since it is analog sensor.
And here is the code you can use:
void setup() { Serial.begin(9600); } int sensorValue; int distance; void loop() { sensorValue = analogRead(0); if(sensorValue>=280&&sensorValue<=512) { Serial.print("Distance: "); distance=28250/(sensorValue-229.5); Serial.print(distance); Serial.println("cm"); } delay(200); }
Please keep in mind that the readings are not that accurate and it might be a good idea to use it only for detecting objects within the range of 100cm – 550cm.
2 thoughts on “How to connect a Sharp 2Y0A710F distance sensor to Arduino”