Arduino Nano 33 IoT - LDR Module

The LDR light sensor module can detect light and see how bright it is. It has two types of outputs: one digital output that shows either LOW or HIGH, and one analog output.

In this lesson, we will learn how to use an Arduino Nano 33 IoT and an LDR light sensor module together to find and measure light. Here is what we will talk about:

Arduino Nano 33 IoT LDR Light Sensor Module

Later, you can change the code to make an LED or a light bulb turn on using a relay when it detects light.

If you want to learn about a simple light sensor, check out the Arduino Nano 33 IoT - Light Sensor tutorial.

Hardware Preparation

1×Arduino Nano 33 IoT
1×Micro USB Cable
1×LDR Light Sensor Module
1×Breadboard
1×Jumper Wires
1×Recommended: Screw Terminal Expansion Board for Arduino Nano
1×Recommended: Breakout Expansion Board for Arduino Nano
1×Recommended: Power Splitter for Arduino Nano

Or you can buy the following sensor kits:

1×DIYables Sensor Kit (30 sensors/displays)
1×DIYables Sensor Kit (18 sensors/displays)
Disclosure: Some of the links provided in this section are Amazon affiliate links. We may receive a commission for any purchases made through these links at no additional cost to you.
Additionally, some of these links are for products from our own brand, DIYables .

Overview of LDR Light Sensor Module

The LDR light sensor module helps you check if there is light or how bright it is around it. It has one pin for digital signals and one for analog signals, giving you different ways to use it.

Pinout

The LDR light sensor has four connection points.

  • VCC pin: Attach this pin to a power source that provides between 3.3V and 5V.
  • GND pin: Attach this pin to the ground (0V).
  • DO pin: This is a digital output pin. It sends a HIGH signal when it's dark and a LOW signal when it's light. There is a built-in knob that lets you change the level that determines dark or light.
  • AO pin: This is an analog output pin. Its value goes down when the light is stronger and goes up when the light is weaker.
LDR Light Sensor Module Pinout
image source: diyables.io

Also, the LDR light sensor module has two LED indicator lights.

  • The PWR-LED light shows if the device is on.
  • The DO-LED light shows the light level on the DO pin: it turns on when there’s light and stays off when it’s dark.

How It Works

About the DO pin:

  • The LDR sensor module has a dial that lets you change its light sensitivity. When there is enough light (above your set level), the sensor output goes low and the DO-LED turns on. When there isn’t enough light (below your set level), the sensor output goes high and the DO-LED turns off.

About the AO pin:

  • The number measured from the AO pin goes in the opposite direction of the brightness around it. In other words, if there is more light (it's brighter), the AO pin number gets smaller. On the other hand, if there is less light (it's darker), the AO pin number becomes larger.

Remember that turning the potentiometer doesn't change the number on the AO pin.

Wiring Diagram

The light sensor module has two outputs. You can choose to use one or both, depending on what you need.

  • Wiring diagram connecting the Arduino Nano 33 IoT to the LDR light sensor module using both its analog and digital outputs.
The wiring diagram between Arduino Nano and 33 IoT Light Sensor Module

This image is created using Fritzing. Click to enlarge image

  • Wiring diagram that shows how to connect the Arduino Nano 33 IoT to the LDR light sensor module using only the AO pin.
The wiring diagram between Arduino Nano and 33 IoT LDR Module

This image is created using Fritzing. Click to enlarge image

  • Wiring layout showing how to connect the Arduino Nano 33 IoT board to the LDR light sensor module using only the DO pin.
The wiring diagram between Arduino Nano and 33 IoT LDR Light Sensor Module

This image is created using Fritzing. Click to enlarge image

※ NOTE THAT:

Please note that the Arduino Nano 33 IoT pins A4 and A5 have built-in pull-up resistors for I2C communication. Although these pins can be used as digital input pins, it is recommended to avoid using them for digital input. If you must use them, do not use internal or external pull-down resistors for these pins

Arduino Nano 33 IoT Code - Read value from DO pin

/* * This Arduino Nano 33 IoT code was developed by newbiely.com * * This Arduino Nano 33 IoT code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-nano-iot/arduino-nano-33-iot-ldr-module */ #define DO_PIN 2 // The Arduino Nano 33 IoT's pin D2 connected to DO pin of the ldr module void setup() { // Initialize the Serial to communicate with the Serial Monitor. Serial.begin(9600); // initialize the Arduino Nano 33 IoT's pin as an input pinMode(DO_PIN, INPUT); } void loop() { int light_state = digitalRead(DO_PIN); if (light_state == HIGH) Serial.println("It is dark"); else Serial.println("It is light"); }

Detailed Instructions

If you are new to the Arduino Nano 33 IoT, be sure to check out our Getting Started with Arduino Nano 33 IoT tutorial. Then, follow these steps:

  • Connect the components to the Arduino Nano 33 IoT board as depicted in the diagram.
  • Use a USB cable to connect the Arduino Nano 33 IoT board to your computer.
  • Launch the Arduino IDE on your computer.
  • Select the Arduino Nano 33 IoT board and choose its corresponding COM port.
  • Copy the code above and open it using the Arduino IDE.
  • Press the Upload button in the Arduino IDE to send the code to your Arduino Nano 33 IoT.
  • Cover and uncover the LDR light sensor using your hand or any object.
  • Look at the result in the Serial Monitor.
COM6
Send
It is light It is light It is dark It is dark It is dark It is light It is light It is light
Autoscroll Show timestamp
Clear output
9600 baud  
Newline  

If you notice that the LED is always on or always off, no matter if there is light or not, you can adjust the potentiometer. This change lets you control how sensitive the sensor is to light.

You can change the code to fit your needs. For example, you can set the LED to light up when it senses light. You can also make the servo motor move. Step-by-step instructions and easy tutorials for these changes are at the end of this guide.

Arduino Nano 33 IoT Code - Read value from AO pin

/* * This Arduino Nano 33 IoT code was developed by newbiely.com * * This Arduino Nano 33 IoT code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-nano-iot/arduino-nano-33-iot-ldr-module */ #define AO_PIN A7 // The Arduino Nano 33 IoT's pin connected to AO pin of the ldr module void setup() { // Initialize the Serial to communicate with the Serial Monitor. Serial.begin(9600); } void loop() { int light_value = analogRead(AO_PIN); Serial.print("The AO value: "); Serial.println(light_value); }

Detailed Instructions

  • Copy the code above and paste it into Arduino IDE.
  • Click the Upload button on Arduino IDE to send the code to your Arduino Nano 33 IoT.
  • Use your hand (or another object) to cover and then uncover the LDR light sensor.
  • Watch the result in the Serial Monitor.
COM6
Send
The AO value: 145 The AO value: 146 The AO value: 146 The AO value: 572 The AO value: 1678 The AO value: 1945 The AO value: 2956 The AO value: 3001 The AO value: 3098 The AO value: 4005 The AO value: 4005 The AO value: 1645 The AO value: 1546 The AO value: 346 The AO value: 172
Autoscroll Show timestamp
Clear output
9600 baud  
Newline  

Video Tutorial

※ OUR MESSAGES

  • As freelancers, We are AVAILABLE for HIRE. See how to outsource your project to us
  • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!