Vous êtes sur la page 1sur 84

Simple Labs' Quick Start Kit for Arduino - LED Interfacing - How To?

The world of LEDS


LEDs (Light Emitting Diodes) are the most commonly used of electronic components. They are
everywhere torches, displays, indicators, etc. Every project will eventually end up having
atleast one led. The Official Arduino Boards and most of the Clones do come with an on-board
LED which you can try with the default blink program found in the File->Examples->Basic
menu of Arduino IDE.
So How to Connect a LED?
The Long of the LED is the Anode (Positive Terminal!) and the short led is the
Cathode(Negative Terminal).

The Terminals of the LED

Place the LED as shown


Place a Current Limiting Resistor (too much current passing through an LED can burn it!)
between the negative terminal of the LED and the '-'ve terminal on the power rail (we will soon
connect this to the '-'ve (aka ground) of our Arduino Board!)

Take a wire from the pin marked 'GND' of your arduino and connect it to the '-'ve power rail of
the breadboard. Now all points of the '-' ve power rail will be connected to the ground of the
arduino!

Next, Connect a wire between the 11th pin of the arduino(yes the 11th pin and not the 13th pin!)
and the positive terminal of the LED. This is going to be our control line for the LED
Programming to control the LED
So how can you control a LED? Well there are only 2 ways to control an LED. you can either
switch it ON / OFF or you can control the intensity with which it glows (Very much like a fan!).
So lets see how to do the first control - ON/OFF (we can call this digital control! Very much 0s
& 1s)

Try the following code. [Blink.ino]


/*
Blink
Turns on an LED on for one second, then off for one second, repeatedly.
This example code is in the public domain.
*/
void setup() {
// initialize the digital pin as an output.
// We have our LED connected to Pin 11
pinMode(11, OUTPUT);
// Sets the 11th pin as an Output pin
}
void loop() {
digitalWrite(11, HIGH); // set the LED on
delay(1000);
// wait for a second
digitalWrite(11, LOW); // set the LED off
delay(1000);
// wait for a second
}

Next, Lets see how to control the intensity of the LED.


The Intensity can be varied by controlling the voltage applied to the individual pins. If you take a
look at the 11th PIN on the arduino, you would see a marking 'PWM' next to it (Remember we
connected our LED to the 11th pin). The PWM pins in addition to generating digital HIGH /
LOW signals can generate analog voltages between 0 & 5.
The PWM Pins [Pins 3,5,6,9,10,11] that can generate a PWM signal of 8-bit resolution.[8-bits
can represent a maximum value of 255, and a 8-bit resolution here means that 5 volts is
represented by 255 divisions. So if you want to generate 1 volt, you would use the value 51]
The analogWrite function will take a 8-bit numerical value as a parameter [called duty cycle] and
produce an output voltage corresponding to this value. It will set the pin to generate a steady
square wave of the specified duty cycle at roughly 490Hz frequency.
Finally, when using a pin in the PWM mode, we don't have to use the pinMode() function.
Try the following code with the same setup and see how the intensity increases and
decreases...[Intensity.ino]
/*
Intensity
Increases the Intensity of a LED from 0 to maximum and on reaching maximum
starts decreasing back to 0
*/
int intensity = 0;
void setup() {
}
void loop() {

while(intensity < 255) // Check if intensity has reached maximum value, if


yes then exit the loop
{
analogWrite(11,intensity);
delay(25);
intensity++;
}
while(intensity > 0) // Check if intensity has reached minimum value, if
yes then exit the loop
{
analogWrite(11,intensity);
delay(25);
intensity--;
}
}

Simple Labs' Quick Start Kit for Arduino - RGB LED Interfacing - How To?
The RGB LED
The RGB led aka the tricolor led is a led that can help generate a multitude of colors by mixing
red, blue & green colors. Its more like 3 leds (red, green & blue) put together into a single led.
It has 4 pins with 1 of the pins being a common cathode and the other 3 pins acting as anodes for
the 3 different colours. by varying the intensity of each of the 3 colours individually, we can
generate various colours. This led is the same as 1 pixel of a LED TV!.
Here is how to wire it up

Pin Mappings of the RGB LED

Place resistor between the common cathode and the '-'ve terminal

Connect RED to Pin 11, Blue to Pin 10 & Green to Pin 9 on the Arduino (these are PWM pins)
Now try the following code first. This code is a normal digital control of all the three colors
separately.[RGB_Blink.ino]
/*
RGB_Blink
Turns on each of the color spectrums for 4 seconds, repeatedly.
*/
void setup() {
// initialize the digital pins as an output.
pinMode(11, OUTPUT);
pinMode(10, OUTPUT);
pinMode(9, OUTPUT);
}
void loop() {
digitalWrite(9,LOW);
digitalWrite(11, HIGH);
delay(4000);
digitalWrite(11, LOW);
digitalWrite(10, HIGH);
delay(4000);
digitalWrite(10, LOW);
digitalWrite(9, HIGH);
delay(4000);
}

Next Lets get generating Colors, try the following code. Play around with the values and get
yourselves comfortable.[RGB.ino]
/* RGB
Sets some random intensity value to the various colours of the RGB LED
*/
void setup()
{
}
void loop()
{
analogWrite(11,153);// Setting the voltage for Blue to around 3 Volts
analogWrite(10,51);// Setting the voltage for Red to around 1 Volt
analogWrite(9,51);// Setting the voltage for Green to around 1 Volt
}

Simple Labs' Quick Start Kit for Arduino Push Button / Switch Interfacing - How To?
The Push Button
Push Buttons like LEDs form a common part of most electronics devices. Push buttons can be
used to get user feedback. (image a common scenario of scrolling through a menu and selecting
an option - there are buttons all around the process!)

Working of a Push Button


So Far we have not used the SUPPLY voltage from the Arduino however, for connecting the
button, we would need this. So, before connecting the Button, we need to connect our '+'ve
terminal to the 5Volts SUPPLY line on the Arduino. Connect as shown in the image below.

There are 2 ways to connect a Push Button to the arduino - the Pull-Down Configuration & the
Pull-Up Configuration. We will take a look at both these.
The Pull-Down Cnfiguration
In this configuration the Push Button is set-up such that it keeps giving a constant LOW signal(0)
when not being pressed and gives a HIGH signal(1) when being pressed. To ensure that it keeps
giving a LOW signal at all times, the Input line is also connect to the '-'ve terminal through a
resistor. So in when the button is not being pressed, the input line stays connected to the
GROUND. When the button is being pressed (and as the path of low resistance is always
preferred) the input line gets connected to the SUPPLY line. Look at the following image to see
how to connect a button in this configuration. We will keep this connection only as a reference as
we will be using the Pull-Up configuration for our circuits.

The Pull-Down Configuration


The Pull-UP Cnfiguration
In this configuration the Push Button is set-up such that it keeps giving a constant HIGH
signal(1) when not being pressed and gives a LOW signal(0) when being pressed. To ensure that
it keeps giving a HIGH signal at all times, the Input line is also connect to the '+'ve terminal
through a resistor. So in when the button is not being pressed, the input line stays connected to
the SUPPLY . When the button is being pressed (and as the path of low resistance is always
preferred) the input line gets connected to the GROUND line. Look at the following image to see
how to connect a button in this configuration. This is the most preferred method to connect a
button.

The Pull-Up Configuration


Now try the following code, Pressing the Button increases the intensity of one colour at a time,
once the maximum intensity of the colour is reached that colour is set to 0 and the intensity of
the next colour starts increasing [ RGB_Button.ino]
/*
RGB_Button
Pressing the Button increases the intensity of one colour at a time, once t
he maximum intensity of the colour is reached
that colour is set to 0 and the intensity of the next colour starts increas
ing
*/
int intensity = 0, pin = 9;
void setup() {
pinMode(2,INPUT); // This is the pin to which we have connected the button
}
void loop() {
if(digitalRead(2)==0) // check if the button is being pressed
{
Serial.println("here");
if(intensity < 255)

{
intensity++;
}
else
{
intensity=0;
analogWrite(pin,intensity);
if(pin<11)
pin++;
else
pin=9;
}
analogWrite(pin,intensity);
}
}

Here's the Output

Simple Labs' Quick Start Kit for Arduino Trimpot / Potentiometer Interfacing - How
To?
Trimpot
Trimpots are used for getting variable / adjustable user inputs. Common example of a trimpot is
the volume knob of your stereo player, Tuning knob of the radio, etc.
A Trimpot aka variable resistor has three pins and an adjustment screw. A Trimpot acts as a
potential divider and gives an output voltage on the 2nd pin. This output voltage is in-between
the voltages supplied to the 1st and 3rd pins. The output voltage can be varied by adjusting the
screw. The 1st and 3rd pins are connected to SUPPLY / GROUND and the middle pin is
connected to Analog Input 0 on the arduino using a wire.
Connect the trimpot as shown in the images below

The Trimpot - See the markings for pins

Place the trimpot as shown

Connect a wire between pin 1 of the trimpot and the '+'ve terminal

Connect a wire between pin 3 of the trimpot and the '-'ve terminal

Connect a wire between pin 2 of the trimpot and the Analog In 0 of the Arduino

Here is the connection going to the Analog In 0


The Analog Input pins on the Arduino let you connect sensors and other analog devices like
trimpots that product a voltage output in the range of 0-5 volts. The Analog input on Arduino is
of 10-bit resolution. 10-bit resolution means that the Voltage range of 0-5 Volts is represented in
1024 steps from 0-1023. So you would be reading an input value in the range of 0-1023 where
1023 would correspond to 5 Volts
Arduino[the IDE!] comes with a serial library that can be used to transmit data serially to a
computer. We shall make use of this library to transmit our trimpot value to a Computer every 1
second. You can open the 'Serial Monitor' in the Arduino IDE to view these values. You can
open the 'Serial Monitor' by going to the 'Tools' menu. When using the 'Serial Monitor' ensure
that the baud rate selected is the same as the one used in the program.

Try the following program and see the values you get by varying the trimpot [
simple_trimpot.ino]
/*
A Simple Program to display the value read from the trimpot onto the Serial
Monitor
*/
int intensity = 0;
void setup() {
Serial.begin(9600);
}
void loop() {
intensity = analogRead(0);
Serial.print("Current Value:");
Serial.print("
");
Serial.println(intensity);
}

If you notice, you will see values from 0-1023. Now we are going to use the trimpot as part of
our previous experiment. We will use the button to select the active color of the RGB LED and
then use the trimpot to set the intensity of that color. Remember that this would involve scaling
0-1023 to 0-255 (or divide by 4!)
Try the following program [RGB_button_trimpot.ino]
/*
Pressing the Button changes the current active color of the RGB LED and var
ying the trimpot changes the intensity of the color
*/
int intensity = 0, pin = 9;
void setup() {
pinMode(2,INPUT);
Serial.begin(9600);
}
void loop() {
if(digitalRead(2)==0) // Switch being pressed
{
if(pin<11)
pin++;
else
pin=9;
analogWrite(9,0);
analogWrite(10,0);
analogWrite(11,0);
while(digitalRead(2)==0);
delay(100);
}
intensity = analogRead(0)/4; // Scaling the input resolution to match with
our output resolution.
analogWrite(pin,intensity);
Serial.print(pin);

Serial.print("
");
Serial.println(intensity);
}

Heres the final setup and the output!

Simple Labs' Quick Start Kit for Arduino Sensor Interfacing - LM35 Temperature
Sensor- How To?
Working with Sensors - LM35
So lets get started with some sensors, LM35 is a simple temperature sensor. LM35 has 3 pins.
Refer to the following image for the pin mappings

This is the LM35 as it looks

The LM35 pin Mapping. Note: The image on the left is a BOTTON view. This is how you will
find it in the Product Datasheet

Place the LM35 as shown

Connect Wires to Supply & Ground. Take a wire from the middle pin and connect it to Analog
In 2 of the Arduino

Heres the finished Setup


Now time for the program. Try the following program. Pressing the Button changes the current
active color of the RGB LED & prints the current temperature value to the Serial Monitor and
varying the trimpot changes the intensity of the color [RGB_button_lm35.ino]

/*
Pressing the Button changes the current active color of the RGB LED & print
s the current temperature value to the Serial Monitor
and varying the trimpot changes the intensity of the color
*/
int intensity = 0, pin = 9;
void setup() {
pinMode(2,INPUT);
Serial.begin(9600);
}
void loop() {
if(digitalRead(2)==0) // Switch being pressed
{
Serial.print("Temperature is : ");
int temp = analogRead(2)/2;
Serial.println(temp);
if(pin<11)
pin++;
else
pin=9;
analogWrite(9,0);
analogWrite(10,0);
analogWrite(11,0);
while(digitalRead(2)==0);
delay(100);
}
intensity = analogRead(0)/4;
analogWrite(pin,intensity);
Serial.print(pin);
Serial.print("
");
Serial.println(intensity);
}

Simple Labs' Quick Start Kit for Arduino Sensor Interfacing - LDR Simple Light
Sensor- How To?
LDR - Light Dependent Resistor - A Simple Light Sensor
The LDR is a variable resistor, whose resistance varies based on the light incident upon it. More
the light, less the resistance. Now the LDR cannot be used directly. We would need to convert
the change in resistance of the ldr to change in voltage. We can achieve this by constructing a
potential divider using the ldr and a fixed resistor. Then we can take the output of the potential
divider and connect it to an Analog In pin on the arduino.
Follow the images below and connect the LDR

This is the LDR

Place the LDR as shown and connect a resistor as shown

Connect Supply & Ground. Take a Wire from the Junction of the Resistor & LDR and connect it
to Analog In 4 of the Arduino

Here is how the Finished Setup will look like


Try the following Code [RGB_button_ldr.ino]
/*
Pressing the Button changes the current active color of the RGB LED & prints
the current temperature value to the Serial Monitor
and the light intensity detected by the LDR determines the intensity level o
f the active color
*/
int intensity = 0, pin = 9;
void setup() {
pinMode(2,INPUT);
Serial.begin(9600);
}
void loop() {
if(digitalRead(2)==0) // Switch being pressed
{
int temp = analogRead(2)/2;
Serial.print("Temperature is : ");
Serial.println(temp);
analogWrite(10,0);
analogWrite(9,0);
analogWrite(11,0);
if(pin<11)
pin++;
else
pin = 9;
intensity = analogRead(4)/4;
analogWrite(pin,intensity);
Serial.print(pin);
Serial.print(" ");
Serial.println(intensity);

while(digitalRead(2)==0);
delay(100);
}
}

Please check the spelling mistakes in program [RGB_button_ldr.ino] and it gives


compiling errors. I had corrected the errors and the program is as follows:
/*
Pressing the Button changes the current active color of the RGB LED & prints the current
temperature value to the Serial Monitor and the light intensity detected by the LDR
determines the intensity level of the active color
*/
int intensity = 0, pin = 9;
void setup() {
pinMode(2,INPUT);
Serial.begin(9600);
}
void loop() {
if(digitalRead(2)==0) // Switch being pressed
{
Serial.print("Temperature is : ");
int temp = analogRead(2)/2;
analogWrite(10,0);
Serial.println(temp);
if(pin<11)
pin++;
else
pin=9;
analogWrite(9,0);
analogWrite(11,0);
while(digitalRead(2)==0);
delay(100);
}
intensity = analogRead(4)/4;
analogWrite(pin,intensity);
Serial.print(pin);
Serial.print(" ");
Serial.println(intensity);
}

Simple Labs' Quick Start Kit for Arduino Generating Sound - Buzzer + Transistor How To?
Generating Sound - Buzzer + Transistor
Next lets see how we can generate sound using a Buzzer. The Buzzer would require more current
than provided by the pins of the arduino. To provide the buzzer with more current, we shall use a
transistor to trigger the buzzer. The transistor in turn will be triggered by a pin on the arduino. If
you do not know about transistors, its advisable you check it out
http://en.wikipedia.org/wiki/Transistor
Here's what our Transistor 2N2222A looks like

2N2222A

Pin Mappings for 2N2222A


E = Emitter
B = Base
C = Collector
The Emitter of a transistor is connected to ground, the device to be triggered is connected
between the Collector of the transistor and SUPPLY. The transistor can be triggered by
Supplying a Trigger voltage to the Base (preferably through a resistor). Depending upon the
trigger voltage, Emitter and Collector of a transistor get in contact thereby allowing current flow
through the device connected.

Buzzer - The Red Wire is Positive & The Blue Wire is Negative.

First Setup the Transistor Side like in the Image

The Blue wire going to the Collector here is the Negative of the Buzzer and the Red wire (the
Positive of the Buzzer ) is connected to the '+'ve terminal of the Breadboard

Now Connect a Wire from the Other end of the Resistor to the 7th pin (digital) of the Arduino

Here is how the Final Setup Looks Like

Try the following code where the Buzzer stays on as you keep pressing the Button in our
previous program [RGB_button_ldr_buzzer.ino]
/*
Pressing the Button changes the current active color of the RGB LED & print
s the current temperature value to the Serial Monitor and Generates a Buzzer
tone
for the duration the button is being pressed.
The light intensity detected by the LDR determines the intensity level of t
he active color
*/
int intensity = 0, pin = 9;
void setup() {
pinMode(2,INPUT);
pinMode(7,OUTPUT);
Serial.begin(9600);
}
void loop() {
if(digitalRead(2)==0) // Switch being pressed
{
digitalWrite(7,HIGH);
Serial.print("Temperature is : ");
int temp = analogRead(2)/2;
Serial.println(temp);
if(pin<11)
pin++;
else
pin=9;
analogWrite(9,0);
analogWrite(10,0);
analogWrite(11,0);
while(digitalRead(2)==0);
delay(100);
digitalWrite(7,LOW);
}
intensity = analogRead(4)/4;
analogWrite(pin,intensity);
Serial.print(pin);
Serial.print("
");
Serial.println(intensity);
}

Simple Labs' Quick Start Kit for Arduino 7-Segment Display Interfacing- How To?
The 7-Segment Display
7-Segment displays are another common component in the world of electronics. These displays
have 8 LEDs split into different segments designed to be able to display numerals from 0-9 and a
dot. All The LEDs have a common ground / supply line. There are 5 pins at the top and 5 pins at
the bottom. The middle pins in the top and bottom are connected to each other internally and
have to be connected to Ground / Supply depending upon the type of the 7-segment Display.
You can control each segment like an individual LED. However, this method of controlling the
7-segment LED to display numbers would be hectic. So, we will use a technique called Port
Manipulation. Pins on the Arduino are grouped together as a PORT. You can control a whole
PORT at a time. Read the following write up on the Arduino website before you proceed => Port
Manipulation
The 7-Segment Display included in the starter kit is a Common Cathode Type.

7 - Segment LED

Segment & Pin Mapping of a 7-Segment LED / We will be connecting segments A-G & P to
digital pins 0-6 & 7 of the Arduino

Place the 7-segment Display on the Breadboard.

Place a 1K resistor between the middle pin on the top and the '-'ve terminal

Connect a Wire from Segment A to digital pin 0 of the Arduino

Connect a Wire from Segment B to digital pin 1 of the Arduino

Connect a Wire from Segment C to digital pin 2 of the Arduino

Connect a Wire from Segment D to digital pin 3 of the Arduino

Connect a Wire from Segment E to digital pin 4 of the Arduino

Connect a Wire from Segment F to digital pin 5 of the Arduino

Connect a Wire from Segment G to digital pin 6 of the Arduino

Connect a Wire from Segment P to digital pin 7 of the Arduino

Our Final Setup with a Program

First Try the following program that cycles from digits 0 - 9. [SEV_SEG.ino]
/*
This is to Display numbers 0-9 on the seven segment LED
*/
/*
Wiring
Seg A Seg B Seg C Seg D Seg E Seg F Seg G Seg H -

Pin
Pin
Pin
Pin
Pin
Pin
Pin
Pin

0
1
2
3
4
5
6
7

*/
/*
To Display '0' we need to make high All Segments except G & H
based on this lets make a list of values to write to port D [pins 07 are grouped together as port D]
When we write a binary value to the port the MSB or the 8th bit will be writt
en to pin 7 and the lsb will be written to pin 0
0
1
2
3
4
5
6
7
8
9

=>
=>
=>
=>
=>
=>
=>
=>
=>
=>

B00111111
B00000110
B01011011
B01001111
B01100110
B01101101
B01111101
B00000111
B01111111
B01101111

*/
int val[]={B00111111,B00000110,B01011011,B01001111,B01100110,
B01101101,B01111101, B00000111, B01111111, B01101111};
void setup()
{
DDRD = B11111111;
}
void loop()
{
for(int i=0; i<10;i++)
{
PORTD = val[i];
delay(1000);
}

Now Try the following program - An extension of our Remote Control Program. Here the Value
of the Button being pressed is displayed on the 7-segment display. [SEV_SEG_TSOP.ino]
/*
This is to Display numbers 09 on the seven segment LED based on Remote Control INPUT
*/
/*
Wiring
Seg A Seg B Seg C Seg D Seg E Seg F Seg G Seg H -

Pin
Pin
Pin
Pin
Pin
Pin
Pin
Pin

0
1
2
3
4
5
6
7

*/
/*
To Display '0' we need to make high All Segments except G & H
based on this lets make a list of values to write to port D [pins 07 are grouped together as port D]
When we write a binary value to the port the MSB or the 8th bit will be writt
en to pin 7 and the lsb will be written to pin 0
0
1
2
3
4
5
6
7
8
9

=>
=>
=>
=>
=>
=>
=>
=>
=>
=>

B00111111
B00000110
B01011011
B01001111
B01100110
B01101101
B01111101
B00000111
B01111111
B01101111

*/
#include <IRremote.h>
int RECV_PIN = 12;
IRrecv irrecv(RECV_PIN);
decode_results results;
int remote = 0, display_value=0;
int val[]={B00111111,B00000110,B01011011,B01001111,B01100110,
B01101101,B01111101, B00000111, B01111111, B01101111};

void setup()
{
DDRD = B11111111; // Declares PORT D as Output, PORTD is digital pins 0-7
irrecv.enableIRIn(); // Start the receiver
}
void loop()
{
if (irrecv.decode(&results)) {
remote = results.value;
switch(remote)
{
case 16 : display_value=1; break;
case 2064 : display_value=2; break;
case 1040 : display_value=3; break;
case 3088 : display_value=4; break;
case 528 : display_value=5; break;
case 2576 : display_value=6; break;
case 2960 : display_value=7; break;
case 3600 : display_value=8; break;
case 272 : display_value=9; break;
case 2320 : display_value=0; break;
}
PORTD = val[display_value];
irrecv.resume(); // Receive the next value
}
}

Simple Labs' Quick Start Kit for Arduino - IR


Proximity Sensor Interfacing- How To?
The IR Proximity Sensor
The IR Proximity sensor is one of the most commonly used sensors. You will find these in
automatic taps, automatic door opening, etc. This sensor works on the principle of
IR reflectance. There is an IR LED (white / light blue in color) that is constantly emitting IR
light. The light when reflected back falls on the IR Receiver LED / Photodiode (the black / dark
blue color led). This received signal is then processed by an Op-Amp and the Op-Amp gives a
HIGH signal. So the sensor module will give a HIGH signal if there is an object in front of the
LED's. The range of sensing can be varied by adjusting the potentiometer on the sensor module.
The maximum range of this module is only a few cms, so don't expect to use this as a distance
sensor ;). The module will not work when pointed at black objects as black color tends to absorb
the IR light.
Note: The IR Sensor and its 3-pin cable will not come attached. You need to fix the Cable on to
the Sensor. There is only 1 way the cable will fit on the sensor module, so, we presume you can't
go wrong about it ;)

The IR Sensor. Look at the Wires and Their Mappings. We will connect these accordingly

Connect the Red Wire of the IR sensor to the '+'ve Terminal & the Black Wire of the IR sensor
to the '-'ve Terminal

Connect the Brown wire of the IR sensor to the 8th pin of the Arduino

This is how your final setup should look like

Lets program to trigger the Buzzer everytime the sensor gives a HIGH signal. Try the following
program. [ULN_Buzzer_IR.ino]
/*
ULN2003- Buzzer
This program drives a Buzzer using ULN2003
*/
void setup()
{
pinMode(7,OUTPUT);
}
void loop()
{
digitalWrite(7,HIGH);
delay(2000);
digitalWrite(7,LOW);
delay(3000);
}

Simple Labs' Quick Start Kit for Arduino - LCD


Interfacing - How To?
LCD - Liquid Crystal Display
LCDs are commonly used display devices that you would find in most appliances / electronic
devices. Your music players, Pay phones, Etc.
Here's an interesting Write up to get you understanding the working of the LCD
http://joshuagalloway.com/lcd.html

Wiring up the LCD

The 16x2 LCD Display

LCD Pin Mappings

First Connect A Wire between the GND pin of the Arduino and the '-'ve terminal. Then Connect
Another Wire from the 5V pin of the Arduino to the '+'ve terminal.

Place the LCD on the Breadboard as Shown (the 16th pin of the LCD is in the LEFT Corner of
the Image)

This is what you should have now

Place the Trimpot Next to the LCD as shown (a bit away from the LCD pins)

Connect the Supply & Ground Lines for the Trimpot

The First and Last pins of the LCD are GND pins. First Connect a Wire from the 1st pin of the
LCD to the '-'ve terminal

Connect a wire from the 16th pin of the LCD to the '-'ve terminal

The 2nd & 15th Pins of the LCD are Supply Pins, Connect Wires from these to the '+'ve
Terminal as shown

The 5th of the LCD is the RW pin. This pin is used to toggle between Read / Write Mode of the
LCD. Writing a HIGH signal to this pin corresponds to Read Mode and Writing a LOW signal
corresponds to Write Mode. Since we will be using only the Write mode, we can wire this pin to
GND / '-'ve terminal [This is equivalent of writing a LOW signal to the pin]

Connect a Wire from the middle pin of the trimpot to the 3rd pin of the LCD. The 3rd pin of the
LCD is the contrast pin and the contrast of the display can be varied by varying the trimpot

Connect a Wire between the RS pin of the LCD (4th pin) and digital pin 2 of the Arudino. The
RS pin helps select between the 2 registers of an LCD - Data & Command - for communication

Connect a wire between the Enable pin (the 6th pin) of the LCD and digital pin 4 of the Arduino

Connect a Wire between D4 of the LCD (11th pin) and digital pin 8 of the Arduino

Connect a Wire between D5 of the LCD (12th pin) and digital pin 9 of the Arduino

Connect a Wire between D6 of the LCD (13th pin) and digital pin 10 of the Arduino

Connect a Wire between D7of the LCD (14th pin) and digital pin 11 of the Arduino

The Finished Setup

Sample Hello World Program


So Lets program the LCD. We can take the sample hello world program found under File ->
Examples -> LiquidCrystal menu of Arduino IDE and change the pin numbers in the following
statement

From
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
To
LiquidCrystal lcd(2,4,8,9,10,11);
####IMPORTANT - IN CASE NOTHING IS DISPLAYED ON THE LCD KEEP VARYING
THE TRIMPOT TILL YOU CAN SEE THE CHARACTERS###
Try the following Simple LCD program [Simple_LCD.ino]
/*
LiquidCrystal Library - Hello World
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.
*/
// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(2,4,8,9,10,11);
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
// (note: 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);
}

// include the library code:


#include
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(2,4,8,9,10,11);
void setup(){
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// initialize the serial communications:
Serial.begin(9600);
}
void loop()
{
// when characters arrive over the serial port...
if (Serial.available()) {
// wait a bit for the entire message to arrive
delay(100);
// clear the screen
lcd.clear();
// read all the available characters
while (Serial.available() > 0) {
// display each character to the LCD
lcd.write(Serial.read());
}
}
}

this above code will help you


if any queries you are free to ask or email me

Simple Labs' Quick Start Kit for Arduino LCD Interfacing - How To?
LCD - Liquid Crystal Display
LCDs are commonly used display devices that you would find in most appliances / electronic
devices. Your music players, Pay phones, Etc.
Here's an interesting Write up to get you understanding the working of the LCD
http://joshuagalloway.com/lcd.html

Wiring up the LCD

The 16x2 LCD Display

LCD Pin Mappings

First Connect A Wire between the GND pin of the Arduino and the '-'ve terminal. Then Connect
Another Wire from the 5V pin of the Arduino to the '+'ve terminal.

Place the LCD on the Breadboard as Shown (the 16th pin of the LCD is in the LEFT Corner of
the Image)

This is what you should have now

Place the Trimpot Next to the LCD as shown (a bit away from the LCD pins)

Connect the Supply & Ground Lines for the Trimpot

The First and Last pins of the LCD are GND pins. First Connect a Wire from the 1st pin of the
LCD to the '-'ve terminal

Connect a wire from the 16th pin of the LCD to the '-'ve terminal

The 2nd & 15th Pins of the LCD are Supply Pins, Connect Wires from these to the '+'ve
Terminal as shown

The 5th of the LCD is the RW pin. This pin is used to toggle between Read / Write Mode of the
LCD. Writing a HIGH signal to this pin corresponds to Read Mode and Writing a LOW signal
corresponds to Write Mode. Since we will be using only the Write mode, we can wire this pin to
GND / '-'ve terminal [This is equivalent of writing a LOW signal to the pin]

Connect a Wire from the middle pin of the trimpot to the 3rd pin of the LCD. The 3rd pin of the
LCD is the contrast pin and the contrast of the display can be varied by varying the trimpot

Connect a Wire between the RS pin of the LCD (4th pin) and digital pin 2 of the Arudino. The
RS pin helps select between the 2 registers of an LCD - Data & Command - for communication

Connect a wire between the Enable pin (the 6th pin) of the LCD and digital pin 4 of the Arduino

Connect a Wire between D4 of the LCD (11th pin) and digital pin 8 of the Arduino

Connect a Wire between D5 of the LCD (12th pin) and digital pin 9 of the Arduino

Connect a Wire between D6 of the LCD (13th pin) and digital pin 10 of the Arduino

Connect a Wire between D7of the LCD (14th pin) and digital pin 11 of the Arduino

The Finished Setup

Sample Hello World Program


So Lets program the LCD. We can take the sample hello world program found under File ->
Examples -> LiquidCrystal menu of Arduino IDE and change the pin numbers in the following
statement
From
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
To
LiquidCrystal lcd(2,4,8,9,10,11);
####IMPORTANT - IN CASE NOTHING IS DISPLAYED ON THE LCD KEEP VARYING
THE TRIMPOT TILL YOU CAN SEE THE CHARACTERS###
Try the following Simple LCD program [Simple_LCD.ino]
/*
LiquidCrystal Library - Hello World
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.
*/

// include the library code:


#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(2,4,8,9,10,11);
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
// (note: 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);
}

// include the library code:


#include
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(2,4,8,9,10,11);
void setup(){
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// initialize the serial communications:
Serial.begin(9600);
}
void loop()
{
// when characters arrive over the serial port...
if (Serial.available()) {
// wait a bit for the entire message to arrive
delay(100);
// clear the screen
lcd.clear();
// read all the available characters
while (Serial.available() > 0) {
// display each character to the LCD
lcd.write(Serial.read());
}

}
}

Simple Labs' Quick Start Kit for Arduino DS1307 Real Time Clock IC Interfacing- How
To?
DS1307 - Real Time Clock IC
The DS1307 lets you explore I2C communication on the arduino.
I2C Communication
I2C is short form for 'Inter Integrated Circuit' I2C Communication is Communication Bus
standard developed by Phillips for standardising Communication between Integrated Circuits.
For Eg. In a circuit, there could be a number of ICs each offering specific functionality[RTC,
Temperature Sensor, EEPROM, etc] and they can all communicate on a single I2C Bus and
provide combined functionalities. Each device on the I2C Bus would have a unique address by
which it can be addressed.
Here's an Interesting Introduction from NXP

I2C on Arduino
The I2C Bus uses 2 lines for Communication - SDA(Serial Data) & SCL (Serial Clock). On the
InduinoX / Arduino, these are available on SDA (Analog Input 4) & SCL (Analog Input 5). The
I2C bus can be accessed using the 'Wire' Library of Arduino. First, lets try out a Library

Wiring up the DS1307

DS1307 Pin Mappings. SDA [Serial Data] / SCL [Serial Clock] correspond to lines for I2C

Communication. We can ignore Vbat & SQW / OUT Pins.

Components - DS1307, Crystal for DS1307, 2 x 10K Resistors

Place the DS1307 IC as shown

Connect a Wire from the 4th pin of DS1307 (GND) to the '-'ve terminal

Connect a Wire from the 8th pin of DS1307 (+5V) to the '+'ve terminal

Place the Cyrstal as shown between the 1st and 2nd pin of the DS1307 IC- There is no polarity
('+' / '-' ve) for the crystal. So you can place it anyway

Place one resistor between the SDA Pin and the '+'ve terminal and one resistor between the SCL
Pin and the '+'ve terminal

Connect a Wire between the SDA pin (pin5 of DS1307) and the SDA pin of the Arduino
(Analog IN 4)

Connect a Wire between the SCL pin (pin6 of DS1307) and the SCL pin of the Arduino (Analog
IN 5)

Final Setup with output from the following program


Try following Sample Program [LCD_RTC.ino]
/*
This program uses the Wire Library (for i2c communication)
This program sets the initial time for the RTC and keeps updating the time on
an LCD everysecond.
*/
#include <Wire.h>
#define rtc 0x68 // The pre-defined address for DS1307
int ss,mm,hh,d,DD,MM,YY,mode;
boolean time_format,meridiem;
int prev;
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(2,4,8,9,10,11);
void setup()
{
Wire.begin();
lcd.begin(16, 2);
set_time();
}
void loop()
{
get_time();
if(ss!=prev)

// lcd Print when the seconds change

{
lcd.setCursor(0,0);
lcd.print("Date:");
lcd.print(DD);
lcd.print("/");
lcd.print(MM);
lcd.print("/");
lcd.print(YY);
lcd.setCursor(0,1);
lcd.print("Time:");
lcd.print(hh);
lcd.print(":");
lcd.print(mm);
lcd.print(":");
lcd.print(ss);
prev=ss;
}
}
void get_time()
{
Wire.beginTransmission(rtc); // start communication over i2c with DS1307
Wire.write((byte)0); // Write the value of the register to point to
Wire.endTransmission(); // End communication over i2c with DS1307
Wire.requestFrom(rtc,7); // This will request 7 bytes of data
//starting from the '0' the register
ss=bcd_to_dec(Wire.read());
mm=bcd_to_dec(Wire.read());
hh=Wire.read();
time_format=hh&(1<<6);
meridiem=hh&(1<<5);
// calculate am or pm
hh=bcd_to_dec(hh&0x1F);
d=bcd_to_dec(Wire.read());
DD=bcd_to_dec(Wire.read());
MM=bcd_to_dec(Wire.read());
YY=bcd_to_dec(Wire.read());
Wire.endTransmission();
}
void set_time()
{
time_format=0;
// 0=24 hour mode, 1=12 hour mode
meridiem=1;
// 0=am, 1=pm
will not be taken into consideration
if time format is 24 hour mode
mode=(time_format<<6)+((time_format&&meridiem)<<5); //calculate the bits
to be added for 12 hour mode
Wire.beginTransmission(rtc);
Wire.write((byte)0);
Wire.write(dec_to_bcd(50));
// seconds
Wire.write(dec_to_bcd(59));
// minutes
Wire.write(mode+dec_to_bcd(11));// hours
Wire.write(dec_to_bcd(3));
// day of the week, startin monday
Wire.write(dec_to_bcd(21));
// date
Wire.write(dec_to_bcd(12));
// month
Wire.write(dec_to_bcd(11));
// year

Wire.endTransmission();
}
int dec_to_bcd(int dec)
{
return dec/10*16 + (dec%10);
}
int bcd_to_dec(int bcd)
{
return bcd/16*10 + (bcd%16);
}