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.
Copy below code to your IDE, choose the correct port and board for your Basic board, save and upload it to the Basic 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 }
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 :
DownLoad Url osoyoo.com
You must be logged in to post a comment.
TEST OK
HARDWARE :
Osoyoo UNO Board (Fully compatible with Arduino UNO rev.3) x 1
Photoresistor Sensor Module x 1
M/M jumpers
USB Cable x 1
PC x 1
Pin Definitions :
VCC : ⇔ UNO 5V
GND : ⇔ UNO GND
A0 : ⇔ UNO A0
Mixly source :
volatile int val;
void setup()
{
Serial.begin(9600);
pinMode(A0, INPUT);
val = 0;
}
void loop()
{
val = analogRead(A0);
Serial.println(val);
delay(1000);
}