Notes About Working with Various Arduino & Netduino Microcontroller Boards

Wednesday, January 16, 2013

Controlling an LCD Backlight with an IR Remote

Yesterday I posted an example of how to use and Arduino Uno, an IR remote, and digital potentiometer to control the contrast of a parallel LCD. This post builds (slightly) on that one by adding a transistor to control the LCD's backlight (LCD pins 15 (A) and 16 (K)). 

The transistor (P2N2222A) is inline between pin 18 (K) of the LCD and GND. Looking at the flat side of the transistor body, the LCD pin is connected to the left side, the transistor's center wire is connected to Arduino digital pin 2, and the right-side wire goes to GND (with a small resistor).

In the section of the code before the setup() method, add the following constant to declare the IR code for the EQ key that turns the backlight off and on:

  // IR code for EQ key
  const long ON_OFF = 0x40BF20DF;

Add the following variable declaration to track the state of the backlight:

  int backlight = HIGH;

Then, add the following to the loop() method body:

if(results.value == ON_OFF) {
  backlight = !backlight;
  digitalWrite(2, backlight);
}

The volume buttons on the remote control the contrast and the EQ button now controls the backlight.    

No comments:

Post a Comment