If you're looking to learn Arduino&LVGL, you'll find a whole new world of possibilities for creating innovative projects. In this article, we'll explore the exciting realm of laser rangefinder using Arduino&LVGL. By following these steps, you'll not only gain a better understanding of Arduino&LVGL but also have a functional laser rangefinder of your own.

We made a testing video here :

Hardware:

 

Assembly Guide:

Step 1: Connecting Matouch -1.9’ display to the breadboard;

Step 2:Connect the Laser Ranging Sensor and the Matouch 1.9" display in the breadboard with jumper cables;

Please note:

  • Red wire:Power,connect to Matouch-1.9’display 5V
  • Green wire:RX to Matouch-1.9’display IO3
  • White wire:TX to Matouch-1.9’display IO1
  • Black wire:GND to Matouch-1.9’display GND

 

Coding Guide:

1. Create a new project in LVGL;

2. Add buttons and label on screen;

3. Add button event;

4. Change the color to your liking

5. According to your preferences in the "ADD FILE ASSETS" to add your favorite pictures, set your screen background;

6. Set the location of the export code and Export UI files and Create Template Project;

7.After exporting, copy lvgl_conf.h to the src folder in the lvgl folder

8. Open ui_event.c in the LaserRanging\libraries\ui\src file of the exported project document, add the key event code and save;

extern int work_flag;
void open_func(lv_event_t *e)
{
	// Your code here
	lv_obj_add_state(ui_Button1, LV_STATE_DISABLED);
	lv_obj_clear_state(ui_Button3, LV_STATE_DISABLED);
	work_flag = 1;
}

void close_func(lv_event_t *e)
{
	// Your code here
	lv_obj_add_state(ui_Button3, LV_STATE_DISABLED);
	lv_obj_clear_state(ui_Button1, LV_STATE_DISABLED); 
	work_flag = 0;
}

9. Copy the four files to the arduino libraries, usually in the form of (C)/Users/Document/arduino/libraries;

10. Open ui.ino through the Arduino IDE to add your code (note that the Arduino esp32 board should be 2.0.17 and its previous version, we used 2.0.11 version), the code of leaser range can be refer to github ;

11. Modify your code, use the Type-C USB cable to connect the board to the PC, select the development board "ESP32S3 Dev Module" and its port;

12. Click Upload code;

 

Result

As you can see in the picture above, this device works great.This handy little device can test the distance up to 20m and has an accuracy of 3cm. If you're interested, we've got a great tutorial that'll show you how to make your own laser rangefinder.