Skip to content

Technik Blog

Programmieren | Arduino | ESP32 | MicroPython | Python | Raspberry Pi | Raspberry Pi Pico

Menu
  • About me
  • Contact
  • Deutsch
  • English
Menu

Arduino Lesson #7 – Photoresistor

Posted on 4. November 202210. March 2024 by Stefan Draeger

In this post, I like to show, how to connect and code a Photoresistor at an analog pin on the Arduino.

Arduino Lesson #7 - Photoresistor
Arduino Lesson #7 – Photoresistor

You get the photoresistor as simple electronic part or pre soldered at a tiny pcb. I show you a circuit with both of them.

  • Buy a Photoresistor
  • Tiny circuit Photoresistor (LDR) at Arduino
    • Circuit with ready to use pcbs with LDR Sensor at Arduino
  • Coding a LDR Photoresistor at Arduino

Buy a Photoresistor

You can find and buy this tiny part, at many shops. The easiest way to get this is at ebay.de for only €3 with shipping cost* for 10 pieces.

Note from me: The links marked with an asterisk (*) are affiliate links. If you make a purchase through these links, I will receive a small commission to help support this blog. The price for you remains unchanged. Thank you for your support!

If you can wait for your delivery, you find some very cheap options at aliexpress.com, banggood.com or whis.com.

Tiny circuit Photoresistor (LDR) at Arduino

First, I like to show you a tiny circuit at Arduino with the simple electronic part. In addition to the LDR, you need a 10 kOhm resistor.

To rebuild the following circuit, you need a 5 mm LED with 220 Ohm Resistor. In the example for this circuit, I like to show how to control the LED brightness with an LDR, but more about that later.

tiny circuit - control LED brightness with LDR at Arduino Nano
tiny circuit – control LED brightness with LDR at Arduino Nano

Circuit with ready to use pcbs with LDR Sensor at Arduino

If you have a ready to use LDR Sensor module, you don’t need an extra 10 kOhm resistor. The circuit is smaller than before.

Arduino UNO - LDR Module with LED
Arduino UNO – LDR Module with LED

Coding a LDR Photoresistor at Arduino

The photoresistor device will be connected to an analog pin and you will receive values from 0 to 1023. In my case I receive values from 300 and 730 this is regarding to the photoresistor.

//LDR resistor at analog pin A0
#define ldr A0
//LED connected to PWM pin D3
#define led 3

//define MIN and MAX value
const int LDR_MAX = 730;
const int LDR_MIN = 320;

void setup() {
  //begin serial communication with 9600baud
  Serial.begin(9600);
  //define that led pin works as output
  pinMode(led, OUTPUT);
}

void loop() {
  //read actual analog value (between 0 and 1023)
  int value = analogRead(ldr);
  //print value to serial interface
  Serial.print("Photoresistor value:");
  Serial.println(value);
  //map value from MIN to MAX into PWM values
  int ledPwmValue = map(value, LDR_MIN, LDR_MAX, 255, 0);
  //write mapped value as PWM signal to LED
  analogWrite(led, ledPwmValue);
}

Here you can find a short Video at YouTube from me where I show how the code above will work.

control LED with LDR value at Arduino Nano V3
Watch this video on YouTube.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Fragen oder Feedback?

Du hast eine Idee, brauchst Hilfe oder möchtest Feedback loswerden?
Support-Ticket erstellen

Newsletter abonnieren

Bleib auf dem Laufenden: Erhalte regelmäßig Updates zu neuen Projekten, Tutorials und Tipps rund um Arduino, ESP32 und mehr – direkt in dein Postfach.

Jetzt Newsletter abonnieren

Unterstütze meinen Blog

Wenn dir meine Inhalte gefallen, freue ich mich über deine Unterstützung auf Tipeee.
So hilfst du mit, den Blog am Leben zu halten und neue Beiträge zu ermöglichen.

draeger-it.blog auf Tipeee unterstützen

Vielen Dank für deinen Support!
– Stefan Draeger

Categories

Links

Blogverzeichnis Bloggerei.de TopBlogs.de das Original - Blogverzeichnis | Blog Top Liste Blogverzeichnis trusted-blogs.com

Stefan Draeger
Königsberger Str. 13
38364 Schöningen

Tel.: 01778501273
E-Mail: info@draeger-it.blog

Folge mir auf

  • Impressum
  • Datenschutzerklärung
  • Disclaimer
  • Cookie-Richtlinie (EU)
©2025 Technik Blog | Built using WordPress and Responsive Blogily theme by Superb
Cookie-Zustimmung verwalten
Wir verwenden Cookies, um unsere Website und unseren Service zu optimieren.
Funktional Always active
Die technische Speicherung oder der Zugang ist unbedingt erforderlich für den rechtmäßigen Zweck, die Nutzung eines bestimmten Dienstes zu ermöglichen, der vom Teilnehmer oder Nutzer ausdrücklich gewünscht wird, oder für den alleinigen Zweck, die Übertragung einer Nachricht über ein elektronisches Kommunikationsnetz durchzuführen.
Vorlieben
Die technische Speicherung oder der Zugriff ist für den rechtmäßigen Zweck der Speicherung von Präferenzen erforderlich, die nicht vom Abonnenten oder Benutzer angefordert wurden.
Statistiken
Die technische Speicherung oder der Zugriff, der ausschließlich zu statistischen Zwecken erfolgt. Die technische Speicherung oder der Zugriff, der ausschließlich zu anonymen statistischen Zwecken verwendet wird. Ohne eine Vorladung, die freiwillige Zustimmung deines Internetdienstanbieters oder zusätzliche Aufzeichnungen von Dritten können die zu diesem Zweck gespeicherten oder abgerufenen Informationen allein in der Regel nicht dazu verwendet werden, dich zu identifizieren.
Marketing
Die technische Speicherung oder der Zugriff ist erforderlich, um Nutzerprofile zu erstellen, um Werbung zu versenden oder um den Nutzer auf einer Website oder über mehrere Websites hinweg zu ähnlichen Marketingzwecken zu verfolgen.
Manage options Manage services Manage {vendor_count} vendors Read more about these purposes
Einstellungen anzeigen
{title} {title} {title}