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; int val = 0; void setup() { Serial.begin(9600); pinMode(photocellPin,INPUT); } void loop() { val=analogRead(photocellPin); Serial.println(val); }
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);
}
the comments on the code that was provided are wrong (line 6). please look and make any changes.
The code in original post is correct. Please run it. If you see any error, please post the error message here and we will help you.