ตัวอย่างโปรแกรมใช้ Arduino
เมื่อไม่มีวัตถุใดๆอยู่ตรงหน้าเซนเซอร์ เอาต์พุตเป็น 1 เมื่อมีวัตถุใดๆอยู่ตรงหน้าเซนเซอร์ เอาต์พุตเป็น 0
int sensorValue_Proximity_Photoelec = 0;
int sensorValue_Proximity_Inductive = 0;
void setup() {
// put your setup code here, to run once:
//start serial connection
Serial.begin(9600);
//configure pin2 as an input and enable the internal pull-up resistor
pinMode(9, INPUT_PULLUP);//Photo
pinMode(10, INPUT_PULLUP);//Metal sensor
pinMode(2, OUTPUT); //CLK step
pinMode(3, OUTPUT); //DIR step
pinMode(4, OUTPUT); //IN1 L298
pinMode(5, OUTPUT); //IN2 L298
}
void loop() {
// put your main code here, to run repeatedly:
sensorValue_Proximity_Photoelec = digitalRead(9);
sensorValue_Proximity_Inductive = digitalRead(10);
Serial.print("Photoelec D9 = ");
Serial.print(sensorValue_Proximity_Photoelec);
Serial.print("t Inductive D10 = ");
Serial.println(sensorValue_Proximity_Inductive);
}

