In this illustration we will going to wire the Infrared distance switch, a high-sensitive photoreflector to detect distance function, ranging from 3cm to 80cm. When the infrared emitted by the emitter it will get reflected on a surface blocked it then the phototransistor will pick up the signal for a distance calculation. This device has integrated with potentiometer to adjust the range for easy and clear to use. Best usage on this device is for robotics, interactive media, industrial and automotive, etc.
As you can see the diagram above the technology behind this effective distance sensor is the modulation from the infrared light, the receiver functionality is sense only if infrared light and only when it receives the correct signal. Therefore it is not very sensitive to ambient light compared to normal infrared detectors. Below are the wiring diagram for testing and how to use this device with Arduino MCU.
Device Characteristics
- Power Supply: 5VDC
- Supply current DC <25mA
- Maximum load current 100mA (Open-collector NPN pulldown output)
- Response time <2ms
- Diameter: 17MM
- Pointing angle: ≤ 15 °, effective from 3-80CM Adjustable
- Detection of objects: transparent or opaque
- Working environment temperature: -25℃+55℃
- Case Material: Plastic
- Lead Length: 45CM
Required Components
Arduino UNO/MEGA/MINI
E18-D80NK Infrared Distance Ranging Sensor
Solder-less Bread Board
Jumper Wire / DuPont Wire
Arduino Sketch Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 14CORE TEST CODE FOR E18-D80NK Infrared Distance Ranging Sensor %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */ void setup() { Serial.begin(9600); //Start serial communication boud rate at 9600 pinMode(5,INPUT); //Pin 5 as signal input } void loop() { while(1) { delay(500); if(digitalRead(5)==LOW) { // If no signal print collision detected Serial.println("Collision Detected."); } else { // If signal detected print collision detected Serial.println("No Collision Detected."); } } } |
obrigado pelo exemplo, pois o meu tem os fios de cor diferente, e voçe tem ai o esquema e código que procurava, Obrigado
Seu bem-vindo, você pode remover a condição while usando simplesmente se condição. :)
Hi, the 10K resistor in SERIES with the sensor output in the schematic, IS NOT a pullup resistor.
You need to remove it AND read your own Type1 and Type2 table information and see how to fit the proper pullup.
OR
You need to remove it and turn the pullup resistor on in the Arduino software.
Pin 5 is not D5 on most board, but GPIO5.
For record, Pin 5 = D1 on nodemcu
Did you mange make it work this sensor on nodemcu?
Yes, it works without issues.. :)