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
  • dougw
    dougw over 6 years ago

    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 of reading and writing EEPROM including on the arduino site:

    https://www.arduino.cc/en/Reference/EEPROM

     

    to write to EEPROM:

    EEPROM.put(eeAddress, f);

     

    to read from EEPROM:

    EEPROM.get(eeAddress, customVar);

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

    Thanks for Reply ;

    I read all possible information online. But I am not expert , therefore I did not find good solution. I tried that code, that ist not perfect, but its work. I need better code for that. please help me for it.

    In start LED brightness is good as saved in EEPROM. But I can not controll properly with remote at start. I press remote button one time, that Its work. Secondly the button ( to increase brightnes) increase light at first press at 255.

     

    my Code

     

    #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

     

     

    IRrecv irrecv(RECV_PIN);

     

    decode_results results;

     

    void setup(){

      irrecv.enableIRIn(); // start the receiver

      before=5; //LED is turned off

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

     

     

     

     

      if( EEPROM.read(0)>0){

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

      }

     

      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(0, bright);

        Serial.println(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(0, bright);

        Serial.println(bright);

      }}

     

     

      irrecv.resume();

    }}

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

    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 whether to increase or decrease brightness should not look at the results.value - they should test the value that was stored in EEPROM.

    On start up, the EEPROM value should be used to set brightness before the main loop.

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

    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 whether to increase or decrease brightness should not look at the results.value - they should test the value that was stored in EEPROM.

    On start up, the EEPROM value should be used to set brightness before the main loop.

    • Cancel
    • Vote Up +1 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