element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • 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 & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • 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
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • 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 401 subscribers
  • Views 2942 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
  • shabaz
    shabaz over 6 years ago

    Hi,

     

    Not sure why you're making this more complicated than it need be.

    If you're happy with the behavior of the existing code (i.e. the dimming and on/off works fine) then why not delete (or comment out, with two slashes like this //

    the line that says

    bright=255;

    (in the code area that is concerned with switching off the LED) and replace the line that says digitalWrite(out,HIGH); with:

    analogWrite(out,bright);

     

    Then, when the remote is used to turn on the LED, it will light at the previous level. No need for EEPROM, unless you're going to be unplugging/plugging the device often, which makes no sense if you're intending to use the remote control. You only have 5 levels of dimness anyway, so on the rarer occasion that you unplug the device (or switch off the mains), then it's quick to set the level again.

     

    Still, if you wish to place the level in EEPROM, then at the point the LED is switched off (at that bright=255; line in the loop function, not the setup function) stick the current brightness level into EEPROM, using:

    EEPROM.write(0, bright);

    That line will stick the brightness level into address 0 of EEPROM.

     

    Then, at the point where the lamp is switched on (which is the line that said digitalWrite(out,HIGH);   ) you can replace that line with these two lines that read from EEPROM and set the level, using:

    bright=EEPROM.read(0);
    analogWrite(out,bright);

     

    And that's it.. you'd need to test it, because I'm mentally doing it, trying to understand this badly formatted code. But I believe those code changes are likely to cover the usual situations, where the brightness level gets recovered after the light is switched off, and then the power is turned off. It won't cover the scenario that the light is on, then the user adjusts the brightness, and then pulls the power. But that's a corner case that would require you to re-architect the code if you wish to do it properly - not worth it until you're more experienced in programming (maybe take a week to learn Arduino, it isn't difficult).

    And please use the syntax highlighting feature, it is described here:

    How to Ask Questions using the Create Discussion tool

    And also please make your code look neat, it allows people to help you. Some tips to get you started are described here: https://www.cs.swarthmore.edu/~newhall/unixhelp/c_codestyle.html

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
Reply
  • shabaz
    shabaz over 6 years ago

    Hi,

     

    Not sure why you're making this more complicated than it need be.

    If you're happy with the behavior of the existing code (i.e. the dimming and on/off works fine) then why not delete (or comment out, with two slashes like this //

    the line that says

    bright=255;

    (in the code area that is concerned with switching off the LED) and replace the line that says digitalWrite(out,HIGH); with:

    analogWrite(out,bright);

     

    Then, when the remote is used to turn on the LED, it will light at the previous level. No need for EEPROM, unless you're going to be unplugging/plugging the device often, which makes no sense if you're intending to use the remote control. You only have 5 levels of dimness anyway, so on the rarer occasion that you unplug the device (or switch off the mains), then it's quick to set the level again.

     

    Still, if you wish to place the level in EEPROM, then at the point the LED is switched off (at that bright=255; line in the loop function, not the setup function) stick the current brightness level into EEPROM, using:

    EEPROM.write(0, bright);

    That line will stick the brightness level into address 0 of EEPROM.

     

    Then, at the point where the lamp is switched on (which is the line that said digitalWrite(out,HIGH);   ) you can replace that line with these two lines that read from EEPROM and set the level, using:

    bright=EEPROM.read(0);
    analogWrite(out,bright);

     

    And that's it.. you'd need to test it, because I'm mentally doing it, trying to understand this badly formatted code. But I believe those code changes are likely to cover the usual situations, where the brightness level gets recovered after the light is switched off, and then the power is turned off. It won't cover the scenario that the light is on, then the user adjusts the brightness, and then pulls the power. But that's a corner case that would require you to re-architect the code if you wish to do it properly - not worth it until you're more experienced in programming (maybe take a week to learn Arduino, it isn't difficult).

    And please use the syntax highlighting feature, it is described here:

    How to Ask Questions using the Create Discussion tool

    And also please make your code look neat, it allows people to help you. Some tips to get you started are described here: https://www.cs.swarthmore.edu/~newhall/unixhelp/c_codestyle.html

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
Children
No Data
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