element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Arduino Forum Arduino LED Dimmer , TV Remote Controll,  Saving  EEPROM
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 11 replies
  • Subscribers 391 subscribers
  • Views 2814 views
  • Users 0 members are here
  • EEPROM
  • dimmer
  • remote controlled
  • arduino
  • led_dimmer
Related

Arduino LED Dimmer , TV Remote Controll,  Saving  EEPROM

arduino007
arduino007 over 6 years ago

Hallo

 

Actually I want to make a LED Dimmer with Arduino with Remote Controll. I tried with online help , It was good. But I need some changing in it. Please help me for it.

 

I want to save last state of LED brightness level after turn it off. I want to save it in EEPROM . If I restart Arduino, It use last Brightness level information from EEPROM and turn LED on at last brightness level. Arduino use its last setting Automatically  and I dont need to Turn it on from Remote Controller. I just change brightness from it. After that I can decrease LED brightness from Remote without Turn it on /Off.

 

Pleas help me for it.

 

 

 

Code for Dimmer LED Strip with TV Remote Controller

https://www.youtube.com/user/greatscottlab

 

 

 

#include <IRremote.h>

int bright;

int before;

int out=9; //connect your LED to pin 9

int steps=5; //dimmer steps, vary those to increase/decrease the steps between full brightness and turned off

int RECV_PIN = 11; //data out of IR receiver connects to pin 11

 

IRrecv irrecv(RECV_PIN);

 

decode_results results;

 

void setup(){

irrecv.enableIRIn(); // start the receiver

  before=0; //LED is turned off

  bright=255; //brightness value is at maximum (255)

pinMode(out,OUTPUT);

}

 

void loop() {

  if (irrecv.decode(&results)) {

 

  if (results.value==0x20DF8D72){ //Code to turn the LED ON/OFF

if(before==0){ // if the LED was turned off, then we turn it on

digitalWrite(out,HIGH);

      before=1; //LED is now turned on

    }

    else{

digitalWrite(out,LOW); //if the LED was turned on, then we turn it off

      before=0;

bright=255;

    }}

  if (results.value==0x20DFF10E && before==1){ //Code to decrease the brightness

if(bright-255/steps<0){

analogWrite(out,bright);

    }

    else{

bright=bright-255/steps;

analogWrite(out,bright);

  }}

  if (results.value==0x20DF718E && before==1){ //Code to increase the brightness

if(bright+255/steps>255){

analogWrite(out,bright);

    }

    else{   

bright=bright+255/steps;

analogWrite(out,bright);

  }}

 

irrecv.resume();

}}

  • Sign in to reply
  • Cancel

Top Replies

  • Gough Lui
    Gough Lui over 6 years ago in reply to arduino007 +2
    I would say that the problem is with the way you're attempting to spread EEPROM writes. Remember that on each boot, you are resetting the addr variable to 2 and the addr3 variable is undefined. In your…
  • dougw
    dougw over 6 years ago +1
    The code to control LED brightness should always get its value by reading it from EEPROM. The code to receive remote control data should only write the received data to EEPROM. There are lots of examples…
  • dougw
    dougw over 6 years ago in reply to arduino007 +1
    If I am reading this correctly, in the main loop, right after the decode line, you should write the results.value to EEPROM. That is the only time you need to write to EEPROM. The "if" statements to test…
Parents
  • Gough Lui
    Gough Lui over 6 years ago

    One should be careful in using the EEPROM in this manner as it has a finite lifetime of about 100,000 programming cycles. Using just one address will wear out the memory at that address - to improve lifetime, many systems recommend spreading the writes across the EEPROM (e.g. by using a circular log style approach) or by limiting it so that your code only writes to EEPROM very infrequently.

     

    With your code, it seems you have 26 "steps", thus going from zero to full brightness will already consume 26 cycles each time. As a result, turning the light up from zero to full and back to zero just 1923 times will consume the cycle life of that particular EEPROM location. Assuming you use the light 5 times a day, this would only last about a year before you might run into reliability issues.

     

    Instead, maybe you can define a timed process looking at the running time and save the brightness to EEPROM only after the light has reached a set brightness and stayed there for a minimum of a minute.. Or you could perhaps just store in the EEPROM a default power-up brightness and a flag that is either on or off, which will tell the unit whether to be on or off at the next power-up but loading a default brightness instead. This way, a write cycle is only consumed every switch-on or switch-off.

     

    If you could make the program use the memory in a circular way (e.g. sequence number + flag written to a single byte, then you could theoretically extend the lifetime by writing new data to the next location and wrapping around once you reach the end. On boot-up, you would read all the EEPROM locations looking for the byte with the highest sequence number or a sudden decrement to the sequence number excepting wrap-around to reload the data, noting that the sequence number must have more bits than the number of locations to be unambiguous as to which one is the latest data. Otherwise you could use a pointer, although this will result in one location being programmed more frequently than the others and being a potential point of failure.

     

    - Gough

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
  • arduino007
    arduino007 over 6 years ago in reply to Gough Lui

    Thank you very much for very detailed reply. can you please write a example code for me. I am not expert programmer.  Thanks

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
Reply
  • arduino007
    arduino007 over 6 years ago in reply to Gough Lui

    Thank you very much for very detailed reply. can you please write a example code for me. I am not expert programmer.  Thanks

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
Children
  • arduino007
    arduino007 over 6 years ago in reply to arduino007

    after many tries , I written that Code. but still not perfect. If I restart Arduino more then one times. I loose last brightness state of LED,  Please check it

     

     

    #include <EEPROM.h>

     

    #include <IRremote.h>

     

    int bright;

    int before;

    int out=9; //connect your LED to pin 9

    int steps=10; //dimmer steps, vary those to increase/decrease the steps between full brightness and turned off

    int RECV_PIN = 11; //data out of IR receiver connects to pin 11

    int addr = 2;  // EEPROM address to save last state

    int addr2 = EEPROM.read(0);  //save next EEPROM number alway in EEPROM addr (0)to save last state of LED Brightnes

    int addr3;

    IRrecv irrecv(RECV_PIN);

     

    decode_results results;

     

     

    void setup(){

     

     

     

     

     

    if (addr2<256 && addr2>0){ 

      EEPROM.write(0,addr2+1);  // add every time next EEPROM number to save last last LED Brigtness State to save EEPROM life

    }

     

     

      irrecv.enableIRIn(); // start the receiver

     

     

     

         if( EEPROM.read(addr2-1)>=0 && EEPROM.read(addr2-1)<=255){            //Check last EEPROM save Data for LED Brightnes

        analogWrite(out,EEPROM.read(addr2-1));  //Save now in Next EEPROM address, That add every time in ERPROM Address(0)

        }

     

     

     

      addr3 = addr2;

      before=5; //LED is turned off

      bright=255; //brightness value is at maximum (255)

     

      pinMode(out,OUTPUT);

     

      Serial.begin(9600);

     

    }

     

     

     

     

    void loop() {

     

     

      if (irrecv.decode(&results)) {

     

     

      if (results.value==0x2FDB847 && before>0 ){ //Code to decrease the brightness

            if(bright-255/steps<0){

          analogWrite(out,bright);

        }

        else{

        bright=bright-255/steps;

        analogWrite(out,bright);

        delay(50);

         EEPROM.write(addr3, bright);

       

      }}

     

      if (results.value==0x2FD9867 ){ //Code to increase the brightness

           if(bright+255/steps>255){

          analogWrite(out,bright);

        }

        else{   

        bright=bright+255/steps;

        analogWrite(out,bright);

        delay(50);

         EEPROM.write(addr3, bright);

       

      }}

     

     

      irrecv.resume();

    }}

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • dougw
    dougw over 6 years ago in reply to arduino007

    It seems you need to increase or decrease the steps variable when you want to decrease or increase the brightness, but I don't see the code to do this.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • Gough Lui
    Gough Lui over 6 years ago in reply to arduino007

    I would say that the problem is with the way you're attempting to spread EEPROM writes. Remember that on each boot, you are resetting the addr variable to 2 and the addr3 variable is undefined.

     

    In your setup, you are reading the first byte from the EEPROM, but then, you appear to be trying to store a zero in the next EEPROM address which makes no sense to me. Then after you enable the receiver, you're checking if the data from the address *minus one* is within a given range, which again, seems to be superfluous since EEPROM returns byte type (i.e. unsigned 8-bit) rather than int type, so it cannot be <0 or >255 either, hence the check always passes.

     

    That's all a mess. Perhaps you should start with just one address first, before trying to implement a circular log storage so to get your ideas firm as to when you are going to store and what you are going to store. There may be no need to "waste" the whole byte with the step value either if you're a little clever with how you define your steps - 16 steps for example could fit into 4-bits, leaving 4-bits to implement a sequence number, allowing you to spread it out between 16-byte positions without needing to implement separate data structures. Otherwise perhaps use "pairs" of EEPROM byte values - first byte = sequence number, second byte = step value. In this case, with 8-bits of sequence number, you could unambiguously determine which is the latest value with <=255 values recorded (occupying 510 bytes of the EEPROM) but now every update costs two-bytes of write.

     

    - Gough

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • Cancel
  • arduino007
    arduino007 over 6 years ago in reply to dougw

    Thanks a lot to find problems in Code.  Actually as I said, I am not expert in Programing. I have only some days experience in Programing. Please send me a right Code that I past in my program. Please help me

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • arduino007
    arduino007 over 6 years ago in reply to Gough Lui

    Thank a lot for detailed information. I have no good experience in programing. I just try to find a solution. I try change my code again after your information.image

    Actually I use a mini LED Dimmer at my home. Its very small and work great. Its save also last brigtness setting and with only two buttons i can controll brightness and i can turn it on/Off.I attached Photo of Dimmer.

     

    I want actually same controller with Ardino. Because of no experience in Programing its for me very difficult to solve to problems in Code. Can you please send me Code for me. that I past in my Program.

     

    Thanks again for Help

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube