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 How do I add a Liquid Crystal Display to my current project
  • 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
  • State Verified Answer
  • Replies 37 replies
  • Answers 2 answers
  • Subscribers 403 subscribers
  • Views 3545 views
  • Users 0 members are here
  • x
  • 1
  • lcd_display
  • arduino
  • 16
Related

How do I add a Liquid Crystal Display to my current project

Former Member
Former Member over 12 years ago

Hello,

 

I recently completed, with some assistance from Coder27, Bill Abbot, Tony, and Mark Beckett the first part of my project ( http://www.element14.com/community/thread/23967?start=0&tstart=0 )

Now the second part - I am wanting to add a small 16 x 1 LCD to finish up my project (see coding below that I will be using)

I would like the LCD to simply show which direction a servo is pointing (as in degrees, such as 0°, 90°, 180°, 270°, or 360° or anywhere in between 0° to 360°)

Please be advised: I do know that arduino 1.0.4 has the LCD Scroll example, but I am sure I dont need the entire code they have.  Also, my LCD is only 16 x 1, not x 2.

Thanks,

~Anna

 

******** BEGINNING OF CODE *************

#include <Servo.h>

 

const int pan1 = 3;     // first servo

const int tilt1 = 5;    // second servo

const int pan2 = 9;     // third servo

const int tilt2 = 11;    // fourth servo

 

const int potpan1 = A0; // Joystick 1 Vertical signal

int val0;

const int pottilt1 = A1;   // Joystick 1 Horizontal signal

int val1;

const int potpan2 = A5;   // Joystick 1 Select signal

int val2;

const int pottilt2= A3;   // Joystick 2 Vertical signal

int val3;

 

int servoVal[4];        // variable to read the value from the analog pin

 

Servo mypan1;                                  // create servo object to control a servo

Servo mytilt1;    // create servo object to control a servo

Servo mypan2;                                  // create servo object to control a servo

Servo mytilt2;    // create servo object to control a servo

 

void setup()

{

 

  // Servo 

  mypan1.attach(pan1);  // attaches the servo

  mytilt1.attach(tilt1);  // attaches the servo

  mypan2.attach(pan2);  // attaches the servo

  mytilt2.attach(tilt2);  // attaches the servo

 

  // Inizialize Serial

  Serial.begin(57600);

}

 

void loop()

{

 

  outputPotentiometers();           // Read and output joystick values

 

  val0 = analogRead(potpan1);            // reads the value of the potentiometer (value between 0 and 1023)

  val0 = map(val0, 0, 1023, 0, 179);     // scale it to use it with the servo (value between 0 and 180)

  mypan1.write(val0);                  // sets the servo position according to the scaled value

 

  //Serial.print("Value of PWM 3:   ");

  //Serial.println(val0);

  //Serial.print("\t");

 

  val1 = analogRead(pottilt1);            // i added

  val1 = map(val1, 0, 1023, 0, 179);     // i added

  mytilt1.write(val1);                  // i added 

 

  //Serial.print("Value of PWM 5:   ");

  //Serial.println(val1);

  //Serial.print("\t");

 

  val2 = analogRead(potpan2);            // i added

  val2 = map(val2, 0, 1023, 0, 179);     // i added

  mypan2.write(val2);                  // i added

 

  //Serial.print("Value of PWM 6:   ");

  //Serial.println(val2);

  //Serial.print("\t");

 

 

  val3 = analogRead(pottilt2);            // i added

  val3 = map(val3, 0, 1023, 0, 179);     // i added

  mytilt2.write(val3);                  // i added

 

  delay(20);                                      

}

 

void outputPotentiometers()     // Display Joystick Values

{

  Serial.print("Pot Pan 1 on ~3:     ");

  Serial.print(analogRead(potpan1));

  Serial.print("\t");

  Serial.print("     Pot Tilt 1 on ~5:     ");

  Serial.print(analogRead(pottilt1));

  Serial.print("\t");

  Serial.print("     Pot Pan 2 on ~9:     ");

  Serial.print(analogRead(potpan2));

  Serial.print("\t");

  Serial.print("     Pot Tilt 2 on ~11:     ");

  Serial.println(analogRead(pottilt2));

  Serial.print("\t");

 

}

 

 

 

********** END OF CODE *************

  • Sign in to reply
  • Cancel

Top Replies

  • ntewinkel
    ntewinkel over 12 years ago +1 suggested
    Here's a good example to start with: http://arduino.cc/en/Tutorial/LiquidCrystal You'd have to change the setup line to be lcd.begin(16,1) for your smaller display (and assuming the lcd lib supports it…
  • mcb1
    mcb1 over 12 years ago in reply to billabott +1 verified
    Annasta Your explanation does give us some clues where your learnng lies, and how you have come to be involved, so thanks. You may have noticed that there are many people asking for help, and a lot are…
  • Former Member
    Former Member over 12 years ago in reply to billabott +1
    If I might add a bit to WATB's reply, we get all sorts of questions here, and the kind of answer you want to give differs based on the motivation for the question. If someone is asking for help with what…
Parents
  • billabott
    0 billabott over 12 years ago

    @Anna

    My user name is billabott.  My full name is William Alan Thomas Bottger.  Attention to details is a fairly important part of this field of study.  One detail that I am curious about is: What in the world is your motivation for doing this project?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 12 years ago in reply to billabott

    Well William Alan Thomas Bottger image

    The motivation for my project is very simply, I want to do it.  A friend of mine has a son who is on a robotics team at school.  She invited me a few months back to go with her and visit an open house the team / students setup.  I wasnt doing anything so I accepted the invite, and glad I did.  I understood from their teacher that anyone can build things with Arduino boards, so with that I had an idea (funny how life works sometimes)

    If you remember from a previous post, I was doing a photoshoot for some students this past saturday ( http://www.element14.com/community/thread/23967?start=48&tstart=0 )

    Photography is something I like to do; the project, which I dont want to give away just yet, will assist me with doing a special shoot configuration.  Thats really all I will elaborate on at this time.

    The lcd portion, well it would be nice to have with the project, but if it is not able to be done, then I wont bother with it.

     

    Hope I answered your question.

    Now my question to you is, why do you ask? image

     

    ~Anna

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • billabott
    0 billabott over 12 years ago in reply to Former Member

    Yes, Anna, you did. Thank you.

     

    I have an abundance of curiosity and often a complete lack of restraint.  I wish you great success with all your Arduino endevours.

     

    There is an important philosophical movement that makes the Arduino community what it is.  It is called Open Source.  I hope you and every new person will take the opportunity to learn, adopt, and practice its principles.

     

    Some OS folks will say that if you ask for free help then you should not expect to have secrets about what the project's big picture is.  Some, but not all, are unwilling to assist someone who insists on compartmentalization.  The choice is yours.

     

    Until we meet again, happy trails to you.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • mcb1
    0 mcb1 over 12 years ago in reply to billabott

    Annasta

    Your explanation does give us some clues where your learnng lies, and how you have come to be involved, so thanks.

     

    You may have noticed that there are many people asking for help, and a lot are just wanting someone else to do their assignment for them.

    In our experience (we have long years and lots) it doesn't really teach you as much as learning yourself, with the occasional push in the right direction.

     

    May we suggest some very good tutorials.

     

    I like

    Adafruit             http://www.ladyada.net/learn/arduino/index.html

    John Boxall       http://tronixstuff.wordpress.com/tutorials/

     

    Nico likes Oomlout     http://www.oomlout.com/a/products/ardx/

     

    and of course the official one    http://arduino.cc/en/Tutorial/HomePage

     

     

    Mark

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Reject Answer
    • Cancel
Reply
  • mcb1
    0 mcb1 over 12 years ago in reply to billabott

    Annasta

    Your explanation does give us some clues where your learnng lies, and how you have come to be involved, so thanks.

     

    You may have noticed that there are many people asking for help, and a lot are just wanting someone else to do their assignment for them.

    In our experience (we have long years and lots) it doesn't really teach you as much as learning yourself, with the occasional push in the right direction.

     

    May we suggest some very good tutorials.

     

    I like

    Adafruit             http://www.ladyada.net/learn/arduino/index.html

    John Boxall       http://tronixstuff.wordpress.com/tutorials/

     

    Nico likes Oomlout     http://www.oomlout.com/a/products/ardx/

     

    and of course the official one    http://arduino.cc/en/Tutorial/HomePage

     

     

    Mark

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Reject Answer
    • Cancel
Children
  • Former Member
    0 Former Member over 12 years ago in reply to mcb1

    Thanks Mark for that added information.

    I guess where my confusion comes in is best explained this way.

    So I have the coding working thanks to those in the previous post, and starting with the first coding, rev A all the way up to rev J (I named them that so I didnt overwrite samples of the same coding)

     

    #include <Servo.h>   // when I enter this, it allows the Servo.h library to load up for the servos,

    #include <LiquidCrystal.h> // am I able, after the Servo.h library, place this library directly after it?  Or can I add this #include statement at the end of the first coding?

     

    So in a nutshell, that is really what the question should have been...........How should the layout of my coding be listed.  Should it be mixed, or should the LCD library coding come after the servo coding.

     

    As far as wiring, there are only 6 connections on my lcd panel (its a 16 x 1) and it looks as though I can use the following coding from the examples:

    ********************************************************
    http://arduino.cc/en/Tutorial/LiquidCrystalAutoscroll

    */

    // include the library code:
    #include <LiquidCrystal.h>

    // initialize the library with the numbers of the interface pins
    LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // Since I am already using ~3, ~5, ~6, & ~9 on the servo project, I am giong to use: 12, 11, 8, 7, 4, & 2 in lieu of the pins listed in the coding

    void setup() {
      // set up the LCD's number of columns and rows:
      lcd.begin(16,2); // this I will change to (16,1) simply because that is the design of the LCD panel I have.

    }

    void loop() {
      // set the cursor to (0,0):
      lcd.setCursor(0, 0);
      // print from 0 to 9:
      for (int thisChar = 0; thisChar < 10; thisChar++) {
       lcd.print(thisChar);
       delay(500);
      }

      // set the cursor to (16,1):
      lcd.setCursor(16,1);
      // set the display to automatically scroll:
      lcd.autoscroll();
      // print from 0 to 9:
      for (int thisChar = 0; thisChar < 10; thisChar++) {
        lcd.print(thisChar);
        delay(500);
      }
      // turn off automatic scrolling
      lcd.noAutoscroll();
     
      // clear screen for the next loop:
      lcd.clear();
    }

    ********************************************************

     

    ~Anna

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
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