Measuring light strength with a Netduino

Measuring light strength with a Netduino

Light sensor schemaMeasuring the light strength is pretty simple when you own a Netduino.

You only need a normal resistor and a Light Dependent Resistor (LDR) which should be connected to the Netduino as shown in the schema.

With these few lines of code you can read the value from the LDR.

This code will open the A0 analog input port and read the value from it.

It returns a value between 0 and 100. 0 means bright and 100 means dark. In this example the value is inverted, so 0 means dark and 100 means bright.

public static void ReadLightSensor()
int minValue = 0;
int maxValue = 100;
int lightingInterval = 15 * 60 * 1000;

// Open the analog port
var lightSensor = new SecretLabs.NETMF.Hardware.AnalogInput(Pins.GPIO_PIN_A0);

// Set the value range between 0 and 100
lightSensor.SetRange(minValue, maxValue);

while (true)
// Read the value and invert it: 0 = dark, 100 = bright
var lightSensorValue = maxValue – lightSensor.Read();

// Do something with the value


If you show the measured values in a chart it will look like this:
Light strength chart

Comments are closed.