Experiencing Bluetooth® issues with Go Direct® sensors on Chromebooks? Get help here.

Shop

Displaying Sensor Data on an LCD Screen

Liquid-crystal displays (LCD) are flat-panel displays that use the light-modulating properties of liquid crystals to produce images. This technology is often used in TVs, computer monitors, and mobile devices. Normally, a standard LCD screen requires 8 pin connections to work with an Arduino®, but we recommend using a serial-enabled 16×2 LCD screen from SparkFun. The nice thing about SparkFun’s display is that it can be easily connected to the DCU using only three wires.
  • LCD pin RX (receive) to DCU line D4 (Arduino pin 9)
  • LCD pin GND to DCU line GND
  • LCD pin VDD to DCU line XP (power)
Once you have wired the LCD screen to the DCU, you can display numbers and text characters with the sample sketch, VernierLibTutorialAnalogLCD. This sketch assumes you have connected a Vernier analog (BTA) sensor and the DCU to the Analog 1 and Digital 2 ports, respectively, on the Vernier Arduino Interface Shield or into Analog and Digital Protoboard Adapter wired as explained in the Connecting Vernier Sensors to the Arduino Using a Breadboard section. You will need to include the SoftwareSerial.h library at the beginning of your sketch in order to access the display functions. To position the cursor, send the special command character 254 followed by the cursor position you’d like to set. Each cursor position is represented by a number.
POSITION LINE 1 LINE 2
1 128 192
2 129 193
3 130 194
4 131 195
5 132 196
6 133 197
7 134 198
8 135 199
9 136 200
10 137 201
11 138 202
12 139 203
13 140 204
14 141 205
15 142 206
16 143 207
If power consumption must be minimized in your project, you can adjust the backlight brightness by sending the special command character 128 followed by a number between 128 (backlight off) to 157 (backlight fully on). You can also adjust the backlight manually by gently turning the trimpot on the back of the LCD screen with a small screwdriver.
/* VernierLibTutorialAnalogLCD (v2018)
 * This sketch reads a data point from a Vernier Analog (BTA) 
 * sensor once every half second and prints the sensor name 
 * and sensor reading with units to an LCD screen connected
 * to the Vernier DCU.
 * 
 * Plug the sensor into the Analog 1 port on the Vernier Arduino 
 * Interface Shield or into an Analog Protoboard Adapter wired 
 * to Arduino pin A0. 
 * Plug the DCU into the Digital 2 port on the shield or into a
 * Digital Protoboard Adapter wired to Arduino pins 6, 7, 8, 9. 
 * Connect the LCD pins RX, GND, VDD to DCU lines 
 * D4, GND, XP respectively.
 * Make sure you connect the DCU to a 5-volt power supply.
 */

#include "VernierLib.h" //include Vernier functions in this sketch
VernierLib Vernier; //create an instance of the VernierLib library
#include <SoftwareSerial.h> //access commands for LCD display
SoftwareSerial mySerial(3,9); //attach the LCD RX line to Arduino pin 9


void setup() {
  Vernier.autoID(); //identify the sensor being used
  mySerial.begin(9600); //setup communication to display
  delay(500); //wait half second for display to boot up
  mySerial.write(124); //send command to adjust backlight brightness of display
  mySerial.write(150); //send number between 157 (max) to 128 (off) to designate brightness
  delay(500); //wait half second for display to start
}

void loop() {
  float sensorReading = Vernier.readSensor(); //read one data value
  mySerial.write(254); //send command to move cursor
  mySerial.write(128); //move cursor to beginning of first line
  mySerial.print(Vernier.shortName()); //display sensor name
  mySerial.write(254); //send command to move cursor
  mySerial.write(138); //move cursor to middle of first line
  mySerial.print(Vernier.sensorUnits()); //display units
  mySerial.write(254); //send command to move cursor
  mySerial.write(192); //move cursor to beginning of second line
  mySerial.print(sensorReading); //display data value
  delay(1000); //wait one second
}

Arduino® and

Arduino Logo

are trademarks of Arduino SA.

SAVE/SHARE YOUR CART