PROJECT Nº 6: LCD display

Learn how to create a program to write words on the display of the Mini Lab with these two exercises.

EXERCISES INDEX:

  • Exercise 6.1: Write words on the LDC display
  • Exercise 6.2: Indicate the light and temperature measured on the display

 

Exercise 6.1: Write words on the LDC display

Learn how to program in order to write words on the LCD display of the Mini Lab. 

DIFFICULTY LEVEL: Advanced.

DURATION OF THE EXERCISE: 45 min.

MATERIALS:

  • LCD display
  • Computer

The Mini Lab will have to be built according to the instructions manual.

What is an LCD display?

LCD is the acronym of Liquid Crystal Display. It’s a thin and flat display composed by a number of colored of monochrome pixels placed in front of a light source or reflective.

There are different types of displays, depending on the number of lines and columns it has. The LCD display included in the Mini Lab kit has 16 columns and 2 lines.

PROGRAMMING CODE: 

You can do this project using Arduino or a visual programming software by blocks compatible. Below you will find the necessary code.

Arduino Code 

  1. Download and install the Arduino IDE program.
  2. In order to program the LCD display with Arduino IDE in Windows, you need to add a library. You can do it by following the steps indicated in this link.
  3. Once you have installed the library, copy the following program in it:
    #include <Wire.h> 
    #include <LiquidCrystal_I2C.h> // LIBRARY FOR THE LCD DISPLAY
    
    LiquidCrystal_I2C lcd(0x27, 16, 2); // CONFIGURATION OF THE LCD DISPLAY
    
    void setup() {
    // CLEAN THE LCD DISPLAY
    lcd.begin(); // INITIALIZE THE LCD SCREEN
    lcd.clear(); // CLEAN THE LCD DISPLAY
    }
    
    void loop() { 
      // WRITE ON LCD DISPLAY
      lcd.setCursor(0, 0);  // WRITE ON THE LINE 1 COLUMN 0
      lcd.print("MINI LAB");  // CONTENT TO WRITE ON THE DISPLAY
      lcd.setCursor(0, 8);  // WRITE ON THE LINE 2 COLUMN 0
      lcd.print("eBOTICS");  // CONTENT TO WRITE ON THE DISPLAY
    }
    
  4. Configure and upload the code, following the indications on the Mini Lab First Steps guide.
  5. Check that the BTL/USB switch on the Build&Code 4in1 board is set to USB, to upload the code correctly.

Code for the visual programming software by blocks compatible

  1. Download and install the program.
  2. In order to program the LCD display with the visual programming software by blocks you need to install the extension LCD I2C PACK de Wu Xin in the program. Follow the steps indicated in the following link.
  3. Once you have installed the extension, copy the following code:
    *Note that every time you charge a new program and the content on the screen changes, you will have to restart the Build&Code 4in1 board.
  4. Configure and upload the code, following the indications on the Mini Lab First Steps guide.
  5. Check that the BTL/USB switch on the Build&Code 4in1 board is set to USB, to upload the code correctly.

RESULT OF THE EXERCISE:

When pressing the button, the buzzer will make a sound and when you stop pressing the buzzer, the button will stop making the sound.

 

Exercise 6.2: Indicate the light and temperature measured on the display

Learn to program the LCD display for it to indicate the light measured by the light sensor and the temperature of the servomotor.

DIFFICULTY LEVEL: Advanced.

DURATION OF THE EXERCISE: 45 min.

MATERIALS:

  • LCD screen
  • 1 Servomotor
  • 1 Analog Light Sensor
  • 1 USB – Micro USB cable
  • Computer

The Mini Lab will have to be built according to the instructions manual.

PROGRAMMING CODE:

You can do this project using the Arduino, Bitbloq and other visual programming software by blocks compatible. Below you will find the necessary code.

Arduino Code 

  1. Download and install the Arduino IDE program. It is available for Windows, Mac OS and Linux.
  2. Open the Arduino program and copy the following program in it:
    #include <Wire.h> 
    #include <LiquidCrystal_I2C.h> // LIBRARY FOR THE LCD DISPLAY
    #include <Servo.h> LIBRARY FOR THE SERVOMOTOR
    
    LiquidCrystal_I2C lcd(0x27, 16, 2); // CONFIGURATION OF THE LCD DISPLAY
    Servo motor; // VARIABLE OF THE SERVOMOTOR
    int pot = 0, pinpot = A1; //VARIABLE  PINS OF THE POTENTIOMETER 
    float degree; // DEGREES VARIABLE OF THE SERVOMOTOR 
    int pinlight = A0, luz; // LDR PIN AND VARIABLE
    
    void setup() {
      // CLEAN LCD DISPLAY
      lcd.begin(); // INITIALIZATION OF THE LCD DISPLAY
      lcd.clear(); // CLEAN LCD DISPLAY
      //CONFIGURATION OF THE SERVOMOTOR
      motor.attach (9);
    }
    
    void loop() {
      // DO THE TURN OF THE POTENTIOMETER WITH THE DEGREES OF THE SERVOMOTOR
      pot = analogRead (pinpot); // READ THE VALUE OF THE POTENTIOMETER
      degree = map (pot, 0,1023, 0, 180); // SCALATE THE VALUES OF THE POTENTIOMETER WITH THE DEGREES OF THE SERVOMOTOR
      if ( degree <= 10)
      {
        motor.write (10); 
      }
      else
      {
        motor.write (degree); 
      }
      //READ THE LIGHT INTENSITY OF THE LIGHT SENSOR
      luz = analogRead( pinlight); // READING THE LIGHT INTENSITY OF THE LIGHT SENSOR
      // WRITE ON THE LCD DISPLAY
      lcd.setCursor(0, 0);  // WRITE ON LINE 1 COLUMN 0 
      lcd.print("S.Luz = ");  // CONTENT TO WRITE ON THE DISPLAY
      lcd.print(luz);  // CONTENT OF THE LIGHT SENSOR
      lcd.setCursor(0, 8);  // WRITE ON LINE 2 COLUMN 0
      lcd.print("Grados M = ");  // CONTENT TO WRITE ON THE DISPLAY
      lcd.print(degree);  // SERVOMOTOR DEGREES
    }
    
  3. Configure and upload the code, following the indications on the Mini Lab First Steps guide.
  4. Check that the BTL/USB switch on the Build&Code 4in1 board is set to USB, to upload the code correctly.

Code for the visual programming software by blocks compatible

  1. Download and install the program.
  2. Open the software and copy the following code. Use the following image as a guide:
  3. Configure and upload the code, following the indications on the Mini Lab First Steps guide.
  4. Check that the BTL/USB switch on the Build&Code 4in1 board is set to USB, to upload the code correctly.

RESULT OF THE EXERCISE: 

The LDC display will show the reading of the LDR light sensor and the constant position in degrees of the servomotor.

With the program you have created, besides showing permanent text, the display will also show text that is constantly changing.

1 0

0