Professional Documents
Culture Documents
So I took ARDUINO board from one of friends to make another LCD Project.The Project was
very simple and small and I loved to code with Arduino.It was Sizzling Hot summer in the
month of June,I was just thinking of what and how to make.Then suddenly an idea came to my
mind.
Immediately I took a Paper,Pen and started preparing a raw idea and briefing about it.I took
some help from one of my friends who was good at Electronics to finalise the idea and he
checked it whether it was correct or not.Luckily my idea and implementation was correct.
Now began the real thrill to get onto some practical work.I switched on my computer and
connected Arduino to it.But before that let me show you what an arduino looks like.
ARDUINO
I interfaced a two line LCD (a Displaytech 162B) and an LM35DZ to make a simple Min/Max
thermometer.
This is really very simple. The LM35DZ has three pins, +5V, ground and a variable voltage
output to indicate the temperature. I plugged it into breadboard and wired the output straight to
the Arduino's analogue input 0.
To test we can run a program to read the sensor, I did the conversion to degrees celsius and then
output it to the serial port (since I don't have an LCD quite yet).
float temperature = 0;
void setup()
Serial.begin(115200);
void loop()
if (Serial.available())
Serial.println((long)temperature);
delay(1000);
}
I used the arduino IDE's serial monitor to look for the output when run - it won't appear unless I
select it.
The Displaytech 162B is a HD44780 compatible device, and it's easy to find guides on how to
interface them with the Arduino. They can be driven with a eight data lines - which uses up most
of the digital I/O pins on the Arduino, or more sensibly you can use 4 bit mode.
I started with 8 bit mode, and whilst it worked it's so trivial to use 4 bit instead it's not worth the
extra wires! I also couldn't get both lines of the display working in 8 bit mode.
3 Ground GND
9 Data bit 0
10 Data bit 1
11 Data bit 2
12 Data bit 3
The resistor on the backlight was added because the backlight LED on the board was getting
rather warm. The display stays bright enough and runs a bit cooler with a resistor on the supply.
The pin allocations on the Arduino were dictated by the LCD4Bit library.I did run it and verified
whether LCD is printing "arduino" as the program runs or not.I needed to twist the potentiometer
to get a readable display.
The code
#include <LCD4Bit.h>
#undef int
#include <stdio.h>
int mintemp=255;
int maxtemp=-255;
int pin13 = 0;
void setup(void){
void loop(void){
int temp;
int val=0;
char buffer[64];
lcd.commandWrite(2); //bring the cursor to the starting position
val = analogRead(lm35pin);
temp = (5*val*100/1024);
maxtemp=temp;
mintemp=temp;
sprintf(buffer,"Current: %i\337C",temp);
lcd.printIn(buffer);
pin13=!pin13;
delay(1000);
I started with 8 bit mode, and whilst it worked it's so trivial to use 4 bit instead it's not worth the
extra wires! I also couldn't get both lines of the display working in 8 bit mode.
3 Ground GND
9 Data bit 0
10 Data bit 1
11 Data bit 2
12 Data bit 3
The other two pins of the potentiometer are connected to +5V and GND and provide a contrast
control (and you will need it at least initally). 50K is over the top for the purpose, 10K is more
typical, but it isn't an issue.
The resistor on the backlight was added because the backlight LED on the board was getting
rather warm. The display stays bright enough and runs a bit cooler with a resistor on the supply.
The pin allocations on the Arduino were dictated by the LCD4Bit library, but you could easily
change them in the library if you needed to.
You can take the test code and library straight from the Arduino Playground 4-bit LCD page.
Run it and verify your LCD is printing "arduino" as the program runs - you will probably need to
twist the potentiometer to get a readable display.
The code
#include <LCD4Bit.h>
#undef int
#include <stdio.h>
int mintemp=255;
int maxtemp=-255;
int pin13 = 0;
void setup(void){
void loop(void){
int temp;
int val=0;
char buffer[64];
lcd.commandWrite(2); //bring the cursor to the starting position
val = analogRead(lm35pin);
temp = (5*val*100/1024);
maxtemp=temp;
mintemp=temp;
sprintf(buffer,"Current: %i\337C",temp);
lcd.printIn(buffer);
pin13=!pin13;
delay(1000);
The
#undef int
fixes an issue in the libraries supplied with my installed version of the dev kit