Recent Changes - Search:

Video Sites




edit SideBar


//LED as Sensor and Emitter
  Read LED as a sensor to detect light levels on A0
   Dorian McIntire

int sensorValue; //light level value read by LED
int threshold = 220; //Threshold adjustment to set the point at which the LED turns on
void setup(){
  Serial.begin(9600); // Use to view sensor value

void loop(){
  sensorValue = analogRead(A0); //Read LED as a sensor

 //Hardcoded threshold. 
  Serial.println(sensorValue); //Use to view sensor value
  if(sensorValue < threshold){
    pinMode(A0, OUTPUT); //Change A0 to a digital output pin
    digitalWrite(A0, HIGH); // Make A0 high

    delay(1000); // Keep the LED on for 1 second
    pinMode(A0,INPUT); //Change A0 back to an Analog input pin
Edit - History - Print - Recent Changes - Search
Page last modified on February 23, 2020, at 07:18 PM