This sensor can handle voltages from both 5V and 3.3V devices.
cybertice : 50 บาท
meltsee.th : 25บาท
int sensor = 26; void setup() { Serial.begin(9600); } void loop() { int val = analogRead(sensor); Serial.print ("ค่าแสง : "); Serial.println(val); delay(100); } // https://www.cybertice.com/product/1534/temt6000-ambient-light-sensor-%E0%B9%80%E0%B8%8B%E0%B9%87%E0%B8%99%E0%B9%80%E0%B8%8B%E0%B8%AD%E0%B8%A3%E0%B9%8C%E0%B8%A7%E0%B8%B1%E0%B8%94%E0%B8%84%E0%B8%A7%E0%B8%B2%E0%B8%A1%E0%B9%80%E0%B8%82%E0%B9%89%E0%B8%A1%E0%B9%81%E0%B8%AA%E0%B8%87
#define LEDPIN 25 //LED brightness (PWM) writing #define LIGHTSENSORPIN 26 //Ambient light sensor reading void setup() { pinMode(LIGHTSENSORPIN, INPUT); pinMode(LEDPIN, OUTPUT); Serial.begin(9600); } void loop() { float reading = analogRead(LIGHTSENSORPIN); //Read light level float square_ratio = reading / 1023.0; //Get percent of maximum value (1023) square_ratio = pow(square_ratio, 2.0); //Square to make response more obvious analogWrite(LEDPIN, 255.0 * square_ratio); //Adjust LED brightness relatively Serial.println(reading); //Display reading in serial monitor delay(500); } // https://learn.sparkfun.com/tutorials/temt6000-ambient-light-sensor-hookup-guide/all