Arduino Code and Video for the E18-D80NK Infrared Obstacle Avoidance Sensor

Arduino Code and Video for the E18-D80NK Infrared Obstacle Avoidance Sensor

In this tutorial, we will learn how to use the E18-D80NK infrared obstacle avoidance sensor with Arduino to detect obstacles and trigger actions, such as turning on an LED or activating a relay. The project will demonstrate how to read the sensor's output and respond accordingly. By the end of this tutorial, you will have a working setup that can detect obstacles and activate outputs based on that detection.

Be sure to watch the associated video for a clearer understanding of the wiring and code implementation (in video at 00:00).

Hardware Explained

The E18-D80NK infrared obstacle avoidance sensor is designed to detect nearby objects using infrared light. It emits infrared rays and detects the reflection from obstacles. When an object is detected within a certain range, the sensor outputs a low signal, which can be read by an Arduino.

This sensor has three main pins: a power pin (usually brown), ground (blue), and a signal pin (black). The signal pin is connected to a digital input on the Arduino to read the obstacle detection status. The output can then control various devices like motors or relays based on the sensor's readings.

Datasheet Details

ManufacturerShenzhen Eighteen Electronics
Part numberE18-D80NK
Logic/IO voltage3.3 V to 5 V
Supply voltage5 V
Output current (per channel)20 mA
Peak current (per channel)200 mA
Detection range2 cm to 30 cm
Output typeDigital
PackageModule

  • Ensure correct wiring to prevent damage to the module.
  • Use a pull-up resistor on the signal line for stable readings.
  • Keep the sensor clean and free from obstructions for accurate detection.
  • Test the sensor range in your specific environment.
  • Be cautious of the power ratings when connecting to relays or motors.

Wiring Instructions

E18-D80NK Infrared Sensor: Wiring with a resistor
E18-D80NK Infrared Sensor: Wiring with resistor — E18-D80NK Infrared Sensor: Wiring with a resistor

To wire the E18-D80NK sensor to the Arduino, start by connecting the brown wire to the 5V pin on the Arduino for power. Next, connect the blue wire to the GND pin to complete the power circuit. Then, take the black wire and connect it to digital pin 2 on the Arduino for signal input.

E18-D80NK infrared sensor: sensitivity screw

If you are using a relay, connect the relay's control pin (usually to pin 9) to the Arduino to control the output based on the sensor's readings. Make sure the relay is properly powered and connected to the AC device you want to control. It is crucial to follow safety precautions when working with AC power.

Code Examples & Walkthrough

The following code demonstrates how to read the sensor's output and control an action based on the detection of an obstacle. The sensor output is read using the SENSOR identifier defined as pin 2, and the action pin is defined as pin 9.

#define SENSOR 2 // define pin 2 for sensor
#define ACTION 9 // define pin 9 as for ACTION

void setup() {
  Serial.begin(9600); // setup Serial Monitor to display information
  pinMode(SENSOR, INPUT_PULLUP); // define pin as Input sensor
  pinMode(ACTION, OUTPUT); // define pin as OUTPUT for ACTION
}

In this excerpt, we set up the serial communication and configure the sensor pin as an input with a pull-up resistor, while the action pin is set as an output. This configuration is essential for reading the sensor and controlling the relay or other devices.

void loop() {
  int L = digitalRead(SENSOR); // read the sensor
  if (L == 0) {
    Serial.println("Obstacle detected");
    digitalWrite(ACTION, HIGH); // send signal
  } else {
    Serial.println("=== All clear");
    digitalWrite(ACTION, LOW); // turn the relay OFF
  }
  delay(500);
}

This part of the code continuously checks the sensor's output. If an obstacle is detected (when L is 0), it sends a HIGH signal to the action pin, which can activate a relay or other components. If no obstacle is detected, it sends a LOW signal, turning off the device.

Demonstration / What to Expect

When you set up the circuit and upload the code, the sensor will continuously monitor for obstacles. If an object comes within the detection range, you should see a message on the serial monitor indicating that an obstacle has been detected, and the connected device will activate. If the path is clear, it will print a message saying "All clear". Make sure to adjust the delay in the loop if you notice any missed detections or unwanted triggers (in video at 00:00).

Video Timestamps

  • 00:00 - Introduction to the project
  • 01:30 - Hardware overview
  • 03:15 - Wiring instructions
  • 05:00 - Code walkthrough
  • 06:45 - Demonstration of the setup

Images

E18-D80NK infrared sensor: connected to Arduino and buzzer
E18-D80NK Infrared Sensor: Connected to Arduino and buzzer
E18-D80NK Infrared Sensor
E18-D80NK Infrared Sensor: Sensor
E18-D80NK Infrared Sensor: TX RX lenses
E18-D80NK Infrared Sensor: TX RX leses
E18-D80NK infrared sensor: sensitivity screw
E18-D80NK Infrared Sensor: Sensitivity screw
E18-D80NK Infrared Sensor: Wiring colors
E18-D80NK Infrared Sensor: Wiring color
E18-D80NK Infrared Sensor: Wiring with a resistor
E18-D80NK Infrared Sensor: Wiring with resistor
E18-D80NK Infrared Sensor: Setting Sensitivity
E18-D80NK Infrared Sensor: Setting Sensitivity
E18-D80NK Infrared Sensor: Demonstration using Arduino
E18-D80NK Infrared Sensor:Demonstration using Arduino
e18-d80nk-infrared-sensor-without-connector-3-80cm
e18-d80nk-infrared-sensor-without-connector-3-80cm
78-Arduino code for the LE18-D80NK infrared obstacle avoidance sensor
Language: C++
Copied!

Things you might need

Resources & references

Files📁

No files available.