Home CodeEspruino Espruino Pico and LDR example

Espruino Pico and LDR example

by shedboy71

A light-dependent resistor is a light-controlled variable resistor. The resistance of a photoresistor decreases with increasing incident light intensity; in other words, it exhibits photoconductivity. A photoresistor can be applied in light-sensitive detector circuits, and light- and dark-activated switching circuits.

A photoresistor is made of a high resistance semiconductor. In the dark, a photoresistor can have a resistance as high as several megohms (MΩ), while in the light, a photoresistor can have a resistance as low as a few hundred ohms. If incident light on a photoresistor exceeds a certain frequency, photons absorbed by the semiconductor give bound electrons enough energy to jump into the conduction band. The resulting free electrons (and their hole partners) conduct electricity, thereby lowering resistance. The resistance range and sensitivity of a photoresistor can substantially differ among dissimilar devices. Moreover, unique photoresistors may react substantially differently to photons within certain wavelength bands.

As you can see later in the schematics its easy to connect one of these to an Espruino Pico, you only require an LDR and a 10k resistor so that this could easily be constructed on a breadboard. I used the following module



Schematics and Layout


pico and ldr_schem

pico and ldr_bb



A simple code example, we will switch on and off the on board LED 1 depending on the value that’s read. So vary the light to the LDR and see what happens.

Type the following into the Espruino web ide and the Send to your Espruino

[codesyntax lang=”javascript”]

setInterval(function() {
  var light = analogRead(A5);
  //the value is between 0 and 1
  if(light >= 0.5)
    digitalWrite(LED1, 0); //led off
    digitalWrite(LED1, 1); //led on
}, 1000);



20PCS x 5528 Light Dependent Resistor LDR 5MM Photoresistor


You may also like