HowTo: ESPEasy – Connect and read LDR to Wemos D1 Mini

Es gibt einige Situationen in denen der Anschluss eines LDRs an einen ESP Sinn macht. So lässt sich nämlich relativ leicht und für wenig Geld die Helligkeit in einem Raum erfassen.

Dieser Wert kann dann zum Beispiel genutzt werden um eine Anwesenheit zu detektieren (Hat jemand das Licht eingeschaltet obwohl ich gar nicht zuhause bin?) oder um der Helligkeit entsprechend eine Display-Helligkeit einzustellen (siehe zum Beispiel: pxlBlck – Automatische Einstellung der Displayhelligkeit via LDR).

Wie Ihr einen LDR an einen ESP8266 anschließt und mit ESPEasy auslesen könnt, ist diesem Artikel beschrieben.


Safety instructions

I know the following notes are always kind of annoying and seem unnecessary. Unfortunately, many people who knew "better" have lost eyes, fingers or other things due to carelessness or injured themselves. Data loss is almost negligible in comparison, but even these can be really annoying. Therefore, please take five minutes to read the safety instructions. Because even the coolest project is not worth injury or other trouble.
https://www.nerdiy.de/sicherheitshinweise/

Affiliate links/advertising links

The links to online shops listed here are so-called affiliate links. If you click on such an affiliate link and make a purchase via this link, Nerdiy.de will receive a commission from the relevant online shop or provider. The price does not change for you. If you make your purchases via these links, you support Nerdiy.de in being able to offer other useful projects in the future. 🙂 


Requirements

For the assembly you have to master soldering tasks. The following articles contain tips on this.

Required tool:

Required material:

In the following list you will find all the parts you need for the assembly.


Connect an LDR to the ESP8266

Damit der ESP8266 die Umgebungshelligkeit mithilfe des LDRs messen kann, müsst Ihr natürlich erstmal einen LDR anschließen. Ein LDR ist ein Lichtabhängiger Widerstand, dessen Widerstand von der Umgebungshelligkeit bzw. dem Licht das auf den LDR trifft abhängig ist.

If the brightness changes, the resistance of the LDR also changes. If the LDR is connected to the ESP8266 via a voltage divider, this resistance and thus the brightness can be measured indirectly using the ADC.

Den grundsätzlichen Schaltplan zum Anschluss eines LDRs an einen ESP8266 könnt auf dem folgenden Schaltplan sehen.

Basically, an LDR is connected to an ESP8266 according to the following circuit diagram.

Weitere Beispiele findet Ihr in den folgenden Artikeln zu den verschiedenen pxlBlck platforms.


LDR an einen Wemos D1 Mini anschließen

Die folgende Anleitung zeigt wie Ihr sehr platzsparend einen LDR an einen Wemos D1 Mini anschließen könnt. Die Anleitung ist ein Auszug aus dem Aufbau Artikel zur pxlBlck - build pxlBlck_RingClock.

Dazu benötigt Ihr einen LDR und einen “normalen” (1/W) 1k Widerstand.

Außerdem ist etwas Schrumpfschlauch (nicht auf dem Bild zu sehen) sehr hilfreich.

Lötet den 1k Widerstand dann wie abgebildet an die gezeigten Kontakte des Wemos D1 MIni.

So wird der Widerstand zwischen GND und dem Eingang des ADCs verlötet. Er funktioniert so als Serienwiderstand zum LDR und bildet in Kombination mit dem LDR einen Spannungsteiler.

Nahaufnahme des verlöteten Widerstands.

Nahaufnahme des verlöteten Widerstands.

Den LDR müsst Ihr nun zwischen den Kontakten des Analog Digital Converters und 3V3 verlöten.

Dazu solltet Ihr mindestens einen der LDR-Kontakte mit einem Schrumpfschlauch gegen Kurzschlüsse schützen.

Der LDR selbst sollte dann ca. 5mm über das Ende der Platine des Wemos D1 Mini hinaus ragen.

Weitere Ansicht des verbauten LDRs.


Configure the ADC of the ESP8266

Damit die Helligkeitswerte des angeschlossenen LDR’s eingelesen werden können müsst Ihr zunächst den Analog digital Converter des ESP8266 konfigurieren. Dank ESPEasy ist dies aber schnell erledigt.

To do this, go to the web interface of your ESPEasy device. To do this, enter the IP address of the device in the address line of your browser.

How to find out the IP address of devices in your network is also described in the article Display/find out the IP address of the devices in the network described.

Wechselt dann in den Bereich “Devices”.

All configured devices are now listed in the table shown.

Klickt nun auf den “Edit” Button in der ersten leeren Zeile.

You will be redirected to a page where you can configure a device.

To configure the Analog to Digital Converter you have to add the entry

Analog input – external

select

Nun solltet Ihr das das Device “Analog input – external” so konfigurieren wie im Bild links angegeben.

Die Einstellungen müsst Ihr dann noch mit einem Klick auf “Submit” bestätigen.


LDR Wert auf anderen Zielbereich skalieren

In den Einstellungen des “Analog Input – internal”-device ist noch eine andere praktische Einstellungsmöglichkeit enthalten.

Ohne weitere Konfiguration wird Euch der ADC-Wert (also ein Wert zwischen 0 und 1023) angezeigt. Falls Ihr den Wert des LDRs bzw. dessen gemessen Helligkeit lieber in einem anderen Bereich konvertieren wollt, könnt Ihr dies hier einstellen.

Dazu habt Ihr in der links dargestellten 2×2 Tabelle die Möglichkeit für zwei Punkte die entsprechenden Werte zu konfigurieren.

Ich habe in diesem Fall (durch ausprobieren) herausgefunden, dass mein LDR bei der höchsten Helligkeit im Raum den Wert 400 hat. Die Helligkeit soll nun in den Bereich 0 bis 10 umgerechnet werden.

Dazu müsst Ihr die Optionen in der Sektion “Point 1” und “Point 2” entsprechend wie im Bild angegeben konfigurieren.


Have fun with the project

I hope everything worked as described for you. If not or you have questions or suggestions please let me know in the comments. I will then add this to the article if necessary.
Ideas for new projects are always welcome. 🙂

PS Many of these projects - especially the hardware projects - cost a lot of time and money. Of course I do this because I enjoy it, but if you think it's cool that I share the information with you, I would be happy about a small donation to the coffee fund. 🙂

Buy Me a Coffee at ko-fi.com       

4 comments

  1. Hello Fab,

    Can I also switch the resistor directly to GND (as shown on your Fritzing diagram) or does it have another influence?

    Thanks,
    Greeting Stefan

    1. Hey Stefan,
      yes of course, that works too. Is electrically exactly the same. 🙂
      The contact to which the resistor is soldered in the pictures also corresponds to ground or GND. The component shown is one of the support/smoothing capacitors.
      In that case, I chose that location only because it was the physically most distant ground contact.
      If it suits you better, you can also choose one of the other ground/GND contacts.

      Good luck and best regards
      Fab

  2. Hello Fab,
    ich würde diese Schaltung gern nehmen, um meinen Stromverbrauch am Stromzähler zu messen. Mein Stromzähler verfügt lediglich über eine rote LED (keine IR), die 1000 pro 1kw/h blinkt. Ist der LDR und der AD Wandler des D1 Minis deiner Meinung nach schnell genug für diesen Anwendungsfall?

    Best regards
    cpauls

    1. Hi cpauls,
      gute Frage. Das hängt davon ab wie lange die LED blink bzw. aufleuchtet. Hattest du die Zeit mal gemessen? 🙂
      Best regards
      Fabian

Kommentar hinterlassen

Your email address will not be published. Erforderliche Felder sind mit * markiert


The reCAPTCHA verification period has expired. Please reload the page.