Arduino LDR sensor

Help me by sharing this post


←PREVIOUS TUTORIAL       NEXT TUTORIAL→

See also original post. LDR sensor module is used to detect the intensity of light. It is associated with both analog output pin and digital output pin labelled as AO and DO respectively on the board. When there is light, the resistance of LDR will become low according to the intensity of light. The greater the intensity of light, the lower the resistance of LDR. The sensor has a potentiometer knob that can be adjusted to change the sensitivity of LDR towards light.

Arduino IR sensor



PART 1 - Schematic

The connections are pretty easy, see the image below with the breadboard circuit schematic. The sensor will give an analog output or digital, according to the amount of visible light received. You could use this afor a light follower robot, detect sunlight or rotate according to the sun position.

We need:
1 x Arduino NANO/UNO: LINK eBay
1 x LDR module: LINK eBay
1 x i2c LCD: LINK eBay
1 x Jump wires: LINK eBay
1 x Breadboard: LINK eBay

LDR sensor arduino tutorial schematic




PART 2 - CODE results on serial monitor

We read the analog value from the sensor and print that to the serial monitor. You could make your own code and activate stuff, detect light, etc...


Download serial monitor example code:


// LDR sensor Test
// http://www.electronoobs.com/eng_arduino_tut75.php

int LED = 11; // Use the onboard Uno LED
int analog_IN = A0;  // This is our input pin


void setup() { 
  pinMode(LED, OUTPUT);
  pinMode(analog_IN, INPUT);
  Serial.begin(9600);
  
}

void loop() {
  int Value = analogRead(analog_IN);  
  Serial.print("Analog read: ");Serial.println(Value);  
  delay(200);
}


Upload the code and make the connections. Then open the serial monitor at 9600 bauds and you will have the analog read printed to the serial monitor. Or go below and download the code with the i2c LCD.





PART 3 - CODE results on LCD
Download LCD example code:
Download i2c LCD library:

// LDR sensor Test
http://www.electronoobs.com/eng_arduino_tut75.php

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

// Set the LCD address to 0x27 or 0x3f for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 20, 4);
int LED = 11; // Use the onboard Uno LED
int analog_IN = A0;  // This is our input pin

void setup() {
  lcd.init();
  lcd.backlight();
  pinMode(LED, OUTPUT);
  pinMode(analog_IN, INPUT);
  Serial.begin(9600);  
}

void loop() {

  int Value = analogRead(analog_IN);  
  Serial.print("Analog read: ");Serial.println(Value);  
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("  Analog  Read  ");
  lcd.setCursor(6,1);
  lcd.print(Value);  
  delay(200);
}


Upload the code and make the connections. Then open the serial monitor at 9600 bauds or just see the results on the LCD screen.






←PREVIOUS TUTORIAL       NEXT TUTORIAL→

Help me by sharing this post








yt_link
insta_link
fb_link
twitter_link

Arduino LDR sensor
page 1/1



ADVERTISERS
PCBWAY PCB service





Gearbest Alfawise U30 2.8 inch Touch Screen DIY Desktop 3D Printer - U30 EU Plug Black
Alfawise U30 2.8 inch Touch Screen DIY Desktop 3D Printer - U30 EU Plug Black only $$162.89

AFFILATE

Gearbest Creality3D CR - 10S 3D Printer - EU Plug Upgrade Version Coffee and Black
Creality3D CR - 10S 3D Printer - EU Plug Upgrade Version Coffee and Black only $$352.94

Gearbest Creality 3D Ender-3 V-slot Prusa I3 DIY 3D Printer Kit 220 x 220 x 250mm Printing Size - EU Plug Black
Creality 3D Ender-3 V-slot Prusa I3 DIY 3D Printer Kit 220 x 220 x 250mm Printing Size - EU Plug Black only $$153.84

Gearbest Alfawise U20 Large Scale 2.8 inch Touch Screen DIY 3D Printer - EU - U20 EU Plug Black
Alfawise U20 Large Scale 2.8 inch Touch Screen DIY 3D Printer - EU - U20 EU Plug Black only $$253.39