Beruflich Dokumente
Kultur Dokumente
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)
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
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!)
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.
{
intensity++;
}
else
{
intensity=0;
analogWrite(pin,intensity);
if(pin<11)
pin++;
else
pin=9;
}
analogWrite(pin,intensity);
}
}
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
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
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);
}
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
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
Connect Wires to Supply & Ground. Take a wire from the middle pin and connect it to Analog
In 2 of the Arduino
/*
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
Connect Supply & Ground. Take a Wire from the Junction of the Resistor & LDR and connect it
to Analog In 4 of the Arduino
while(digitalRead(2)==0);
delay(100);
}
}
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
Buzzer - The Red Wire is Positive & The Blue Wire is Negative.
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
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 a 1K resistor between the middle pin on the top and the '-'ve terminal
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
}
}
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
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);
}
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)
Place the Trimpot Next to the LCD as shown (a bit away from the LCD pins)
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
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);
}
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
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)
Place the Trimpot Next to the LCD as shown (a bit away from the LCD pins)
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
}
}
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
DS1307 Pin Mappings. SDA [Serial Data] / SCL [Serial Clock] correspond to lines for I2C
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)
{
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);
}