Distance measurement using Raspberry Pi and sensor E18-D80NK

The sensor enables distance measurement. It works in a digital way, i.e. it sends out the so-called zeros and ones depending on whether the object has been detected or not. The sensitivity is adjusted by means of a knob in the module housing.

We will need the following elements:

Connection with Raspberry Pi

The two devices shall be combined as shown in the table below

GPIO Raspberry Pi Sensor E18-D80NK
5 V Red or brownwire
GND Green or bluewire

1

Yellow or blackwire

Diagram of connection between E18-D80NK and Raspberry Pi.

Support

To use the GPIO pins in Raspberry we need a library that allows us to do so. For this we will use the wiringPi library. Description how to download and install it can be found here. Just copy the next commands. Finally, to check the installation:

  • gpio readall

After this command we should see the table below:

Now we will write a simple program. Create an e18_d80.cpp file

  • nano e18_d80.cpp

The file should contain the following program:

#include 
#include  
using namespace std; 

Int sensor = 1; //pin GPIO1 Raspberry connected to sensor output

int main(void)
{
  wiringPiSetup();

  pinMode(sensor, INPUT); // setting pin 2 in Raspberry as output
  cout<

Then save the changes to the file and close it. To compile the created file we use the command:

  • g++ -Wall -o e18_d80.oe18_d80.cpp -lwiringPi

The program is started with the following command:

  • sudo ./e18_d80.o

The result of the program can be viewed on the monitor:

Screenshot of the monitor.

Botland.store - shop for makers!