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. 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
  5. This comment has been removed by the author.

    ReplyDelete
  6. 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
  7. 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
  8. yes please i also got black boxes :(
    please reply as soon as possible

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

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

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

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

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

    ReplyDelete
  14. 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
  15. 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
  16. @DejtabejzJanuary 24, 2015 at 7:22 AM
    Set the contrast to 100 to display content

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

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

    ReplyDelete
  19. 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
  20. 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
  21. Mechatronics training equipment for Education, http://www.dolangeducation.com/mechatronics-training-series-fa-series/

    ReplyDelete
  22. my lcd is showing box in one row

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

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

    ReplyDelete
  25. Getting error in code plz hell

    ReplyDelete
  26. 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
  27. 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
  28. 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
  29. 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
  30. 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
  31. 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
  32. This post is really nice and informative. The explanation given is really comprehensive and useful.... online data science training

    ReplyDelete
  33. Thanks for sharing such a great information..Its really nice and informative..

    big data training

    ReplyDelete
  34. Wow what a great blog, i really enjoyed reading this, good luck in your work. Indian spices Melbourne

    ReplyDelete
  35. Wow what a great blog, i really enjoyed reading this, good luck in your work. Tatcha Eye Cream

    ReplyDelete
  36. Great post! I am actually getting ready to across this information, It’s very helpful for this blog.Also great with all of the valuable information you have Keep up the good work you are doing well.
    Artificial Intelligence Course
    Java Course
    AWS Course
    Machine Learning Course
    Data Science Course
    DevOps Course

    ReplyDelete
  37. Hi, I am Veronica Kate. I am working as a full-time academic consultant with Livewebtutors. We are providing paper editing service and Deakin Referencing Generator to university and college students across the globe. I have been successfully helping students, scholars and professionals in various services like I mentioned above for more than 5 syears and hold excellent writing, proofreading and editing skills. You would also find various academic tools on Livewebtutors like Paraphrasing Tool and Harvard Referencing Generator.

    ReplyDelete
  38. This comment has been removed by the author.

    ReplyDelete
  39. This comment has been removed by the author.

    ReplyDelete
  40. This comment has been removed by the author.

    ReplyDelete
  41. Almost All Universities Relesed Their BCom Exam Result 1st, 2nd, 3rd Year After Conduct Exams In March-May 2019-20.
    Allahabad University BCOM 1st Year Result 2020
    AU BCOM 2nd Year Result 2020
    AU BCOM 3rd Year Result 2020

    ReplyDelete
  42. Hello,

    Great Post. It's very Useful Information. In Future, Hope To See More Post. Thanks You For Sharing.
    CTET Coaching In Noida
    UPTET Coaching In Noida
    B.Ed Entrance Coaching In Noida
    Thanks
    Shweta Singh

    ReplyDelete
  43. Search Engine Optimization company in Noida Delhi-Ncr is all you need to boost your traffic online. Search engine optimization services should be chosen wisely.
    SEO company in Noida
    SEO agency in Noida

    ReplyDelete
  44. Nice Blog…!! Thanks for sharing this article. If you want to be a Mobile Expert. Check out for Mobile Repairing Course In Delhi India .

    ReplyDelete
  45. Stunning post and content writing thanks for sharing with us.

    Find safety gloves standards uk</a

    ReplyDelete

Post a Comment

Popular Posts