Change the intensity of the light as per user input. Help is appreciated!!

Hi there,

Actually I need to know how to change the brightness of a LED as per user input from a webpage. I have implemented up to, user can read the current light level (as in LUX units) and on/off the lights per section as desired. I can't think of how to control the intensity of the light as per user input. e.g: If the user input 40LUX as the desired light level then LED should change its brightness accordingly. Please help me on this one. I searched the internet but I couldn't find anything related to my requirement :frowning:

Thanks in advance,
Udesh

In this case, the LED is not affected by the data. I guess that because of the serial only sends strings and the analog out in Arduino uses bytes. There might be some really simple solution for this. But I can't figure it out.

int ledPin = 9;
int val;

void setup()
{
  // begin the serial communication
  Serial.begin(9600);
  pinMode(ledPin, OUTPUT);
}

void loop()
{


  // check if data has been sent from the computer
  if (Serial.available()) {
    // read the most recent byte (which will be from 0 to 255)
    val = Serial.read();
    // set the brightness of the LED
    analogWrite(ledPin, val);
  }
}

But my requirement is to give inputs via a web page not from the serial. Please someone help me on this. Please!! Please!!!

You will need to calibrate the lux levels coming from the LED to the settings (0-255) on the pin, so that when you see '40 lux' you can convert it to the equivalent output setting.

I don't know of any way other than to get a luxmeter and do the measurements directly, then build a translation table (or work out the formula for best fit to the datapoint) to allow you do do the calcs.

Thanks for your kind reply. Actually I don't really know how to do what u said. I'm new to electronics and arduino stuffs. I'm an IT student desperately need this part to complete my project. Let's forget about the LUX thing. Is it possible to let the user to select a predefined value from a drop-down list in the webpage. Then the LED brightness changes according to the selected value. If I can complete up to this I might be able to come up with a formula to get the LUX value and change the brightness according to the LUX level. Pls help me on this will ya!

Is it possible to let the user to select a predefined value from a drop-down list in the webpage. Then the LED brightness changes according to the selected value.

Yes.

Wire the LED to a pin capable of PWM and do an analogWrite(value) to it to control it's brightness.

Thanks for ur prompt reply. OK analogread (pin) to read a voltage from a pin and analogwrite (pin value) to write a PWM value to a pin which can control the brightness of a LED but I can't think of way to do the calibration phase. Please could you provide me an example.

Please could you provide me an example.

No it is an assignment, if you can't work it out then don't submit that part.

You said:-

Let's forget about the LUX thing

How do you think you should calibrate it then?