Proximity Sensor Interfacing to an Arduino (sinking sensor)

Proximity Sensor Interfacing to an Arduino (sinking sensor)

A video to show how to interface a sinking proximity sensor to an Arduino. When the sensor is activated a green LED lights up and a tone is generated from a speaker. When the sensor is inactivated a red LED lights up.

int sensorVal;

void setup(){
//configure pin2 as an input and enable the internal pull-up resistor
pinMode(2, INPUT_PULLUP);

pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
pinMode(13, OUTPUT);
}

void loop(){

sensorVal = digitalRead(2);
// The Logic is inverted a low on pin 2 means a sinking switch is activated
// and a high on pin 2 means the switch is unactivated and pulled up by the internal resistor
// this is not a problem since the controller can interpret the data any way we tell it to

if (sensorVal == HIGH) {
digitalWrite(11, LOW);
digitalWrite(12, HIGH);
noTone(13);

}
else { //sensorVal = LOW
digitalWrite(11, HIGH);
digitalWrite(12, LOW);
tone(13,1000);
}
}

Check out out the following link to see how to connect an PNP sensor:

https://plus.google.com/u/0/photos/photo/104501828577578493064/6345557141306795602?icm=false&authkey=CNXdgJKLg4nYtQE

Hope this helps.

Dorian
Proximity Sensor Interfacing to an Arduino (sinking sensor)



Proximity Sensor Interfacing to an Arduino (sinking sensor)

47 Comments

Add a Comment

Alamat email Anda tidak akan dipublikasikan. Ruas yang wajib ditandai *