Because most of sensors used with arduino are made as shields, in these project we will use a wenglor HB03PBT7 sensor. These wenglor industrial sensor detect distance by measuring angles. The color, shape and surface characteristics of the object have practically no influence on sensor switching performance.
The most important characteristics are:
Range: 10-30mm
Supply voltage:10-30VDC
Type: PNP(NO)
Connection: M8x1; 4-pin
The full datasheet here.
In the images below we see the sensor in left and the connection diagram in the right:
Now in the connection diagram we have:
+ (10-30VDC); – (GND) and A(signal)
The 1 to 4 pins in the M8 connection cable respect the color code in here(1-brown; 2-white; 3-blue; 4-black)
To demonstrate how its works we will connect it to the arduino and when it detect an object the LED from pin 13 will switch on.
The voltage supply we use is 12VDC so between pin 1 and 3 we apply 12VDC. From pin 4 we receive a 12 VDC that arduino can’t support so we make a voltage divider to obtain around 4 volts(any voltage higher than 3volts are considered high level as you can see here).
In the image below is the voltage divider:
The program is very simple:
void setup() {
// initialize digital pin 13 as an output.
pinMode(13, OUTPUT);
pinMode(2,INPUT);
}
// the loop function runs over and over again forever
void loop() {
if (digitalRead(2)==HIGH){
digitalWrite(13, HIGH);
}
if (digitalRead(2)==LOW){
digitalWrite(13, LOW);
}
}
Please let us in the comment zone any suggestions that you think will improve the article!
If you like the article click the follow button from social media to stay in touch with us!
A short video is :