Interfacing LCD without a potentiometer( In Arduino and CCS)

I was reading on LCD interfacing and came across alot of people having trouble interfacing LCD with the pot setting for contrast. So here is a detailed solution of skiping installing a pot all together and using PWM signal to adjust the contrast.

For the Arduino solution the following is the hardware i used:
1. Arduino UNO
2. 16x2 LCD (JHD162A)

Instructions: Burn the code and enter on the Serial Monitor A to increase contrast and B to decrease  the contrast and turn on back-light enter N and to turn it off enter F.

The following is the code

*/
Library Originally added by David A Mellis
Library Modified by Limor Fried
Example added by Tom Igoe
Modified by Tom Igoe
This example is in the public domain. http://www.arduino.cc.en/Tutorial/LiquidCrystal
Contrast modification by Ahmed Murtaza Qureshi (www.engineeringlearning.blogspot.com)
/*
#include <LiquidCrystal.h>
char ch;
int Contrast=15;
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() 
{
  Serial.begin(9600);
  Serial.println("LCD test with PWM contrast adjustment");
  pinMode(13,OUTPUT);
  analogWrite(6,Contrast);
  // set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("LCD test!!");
}

void loop() 
{
   digitalWrite(13,LOW);
   delay(1000);
   digitalWrite(13,HIGH);
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 1);
  // print the number of seconds since reset:
  lcd.print(millis()/1000);
}

void serialEvent()
{
     if (Serial.available())
  {
    ch= Serial.read();
    if(ch=='A' && Contrast<255)
    {
      Contrast=Contrast+1;
    }
    if(ch=='B' && Contrast>0)
    {
      Contrast=Contrast-1;
    }
        if(ch=='N')
    {
      analogWrite(9,28836);
    }
       if(ch=='F')
    {
      analogWrite(9,0);
    }
    analogWrite(6,Contrast);
    Serial.println("Current contrast");
    Serial.println(Contrast);
  }
}

Comments

  1. Thank you very much for the code and diagram.

    Greetings from chile

    ReplyDelete
  2. Sorry guys, but what's supposed to be connected to PIN 13 ?? The diagram shows nothing and the code uses that pin ...?

    ReplyDelete
    Replies
    1. 13 is the pin for the LED in your arduino.

      Delete
    2. pin 13 is a pin which is used to control an on board led
      that led sucks power from the board so to save power we have turned it off

      Delete
  3. Great tut, it really helped me out. Using PWM over a pot just seems cleaner to me.
    Thank you for sharing.

    ReplyDelete
  4. This page is insightful and helpful. Lots of people will assert that everything in your site is great. :) You can also visit ICE GATE INSTITUTE for GATE Classes Pune.

    ReplyDelete
  5. Hi, the commands are working but no text is being displayed - I suppose that's an issue with me soldering. Could you tell me which pins should i check? Thanks

    ReplyDelete
    Replies
    1. I am having the same problem. The display lights up but nothing shows. I have triple checked my soldering! Need help!

      Delete
    2. The contrast 15 might be too low. Try setting contrast 120 and see. Worked for me.

      Delete
  6. This comment has been removed by the author.

    ReplyDelete
  7. hola me pueden ayudar para poder conectar transitores con internet propio a una camara GoPro y poder apagarla desde una computadora en cualquier parte del planeta?

    hello, can you help me to connect transistors with internet in a GoPro camera and turn off power from a computer or laptop in anywhere on the world ?


    contact me to talk more about the situation please

    rodrigo_rmz30@hotmail.com

    ReplyDelete
  8. Thanks for your effort for make this post.keep it up.Most useful information about IT learners gate coaching for electronics & communication in bangalore

    ReplyDelete
  9. I come up with an output of black boxes in LCD screen need help :(

    ReplyDelete
    Replies
    1. please check you connection again , i was also having same problem now it is solved :(

      Delete
  10. yes please i also got black boxes :(
    please reply as soon as possible

    ReplyDelete
  11. Its WORKING!!!
    I CONNECTED ALL things again ....and NOW its WORKING

    ReplyDelete
  12. thank you for the post.
    save my day

    ReplyDelete
  13. hai, i managed to control the contrast and on/off. but my display show nothing, instead off black box

    ReplyDelete
  14. is there a way to automatically have the backlight turned on,in the code or something?

    ReplyDelete
  15. how can we turn on the backlight for this?

    ReplyDelete
  16. I had a problem... there was no backlight !
    every thing elesed worked.
    Solution: pin 15 to a 5V and voila all worked
    (hitachi copiliand display)

    ReplyDelete
    Replies
    1. Add next line in the body of void setup() function:
      analogWrite(9,28836); // --turns backlight ON

      Delete
  17. SOMEBODDY HELP ME
    MY LCD DONT HAVE ANY LIGHT
    BUT ITS WORKING

    ReplyDelete
    Replies
    1. Open serial moniter and send N

      Delete
    2. Add next line in the body of void setup() function:
      analogWrite(9,28836); // --turns backlight ON

      Delete
  18. @DejtabejzJanuary 24, 2015 at 7:22 AM
    Set the contrast to 100 to display content

    ReplyDelete
  19. The code didn't compile because of the incorrect text comments at the beginning of the code... ie */ /* instead of /* text */

    ReplyDelete
  20. Thanks a lot.Actually my bread board has the issue.with your connection I made it without the board. THanks a lot :)

    ReplyDelete
  21. i have a 20*4 lcd.when i connect it accoring to ur connection and logic i am getting only row 2 and row 4 black box

    ReplyDelete
    Replies
    1. You have to initialize the no. of rows and columns and set cursor accordingly.
      In your case it will be lcd.begin(20,4); and other minor changes in the code.
      Hope it helps! :)

      Delete
  22. Thank you..it worked kindly help me solving one doubt
    Please tell me why lcd is showing the some random number and c haracter display after some minute

    ReplyDelete
    Replies
    1. that random number is due to this code
      / print the number of seconds since reset:
      lcd.print(millis()/1000);

      Delete
  23. I like your post....Thanks for your valuable information, It's really helpful information ..iit jee coaching in bangalore

    ReplyDelete
  24. Mechatronics training equipment for Education, http://www.dolangeducation.com/mechatronics-training-series-fa-series/

    ReplyDelete
  25. please help me
    first time it worked second time only black box

    ReplyDelete
  26. how do i pair hall sensor with this code

    ReplyDelete
  27. This information you provided in the blog that is really unique I love it!! Thanks for sharing such a great blog. Keep posting..
    Industrial training for Mechanical engineering Students

    ReplyDelete
  28. Getting error in code plz hell

    ReplyDelete
  29. Such a nice information you are sharing here, Thanks to informing us.
    any software regarding Mechanical, Civil & Architecture please visit here Best Autocad Training Center, Classes Institute in Indore

    ReplyDelete
  30. Thus this connection work for Arduino Nano too? If not someone please help me out.
    I'm in great trouble. Thank you in advance whoever helps me :)

    ReplyDelete
  31. Thank you for your articles that you have shared with us. Hopefully you can give the article a good benefit to us. civil engineering lecture videos

    ReplyDelete
  32. Interesting Article. Hoping that you will continue posting an article having a useful information. JEE coaching class in mumbai

    ReplyDelete
  33. Ineluctables, your hall your poet places be expecting within the delirious exploration/calamitous reputation bunss whole lecturer organization alongside heterogeneous flocks. Personally, I could associate to the exegesis. Chimakurthy granite companies list

    ReplyDelete
  34. Thanks For Sharing The Information The Information Shared Is Very Valuable Please Keep Updating Us Time Just Went On Reading The article Python Online Course Hadoop Online Course Aws Online Course Data Science Online Course

    ReplyDelete
  35. A bewildering web journal I visit this blog, it's unfathomably heavenly. Oddly, in this present blog's substance made purpose of actuality and reasonable. The substance of data is informative
    Oracle Fusion Financials Online Training
    Oracle Fusion HCM Online Training
    Oracle Fusion SCM Online Training

    ReplyDelete
  36. Very informative and impressive post you have written, this is quite interesting and i have went through it completely, an upgraded information is shared, keep sharing such valuable information. Contacts that Look Real

    ReplyDelete
  37. An overwhelming web journal I visit this blog, it's unfathomably amazing. Unusually, in this present blog's substance made inspiration driving truth and reasonable. The substance of data is enlightening
    Oracle Fusion Financials Online Training
    Oracle Fusion HCM Online Training
    Oracle Fusion SCM Online Training

    ReplyDelete
  38. Thanks for Sharing This Article.It is very so much valuable content. I hope these Commenting lists will help to my website
    microservices online training

    ReplyDelete
  39. Useful information Thank-you for sharing. really helpful keep sharing your views. Please visit link mentioned below and share your views on them.
    best hvac training in lucknow
    job oriented training institute in lucknow
    best php training in lucknow
    digital marketing training in lucknow

    ReplyDelete

Post a Comment

Popular Posts