/esp32-ldr

A demo project that shows how to read a light dependent resistor (LDR) on ESP32 with MicroPython.

Primary LanguagePythonMIT LicenseMIT

Reading an LDR on ESP32 with MicroPython

This is a demo project that shows how to read a light dependent resistor (LDR) on ESP32 with MicroPython.

Check out this blog for details.

Components

  1. ESP32 development board
  2. A light dependent resistor (LDR)
  3. 10 KOhm resistor
  4. Breadboard
  5. Wires

Circuit

Circuit

Requirements

  1. esptool for flashing ESP32
  2. mpfshell for uploading files to ESP32
  3. minicom for connecting to ESP32 for debugging purposes

Uploading MicroPython and the code to ESP32

The steps below were tested only on Linux (Ubuntu 18 and 20). This may or may not work in other environments.

The directory scripts contains scripts that do the job.

Note that some ESP32 development boards require pressing the EN button while holding the Boot button for switching the board to the mode for erasing or uploading firmware.

First, erase the old firmware on the ESP32:

$ sh scripts/erase.sh

Next, upload MicroPython v1.13:

$ sh scripts/flash.sh
$ sh scripts/verify.sh

Then, upload the code to the board:

$ sh scripts/upload.sh

Finally, you can connect to the board with minicom and see the measured values of the LDR:

$ sh scripts/minicon.sh
value = 18.92552
value = 18.87668
value = 5.006105
value = 18.63248
...

Try covering the LDR with a hand or putting more light on it. See how the values change.

What it looks like

drawing