Skip to Content
This is the Beta version of our new Learning Paths approach. Please email feedback.

Ambient Light Sensor

ambient_light_sensor.ino
/* Project: Smart Home Component: Ambient Light Sensor Sketch Description: This sketch has functions to read the intensity of ambient light from a light sensor. Author: STEMVentor Educonsulting This code is copyrighted. Please do not reuse or share for any purpose other than for learning with subscribed STEMVentor programs. This code is for educational purposes only and is not for production use. */ // LIBRARIES // PIN DEFINTIONS // See board_parameters.h // GLOBAL CONSTANTS // See board_parameters.h // GLOBAL VARIABLES // INITIALIZE OBJECTS // LOCAL FUNCTIONS void ambientLightSensorSetup() { pinMode(AMBIENT_LIGHT_SENSOR_DIGITAL_PIN, INPUT); // You don't need to set pin mode for analog pins. if(OPERATING_MODE == 'D'){ Serial.println("Ambient Light sensor ready!"); } } structDigitalAnalogValues readAmbientLightSensorValues() { structDigitalAnalogValues ambient_light_sensor_values; ambient_light_sensor_values.digital_value = digitalRead(AMBIENT_LIGHT_SENSOR_DIGITAL_PIN); ambient_light_sensor_values.analog_value = analogRead(AMBIENT_LIGHT_SENSOR_ANALOG_PIN); return ambient_light_sensor_values; }