const int sensorMin=0;
const int sensorMax=600;
void setup() {
//initialize serial communication:
Serial.begin(9600);
}
void loop() {
//read the sensor:
int sensorReading=analogRead(A0);
// map the sensor range to range of four options:
int range=map(sensorReading,sensorMin,sensorMax,0,3);
//do something different depending on the range value:
switch (range) {
case 0: //your hand is on the sensor
Serial.println("dark");
break;
case 1: //your hand is close to the sensor
Serial.println("dim");
break;
case 2: //your hand is a few inches from the sensor
Serial.println("medium");
break;
case 3: //your hand is nowhere near the sensor
Serial.println("bright");
break;
}
delay(1); //delay in between reads for stability
}