Showing posts with label Arduino. Show all posts
Showing posts with label Arduino. Show all posts

Sunday, 12 January 2020

Display Custom Characters on 16 x 2 LCD Display Module Using Arduino

January 12, 2020 0

This tutorial is about making/building your own characters/special images and then displaying them on character 16×2 lcd. Generating custom characters or special character images and displaying on lcds of any sizes (16×1,16×2,8×1,8×2,20×1,20×2,40×1,40×2 etc) is not a very hard task. One must go through the internal structure of lcd control set in order to know how the character lcd works? Once you know how the lcd works and what features it offers. Then you can easily build and display characters of your desire on lcd screen in a defined matrix.



    What are custom characters?

    Custom characters are self made characters which we design by our self. We have full control on designing them with some constraints which i will discuss later. Like if we want to display a smiley ðŸ™‚ on 16×2 lcd. We don’t have an ASCII character for smiley to display it on 16×2 lcd. Example of custom characters is below.  

    How custom characters are displayed on 16×2 lcd?

    Before beginning any further i recommend you to please take the 16×2 lcd display introduction tutorial. Tutorial will let you know about the pinout and internal structure of 16×2 LCD. (Click below)   

    16 × 2 LCD has an internal ​CG-RAM (Character Generated RAM) in which we can generate or create our custom character. The size of CG-RAM is 64 bytes. We can generate / place 8 characters of size 5 × 8 at a time in CG-RAM. We can also place 5 × 10 size characters in CG-RAM but only 4.
    5 × 8 represents the dimension of the matrix in which a particular character can be displayed. 5 represents the Number of Columns and 8 represents the Number of Rows in a matrix. 5 × 8 combined is a matrix size. Matrix is composed of pixels which we turn on and off to represent or make a character. For example to display a smiley ðŸ™‚ in 5 × 8 dimension individual pixels on and off will be same like below.   

    The above Binary or Hex values are then arranged in a byte array. Byte array is then placed in to CG-RAM of 16 × 2 LCD. Now when we want to display this smiley character on LCD screen we just call its address in CG-RAM and finally the character will appear on 16 × 2 LCD screen.

    Circuit Diagram 





    How to Generate Byte Code for Custom Characters


    1. Visit https://maxpromer.github.io/LCD-Character-Creator/
    2. Create the Character You Want
    3. Copy the byte char array code. Example : byte customChar[] = { B00000, B00000, B01010, B10101, B10001, B01010, B00100, B00000 };
    4. Paste the code accordingly in my source code and change the name accordingly. 

    Source Code 


       
     /*  
       
                Custom Characters  
            16 x 2 LCD Display with Arduino  
       
                 HarshTronics  
       
            For More :  
            https://www.harshtronic.blogspot.com  
            https://www.instagram.com/harshtronics  
              
     */  
       
     #include <LiquidCrystal.h>          // includes the LiquidCrystal Library   
     LiquidCrystal lcd(12, 11, 5, 4, 3, 2);    // Creates an LC object. Parameters: (rs, enable, d4, d5, d6, d7)   
     int contrast = 100;  
       
     byte s1[8]=                  // Array of bytes  
     {  
      B00000,                   // B stands for binary formatter and the 5 numbers are the pixels  
      B00000,   
      B01010,   
      B10101,   
      B10001,   
      B01010,   
      B00100,   
      B00000                     
        
     };  
       
     byte s2[8]={B00100,  
      B01110,  
      B01110,  
      B01110,  
      B11111,  
      B00000,  
      B00100,  
      B00000,};  
        
     byte s3[8]=  
     {  
      0b01110,  
      0b01110,  
      0b00100,  
      0b01110,  
      0b10101,  
      0b00100,  
      0b01010,  
      0b01010,};  
       
     byte s4[8]={B00100,B01010,B11111,B01010,B10101,B11011,B10001,};   
       
     byte s5[8]=  
     { B00000,  
      B01110,  
      B10001,  
      B10001,  
      B10001,  
      B01010,  
      B11011,  
      B00000,  
     };  
       
     byte s6[8] =   
     {  
      B00000,  
      B00000,  
      B01010,  
      B00000,  
      B10001,  
      B01110,  
      B00000,  
      B00000,  
     };  
     void setup() {   
      analogWrite(6,contrast);  
      lcd.begin(16,2);             // Initializes the interface to the LCD screen, and specifies the dimensions (width and height) of the display  
      lcd.createChar(1, s1);          // Create a custom character for use on the LCD. Up to eight characters of 5x8 pixels are supported  
      lcd.createChar(2, s2);  
      lcd.createChar(3, s3);  
      lcd.createChar(4, s4);  
      lcd.createChar(5, s5);  
      lcd.createChar(6, s6);  
     }  
     void loop()   
     {   
      lcd.clear();  
      lcd.setCursor(0,0);  
      lcd.print("Custom Character");  
        
      for(int i=5;i<11;i++)  
      {  
       lcd.setCursor(i,1);  
       lcd.write(i-4);  
       delay(500);  
      }   
       
      delay(50000);  
     }  
    

    Wednesday, 25 December 2019

    Interfacing of 16 x 2 LCD Display Module with Arduino

    December 25, 2019 0
    In this Tutorial of Interfacing of 16 x 2 LCD Display with Arduino, we will learn how to connect an LCD (Liquid Crystal Display) to the Arduino board. LCD's like these are very popular and broadly used in electronics projects as they are good for displaying information like sensors data from your project, and also they are very cheap.





      Pinout of 16 x 2 LCD :

      Pin No:

      Pin Name:

      Description

      1

      Vss

      Ground pin connected to system ground

      2

      Vcc

      Powers the LCD with +5V (4.7V – 5.3V)

      3

      VE

      Decides the contrast level of display i.e. dimming the brightness or increasing the brightness of LCD. Grounded to get maximum contrast.

      4

      RS

      There are two very important registers inside the LCD. The RS pin is used for the selection of these registers. If RS = 0, the instruction command code register is selected, which allows the user to send commands for the LCD such as clear display, cursor at home, and so on. If RS = 1, the data register is selected. It allows the user to send data that is to be displayed on the LCD.

      5

      R/W

      This pin toggles the display among the read or writes operation, and it is connected to a microcontroller unit pin to get either 0 or 1 (0 = Write Operation, and 1 = Read Operation).

      6

      E

      Sends data to data pins when a high to low pulse is given; Extra voltage push is required to execute the instruction and EN(enable) signal is used for this purpose. This pin should be held high to execute Read/Write process, and it is connected to the microcontroller unit & constantly held high.

      7

      D0

      Data pins 0 to 7 forms a 8-bit data line. They can be connected to Microcontroller to send 8-bit data.

      These LCD’s can also operate on 4-bit mode in such case Data pin 4,5,6 and 7 will be left free.

      8

      D1

      9

      D2

      10

      D3

      11

      D4

      12

      D5

      13

      D6

      14

      D7

      15

      A

      Backlight LED pin positive terminal

      16

      K

      Backlight LED pin negative terminal

       

       



      Features of 16 x 2 LCD Module :

      • Operating Voltage is 4.7V to 5.3V.
      • Current consumption is 1mA without backlight.
      • Alphanumeric LCD display module, meaning can display alphabets and numbers.
      • Consists of two rows and each row can print 16 characters.
      • Each character is build by a 5×8 pixel box.
      • Can work on both 8-bit and 4-bit mode.
      • It can also display any custom generated characters.
      • Available in Green and Blue Backlight.

      Components Required :

      1 x Breadboard ( FlyRobo : http://bit.ly/2rwkVT3 ; Robu.in : http://bit.ly/2PrO9dU )
      1 x Arduino Uno ( FlyRobo : http://bit.ly/2rwkVT3 ; Robu.in : http://bit.ly/2PrO9dU )
      1 x (16 x 2 LCD Module) ( FlyRobo : http://bit.ly/2PRH5IQ ; Robu.in : http://bit.ly/2MsCBX3 )
      Jumper Cables  ( FlyRobo : http://bit.ly/2qzBQ6L ; Robu.in : http://bit.ly/2LzGwRq )
      Arduino USB Cable

      Circuit Diagram :


      LCD PIN

      ARDUINO PIN

      Vss

      GND

      Vdd

      5V

      V0

      D6

      RS

      D12

      RW

      GND

      E

      D11

      D0

      -

      D1

      -

      D2

      -

      D3

      -

      D4

      D5

      D5

      D4

      D6

      D3

      D7

      D2

      A

      5V

      K

      GND

       



      Source Code :


         
       /*  
         
              16 x 2 LCD Display with Arduino  
         
                   HarshTronics  
         
              For More :  
              https://www.harshtronic.blogspot.com  
              https://www.instagram.com/harshtronics  
                
        */  
         
       #include <LiquidCrystal.h>            // includes the LiquidCrystal Library   
       LiquidCrystal lcd(12, 11, 5, 4, 3, 2);      // Creates an LC object Parameters: (RS, E, D4, D5, D6, D7)   
       int contrast = 100;  
         
       void setup()   
       {   
        analogWrite(6,contrast);  
        lcd.begin(16,2);                         // Initializes the interface to the LCD screen, and specifies the dimensions (width and height) of the display }   
       }  
         
       void loop()   
       {   
        lcd.setCursor(3,0);   
        lcd.print("Welcome to");               // Prints "Welcome to" on the LCD   
        delay(3000);                           // 3 seconds delay   
        lcd.setCursor(2,1);                    // Sets the location at which subsequent text written to the LCD will be displayed   
        lcd.print("HarshTronics");            // Prints "HarshTronics" on the LCD  
        delay(3000);                          // 3 seconds delay   
        lcd.clear();                          // Clears the display   
         
        lcd.setCursor(4,0);  
        lcd.print("Arduino");                 // Prints "Arduino" on the LCD   
        delay(3000);                         // 3 seconds delay   
        lcd.setCursor(2,1);                  // Sets the location at which subsequent text written to the LCD will be displayed   
        lcd.print("LCD Tutorial");   
        delay(3000);   
        lcd.clear();                        // Clears the display   
         
        lcd.setCursor(0,0);   
        lcd.print("Subscribe on");  
        lcd.setCursor(3,1);   
        lcd.print("Youtube");   
          
        for (int positionCounter = 0; positionCounter < 4; positionCounter++)   
        {  
         lcd.scrollDisplayRight();        // scroll one position right  
         delay(1000);  
        }  
          
        for (int positionCounter = 4; positionCounter > 0; positionCounter--)   
        {  
         lcd.scrollDisplayLeft();        // scroll one position left  
         delay(1000);  
        }  
          
        lcd.clear();  
         
        for(int i=0;i<=7;i++)  
        {  
         lcd.setCursor(i,0);  
         lcd.blink();                   //Displays the blinking LCD cursor   
         delay(1000);  
        }   
         
        lcd.noBlink();                 // Turns off the blinking LCD cursor   
          
        for(int i=7;i<=15;i++)  
        {  
         lcd.setCursor(i,0);  
         lcd.cursor();                // Displays an underscore (line) at the position to which the next character will be written   
         delay(1000);   
        }  
          
        lcd.noCursor();               // Hides the LCD cursor   
        lcd.clear();                  // Clears the LCD screen   
       }  
         
       /*  
                   HarshTronics  
         
              For More :  
              https://www.harshtronic.blogspot.com  
              https://www.instagram.com/harshtronics  
                
        */  
      



      Feel free to ask any question in the comments section below.

      Tuesday, 10 December 2019

      Arduino LED Pattern

      December 10, 2019 0
      The Arduino is a great platform for playing with electronics. It’s open source hardware and it has a great community behind it. Most of us tried Blinking LED using Arduino as a Beginner. Let’s do something cool using LED's with Arduino. In this project, we will make LED's blink in different patterns. The program has totally 11 different patterns. You can include more patterns if you like. 




      Components Required :


                To Purchase the Components Click on the Links given i.e FlyRobo or Robu.in 



      • Arduino USB Cable


      Circuit Diagram :








      Source Code :

      Note : Remove Rx/Tx pins of Arduino while uploading the Code.

       /*  
         
              Multiple LED Patterns Using Arduino  
         
                   HarshTronics  
         
              For More :  
              https://www.harshtronic.blogspot.com  
              https://www.instagram.com/harshtronics  
                
        */  
         
       void setup()   
       {  
        for (int i = 5; i <= 13; i++) // Set Pins 5 to 13 as Output  
        {  
         pinMode(i, OUTPUT);  
        }  
       }  
         
       void loop()  
       {  
        for(int i=0;i<5;i++)  { pattern1(); }     //pattern 1  
        for(int i=0;i<5;i++)  { pattern2(); }     //pattern 2  
        for(int i=0;i<5;i++)  { pattern3(); }     //pattern 3  
        for(int i=0;i<5;i++)  { pattern4(); }     //pattern 4  
        for(int i=0;i<5;i++)  { pattern5(); }     //pattern 5  
        for(int i=0;i<5;i++)  { pattern6(); }     //pattern 6  
        for(int i=0;i<5;i++)  { pattern7(); }     //pattern 7  
        for(int i=0;i<5;i++)  { pattern8(); }     //pattern 8  
        for(int i=0;i<5;i++)  { pattern9(); }     //pattern 9  
        for(int i=0;i<5;i++)  { pattern10(); }    //pattern 10  
        for(int i=0;i<25;i++) { pattern11(); }    //pattern 11  
        clear();  
        delay(5000);   
       }  
         
       void pattern1()  
       {  
        for(int i=5;i<14;i++)  
        {  
         digitalWrite(i,HIGH);  
         delay(100);  
         digitalWrite(i,LOW);  
        }  
       }  
         
       void pattern2()  
       {  
        for(int j=5; j<14; j++)  
        {  
         digitalWrite(j, HIGH);  
         delay(30);  
         digitalWrite(j, LOW);  
         delay(30);  
        }  
        for(int k = 15; k>5; k--)  
        {  
         digitalWrite(k, HIGH);  
         delay(30);  
         digitalWrite(k, LOW);  
         delay(30);  
        }  
       }  
         
       void pattern3()  
       {  
        for(int i=5;i<14;i++)  
        {  
         digitalWrite(i,HIGH);  
         delay(100);  
        }  
        for(int i=5;i<14;i++)  
        {  
         digitalWrite(i,LOW);  
         delay(100);  
        }   
       }  
         
       void pattern4()  
       {  
        for(int i = 15; i >= 5; i--)  
        {  
         digitalWrite(i, HIGH);  
         delay(20);  
         digitalWrite(i+1, LOW);  
         delay(20);  
        }  
        for(int i = 15; i >= 5; i--)  
        {  
         digitalWrite(i+1, HIGH);  
         delay(20);  
         digitalWrite(i+2, LOW);  
         delay(20);  
        }  
        for(int i = 15; i >= 5; i--)  
        {  
         digitalWrite(i+2, HIGH);  
         delay(20);  
         digitalWrite(i+3, LOW);  
         delay(20);  
        }  
        for(int i = 15; i >= 5; i--)  
        {  
         digitalWrite(i+3, HIGH);  
         delay(20);  
         digitalWrite(i+4, LOW);  
         delay(20);  
        }  
        for(int i = 15; i >= 5; i--)  
        {  
         digitalWrite(i+4, HIGH);  
         delay(20);  
         digitalWrite(i+5, LOW);  
         delay(20);  
        }  
        for(int i = 15; i >= 5; i--)  
        {  
         digitalWrite(i+5, HIGH);  
         delay(20);  
         digitalWrite(i+6, LOW);  
         delay(20);  
        }  
        for(int i = 15; i >= 5; i--)  
        {  
         digitalWrite(i+6, HIGH);  
         delay(20);  
         digitalWrite(i+7, LOW);  
         delay(20);  
        }  
        for(int i = 15; i >= 5; i--)  
        {  
         digitalWrite(i+7, HIGH);  
         delay(20);  
         digitalWrite(i+8, LOW);  
         delay(20);  
        }  
        for(int i = 15; i >= 5; i--)  
        {  
         digitalWrite(i+8, HIGH);  
         delay(20);  
         digitalWrite(i+9, LOW);  
         delay(20);  
        }  
        for(int i = 15; i >= 5; i--)  
        {  
         digitalWrite(i+9, HIGH);  
         delay(20);  
         digitalWrite(i+10, LOW);  
         delay(20);  
        }  
        for(int i = 15; i >= 5; i--)  
        {  
         digitalWrite(i+10, HIGH);  
         delay(20);  
         digitalWrite(i+11, LOW);  
         delay(20);  
        }  
        for(int i = 15; i >= 5; i--)  
        {  
         digitalWrite(i+13, HIGH);  
         delay(20);  
         digitalWrite(i, LOW);  
        }  
       }  
         
       void pattern5()  
       {  
        for(int j=5; j<14; j++)  
        {  
         digitalWrite(j, LOW);  
         delay(30);  
         digitalWrite(j, HIGH);  
         delay(30);  
         digitalWrite(j-2, LOW);  
         delay(30);  
         digitalWrite(j, HIGH);  
        }  
        for(int k = 15; k>5; k--)  
        {  
         digitalWrite(k, LOW);  
         delay(30);  
         digitalWrite(k, HIGH);  
         delay(30);  
         digitalWrite(k+2, LOW);  
         delay(30);  
         digitalWrite(k, HIGH);  
        }  
       }  
         
        void clear()  
        {  
         for(int i=5;i<14;i++)  
         {  
          digitalWrite(i,LOW);   
         }  
        }  
         
        void pattern6()  
        {  
         int count = 13;   
         
         for (int i = 5; i < 13; i++)   
         {  
          clear();  
          digitalWrite(i, HIGH);     
          digitalWrite(count, HIGH);   
          count--;  
          if (count != 9)   
          {  
           delay(100);  
          }  
         }  
         
         for (int i = 13; i > 5; i--)   
         {   
          clear();  
          digitalWrite(i, HIGH);   // chaser 1  
          digitalWrite(count, HIGH); // chaser 2  
          count++;  
          if (count != 10)   
          {  
           delay(100);  
          }    
         }   
        }  
         
       void pattern7()  
       {  
        for(int i=5; i<14; i++)  
         {  
          digitalWrite(i, HIGH);  
          delay(50);  
         }  
        for(int i=5; i<14; i++)  
         {  
         digitalWrite(i, LOW);  
         delay(50);  
         }  
          
          
        for(int i = 14; i>=5; i--)  
        {  
         digitalWrite(i, HIGH);  
         delay(50);  
        }  
        for(int i = 14; i>=5; i--)  
        {  
         digitalWrite(i, LOW);  
         delay(50);  
        }  
       }  
         
       void pattern8()  
       {  
        for(int j = 5; j <= 13; j++)  
        {  
         digitalWrite(j, HIGH);  
         delay(100);  
         j=j+1;  
        }  
           
        for(int j = 5; j <= 13; j++)  
        {  
         digitalWrite(j, LOW);  
         delay(100);  
        }  
          
        for(int k = 14; k > 5; k--)  
        {  
         digitalWrite(k, HIGH);  
         delay(100);  
         k=k-1;  
        }  
        for(int k = 14; k > 5; k--)  
        {  
         digitalWrite(k, LOW);  
         delay(100);  
        }  
       }  
         
       void pattern9()  
       {  
        {  
        digitalWrite(5,HIGH);  
        digitalWrite(7,HIGH);  
        digitalWrite(9,HIGH);  
        digitalWrite(11,HIGH);  
        digitalWrite(13,HIGH);  
        digitalWrite(6,LOW);  
        digitalWrite(8,LOW);  
        digitalWrite(10,LOW);  
        digitalWrite(12,LOW);   
        }  
        delay(150);  
        {  
        digitalWrite(5,LOW);  
        digitalWrite(7,LOW);  
        digitalWrite(9,LOW);  
        digitalWrite(11,LOW);  
        digitalWrite(13,LOW);  
        digitalWrite(6,HIGH);  
        digitalWrite(8,HIGH);  
        digitalWrite(10,HIGH);  
        digitalWrite(12,HIGH);  
        }  
        delay(150);  
       }  
         
       void pattern10()  
       {  
         {  
        digitalWrite(5,HIGH);  
        digitalWrite(6,HIGH);  
        digitalWrite(7,HIGH);  
        digitalWrite(8,HIGH);  
        digitalWrite(9,HIGH);  
        digitalWrite(10,LOW);  
        digitalWrite(11,LOW);  
        digitalWrite(12,LOW);  
        digitalWrite(13,LOW);   
        }  
        delay(150);  
        {  
        digitalWrite(9,HIGH);  
        digitalWrite(10,HIGH);  
        digitalWrite(11,HIGH);  
        digitalWrite(12,HIGH);  
        digitalWrite(13,HIGH);  
        digitalWrite(5,LOW);  
        digitalWrite(6,LOW);  
        digitalWrite(7,LOW);  
        digitalWrite(8,LOW);  
        }  
        delay(150);   
       }  
         
       void pattern11()   
       {  
        int randomled = random(5, 14);  
        digitalWrite(randomled, HIGH);  
        delay(50);  
        digitalWrite(randomled, LOW);  
        delay(50);  
       }  
         
       /*  
                   HarshTronics  
         
              For More :  
              https://www.harshtronic.blogspot.com  
              https://www.instagram.com/harshtronics  
                
        */