Introduction

Photoresistor Sensor Module 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.

Features

How to use with Arduino?

Connection

Code Upload

Copy below code to your Arduino IDE, choose the correct port and board for your arduino, save and upload it to the Arduino board.

int photocellPin = A0;    // select the input pin for the photoresistor
int val = 0;       // variable to store the value coming from the sensor 

void setup() { 
  Serial.begin(9600);//Set the baudrate to 9600,make sure it's same as your software settings
 // pinMode(ledPin, OUTPUT);  // declare the ledPin as an OUTPUT  
   pinMode(photocellPin, INPUT);  // declare the ledPin as an OUTPUT  
} 

void loop() { 
  val = analogRead(photocellPin);   // read the value from the sensor  
  Serial.println(val);   //The serial will print the light value
} 

Running Result

After compile this sketch, simply click the “Upload” button in the environment. Wait a few seconds – you should see the RX and TX leds on the board flashing. If the upload is successful, the message “Done uploading.” will appear in the status bar.

In the same time,change the brightness of the environment, open the Serial Monitor and you will get the output data as below :