Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 30

Thread: Using Arduino to Auto-dim LED EBY701?

  1. #11
    Vendor - Qube colin's Avatar
    Join Date
    Dec 2006
    Posts
    796
    I just meant that one example was too complicated. It has three LEDs in a crossfade. Speakin of which, where is stevey!

  2. #12
    Raw Wave
    Join Date
    Nov 2009
    Posts
    2,118
    Hopefully if he's intending to use the Arduino, he'll figure out from the linked example that the key instruction is " AnalogWrite (Pin, Val); "
    where Val is 0-255
    and Pin is a digital output.

    That example provides the code needed - just cut out (or don't connect) the other LEDs.

    As to the programming language (syntax) - don't ask me. I use assembler! (And I've only just started looking at the ATmega set.)

  3. #13
    Constant Bitrate Sleepyz0mby's Avatar
    Join Date
    Feb 2010
    Location
    PanamaCityBeach/NewOrleans
    Posts
    171
    i've played with that code linked above and a few things to keep in mind is that around about 5% duty cycle the leds will flicker, and thats deponent on the MOSFET and leds.

    I'll go through and slim the code that i have so far to just 1 photoresistor and 1 output if you'd like it.

    another edit: dedicating a whole arduino to dimm the backlight is a bit of overkill, no? maybe somebody can point in the direction of a simple circuit that can do this....
    IDK just a random thought

  4. #14
    Raw Wave
    Join Date
    Nov 2009
    Posts
    2,118
    The flicker will be frequency - the MOSFETs & LEDs are capable of much faster switching.
    Else it's beating with lighting (eg multiples of 50 or 60 Hz).

    Decrease the cycle delay.

  5. #15
    What can I say? I like serial. Curiosity's Avatar
    Join Date
    Mar 2004
    Location
    Florence Yall, BFKY
    Posts
    2,684
    I use a 12F683 for some small PWM products. It can do what you need cheaply and it's fast. The speed issue has more to to with switching the MOSFET. For example sourcing with 5V logic as a control requires transistors to open and close the gate. You can get it faster with less parts by using a TTL level MOSFET on the sink side. As far as flickering at the low end, just set a minimum you can live with.

  6. #16
    Constant Bitrate Sleepyz0mby's Avatar
    Join Date
    Feb 2010
    Location
    PanamaCityBeach/NewOrleans
    Posts
    171
    i just assumed it was it was the mosfet's i was using were slow. i started using a solidstate relay (opto-isolator -> mosfet pair) cause i am still a noob so i didnt want to risk my arduino... and i got a bunch layin around...

    sorry i fell asleep last night ill work on the code today... where is the op?

  7. #17
    Constant Bitrate
    Join Date
    Feb 2008
    Posts
    112
    I'm here, sorry, been out for a few days.

    Thanks for all the input and discussion, very cool that theres some people interested.

    Now, ... I'm unsure how the mosfet stuff works, etc... I have been playing with a little code on the web that has been pre-written for the arduino, I have seen some Photo-cell sample code and trying to link it to control the pwm outputs of my arduino, I think this should be pretty simple, I'm having a hard time putting the code together though, linking the ambient light sensor code to the pwm current output code and putting delays on, etc... so that if it goes dark, it will slowly converge to a lower current output instead of being instant, etc..

  8. #18
    Constant Bitrate Sleepyz0mby's Avatar
    Join Date
    Feb 2010
    Location
    PanamaCityBeach/NewOrleans
    Posts
    171
    // dimmer

    const int ledPin = 9; // LED output pin
    const int lightPin = 0; // Photoresitor input pin

    int lightvalue = 0;
    int output = 0;

    void setup() {
    // initialize serial communications at 9600 bps:
    Serial.begin(9600);
    }

    void loop() {
    // read photoresitor
    lightvalue = analogRead (lightPin);
    // configure light reading to led out
    output = map (lightvalue, 0, 255, 0, 255);
    // write output value
    analogWrite (ledPin, output);

    // debug section - writes to moniter
    Serial.print ("lightvalue = ");
    Serial.print (lightvalue);
    Serial.print (" - output = ");
    Serial.println (output);

    // delay 50ms
    delay (50);
    }

    -END- dont copy this

    most basic dimming example i can come up with. i'm still pretty new to this so maybe some one with a better eye may have suggestions, but it works pretty good. however, it may benefit from a little smoothing and i havent tested it on a led backlight cause i dont have one -yet-

    best pic i can find for the photoresistor. Vcc = 3.3v ; v = lightPin
    [Right] the first one is the i used
    [Left] the other one will reverse the relationship between input and output


    help this helps

    another edit: i used a 330 1/4 watt resister, you may also use a variable resister to trim input rather than adjusting input via code

  9. #19
    What can I say? I like serial. Curiosity's Avatar
    Join Date
    Mar 2004
    Location
    Florence Yall, BFKY
    Posts
    2,684
    You could also delay it a bit so it doesn't jump derectly to the input value, and probably slow it down a bunch.

    Code:
    // dimmer
    
    const int ledPin   = 9;    // LED output pin
    const int lightPin = 0;    // Photoresitor input pin
    
    int lightvalue     = 0;    
    int delayedvalue   = 0;
    int output         = 0;
    
    void main()
    { 
      // initialize serial communications at 9600 bps:
      Serial.begin(9600); 
    
      lightvalue = analogRead (lightPin);
      delayedvalue = lightvalue;
    
      forever()
      {
        // read photoresitor
        lightvalue = analogRead (lightPin);
    
        // fade the value a bit
        if(lightvalue > delayedvalue)
          delayedvalue++;
        if(lightvalue < delayedvalue)
          delayedvalue--;
    
        // configure light reading to led out
        output = map (delayedvalue, 0, 255, 0, 255);
    
        // Set a minimum value (i.e. 10) or use map() whatever works best
        if(output < 10)
          output = 10;
    
        // write output value
        analogWrite (ledPin, output);
      
        // debug section - writes to moniter 
        Serial.print ("lightvalue = ");
        Serial.print (lightvalue);
        Serial.print (" - output = ");
        Serial.println (output);
      
        // delay 50ms
        delay (50);
      }
    }
    Or averaging, which usually gives better results with ADC values

    Code:
    // dimmer
    
    const int ledPin   = 9;    // LED output pin
    const int lightPin = 0;    // Photoresitor input pin
    
    int lightvalue[32] = {0};
    int idx            = 0;
    int delayedvalue   = 0;
    int output         = 0;
    
    void main()
    { 
      int i;
      int total;
    
      // initialize serial communications at 9600 bps:
      Serial.begin(9600); 
    
      forever()
      {
        // read photoresitor
        lightvalue[idx++] = analogRead (lightPin);
        if(idx >= 32) idx = 0;
    
        // avarge the light value
        for(i = 0, total = 0; i < 32; i++) total += lightvalue[i];
        delayedvalue = total / 32;
    
        // configure light reading to led out
        output = map (delayedvalue, 0, 255, 0, 255);
    
        // Set a minimum value (i.e. 10) or use map() whatever works best
        if(output < 10)
          output = 10;
    
        // write output value
        analogWrite (ledPin, output);
      
        // debug section - writes to moniter 
        Serial.print ("delayed = ");
        Serial.print (delayedvalue);
        Serial.print (" - output = ");
        Serial.println (output);
      
        // delay 50ms
        delay (50);
      }
    }

  10. #20
    Constant Bitrate Sleepyz0mby's Avatar
    Join Date
    Feb 2010
    Location
    PanamaCityBeach/NewOrleans
    Posts
    171
    i have to say though that a well placed light senser and code will make a more appealing backlight than too much delay, via direct delay or averaging.

    think about it... the only time your eye will notice a change in backlight intensity is when it's different from the ambient light. Other wise, when is just about perfect, the screen will look like it's the same brightness all the time. Again i haven't tried this with a backlight, but i have noticed it with a bunch of -really- bright leds.

Page 2 of 3 FirstFirst 123 LastLast

Similar Threads

  1. Browse by Cover (Coverflow) - Updated 11/8/07
    By moahdib in forum RR Plugins
    Replies: 316
    Last Post: 09-20-2008, 08:51 PM
  2. Telematics.net
    By IntellaWorks in forum Software & Software Development
    Replies: 40
    Last Post: 11-05-2004, 08:20 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •