...
One type of simple sensor is a photoresistor. It changes its electrical conductivity (resistance) depending on the incidence of brightness and can therefore also be called a brightness sensor. To connect the sensor we use Many sensors also act as a variable resistor, and unfortunately our arduino isn't designed to measure resistance; we need to convert this resistance to a variation in voltage. To do this, we need a so-called voltage divider circuit.
...
For our photoresistor there is the following circuit:
Example-Code
For the code, let's output the values read from Arduino via the Serial Monitor (see: Serial).
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
#define BRIGHTNESS A0 void setup() { Serial.begin(9600); } void loop() { int reading = analogRead(BRIGHTNESS); // We get the sensor value here Serial.println(reading); // We send the message to serial } |
...