im trying to receive analog output from this keyence laser sensors and amp via arduino, but the current output is just giving me some random values not the real measurements
wiring diagram from the manual:
(link:Connection and wiring, Connection and wiring -9 | KEYENCE IL Series User Manual | Page 29 / 140)
i connected the analog pin to A0 on my arduino uno 3 board and analog shield pin to gnd, can anyone correct me if im wrong?
code:
const int analogPin = A0; // Analog pin for distance measurement
void setup() {
Serial.begin(9600);
}
void loop() {
int sensorValue = analogRead(analogPin); // Read the analog input
Serial.println(sensorValue);
float voltage = sensorValue * (5.0 / 1023.0); // Convert to voltage
float offset = 1.0;
float scaleFactor = 10.0;
float distance = (voltage - offset) * scaleFactor; // Convert voltage to distance
Serial.print("Distance: ");
Serial.print(distance);
Serial.println(" mm");
delay(500);
}