ESP8266 Light Meter Part 2
My88K-MRR My88K-MRR
117 subscribers
86 views
0

 Published On Jul 1, 2023

Part 2 of this video shows the senors and sketch writing for the light meter and its testing.

ESP8266 Sensor Sketch
https://github.com/CraftzAdmin/esp32/...
http://www.esp8266learning.com/wemos-...



//#define LEDPIN 11 //LED brightness (PWM) writing
#define LIGHTSENSORPIN A0 //Ambient light sensor reading

void setup() {
pinMode(LIGHTSENSORPIN, INPUT);
// pinMode(LEDPIN, OUTPUT);
Serial.begin(115200);
}

void loop() {
float reading = analogRead(LIGHTSENSORPIN); //Read light level

float volts = analogRead(LIGHTSENSORPIN) * 3.3 / 1023.0; // Convert reading to VOLTS
float VoltPercent = analogRead(LIGHTSENSORPIN) / 1023.0 * 100; //Reading to Percent of Voltage

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.print(reading);
Serial.println(" lx"); //Display reading in serial monitor
Serial.print(volts);
Serial.println(" volts");

delay(1000);
}

show more

Share/Embed