const int sensorPin=0; // Define Sensor input pin A0 const int ledPin= 13; // LED pin is 13 const int threshold= 100; // The value off threshold which will start from it int PWMLED =6; // This LED connected with PWM to change brightness // due to changes in sensor reading void setup() { pinMode(ledPin, OUTPUT); //Set ledPin as an OUTPUT pinMode(PWMLED, OUTPUT); //Set PWMLED as an OUTPUT Serial.begin(9600); } void loop() { int val= analogRead(sensorPin); // Define "val" as an integer and save the sensor's // value there Serial.println(val); // Display sensor's value on serial monitor if (val >= threshold) //Compair sensor's value with threshold { analogWrite(PWMLED,val); //Transfer sensor's value to the PWMLED delay(500); //Delay for 0.5s } else analogWrite(PWMLED,0); //if val less than threshold the PWMLED will off }