Four Digit Seven Segment LED Display

  

 

Update: LDR control of brightness can be found here.

This display has a TM1637 display driver and was made by Seed Studio although there are a number of copies around. The display has four connections, Vcc, Gnd, Clock and Data. I had so much trouble trying to get this to work, I found two different libraries but neither seemed to work. Even the library and example from Seed Studio just would not work for me.

Eventually I found this blog that explained what was needed. Most of the other tutorials used a number of libraries (anything up to five!) but this sketch used no library at all. It seems that the sequence used to send data to the driver has to be done in a specific way.

I wanted to build a clock, but the blog gave a sketch for a timer, so I have modified the original sketch so that the clock shows Hours and Minutes. The sketch is the work of the original blogger, but I publish my modified version here with the original author data intact.

The time can be set by editing the time set section, mine was set to start at 22:11. Edit this setting the time a minute or so fast then at the correct time press Reset on the Arduino. The clock shows time in the 24 hour format.

Connections:

Arduino TM1637 display
PIN #7 ------------------ CLK
PIN #8 ------------------ DIO
5V ---------------------- VCC
GND --------------------- GND

The Sketch:

/* TM1637 4 Digit Seven Segment Display, Clock
Credit to Blog 3D Logic.com */


/* 24 hour clock code by Chris Rouse

Connections:
Vcc on Display to 5 volts on Arduino
Gnd on Display to Gnd on Arduino
CLK on Display to Pin 2 on Arduino
DIO on Display to pin 3 on Arduino
*/

const int clock = 2;
const int data = 3;

/*0*/ /*1*/ /*2*/ /*3*/ /*4*/ /*5*/ /*6*/ /*7*/ /*8*/ /*9*/
uint8_t digits[] = { 0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f };
byte tcnt2;
//unsigned long time = 0; // 86390000;

/********************************************************
Set clock to desired time if required
Otherwise REM the next 3 lines out and the clock
will start from 00:00
Do not add leading zeros to the values
time is in 24 hour format
**********************************************************/
unsigned long setMinutes = 11;
unsigned long setHours = 22;
unsigned long time = (setMinutes * 60 * 1000) + (setHours * 3600 *1000);
/***************************************************************/

void setup()
{
pinMode(13, OUTPUT);
digitalWrite(13, LOW);
setupInterrupt();

pinMode(clock, OUTPUT);
pinMode(data, OUTPUT);

// initialise display and set brightness
// 0x88 is dim and increasing value to 0x8C increases brightness
start();
writeValue(0x8c);
stop();

// clear display
write(0xff, 0xff, 0xff, 0xff);
}

// Credits for the interrupt setup routine:
// http://popdevelop.com/2010/04/mastering-timer-interrupts-on-the-arduino/
void setupInterrupt()
{
/* First disable the timer overflow interrupt while we're configuring */
TIMSK2 &= ~(1<<toie2);

</toie2);

/* Configure timer2 in normal mode (pure counting, no PWM etc.) */
TCCR2A &= ~((1<<wgm21) |="" (1<<wgm20));

TCCR2B &= ~(1<<wgm22);

</wgm22);

/* Select clock source: internal I/O clock */
ASSR &= ~(1<<as2);

</as2);

/* Disable Compare Match A interrupt enable (only want overflow) */
TIMSK2 &= ~(1<<ocie2a);

</ocie2a);

/* Now configure the prescaler to CPU clock divided by 128 */
TCCR2B |= (1<<cs22) |="" (1<<cs20);="" set="" bits

TCCR2B &= ~(1<<cs21); clear="" bit

/* We need to calculate a proper value to load the timer counter.
* The following loads the value 131 into the Timer 2 counter register
* The math behind this is:
* (CPU frequency) / (prescaler value) = 125000 Hz = 8us.
* (desired period) / 8us = 125.
* MAX(uint8) + 1 - 125 = 131;
*/
/* Save value globally for later reload in ISR */
tcnt2 = 131;

/* Finally load end enable the timer */
TCNT2 = tcnt2;
TIMSK2 |= (1<<toie2);
}</toie2);
/*
* Install the Interrupt Service Routine (ISR) for Timer2 overflow.
* This is normally done by writing the address of the ISR in the
* interrupt vector table but conveniently done by using ISR() */
ISR(TIMER2_OVF_vect) {
/* Reload the timer */
TCNT2 = tcnt2;

time++;
time = time % 86400000;

}

void loop()
{
unsigned long t = (unsigned long)(time/1000);
uint8_t minutes = (byte)((t / 60) % 60);
uint8_t hours = (byte)((t / 3600) % 23);
uint8_t seconds = (byte)(t % 60);

// blink onboard LED every Second
if(((seconds/2)*2) == seconds) {
digitalWrite(13, LOW);
}
else {
digitalWrite(13, HIGH);
}
//
// display the time
write(digits[hours / 10], digits[hours % 10] | ((seconds & 0x01) << 7), digits[minutes / 10], digits[minutes % 10]);
}

void write(uint8_t first, uint8_t second, uint8_t third, uint8_t fourth)
{
start();
writeValue(0x40);
stop();

start();
writeValue(0xc0);
writeValue(first);
writeValue(second);
writeValue(third);
writeValue(fourth);
stop();
}

void start(void)
{
digitalWrite(clock,HIGH);//send start signal to TM1637
digitalWrite(data,HIGH);
delayMicroseconds(5);

digitalWrite(data,LOW);
digitalWrite(clock,LOW);
delayMicroseconds(5);
}

void stop(void)
{
digitalWrite(clock,LOW);
digitalWrite(data,LOW);
delayMicroseconds(5);

digitalWrite(clock,HIGH);
digitalWrite(data,HIGH);
delayMicroseconds(5);
}

bool writeValue(uint8_t value)
{
for(uint8_t i = 0; i < 8; i++)
{
digitalWrite(clock, LOW);
delayMicroseconds(5);
digitalWrite(data, (value & (1 << i)) >> i);
delayMicroseconds(5);
digitalWrite(clock, HIGH);
delayMicroseconds(5);
}

// wait for ACK
digitalWrite(clock,LOW);
delayMicroseconds(5);

pinMode(data,INPUT);

digitalWrite(clock,HIGH);
delayMicroseconds(5);

bool ack = digitalRead(data) == 0;

pinMode(data,OUTPUT);

return ack;
}

Things to do:
The brightness of the display can be altered and there are eight levels from dim to bright, adding an LDR circuit could be used to dim the display as the light level drops. 

List of Keyes Boards/Sensors for Arduino

I thought that it could be useful to compile a list of the little Keyes boards and to link them to blogs on this site, wherever possible.


KY-001. Temperature Sensor DS18B20. Find sketch here.

KY-002. Vibration Sensor, outputs a LOW when vibrated. Find sketch here.

KY-003. Hall Effect Sensor. Find sketch here.

KY-004. Push button, outputs a HIGH when pressed

KY-005. InfraRed Emitter

KY-006. Passive Buzzer, needs a signal to operate, like a speaker.

  
AD-007. HC-SR05 PIR, motion detector. This module is included in the Sunkey Sensors kit.

KY-008. Laser 5 volts 650nm. Find sketch here.

KY-009. Three colour, SMD, LED. Find sketch here.

KY-010. Opto Light Switch, output HIGH when beam broken. Find sketch here.

KY-011. Two colour LED, Red and Green

KY-012. Active Buzzer. Find sketch here.

KY-013. Temperature Sensor, Analogue. Find sketch here.

  
AD-014. GY65 Atmospheric pressure sensor, similar to BMP180. This module is part of the Sunkey Sensor kit.

KY-015. Humidity Sensor, DHT 11

KY-016. Three colour LED. Find sketch here.

kY-017. Mercury Tilt Switch

KY-018. LDR, Analogue output. Find sketch here.

KY-019. Single 5 volt relay

KY-020. Tilt Sensor

KY-021. Reed Switch

KY-022. InfraRed Receiver, based on 1838 IR Receiver/Decoder

KY-023. X/Y Joystick, two potentiometers and a button

KY-024. Hall Effect Sensor, digital output only

KY-025. Reed Relay, digital output only

KY-026. Flame Sensor, digital output only

KY-027. Magic Light Cup Module, LED Blinks as Mercury switch Tilts

KY-028. Temperature Sensor, Analog sensor with HIGH when temp reached.

  
KY-029. Two colour LED module. Red and Green.

  
KY-030. MQ02 Gas Sensor.

KY-031. Hit Sensor, similar to a vibration sensor find sketch here.

KY-032. Obstacle Avoidance Detector, IR Tx/Rx pair

KY-033. Line Follower

KY-034. Automatic flashing LED Module, seven colours

KY-035. Hall Effect Sensor, Digital Switch Output only

KY-036. Metal Touch Sensor, Digital output. Sketch can be found here.

KY-037. Microphone Sound Sensor, Digital Output only

KY-038. Microphone Sound Sensor, digital and Analogue output

KY-039. Pulse Rate Detector, high sensitivity so shield from mains lighting

KY-040. Rotary Encoder

Tiny OS Bluetooth Bee Shield, using as a Master unit

 

I looked at the TinyOS Bluetooth Bee Shield in an earlier blog, here  and although I described how to set it up as a Master Unit I did not describe a project using it in a Master Role. I have just posted a series on the HC05/HC06 Bluetooth devices used in a remote thermometer project.

The TinyOS Bluetooth Bee acts just like an HC05, with the only difference being the Key pin used to switch the AT mode is connected through a switch to Vcc. This means that a sketch cannot use an Arduino pin to control the Key pin.

The series of blogs on the HC05/HC06 can be found here and this page has links to all the various parts. This shield plugs straight onto the Arduino and does not need a Logic Level Converter.

The project can be built and the HC05 and Logic Level Converter are simply replaced with the TinyOS Bluetooth Bee, upload the sketch as used in the HC05 project.

This shield has two small switches as a block in the middle of the small Bluetooth board. The earlier blog here shows how to set the shield for use with Software Serial.  With the sketch from the Remote Temperature Master uploaded onto an Arduino remover the power and plug the TinyOS shield in. Make sure that the two small switches are pushed over to the left (towards pin 1 on the Arduino) and apply power.

Now move the two switches to the Right, and press Reset on the Arduino and if all is well after about 25 seconds the blue LED will light and the LED on the Slave unit will remain lit. The two boards will have linked.

JMYCU Bluetooth units, HC05 and HC06 Part 3 – linking two Arduino’s 

Part 1 setting up the HC06 Slave Bluetooth unit is here.

Part 2. Setting up the HC05 Master/Slave unit is here.

The Universal Bluetooth Receiver with LCD display is here.

Important note: if the Key pin on the HC05 is HIGH when the power is connected it will enter th AT Mode using a baud rate of 38400. As the Slave is set at 9600 baud this presents problems. However, if the Key pin is taken HIGH after power is applied the baud rate is unchanged. In the sketch used here the Key pin is connected to Arduino pin 4. This pin is taken HIGH shortly after power is applied. The HC05 will enter AT mode at 9600 baud rate and is set as a Master Unit, then paired with the HC06. The Key pin can be left HIGH and still the HC05 will be able to communicate with the HC06 as long as the Key pin was taken high after the power was applied.

Once the two Bluetooth units are working the next thing is to link the Master with the Slave. It is useful to use the Universal Bluetooth Receiver with LCD display and the link for this is shown above. 

We now need to apply power to the Arduino/Slave then load the next sketch into the Arduino/Master unit, this will allow AT commands to be sent to the HC05.

With both Arduinos powered On type the following commands into the Serial Monitor connected to th Master make sure NL/CR has been selected.

AT+INIT (only do this once , after applying the power)
AT+INQM=0,9,30 (this will search for up to nine Bluetooth units)
AT+ROLE=1 (sets the HC05 as a master, it will not search unless this is done)
AT+INQ (prints out the address of nearby Bluetooth units)

The bluetooth addresses of nearby units will now be displayed. The address is the first three groups separated by a comma, there are two other groups of numbers.

My HC06 gave 13,1B,412154 as the address.

Once you have identified the HC06 on the Slave Arduino type

AT+LINK=13,1B,412154 (inset your address here)

to link to the HC06. Remember to make sure LF and CR are selected in the serial monitor, or send \r\n with each command. Once linked the LED on the HC06 will stop flashing and remain lit.


/*******************************************************
// HC05 Master connects to HC06 Slave
//
// On first running the Bluetooth module is reaset to factory settings then the speed is set to 9600
//
// Connect RX from the HC05 to pin 2 on the Arduino.
// Connect TX from the HC05 to pin 3 on the Arduino

// to send AT commands KEY is connected to Vcc
// after power is connected, to keep the baud rate at 9600
// by controling the Key pin with Arduino pin 4
// Switch the power on
// Open up the Serial Port Monitor
// Type in AT and click on the SEND button, OK will be printed in the monitor
// showing that the module is receiving commands.
//
*****************************************************/

#include <softwareSerial.h>
SoftwareSerial mySerial(2, 3); // RX, TX
#define keyPin 4 // connects to HC05 KEY
String buildString = ""; // Stores response of bluetooth device
// which simply allows \n between each response.

void setup()
{
// Open serial communications and wait for port to open:
// Hardware Serial port set to 9600
Serial.begin(9600);
// SoftwareSerial "com port" data rate. 38400.
mySerial.begin(9600); // default speed in AT mode
//
pinMode(keyPin, OUTPUT);
digitalWrite(keyPin, LOW); // puts HC05 into communication mode
//
delay(1000);
digitalWrite(keyPin, HIGH); // put HC05 into AT mode
delay(200);
//
// reset bluetooth module to factory settings
// Note: the delay blocks are necessary to allow the commands to take place

// this will take about 25 seconds to link up with HC06
Serial.println("Initialising this will take about 25 seconds...");
mySerial.write("AT+ORGL\r\n");
delay(2000);
mySerial.write("AT+UART=9600,0,0\r\n");
delay(2000);
mySerial.write("AT+NAME=BluetoothBee\r\n");
delay(4000);
mySerial.write("AT+INIT\r\n");
delay(4000);
mySerial.write("AT+INQM=0,9,30\r\n");
delay(4000);
mySerial.write("AT+ROLE=1\r\n");
delay(4000);
mySerial.write("AT+INQ\r\n");
delay(4000);
mySerial.write("AT+LINK=13,1,41254\r\n");
delay(2000);
Serial.println("HC-05 set as a Master, trying to connect to slave");
}

void loop() {
mySerial.write("testing...");
delay(1500);
mySerial.write("connection");
delay(1500);
}

As far as I can determine the HC05 in Master mode will only connect with an HC06. The TinyOS Bluetooth Shield uses an HC05 ( see this post here) and so will also connect with an HC 06 and can use all of the code shown above.

Remote Bluetooth Thermometer using an Arduino

This project uses the Universal Bluetooth Receiver with LCD display here. A TMP36 analogue temperature sensor, described here, is used and the data is sent via Bluetooth HC05 Bluetooth, set as a Master (described here). The temperature is displayed on the remote receiver.

 

The receiver is built as described in the link above, but a small change is made to the sketch to allow it to show temperature. Upload the following sketch

/*
Universal Bluetooth receiver with LCD Display

Uses a 1602a 2 line by 16 character display
and a HC06 Bluetooth Slave. Allows temperature to be displayed.

The LCD circuit:
* LCD RS pin to digital pin 12
* LCD Enable pin to digital pin 11
* LCD D4 pin to digital pin 5
* LCD D5 pin to digital pin 4
* LCD D6 pin to digital pin 3
* LCD D7 pin to digital pin 2
* LCD R/W pin to ground
* 10K variable resistor:
* ends to +5V and ground
* wiper to LCD VO pin (pin 3)

The Bluetooth circuit:
* Vcc and Gnd on HC06 to Arduino +5volts and Gnd
* HC06 Tx to Arduino pin 6, through a logic level convertor
* HC06 Rx to Arduino pin 7, through a logic level convertor
*/

// include the libraries:
#include <softwareSerial.h>
SoftwareSerial mySerial(6,7); // RX, TX
#include <LiquidCrystal.h>

// Initialize the LCD library with the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
Serial.begin(9600); // used to debug
// set up the LCD's number of columns and rows
lcd.begin(16, 2);
mySerial.begin(9600); // default baudrate for the HC06
lcd.setCursor(0,0); // set cursor at the start of the first line
lcd.print("Universal");
lcd.setCursor(0,1); // set cursor at the start of the first line
lcd.print("Serial Receiver");
}

void loop() {
if (mySerial.available()) {
// wait a bit for the entire message to arrive
delay(100);
// clear the screen
lcd.clear();
// Print a message to the LCD
lcd.setCursor(0,0); // set cursor at the start of the first line
lcd.print("Remote Temp:");
lcd.setCursor(0, 1); // first character line 2
// read all the available characters
while (mySerial.available() > 0) {
// display each character to the LCD
lcd.write(mySerial.read());
}
lcd.print((char)223); // the degree symbol
lcd.print("C");
}
}

To check everything is working correctly the LED on the HC06 should be blinking and the display should show the Universal Serial Receiver. Use your mobile phone, or other device, to connect to the HC06   And send a number for example 30.5, the LCD display should change and show Remote Temp: 30.5*C try sending other values. Once all is working well build the Bluetooth Master (link shown at the top of the page), adding a TMP 36 temperature sensor (link shown at the top of the page). The output of the TMP36 should be connected to A1 (pin 15).

Upload the following sketch
  
/*******************************************************
// Remote Bluetooth Thermometer
//
// Connect RX from the HC05 to pin 2 on the Arduino.
// Connect TX from the HC05 to pin 3 on the Arduino
//
// Connect Gnd on the TMP 36 to Arduino Gnd
// Connect Vcc on TMP 36 to Arduino 3.3v
// Connect Arduino 3.3 v to Arduino ARef
// Connect Output on TMP36 (centre pin) to A1 (pin 15)
//
*****************************************************/

#include <softwareserial.h>
SoftwareSerial mySerial(2, 3); // RX, TX
#define keyPin 4 // connects to HC05 KEY
String buildString = ""; // Stores response of bluetooth device
// which simply allows \n between each response.

// TMP36
#define aref_voltage 3.3 // we tie 3.3V to ARef and measure it with a multimeter!

//TMP36 Pin Variables
int tempPin = 1; //the analog pin the TMP36's Vout (sense) pin is connected to
//the resolution is 10 mV / degree centigrade with a
//500 mV offset to allow for negative temperatures
int tempReading; // the analog reading from the sensor
//

void setup()
{
// Open serial communications and wait for port to open:
// Hardware Serial port set to 9600
Serial.begin(9600);
// SoftwareSerial "com port" data rate. 38400.
mySerial.begin(9600); // default speed in AT mode
//
// TMP36
// set the aref to something other than 5v
analogReference(EXTERNAL);
//
pinMode(keyPin, OUTPUT);
digitalWrite(keyPin, LOW); // puts HC05 into communication mode
//
delay(1000);
digitalWrite(keyPin, HIGH); // put HC05 into AT mode
delay(200);
//
// reset bluetooth module to factory settings
// Note: the delay blocks are necessary to allow the commands to take place

// this will take about 25 seconds to link up with HC06
Serial.println("Initialising this will take about 25 seconds...");
mySerial.write("AT+ORGL\r\n");
delay(2000);
mySerial.write("AT+UART=9600,0,0\r\n");
delay(2000);
mySerial.write("AT+NAME=BluetoothBee\r\n");
delay(4000);
mySerial.write("AT+INIT\r\n");
delay(4000);
mySerial.write("AT+INQM=0,9,30\r\n");
delay(4000);
mySerial.write("AT+ROLE=1\r\n");
delay(4000);
mySerial.write("AT+INQ\r\n");
delay(4000);
mySerial.write("AT+LINK=13,1,41254\r\n"); // insert your address here
delay(2000);
Serial.println("HC-05 set as a Master, trying to connect to slave");
}

void loop() {
tempReading = analogRead(tempPin);
// converting that reading to voltage, which is based off the reference voltage
float voltage = tempReading * aref_voltage;
voltage /= 1024.0;

// Send temperature in Centigrade
float temperatureC = (voltage - 0.5) * 100 ; //converting from 10 mv per degree with 500 mV offset
//to degrees ((volatge - 500mV) times 100)
Serial.print(temperatureC); Serial.println(" degrees C");
mySerial.print(temperatureC);
delay(1000);


/* Un REM this code if Farenheight is required and REM out the above Centigrade Code
// Send temperature in Farenheight
float temperatureC = (voltage - 0.5) * 100 ; //converting from 10 mv per degree with 500 mV offset
float temperatureF = (temperatureC * 9.0 / 5.0) + 32.0;
Serial.print(temperatureC); Serial.println(" degrees C");
mySerial.print(temperatureF);
delay(1000);
*/
}

The way that this sketch sets the HC05 as a master and links to the HC06 Slave unit is described in the blog post on how to set up the HC05 ( link shown at the top of this page).

Apply power to the Slave Unit and the Master Unit, the LEDs on both Bluetooth units will start to blink. after 25 to 30 seconds the two units will pair and the LEDs will stop blinking. The temperature will be displayed on the LCD.

Troubleshooting:

In the event that the setup does not work you will have to systematically check everything. First make sure the receiver is working by pairing it with a mobile phone using an app like Blueterm. If all is well check the wiring on the Master, run through the pairing routine and check you have the right address for your Slave unit. Try running everything again with the Serial monitor connected to the master unit.

Universal Bluetooth receiver with LCD display.

  

This project uses an Arduino UNO to act as a remote receiver for data sent via Bluetooth from a remote location. The data is displayed on an LCD display and although Bluetooth is used here it could just as easily be Infra Red (for short range communication) or radio (for long range communication). A suitable transmitter will be described in part 2.

Components used:

Blogs for the Bluetooth unit can be found here and the Liquid Crystal display here.

The wiring for the Bluetooth unit is here, note a logic level shifting board is needed as the HC06 Tx/Rx pins are 3 volt logic. Only connect 3.3 volts to the Logic level shit board if it does not have a 3 volt regulator, otherwise you will burn out the regulator.

 

The wiring for the LCD display is here

 

All the components could be mounted on a single breadboard. After the circuit has been built upload the sketch below:

/*
Universal Bluetooth receiver with LCD Display
Uses a 1602a 2 line by 16 character display
and a HC06 Bluetooth Slave

The LCD circuit:
* LCD RS pin to digital pin 12
* LCD Enable pin to digital pin 11
* LCD D4 pin to digital pin 5
* LCD D5 pin to digital pin 4
* LCD D6 pin to digital pin 3
* LCD D7 pin to digital pin 2
* LCD R/W pin to ground
* 10K variable resistor:
* ends to +5V and ground
* wiper to LCD VO pin (pin 3)

The Bluetooth circuit:
* Vcc and Gnd on HC06 to Arduino +5volts and Gnd
* HC06 Tx to Arduino pin 6, through a logic level convertor
* HC06 Rx to Arduino pin 7, through a logic level convertor
*/

// include the libraries:
#include <SoftwareSerial.h>
SoftwareSerial mySerial(6,7); // RX, TX
#include <LiquidCrystal.h>

// Initialize the LCD library with the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
Serial.begin(9600); // used to debug
// set up the LCD's number of columns and rows
lcd.begin(16, 2);
mySerial.begin(9600); // default baudrate for the HC06
lcd.setCursor(0,0); // set cursor at the start of the first line
lcd.print("Universal");
lcd.setCursor(0,1); // set cursor at the start of the first line
lcd.print("Serial Receiver");
}

void loop() {
if (mySerial.available()) {
// wait a bit for the entire message to arrive
delay(100);
// clear the screen
lcd.clear();
// Print a message to the LCD
lcd.setCursor(0,0); // set cursor at the start of the first line
lcd.print("Remote Temp:");
lcd.setCursor(0, 1); // first character line 2
// read all the available characters
while (mySerial.available() > 0) {
// display each character to the LCD
lcd.write(mySerial.read());
}
}
}

The sketch prints a string on the first line, in this case Remote Temp: and data sent via Bluetooth on the second line. 

Testing the project:

I normally use BlueTerm on my Android phone to connect to the HC06, but it sends characters one at a time as they are typed in. I use BlueSerial that allows a sentance to be typed in, then sent. Connect your device to the HC06, you should find it listed as linvor unles you have changed it. Send a sentance of less than 16 characters and it will appear on the second line.

1602a Liquid Crystal Display with an Arduino

Unlike the LCD Button shield this display is not designed to stack on top of the Arduino. As such if you need to add other components, such as a temperature sensor, then this display can be easier to use.

 

In addition to the display and Arduino a potentiometer is needed to adjust the contrast so that the display is visible. Connect the display as shown, the potentiometer’s value is 4k7 ohms and this simple sketch shows how the display can be used. In the line LCD.setCursor(n,m) n is the digit number from 0 to 15 and m is the line number from 0 to 1.


/*
1602a LiquidCrystal Library

Demonstrates the use a 16x2 LCD display. The LiquidCrystal library works with all LCD displays that are compatible with the Hitachi HD44780 driver. There are many of them out there, and you can usually tell them by the 16-pin interface. This sketch prints "Hello World!" to the LCD and shows the time since the sketch started, in seconds.

The circuit:

* LCD RS pin to digital pin 12
* LCD Enable pin to digital pin 11
* LCD D4 pin to digital pin 5
* LCD D5 pin to digital pin 4
* LCD D6 pin to digital pin 3
* LCD D7 pin to digital pin 2
* LCD R/W pin to ground
* 10K variable resistor:
* ends to +5V and ground
* wiper to LCD VO pin (pin 3)
*/

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

// Initialize the library with the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
// set up the LCD's number of columns and rows
lcd.begin(16, 2);
// Print a message to the LCD
lcd.print("hello world!");
}


void loop() {
// set the cursor to column 0, line 1
// (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);
}