Loading...
Pages: [1]   Go Down
Author Topic: Change the intensity of the light as per user input. Help is appreciated!!  (Read 497 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 smiley-sad

Thanks in advance,
Udesh
« Last Edit: June 04, 2012, 12:07:58 am by udeshplus » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Code:
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!!!
« Last Edit: June 05, 2012, 07:18:04 am by udeshplus » Logged

Sydney
Offline Offline
God Member
*****
Karma: 14
Posts: 716
Big things come in large packages
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: June 05, 2012, 01:42:02 pm by marco_c » Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 277
Posts: 25556
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 277
Posts: 25556
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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:-
Quote
Let's forget about the LUX thing

How do you think you should calibrate it then?
Logged

Pages: [1]   Go Up
Print
 
Jump to: