Hi everybody,
I'm trying to dim some LEDs with an IR proximity sensor (both are connected to the Arduino UNO). I would the most we're close from the sensor, the most the light is low.
I came up to switch between to power values but I don't come up to dim it. I think it's pretty simple, but I don't know how to do it. I made some research and all I found this person that tried to make almost the same thing but unfortunately the code doesn't work for me
Here's mine:
int x;
int led = 9;Â Â Â Â Â // the PWM pin the LED is attached to
int brightness = 0;Â Â // how bright the LED is
int fadeAmount = 5;Â Â // how many points to fade the LED by
void setup() {
 //initialize serial communications at a 9600 baud rate
 Serial.begin(9600);
 pinMode(led, OUTPUT);
}
void loop() {
 x= analogRead(0);
 Serial.println(x);
 // set the brightness of pin 9:
 analogWrite(led, brightness);
 // change the brightness for next time through the loop:
 brightness = brightness + fadeAmount;
 // reverse the direction of the fading at the ends of the fade:
Â
 // automatically dim the led
 /*if (brightness <= 0 || brightness >= 255) {
  fadeAmount = -fadeAmount;
 }*/
 // switch between two values according to the value of the sensor.
 /*if(x >= 200) {
  brightness = 255;
 } else {
  brightness = 20;
 }*/
Â
 // wait for 30 milliseconds to see the dimming effect
 delay(35);
}
Thanks so much for your help
Alexandre