{"id":52281,"date":"2026-11-01T10:50:50","date_gmt":"2026-11-01T10:50:50","guid":{"rendered":"http:\/\/siratek.net\/index.php\/tutorials\/ldr-light-sensor\/"},"modified":"2026-11-01T10:50:50","modified_gmt":"2026-11-01T10:50:50","slug":"ldr-light-sensor","status":"publish","type":"siratek_tutorial","link":"https:\/\/siratek.net\/index.php\/tutorials\/ldr-light-sensor\/","title":{"rendered":"Measuring Light with an LDR"},"content":{"rendered":"<body><p><\/p>\n<h2>What it does<\/h2>\n<p>A light-dependent resistor is a resistor whose value falls as light falls on it. In the dark it might be hundreds of kilohms; in bright light, a few hundred ohms.<\/p>\n<p>That is the whole part. It has no electronics, no output pin and no polarity, and it does not produce a voltage on its own. Which raises the question this tutorial really answers: an Arduino measures voltage, so how do you read a resistance?<\/p>\n<p>The technique is the same one the potentiometer used, and once you have it you can read a thermistor, a soil moisture probe, a force-sensing resistor and half a dozen other parts that work the same way.<\/p>\n<h2>Before you begin<\/h2>\n<h3>Required parts and tools<\/h3>\n<ul>\n<li>An Arduino Uno or compatible board.<\/li>\n<li>One LDR. The Siratek part is a bare two-legged photoresistor, not a module.<\/li>\n<li>One 10 kilohm resistor. This is required, not optional.<\/li>\n<li>A breadboard and three jumper wires.<\/li>\n<\/ul>\n<h3>Why you need the fixed resistor<\/h3>\n<p>An analog pin measures voltage. The LDR changes resistance. On its own, a changing resistance produces no voltage for the pin to read.<\/p>\n<p>Pairing it with a fixed resistor makes a <strong>voltage divider<\/strong>: the two share the 5 V between them, in proportion to their resistances, and the point between them moves as the light changes. That junction is what you connect to <code>A0<\/code>.<\/p>\n<p>With the LDR on the 5 V side and the fixed resistor to ground:<\/p>\n<ul>\n<li><strong>Bright light:<\/strong> LDR resistance is low, so it drops little, and the junction sits high. The reading rises.<\/li>\n<li><strong>Darkness:<\/strong> LDR resistance is high, so it drops most of the 5 V, and the junction falls. The reading drops.<\/li>\n<\/ul>\n<p>Swap the two components and the relationship inverts. Neither is wrong; just know which you built.<\/p>\n<p>Without the fixed resistor, <code>A0<\/code> is connected to 5 V through the LDR and to nothing else. It will read near maximum whatever the light does, which looks exactly like a broken sensor.<\/p>\n<h3>Choosing the fixed resistor<\/h3>\n<p>10 kilohms is the usual choice and works for ordinary indoor light. The divider is most sensitive when the fixed resistor is near the LDR\u2019s resistance in the conditions you care about, so for detecting <em>darkness<\/em> a larger value gives more useful spread, and for bright sunlight a smaller one does.<\/p>\n<p>Start at 10 k. Change it only if your readings bunch up at one end of the range.<\/p>\n<h3>It is not a light meter<\/h3>\n<p>An LDR gives you <em>more light<\/em> and <em>less light<\/em>, not lux. Readings vary between individual parts, with temperature, and with how the component is angled. Anything you build should compare against a threshold you measured in place, never against a number copied from a tutorial, including this one.<\/p>\n<h2>Pin reference<\/h2>\n<table>\n<thead>\n<tr>\n<th>Pin or label<\/th>\n<th>Connect to<\/th>\n<th>Purpose<\/th>\n<th>Notes<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>LDR, either leg<\/td>\n<td>Uno <code>5V<\/code><\/td>\n<td>Top of the divider<\/td>\n<td>An LDR has no polarity<\/td>\n<\/tr>\n<tr>\n<td>LDR, other leg<\/td>\n<td>The junction, and <code>A0<\/code><\/td>\n<td>The point that moves<\/td>\n<td>Also goes to the fixed resistor<\/td>\n<\/tr>\n<tr>\n<td>10 k resistor, one end<\/td>\n<td>The junction<\/td>\n<td>Bottom of the divider<\/td>\n<td>Same row as the LDR\u2019s lower leg<\/td>\n<\/tr>\n<tr>\n<td>10 k resistor, other end<\/td>\n<td>Uno <code>GND<\/code><\/td>\n<td>Return path<\/td>\n<td><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<figure class=\"siratek-tutorial-figure\"><img decoding=\"async\" src=\"http:\/\/siratek.net\/wp-content\/uploads\/2026\/11\/ldr-light-sensor-divider.svg\" alt=\"An LDR and a 10 kilohm resistor in series between 5V and ground, with the junction between them wired to A0\" loading=\"lazy\"><figcaption>The fixed resistor is what turns a changing resistance into a changing voltage.<\/figcaption><\/figure>\n<h2>Wiring steps<\/h2>\n<ol>\n<li>Unplug the USB cable.<\/li>\n<li>Put the LDR across two breadboard rows. Either way round is fine.<\/li>\n<li>Run a wire from one LDR leg to <code>5V<\/code>.<\/li>\n<li>Put one end of the 10 k resistor in the same row as the LDR\u2019s other leg. This shared row is the junction.<\/li>\n<li>Run the resistor\u2019s other end to <code>GND<\/code>.<\/li>\n<li>Run a wire from the junction row to <code>A0<\/code>.<\/li>\n<li>Check that the junction row really has three things in it: the LDR leg, the resistor leg and the wire to <code>A0<\/code>. If <code>A0<\/code> is anywhere else, the reading will not move.<\/li>\n<li>Plug the USB cable back in.<\/li>\n<\/ol>\n<h2>Software and libraries<\/h2>\n<p>No library is required. <code>analogRead()<\/code> is part of the Arduino core.<\/p>\n<h2>Minimal working example<\/h2>\n<pre><code>\/\/ Siratek: reading an LDR through a voltage divider.\n\nconst int ldrPin = A0;\n\nvoid setup() {\n  Serial.begin(9600);\n  Serial.println(\"Siratek: cover the sensor and watch the reading.\");\n}\n\nvoid loop() {\n  int reading = analogRead(ldrPin);\n\n  Serial.print(\"light = \");\n  Serial.println(reading);\n\n  delay(200);\n}<\/code><\/pre>\n<p>Run this first and do two things: cup your hand over the LDR, and shine a phone torch on it. Write down the two numbers. Those are the real limits in your room, and every threshold you choose should sit between them.<\/p>\n<h3>A light that comes on in the dark<\/h3>\n<pre><code>\/\/ Siratek: switching an LED on when the light falls below a threshold.\n\nconst int ldrPin = A0;\nconst int ledPin = 9;\n\n\/\/ Measure your own. This is the midpoint between covered and lit, in your room.\nconst int darkBelow = 400;\n\nvoid setup() {\n  pinMode(ledPin, OUTPUT);\n  Serial.begin(9600);\n}\n\nvoid loop() {\n  int reading = analogRead(ldrPin);\n  bool dark = reading &lt; darkBelow;\n\n  digitalWrite(ledPin, dark ? HIGH : LOW);\n\n  Serial.print(\"light = \");\n  Serial.print(reading);\n  Serial.println(dark ? \"  dark\" : \"  lit\");\n\n  delay(200);\n}<\/code><\/pre>\n<p>Right on the threshold this will flicker, switching on and off as the reading wavers by a count or two. The fix is to use two thresholds rather than one: switch on below 380 and off above 420, so the reading has to move meaningfully before anything changes. That gap is called hysteresis, and it is worth adding to anything that drives a relay or a light.<\/p>\n<h2>Expected result<\/h2>\n<p>A reading between 0 and 1023 that rises in bright light and falls when covered, with the wiring above.<\/p>\n<p>Typical indoor values might run from a few dozen covered to the high hundreds under a lamp, but do not treat those as targets. What matters is that your own numbers move a long way between covered and lit. A reading that barely shifts means the divider is wrong, not that the room is evenly lit.<\/p>\n<p>The value also wavers by a count or two when nothing changes. That is genuine measurement noise, and averaging eight readings smooths it, exactly as in the potentiometer tutorial.<\/p>\n<h2>Troubleshooting<\/h2>\n<table>\n<thead>\n<tr>\n<th>Symptom<\/th>\n<th>Likely cause<\/th>\n<th>Check or fix<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Always near 1023<\/td>\n<td>Fixed resistor missing<\/td>\n<td>Fit the 10 k from the junction to <code>GND<\/code><\/td>\n<\/tr>\n<tr>\n<td>Always near 0<\/td>\n<td><code>5V<\/code> not connected, or LDR open<\/td>\n<td>Check the top of the divider<\/td>\n<\/tr>\n<tr>\n<td>Reading never moves<\/td>\n<td><code>A0<\/code> not on the junction row<\/td>\n<td>It must share a row with both components<\/td>\n<\/tr>\n<tr>\n<td>Reading moves the wrong way<\/td>\n<td>LDR and resistor swapped<\/td>\n<td>Expected; swap them or invert the test<\/td>\n<\/tr>\n<tr>\n<td>Only a small range<\/td>\n<td>Fixed resistor far from the LDR\u2019s range<\/td>\n<td>Try 4.7 k in bright light, 47 k for darkness<\/td>\n<\/tr>\n<tr>\n<td>Flickers at the threshold<\/td>\n<td>Single threshold<\/td>\n<td>Use two, with a gap between them<\/td>\n<\/tr>\n<tr>\n<td>Jumps around constantly<\/td>\n<td>Loose leg, or mains flicker nearby<\/td>\n<td>Reseat, then average several readings<\/td>\n<\/tr>\n<tr>\n<td>Different from a friend\u2019s board<\/td>\n<td>Parts vary a great deal<\/td>\n<td>Normal; always measure your own thresholds<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>Next steps<\/h2>\n<ul>\n<li><strong>Easier first:<\/strong> <em>Read a Potentiometer<\/em>, which is the same divider with a knob instead of light.<\/li>\n<li><strong>Related products:<\/strong> the DHT11 for temperature and humidity, or the flame sensor, which uses this same arrangement with an infrared-sensitive part.<\/li>\n<li><strong>Next project:<\/strong> a night light that fades up as the room darkens, using PWM rather than a simple on and off.<\/li>\n<\/ul>\n<h2>Sources and attribution<\/h2>\n<p>All text, wiring guidance and code in this tutorial are original Siratek work.<\/p>\n<ul>\n<li>Arduino core documentation for <code>analogRead()<\/code>.<\/li>\n<\/ul>\n<p>LDR resistance ranges vary widely between parts and are given here as rough orders of magnitude. Every threshold in this tutorial is presented as something the reader must measure rather than copy. No third-party tutorial text, diagrams, photographs or code has been reproduced here.<\/p>\n<p><\/p>\n<\/body>","protected":false},"excerpt":{"rendered":"<p>A light-dependent resistor is a resistor whose value falls as light falls on it. In the dark it might be hundreds of kilohms; in bright light, a few hundred ohms.<\/p>\n","protected":false},"featured_media":0,"template":"","siratek_tutorial_level":[],"class_list":["post-52281","siratek_tutorial","type-siratek_tutorial","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Measuring Light with an LDR - siratek<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"http:\/\/siratek.net\/index.php\/tutorials\/ldr-light-sensor\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Measuring Light with an LDR - siratek\" \/>\n<meta property=\"og:description\" content=\"A light-dependent resistor is a resistor whose value falls as light falls on it. In the dark it might be hundreds of kilohms; in bright light, a few hundred ohms.\" \/>\n<meta property=\"og:url\" content=\"http:\/\/siratek.net\/index.php\/tutorials\/ldr-light-sensor\/\" \/>\n<meta property=\"og:site_name\" content=\"siratek\" \/>\n<meta property=\"og:image\" content=\"http:\/\/siratek.net\/wp-content\/uploads\/2026\/11\/ldr-light-sensor-divider.svg\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"http:\\\/\\\/siratek.net\\\/index.php\\\/tutorials\\\/ldr-light-sensor\\\/\",\"url\":\"http:\\\/\\\/siratek.net\\\/index.php\\\/tutorials\\\/ldr-light-sensor\\\/\",\"name\":\"Measuring Light with an LDR - siratek\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/siratek.net\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"http:\\\/\\\/siratek.net\\\/index.php\\\/tutorials\\\/ldr-light-sensor\\\/#primaryimage\"},\"image\":{\"@id\":\"http:\\\/\\\/siratek.net\\\/index.php\\\/tutorials\\\/ldr-light-sensor\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/siratek.net\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/ldr-light-sensor-divider.svg\",\"datePublished\":\"2026-11-01T10:50:50+00:00\",\"breadcrumb\":{\"@id\":\"http:\\\/\\\/siratek.net\\\/index.php\\\/tutorials\\\/ldr-light-sensor\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\\\/\\\/siratek.net\\\/index.php\\\/tutorials\\\/ldr-light-sensor\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\\\/\\\/siratek.net\\\/index.php\\\/tutorials\\\/ldr-light-sensor\\\/#primaryimage\",\"url\":\"https:\\\/\\\/siratek.net\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/ldr-light-sensor-divider.svg\",\"contentUrl\":\"https:\\\/\\\/siratek.net\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/ldr-light-sensor-divider.svg\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\\\/\\\/siratek.net\\\/index.php\\\/tutorials\\\/ldr-light-sensor\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/siratek.net\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Tutorials\",\"item\":\"https:\\\/\\\/siratek.net\\\/index.php\\\/tutorials\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Measuring Light with an LDR\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/siratek.net\\\/#website\",\"url\":\"https:\\\/\\\/siratek.net\\\/\",\"name\":\"siratek\",\"description\":\"Your Best Electronic Retail Shop\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/siratek.net\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Measuring Light with an LDR - siratek","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"http:\/\/siratek.net\/index.php\/tutorials\/ldr-light-sensor\/","og_locale":"en_US","og_type":"article","og_title":"Measuring Light with an LDR - siratek","og_description":"A light-dependent resistor is a resistor whose value falls as light falls on it. In the dark it might be hundreds of kilohms; in bright light, a few hundred ohms.","og_url":"http:\/\/siratek.net\/index.php\/tutorials\/ldr-light-sensor\/","og_site_name":"siratek","og_image":[{"url":"http:\/\/siratek.net\/wp-content\/uploads\/2026\/11\/ldr-light-sensor-divider.svg","type":"","width":"","height":""}],"twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"http:\/\/siratek.net\/index.php\/tutorials\/ldr-light-sensor\/","url":"http:\/\/siratek.net\/index.php\/tutorials\/ldr-light-sensor\/","name":"Measuring Light with an LDR - siratek","isPartOf":{"@id":"https:\/\/siratek.net\/#website"},"primaryImageOfPage":{"@id":"http:\/\/siratek.net\/index.php\/tutorials\/ldr-light-sensor\/#primaryimage"},"image":{"@id":"http:\/\/siratek.net\/index.php\/tutorials\/ldr-light-sensor\/#primaryimage"},"thumbnailUrl":"http:\/\/siratek.net\/wp-content\/uploads\/2026\/11\/ldr-light-sensor-divider.svg","datePublished":"2026-11-01T10:50:50+00:00","breadcrumb":{"@id":"http:\/\/siratek.net\/index.php\/tutorials\/ldr-light-sensor\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/siratek.net\/index.php\/tutorials\/ldr-light-sensor\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/siratek.net\/index.php\/tutorials\/ldr-light-sensor\/#primaryimage","url":"https:\/\/siratek.net\/wp-content\/uploads\/2026\/11\/ldr-light-sensor-divider.svg","contentUrl":"https:\/\/siratek.net\/wp-content\/uploads\/2026\/11\/ldr-light-sensor-divider.svg"},{"@type":"BreadcrumbList","@id":"http:\/\/siratek.net\/index.php\/tutorials\/ldr-light-sensor\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/siratek.net\/"},{"@type":"ListItem","position":2,"name":"Tutorials","item":"https:\/\/siratek.net\/index.php\/tutorials\/"},{"@type":"ListItem","position":3,"name":"Measuring Light with an LDR"}]},{"@type":"WebSite","@id":"https:\/\/siratek.net\/#website","url":"https:\/\/siratek.net\/","name":"siratek","description":"Your Best Electronic Retail Shop","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/siratek.net\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/siratek.net\/index.php\/wp-json\/wp\/v2\/siratek_tutorial\/52281","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/siratek.net\/index.php\/wp-json\/wp\/v2\/siratek_tutorial"}],"about":[{"href":"https:\/\/siratek.net\/index.php\/wp-json\/wp\/v2\/types\/siratek_tutorial"}],"version-history":[{"count":0,"href":"https:\/\/siratek.net\/index.php\/wp-json\/wp\/v2\/siratek_tutorial\/52281\/revisions"}],"wp:attachment":[{"href":"https:\/\/siratek.net\/index.php\/wp-json\/wp\/v2\/media?parent=52281"}],"wp:term":[{"taxonomy":"siratek_tutorial_level","embeddable":true,"href":"https:\/\/siratek.net\/index.php\/wp-json\/wp\/v2\/siratek_tutorial_level?post=52281"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}