Arduino and photoelectric sensor

Hi guys,

I got a little question for you.. I'm trying to use an Arduino UNO for monitoring a couple of photoelectric sensors:

http://cdn.kempstoncontrols.com/files/1b834328a13d98eb3de9e191455eb767/FHDK%2010P5101/S35A.pdf

Those sensors are powered by an external power supply and I've connected the black cable to the arduino A0 analog input. I'm printing the sensor value read but even if there's something near to the sensor or not, the sensor value is the same..

Could you please explain me why??

This is the sketch:

int sensorPin = A0;  
int pinout = 8;
int sensorValue = 0;  

void setup() {

  Serial.begin(9600);
  pinMode(pinout, OUTPUT);
  
}

void loop() {

  sensorValue = analogRead(sensorPin);    
  
  Serial.println(sensorValue); 

  digitalWrite(pinout, HIGH);  
  delay(1000);
  
  digitalWrite(pinout, LOW);
}

Pin8 is linked to an external GPIO box linked to an RFID reader..

I need to connect several sensor to the Arduino UNO and then do a binary encode of the number of sensor activated for giving it to the GPIO box which can handle only 4 inputs.

You will also need to connect the ground (blue) wire to your arduino ground and it looks like the signal returned is digital HIGH/LOW (light/dark) and not analogue. The threshold of where the sensor switches on the light level is usually controlled by a small potentiometer on the sensor.

I've connected the ground to the Arduino but the sensor doesn't work.. Maybe you have to know that this is the external power supply..

https://mall.industry.siemens.com/mall/catalog/products/10073753?tree=CatalogTree&activeTab=order#activetab=order&

I also changed the sketch for the digital input..

int sensorPin = 7;  
int pinout = 8;
int sensorValue = LOW;  

void setup() {

  Serial.begin(9600);
  pinMode(pinout, OUTPUT);
  
}

void loop() {

  sensorValue = digitalRead(sensorPin);  
  
  Serial.println(sensorValue); 
  
  if (sensorValue != LOW)
  {
    digitalWrite(pinout, HIGH);
  }
  
  else
  {
    digitalWrite(pinout, LOW);
  }

  delay(500);

}

MrBartowski: I've connected the ground to the Arduino but the sensor doesn't work.. Maybe you have to know that this is the external power supply.

Usually these sensors have relays in and you can hear them click over from one state to the other as the sensor is uncovered/covered. Does it have a small adjustment pot on it to alter the threshold level? As long as it's only the ground your sharing with arduino you should be fine. Don't connect the 24V DC to arduino.

I’ve solved the problem connecting also the source of the sensor to the Arduino 5V power pin. Now it works but I’m wondering why does it work. Sensor datasheet says that voltage supply should be 10…30VDC

Could you please explain me this?

MrBartowski: I've solved the problem connecting also the source of the sensor to the Arduino 5V power pin. Now it works but I'm wondering why does it work. Sensor datasheet says that voltage supply should be 10...30VDC

Could you please explain me this?

You will need to explain, draw or take picture of how you have it connected up. What colour is the 'source of the sensor' wire? I think you should have either the white or black wire connected to a digital pin with internal pullup resistor turned on and the blue wire connected to arduino ground.

The colour of the 'source of the sensor wire' is brown. The colour of the 'ground of the sensor wire' is blue. The colour of the 'control of the sensor wire' is black.

I've connected wires like this:

  • the brown one to the 5V power supply of the Arduino;
  • the blu one to the GND of the Arduino;
  • the black one to the digital pin (n° 6);

Thanks for your support!

MrBartowski: - the brown one to the 5V power supply of the Arduino;

So the arduino is supplying 5V to power the sensor? Be sure the sensor does not draw to many amps for the 5V arduino supply.

hi
please, you can try this scheme

baumer sensor.pdf (11.6 KB)

Hi Riva, thanks for your advice:

So the arduino is supplying 5V to power the sensor? Be sure the sensor does not draw to many amps for the 5V arduino supply.

but .. what do you mean with "Be sure the sensor does not draw to many amps for the 5V arduino supply"? How can I do that?

and for stefa24.. I don't understand why I have to put a 10K resistor between the power supply and the power input of the sensor.. and I have another question.. Is it the same if I put a 333 resistor instead of the 500 resistor you suggested to link the black wire?

Thank you so much guys!

MrBartowski: Hi Riva, thanks for your advice:

but .. what do you mean with "Be sure the sensor does not draw to many amps for the 5V arduino supply"? How can I do that?

From what you had written I thought you might be using the 5V pin on the arduino to power the sensor and this pin has a limit on how many mA it can supply, so be sure the sensor does not draw more than the pin should supply.