Arduino > Photo-résistance (photocell/photoresistor/Light Dependent Resistor/LDR/CdS)

La photorésistance (photocell/photoresistor/Light Dependent Resistor/LDR/CdS) peut servir à mesurer une quantité lumineuse. Elle doit être branchée à une entrée analogique et nécessite un diviseur de tension.

« Photocells are sensors that allow you to detect light. They are small, inexpensive, low-power, easy to use and don't wear out. For that reason they often appear in toys, gadgets and appliances. They are often referred to as CdS cells (they are made of Cadmium-Sulfide), light-dependent resistors (LDR), and photoresistors.

Photocells are basically a resistor that changes its resistive value (in ohms Ω) depending on how much light is shining onto the squiggly face. They are very low cost, easy to get in many sizes and specifications, but are very innacurate. Each photocell sensor will act a little differently than the other, even if they are from the same batch. The variations can be really large, 50% or higher! For this reason, they shouldn't be used to try to determine precise light levels in lux or millicandela. Instead, you can expect to only be able to determine basic light changes.» source 

1.  Mesurer la lumière


Adafruit_measuring_light.pdf

2.  Tester une photo-résistance

«The easiest way to determine how your photocell works is to connect a multimeter in resistance-measurement mode to the two leads and see how the resistance changes when shading the sensor with your hand, turning off lights, etc. Because the resistance changes a lot, an auto-ranging meter works well here. Otherwise, just make sure you try different ranges, between 1MΩ and 1KΩ before 'giving up'.» source 

3.  Branchement

3.1  Valeur de la résistance du diviseur de tension

La photo-résistance doit être branchée à une entrée analogique et nécessite un diviseur de tension doit la valeur est calculée selon la formule suivante :

résistance du diviseur de tension = racine carrée(valeur minimale de la résistance * valeur maximale de la résistance)

3.2  Circuit


Adafruit_using_photocell.pdf

4.  Code: envoyer la lecture de la photo-résistance à chaque 50ms

// ICLUDE CHRONO
#include <Chrono.h>

Chrono messageSendInterval = Chrono();

// ICLUDE MASSAGE PACKER
#include <AsciiMassagePacker.h>

// PACKER(FOR SENDING) INSTANCE:
AsciiMassagePacker outbound;

void setup() {

        // INITIATE SERIAL COMMUNICATION.
        Serial.begin(57600);

}

void loop() {

        if ( messageSendInterval.hasPassed(100) ) {
                messageSendInterval.restart();

                int photocellReading = analogRead( A0 );

                outbound.beginPacket("a0");
                outbound.addInt( photocellReading );
                outbound.endPacket();

                Serial.write(outbound.buffer(), outbound.size());

        }

}