And my objective is to calculate the width of the Paper in my industry , a defective product(paper) will have more width when compared to the good product(paper).
the laser sensor is fixed above the paper conveyor. And the sensor gives long output for long product(defective) and a short output for good product(paper) and i am here trying to find the defective one.
And my code is
int pin = 4;
unsigned long duration;
void setup()
{
Serial.begin(9600); // open the serial port at 9600 bps:
pinMode(pin, INPUT);
}
void loop() {
Serial.print("\n"); // prints a tab
duration = pulseIn(pin,HIGH);
Serial.print(duration,DEC);
delay(250);
}
But the decimal value which i see in serial monitor is not constant and i see more error values.
I don't know if this is because of the program or the limits of the hardware?
Any help you can give will be most useful, thank you for your time.
Well, start by posting a complete schematic of your setup, make all grounds are connected together.
Post a link to the optical sensor.
Perhaps use
pinMode(pin, INPUT_PULLUP);
if your sensor pulls the pin low during one of its levels (paper or no-paper).