2007 - Super - Started - Kit - Guid Book
2007 - Super - Started - Kit - Guid Book
Preface
Sun Robotics is a technical service team of open source software and hardware. Dedicated
to applying the Internet and the latest industrial technology in open source area, we strive
to provide best hardware support and software service for general makers and electronic
enthusiasts around the world. We aim to create infinite possibilities with sharing. No
matter what field you are in, we can lead you into the electronic world and bring your
ideas into reality.
This is Super Starter Kit for Arduino. Some common electronic components and sensors
are included. Through the learning, you will get a better understanding of Arduino, and
be able to make fascinating works based on Arduino.
Contents
Getting Started with Arduino
Installing Arduino IDE and using the Uno R3 board
About Arduino Uno R3 board
Lesson- 1 Blinking LED
Lesson- 2 Four Blinking LEDS
Lesson- 3 Controlling an RGB LED
Lesson- 4 Push button – LED Blinking
Lesson -5 Seven Segment Display Interface
Lesson- 6 3 _WAY TRAFFIC LIGHT CONTROLLER
Lesson- 7 RGB LED push button color change
Lesson- 8 Multiple tones with one Piezo Buzzer
Lesson- 9 Seeing the light using Photo resistor with an arduino
Lesson- 10 LCD 1602 Display
Lesson- 11 HC-SR04 Project
Lesson- 12 PIR sensor
Lesson- 13 Showing the temperature and humidity sensor in using arduino
Lesson- 14 Touch Sensor arduino Interface
Lesson- 15 Magnetic Reed Switch
Lesson- 16 IR_Receiver using arduino
Getting Started with Arduino
What is an Arduino?
Arduino is an open-source physical computing platform designed to make experimenting with
electronics more fun and intuitive. Arduino has its own unique, simplified programming language,
a vast support network, and thousands of potential uses, making it the perfect platform for both
beginner and advanced DIY enthusiasts.
www.arduino.cc
Access the Internet: In order to get your Arduino up and running, you'll need to download some
software first from www.arduino.cc (it's free!). This software, known as the Arduino IDE, will
allow you to program the Arduino to do exactly what you want. It’s like a word processor for
writing programs. With an internet-capable computer, open up your favorite browser and type
in the following URL into the address bar:
www.arduino.cc/en/Main/Software
2
Web: www.sunrobotics.co.in
Email:[email protected]
3
Web: www.sunrobotics.co.in
Email:[email protected]
For different operating system platforms, the way of using Arduino IDE is different. Please refer
to the following links: Windows User:http://www.arduino.cc/en/Guide/Windows Mac OS X
Userhttp://www.arduino.cc/en/Guide/MacOSXLinuxUserhttp://playground.arduino.cc/Learnin
g/Linux For more detailed information about Arduino IDE, please refer to the following link:
http://www.arduino.cc/en/Guide/HomePage
Use the USB cable provided in the kit to connect the Arduino to one of your computer’s USB
inputs.
Windows Installation Process: Go to the web address below to access the instructions for
installations on a Windows-based computer.
http://arduino.cc/en/Guide/Windows
Macintosh OS X Installation Process: Macs do not require you to install drivers. Enter the
following URL if you have questions. Otherwise proceed to next page.
http://arduino.cc/en/Guide/MacOSX
Linux: 32 bit / 64 bit, Installation Process Go to the web address below to access the instructions
for installations on a Linux-based computer.
4
Web: www.sunrobotics.co.in
Email:[email protected]
http://www.arduino.cc/playground/Learning/Linux
5
Web: www.sunrobotics.co.in
Email:[email protected]
STEP-5: Select your board: Arduino Uno
Windows: Select the serial device of the Arduino board from the Tools | Serial Port menu. This
is likely to be com3 or higher (COM1 and COM2 are usually reserved for hardware serial ports).
To find out, you can disconnect your Arduino board and re-open the menu; the entry that
disappears should be the Arduino board. Reconnect the board and select that serial port.
6
Web: www.sunrobotics.co.in
Email:[email protected]
Mac OS: Select the serial device of the Arduino board from the Tools > Serial Port menu. On the
Mac, this should be something with /dev/tty.usbmodem (for the Uno or Mega 2560) or
/dev/tty.usbserial (for older boards) in it.
Linux: http://playground.arduino.cc/Learning/Linux
7
Web: www.sunrobotics.co.in
Email:[email protected]
NOTE: Do NOT use a power supply greater than 20 Volts as you will overpower (and thereby
destroy) your Arduino. The recommended voltage for most Arduino models is between 6 and 12
Volts. Pins (5V, 3.3V, GND, Analog, Digital, PWM, AREF)
The pins on your Arduino are the places where you connect wires to construct a circuit (probably
in conjuction with a breadboard and some wire. They usually have black plastic ‘headers’ that
allow you to just plug a wire right into the board. The Arduino has several different kinds of pins,
each of which is labeled on the board and used for different functions.
GND (3): Short for ‘Ground’. There are several GND pins on the Arduino, any of which can
be used to ground your circuit.
5V (4) & 3.3V (5): As you might guess, the 5V pin supplies 5 volts of power, and the 3.3V
pin supplies 3.3 volts of power. Most of the simple components used with the Arduino
run happily off of 5 or 3.3 volts.
Analog (6): The area of pins under the ‘Analog In’ label (A0 through A5 on the UNO) are
Analog In pins. These pins can read the signal from an analog sensor (like a temperature
sensor) and convert it into a digital value that we can read.
Digital (7): Across from the analog pins are the digital pins (0 through 13 on the UNO).
These pins can be used for both digital input (like telling if a button is pushed) and digital
output (like powering an LED).
PWM (8): You may have noticed the tilde (~) next to some of the digital pins (3, 5, 6, 9,
10, and 11 on the UNO). These pins act as normal digital pins, but can also be used for
something called Pulse-Width Modulation (PWM). We have a tutorial on PWM, but for
now, think of these pins as being able to simulate analog output (like fading an LED in and
out).
AREF (9): Stands for Analog Reference. Most of the time you can leave this pin alone. It is
sometimes used to set an external reference voltage (between 0 and 5 Volts) as the upper
limit for the analog input pins.
Reset Button
Just like the original Nintendo, the Arduino has a reset button (10). Pushing it will temporarily
connect the reset pin to ground and restart any code that is loaded on the Arduino. This can be
very useful if your code doesn’t repeat, but you want to test it multiple times. Unlike the original
Nintendo however, blowing on the Arduino doesn’t usually fix any problems.
TX RX LEDs
8
Web: www.sunrobotics.co.in
Email:[email protected]
TX is short for transmit, RX is short for receive. These markings appear quite a bit in electronics
to indicate the pins responsible for serial communication. In our case, there are two places on
the Arduino UNO where TX and RX appear – once by digital pins 0 and 1, and a second time next
to the TX and RX indicator LEDs (12). These LEDs will give us some nice visual indications
whenever our Arduino is receiving or transmitting data (like when we’re loading a new program
onto the board).
Main IC
The black thing with all the metal legs is an IC, or Integrated Circuit (13). Think of it as the brains
of our Arduino. The main IC on the Arduino is slightly different from board type to board type,
but is usually from the ATmega line of IC’s from the ATMEL company. This can be important, as
you may need to know the IC type (along with your board type) before loading up a new program
from the Arduino software. This information can usually be found in writing on the top side of
the IC. If you want to know more about the difference between various IC’s, reading the
datasheets is often a good idea.
Voltage Regulator
The voltage regulator (14) is not actually something you can (or should) interact with on the
Arduino. But it is potentially useful to know that it is there and what it’s for. The voltage regulator
does exactly what it says – it controls the amount of voltage that is let into the Arduino board.
Think of it as a kind of gatekeeper; it will turn away an extra voltage that might harm the circuit.
Of course, it has its limits, so don’t hook up your Arduino to anything greater than 20 volts.
9
Web: www.sunrobotics.co.in
Email:[email protected]
Lesson 1 - Blinking LED
Overview:
In this practical, we will start the journey of learning Arduino UNO .To begin, let's learn how
to make an LED blink.
Components:
1 x Arduino UNO
1 x USB Cable
1 x 220Ω Resistor
1 x LED
1 x BreadBoard
2 x Jumper Wires
Principle:
In this lesson, we will program the Arduino's GPIO output high level (+5V) and low level (0V), and
then make the LED which is connected to the Arduino’s GPIO flicker with a certain frequency.
The LED is the abbreviation of light emitting diode. It is usually made of gallium arsenide, gallium
phosphide semiconductor materials. The LED has two electrodes: a positive electrode and a
negative one. It lights up only when a forward current passes, and it can flash red, blue, green,
yellow, etc. The color of the light depends on the material it is made.
In general, the drive current for LED is 5-20mA. Therefore, in reality it usually needs an extra
resistor for current limitation so as to protect the LED.
10
Web: www.sunrobotics.co.in
Email:[email protected]
2. What is resistor?
The main function of the resistor is to limit currents. In the circuit, the character ‘R’ represents
resistor, and the unit of resistor is ohm(Ω).
A band resistor is used in this experiment. It is a resistor with a surface coated with some
particular color through which the resistance can be identified directly.
Schematic :
3. Key functions:
●setup()
The setup() function is called when a sketch starts. Use it to initialize variables, pin modes, start
using libraries, etc. The setup function will only run once, after each powerup or reset of the
Arduino board.
●loop()
After creating a setup() function, which initializes and sets the initial values, the loop()function
does precisely what its name suggests, and loops consecutively, allowing your program to change
and respond. Use it to actively control the Arduino board.
●pinMode()
Configures the specified pin to behave either as an input or an output.
As of Arduino 1.0.1, it is possible to enable the internal pullup resistors with the mode
INPUT_PULLUP. Additionally, the INPUT mode explicitly disables the internal pullups.
●digitalWrite()
11
Web: www.sunrobotics.co.in
Email:[email protected]
Write a HIGH or a LOW value to a digital pin. If the pin has been configured as an OUTPUT with
pinMode(), its voltage will be set to the corresponding value: 5V (or 3.3V on 3.3V boards) for
HIGH, 0V (ground) for LOW.
If the pin is configured as an INPUT, digitalWrite() will enable (HIGH) or disable (LOW) the
internal pullup on the input pin. It is recommended to set the pinMode() to INPUT_PULLUP to
enable the internal pull-up resistor
●delay()
Pauses the program for the amount of time (in miliseconds) specified as parameter. (There are
1000 milliseconds in a second.)
Procedure:
Step 1: Build the circuit as below:
Step 2: Program : You can copy paste the below program in the IDE or open the code directly.
from the “CODE” folder that comes with the DVD/from the downloaded Zip folder.
/***********************************************************
File name: 01_blinkingLed.ino Description:
Let, LED blinking
***********************************************************/
int ledPin = 13;// LED connected to digital pin 13
void setup() {
pinMode(ledPin,OUTPUT);
}
void loop()
{
digitalWrite(ledPin,HIGH); // set the LED on
delay(1000); // wait for a second
digitalWrite(ledPin,LOW); // set the LED off
delay(1000); // wait for a second
}
Step 3: Compile the program and upload to Arduino UNO board. Now you can see the LED
blinking.
12
Web: www.sunrobotics.co.in
Email:[email protected]
Lesson 2 - Four Blinking LED
Overview:
In the first lesson, we have learned how to make an LED blink by programming the Arduino.
Today, we will use the Arduino to control 4 LEDs to make the LEDs show the effect of flowing.
Components:
1 x Arduino UNO
1 x USB Cable
4 x 220Ω Resistor
4 x LED
1 x BreadBoard
Several Jumper Wires
Principle:
The principle of this experiment is very simple and is quite similar with that in the first lesson.
1 . Key function
The for statement is used to repeat a block of statements enclosed in curly braces. An increment
counter is usually used to increment and terminate the loop. The for statement is useful for any
repetitive operation, and is often used in combination with arrays to operate on collections of
data/pins.
13
Web: www.sunrobotics.co.in
Email:[email protected]
Procedure:
Step 1: Build the circuit
14
Web: www.sunrobotics.co.in
Email:[email protected]
void setup() {
pinMode(led1,OUTPUT);
pinMode(led2,OUTPUT);
pinMode(led3,OUTPUT);
pinMode(led4,OUTPUT);
}
void loop() {
digitalWrite(led1,HIGH);
delay(50);
digitalWrite(led1,LOW);
digitalWrite(led2,HIGH);
delay(50);
digitalWrite(led2,LOW);
digitalWrite(led3,HIGH);
delay(50);
digitalWrite(led3,LOW);
digitalWrite(led4,HIGH);
delay(50);
digitalWrite(led4,LOW);
delay(200);
}
15
Web: www.sunrobotics.co.in
Email:[email protected]
Lesson 3 - Controlling an RGB LED (Common cathode)
Overview :
In this lesson, we will program the Arduino for RGB LED control, and make RGB LED
emits several of colors of light.
Components:
1 X Arduino UNO
1 X USB Cable
1 X RGB LED
3 X 220Ω Resistor
1 X Breadboard
Several jumper wires
Principle:
RGB LEDs consist of three LEDs: red, green and blue. These three colored LEDs are
capable of producing any color. Tri-color LEDs with red, green, and blue emitters, in
general using a four-wire connection with one common lead (anode or cathode).
What we use in this experiment is a common anode RGB LED. The longest pin is the
common anode of the three LEDs. The pin is connected to the +5V pin of the Arduino,
and the rest pins are connected to pin D8, D9, and D10 of the Arduino with a current
limiting resistor between.
16
Web: www.sunrobotics.co.in
Email:[email protected]
In this way, we can control the color of an RGB LED by 3-channel PWM signals.
Schematic:
Common cathode
Procedure:
Step 1: Build the circuit
17
Web: www.sunrobotics.co.in
Email:[email protected]
/***********************************************************
File name: 03_RGB blinkingLed.ino Description:
Let, RGB led blinks. *********************************************/
void setup() {
pinMode (8,OUTPUT);
pinMode (9,OUTPUT);
pinMode (10,OUTPUT);
}
void loop() {
digitalWrite (8,HIGH);
digitalWrite (10,LOW);
delay(1000);
digitalWrite (9,HIGH);
digitalWrite (8,LOW);
delay(1000);
digitalWrite (10,HIGH);
digitalWrite (9,LOW);
delay(1000);
}
Step 3: Compile the program and upload to Arduino UNO board
Now, you can see the RGB LED flash red, green, blue, yellow, white and purple light, and then go
out. Each state lasts for 1s each time, and the LED flashes colors repeatedly in such sequence.
or
18
Web: www.sunrobotics.co.in
Email:[email protected]
Lesson 3 - Controlling an RGB LED (Common Anode)
Overview :
In this lesson, we will program the Arduino for RGB LED control, and make RGB LED
emits several of colors of light.
Components:
1 X Arduino UNO
1 X USB Cable
1 X RGB LED
3 X 220Ω Resistor
1 X Breadboard
Several jumper wires
Principle:
RGB LEDs consist of three LEDs: red, green and blue. These three colored LEDs are
capable of producing any color. Tri-color LEDs with red, green, and blue emitters, in
general using a four-wire connection with one common lead (anode or cathode).
What we use in this experiment is a common anode RGB LED. The longest pin is the
common anode of the three LEDs. The pin is connected to the +5V pin of the Arduino,
and the rest pins are connected to pin D8, D9, and D10 of the Arduino with a current
limiting resistor between.
19
Web: www.sunrobotics.co.in
Email:[email protected]
In this way, we can control the color of an RGB LED by 3-channel PWM signals.
Schematic:
Common Anode
Procedure:
Step 1: Build the circuit
20
Web: www.sunrobotics.co.in
Email:[email protected]
Step 2: Program code
/***********************************************************
File name: 03_RGB blinkingLed.ino Description:
Let, RGB led blinks.
***********************************************************/
void setup() {
pinMode (8,OUTPUT);
pinMode (9,OUTPUT);
pinMode (10,OUTPUT);
}
void loop() {
digitalWrite (8,HIGH);
digitalWrite (10,LOW);
delay(1000);
digitalWrite (9,HIGH);
digitalWrite (8,LOW);
delay(1000);
digitalWrite (10,HIGH);
digitalWrite (9,LOW);
delay(1000);
}
Step 3: Compile the program and upload to Arduino UNO board
Now, you can see the RGB LED flash red, green, blue, yellow, white and purple light, and then go
out. Each state lasts for 1s each time, and the LED flashes colors repeatedly in such sequence.
21
Web: www.sunrobotics.co.in
Email:[email protected]
Lesson 4 – Push button – LED Blinking
Overview:
In this lesson, we will learn how to detect the state of a button, and then toggle the state of the
LED based on the state of the button.
Components:
1 x Arduino UNO
1 x USB Cable
1 x 220Ω Resistor
1 x 10KΩ Resistor
1 x LED
1 x Push Button
1 x Breadboard
Several jumper wires
Principle
1. Button
Buttons are a common component used to control electronic devices. They are usually used as
switches to connect or disconnect circuits. Although buttons come in a variety of sizes and
shapes, the one used in this experiment will be a 12mm button as shown below.
The button we used is a normally open type one. The two contacts of a button are in the off state
under the normal conditions; only when the button is pressed they are closed.
The button jitter must happen in the process of using. The jitter waveform is as the flowing
picture:
22
Web: www.sunrobotics.co.in
Email:[email protected]
Each time you press the button, the Arduino will regard you have pressed the button many times
due to the jitter of the button. You should deal with the jitter of buttons before using. You can
eliminate the jitter through software programming. Besides, you can use a capacitor to solve the
issue. Take the software method for example. First, detect whether the level of button interface
is low level or high level. If it is low level, 5~10ms delay is needed. Then detect whether the level
of button interface is low or high. If the signal is low, you can infer that the button is pressed
once. You can also use a 0.1uF capacitor to avoid the jitter of buttons.
2. Interrupt
Hardware interrupts were introduced as a way to reduce wasting the processor's valuable time
in polling loops, waiting for external events. They may be implemented in hardware as a distinct
system with control lines, or they may be integrated into the memory subsystem .
. Key functions:
●attachInterrupt(interrupt, ISR, mode)
Specifies a named Interrupt Service Routine (ISR) to call when an interrupt occurs.
Replaces any previous function that was attached to the interrupt. Most Arduino boards have
two
external interrupts: numbers 0 (on digital pin 2) and 1 (on digital pin 3).
Generally, an ISR should be as short and fast as possible. If your sketch uses multiple ISRs, only
one can run at a time, other interrupts will be ignored (turned off) until the current one is
finished. as delay() and millis() both rely on interrupts, they will not work while an ISR is running.
delayMicroseconds(), which does not rely on interrupts, will work as expected.
Syntax:
attachInterrupt(pin, ISR, mode)
Parameters: pin: the pin number
23
Web: www.sunrobotics.co.in
Email:[email protected]
ISR: the ISR will be called when the interrupt occurs; this function must take no parameters and
return nothing. This function is sometimes referred to as an interrupt service routine.
mode: defines when the interrupt should be triggered. Four constants are predefined as valid
values:
-LOW to trigger the interrupt whenever the pin is low,
-CHANGE to trigger the interrupt whenever the pin changes value -RISING to trigger
when the pin goes from low to high, -FALLING for when the pin goes from high to low.
●digitalRead()
Reads the value from a specified digital pin, either HIGH or LOW. Syntax:
digitalRead(pin)
Parameters:
pin: the number of the digital pin you want to read (int) Returns:
HIGH or LOW ●delayMicroseconds(us)
Pauses the program for the amount of time (in microseconds) specified as parameter. There are
a thousand microseconds in a millisecond, and a million microseconds in a second.
Currently, the largest value that will produce an accurate delay is 16383. This could change in
future Arduino releases. For delays longer than a few thousand microseconds, you should use
delay() instead.
Syntax:
delayMicroseconds(us)
Parameters:
24
Web: www.sunrobotics.co.in
Email:[email protected]
Schematic :
Procedure:
Step 1: Build the circuit
25
Web: www.sunrobotics.co.in
Email:[email protected]
Step 2: Program: Open /Copy the code from the “CODE” Folder
/***********************************************************
File name: 04_Push button LED Blinking .ino Description:
Let, LED blinking and control by push button.
*************************************************************/
26
Web: www.sunrobotics.co.in
Email:[email protected]
Lesson 5 – Seven Segment Display Interface
Overview:
In this lesson, we will program the Arduino to achieve the controlling of a segment display.
Components
1 x Arduino UNO
1 x USB Cable
1 x 220Ω Resistor
1 x Push Button
1 x 7-segment Display
1 x Breadboard
Several jumper wires
Principle
The seven-segment display is a form of electronic display device for displaying decimal numerals
that is an alternative to the more complex dot matrix displays.
Seven-segment displays are widely used in digital clocks, electronic meters, basic calculators, and
other electronic devices that display numerical information.
The seven-segment display is an 8-shaped LED display device composed of eight LEDs (including
a decimal point). The segments respectively named a, b, c, d, e, f, g, and dp.
The segment display can be divided into two types: common anode and common cathode
segment displays, by internal connections.
For a common-anode LED, the common anode should be connected to the power supply (VCC);
for a common-cathode LED, the common cathode should be connected to the ground (GND).
Each segment of a segment display is composed of an LED, so a resistor is needed for protecting
the
27
Web: www.sunrobotics.co.in
Email:[email protected]
LED.
A 7-segment display has seven segments for displaying a figure an done more for displaying a
decimal point. For example, if you want to display a number '1', you should only light the segment
b and c, as shown below.
Schematic :
Procedure:
Step 1: Build the circuit
28
Web: www.sunrobotics.co.in
Email:[email protected]
Step 2: Program Code:
/***********************************************************
File name: 05_7 Segment Display Interface.ino Description:
Let, seven segment display using push button.
***********************************************************/
int pushButton = 12;
unsigned int buttonState = 0;
void loop() {
if (digitalRead(pushButton) == 1)
{
buttonState = buttonState + 1;
29
Web: www.sunrobotics.co.in
Email:[email protected]
while (digitalRead(pushButton) == 1)
{
delay (5);
}
}
Serial.println(buttonState);
delay(1); // delay in between reads for stability
sevenSegWrite(buttonState);
if (buttonState == 9)
{
hringur();
buttonState = 0;
}
}
void hringur(){
while (buttonState == 9)
{
Serial.println(buttonState);
delay(1); // delay in between reads for stability
if (digitalRead(pushButton) == 1)
{
buttonState = buttonState + 1;
while (digitalRead(pushButton) == 1)
{
delay (5);
}
}
}
return;
}
void sevenSegWrite(unsigned int digit) {
unsigned int pin = 2;
for (unsigned int segCount = 0; segCount < 8; segCount++) {
digitalWrite(pin, seven_seg_digits[digit][segCount]);
pin++;
digitalWrite(9, 1);
}
return;
}
30
Web: www.sunrobotics.co.in
Email:[email protected]
Lesson 6 – 3 WAY TRAFFIC LIGHT Controller
Overview:
In the second lesson, we have learned how to make a LEDs blink by programming the Arduino.
Today, we will use the Arduino to control different LEDs different color to make the LEDs show
the effect of flowing in traffic light system.
Components:
1 x Arduino UNO
1 x USB Cable
3 x 200Ω Resistor
3 x 5mm RED LED
3 x 5mm YELLOW LED
3 x 5mm GREEN LED
1 x Breadboard
Several jumper wires
Principle:
The principle of this experiment is very simple and is quite similar with that in the second lesson.
This Arduino based 3-Way Traffic Light Controller is a simple project which is useful to understand
the working of traffic lights which we see around us. We have covered a simpler version of traffic
lights in this traffic light circuit. Here have demonstrated it for 3 sides or ways. Now let’s get into
the project.
The code for this Arduino Traffic Light Controller Project is simple and can be easily understood.
Here we have demonstrated Traffic lights for the 3 ways road and the code glows LED’s on all the
three sides in a particular sequence, in which the actual Traffic Lights works. Like, at a time, there
will be two Red signals on any of the two sides and one Green light on the remaining side. And
yellow light will also glow, for 1 second each time, in between transition from Red to Green,
means first red light glows for 5 second then yellow light glows for 1 second and then finally green
light will be turned on.
31
Web: www.sunrobotics.co.in
Email:[email protected]
Schematic:
Procedure:
Step 1: Build the circuit
32
Web: www.sunrobotics.co.in
Email:[email protected]
Step 2: Program code
/***********************************************************
File name: 06_3 WAY TRAFFIC LIGHT .ino Description:
Let,3 way traffic light using LED blinks.
***************************************************************/
void setup() {
// configure the output pins
pinMode(2,OUTPUT);
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
pinMode(6,OUTPUT);
pinMode(7,OUTPUT);
pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
pinMode(10,OUTPUT);
}
void loop()
{
digitalWrite(2,1); //enables the 1st set of signals
digitalWrite(7,1);
digitalWrite(10,1);
digitalWrite(4,0);
digitalWrite(3,0);
digitalWrite(6,0);
digitalWrite(8,0);
digitalWrite(9,0);
digitalWrite(5,0);
delay(4000);
33
Web: www.sunrobotics.co.in
Email:[email protected]
digitalWrite(10,1);
digitalWrite(2,0);
digitalWrite(3,0);
digitalWrite(6,0);
digitalWrite(8,0);
digitalWrite(9,0);
digitalWrite(7,0);
delay(4000);
34
Web: www.sunrobotics.co.in
Email:[email protected]
Lesson 7 - RGB LED push button color change
Overview:
In this lesson, we will program the Arduino to change RGB LED color with the press of a button.
Components
1 x Arduino UNO
1 x USB Cable
1 x RGB LED
3 x 220Ω Resistor
1 x BreadBoard
Several jumper wires
Principle
RGB LEDs consist of three LEDs: red, green and blue. These three colored LEDs are capable of
producing any color. Tri-color LEDs with red, green, and blue emitters, in general using a four-
wire connection with one common lead (anode or cathode).
What we use in this experiment is a common anode RGB LED. The longest pin is the common
anode of the three LEDs. The pin is connected to the +5V pin of the Arduino, and the rest pins
are connected to pin D9, D10, and D11 of the Arduino with a current limiting resistor between
using then push button.
35
Web: www.sunrobotics.co.in
Email:[email protected]
Schematic :
Procedure:
Step 1: Build the circuit
36
Web: www.sunrobotics.co.in
Email:[email protected]
Step 2: Program
/***********************************************************
File name: 07 RGB LED push button color change.ino Description:
Let, RGB led using push button color will be change
*************************************************************/
const int buttonPin = 3;
const int redPin = 11;
const int greenPin = 10;
const int bluePin = 9;
int counter = 0;
void setup()
{
pinMode(buttonPin, INPUT);
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
}
void loop()
{
int buttonState;
buttonState = digitalRead(buttonPin);
if (buttonState == LOW) // light the LED
{
counter++;
delay(150);
}
if (counter == 0)
{
digitalWrite(redPin, LOW);
digitalWrite(greenPin, LOW);
digitalWrite(bluePin, LOW);
}
else if (counter == 1)
{
digitalWrite(redPin, HIGH);
digitalWrite(greenPin, LOW);
digitalWrite(bluePin, LOW);
}
else if (counter == 2)
{
digitalWrite(redPin, LOW);
digitalWrite(greenPin, HIGH);
digitalWrite(bluePin, LOW);
}
else if (counter == 3)
{
digitalWrite(redPin, LOW);
digitalWrite(greenPin, LOW);
digitalWrite(bluePin, HIGH);
}
{
counter = 0;
}
}
Step 3: Compile the program and upload to Arduino UNO board
37
Web: www.sunrobotics.co.in
Email:[email protected]
Lesson – 8 Multiple tones with one Piezo Buzzer
Overview:
In this lesson, you will learn how to use a buzzer.
Components
1 x Arduino UNO
1 x USB Cable
1 x Buzzer
1 x BreadBoard
2 x Jumper Wires
Principles
The working principle of buzzer it to use PWM generating audio to make the air to vibrate.
Appropriately changed as long as the vibration frequency, it can generate different sounds. For
example, sending a pulse of 523Hz, it can generate Alto Do, pulse of 587Hz, it can generate
midrange Re, pulse of 659Hz, it can produce midrange Mi. By the buzzer, you can play a song.
We should be careful not to use the UNO R3 board analog Write () function to generate a pulse
to the buzzer, because the pulse output of analog Write () is fixed (500Hz).
Schematic
38
Web: www.sunrobotics.co.in
Email:[email protected]
Procedure:
Step 1: Build the circuit
Step 2: Program: Open /Copy the code from the “CODE” Folder
/***********************************************************
File name: 8 Buzzer Arduino Circuit .ino Description:
Let, Buzzer will be tone
*************************************************************/
const int buzzer= 8;
void setup() {
pinMode (buzzer,OUTPUT);
}
void loop() {
tone(buzzer,1000);
delay(1000);
noTone(buzzer);
delay(1000);
}
Step 3: Compile the program and upload to Arduino UNO board
39
Web: www.sunrobotics.co.in
Email:[email protected]
Lesson 9 - Seeing the light using Photo resistor with an
arduino
Overview:
In this lesson, we will learn how to measure the light intensity by photo resistor.
Components
1 x Arduino UNO
1 x USB cable
1 x 10kΩ Resistor
1 x 220Ω Resistor
1 x LED
1 x Photo Resistor
1 x BreadBoard
Jumper wires
Principle:
A photo resistor is a light-controlled variable resistor. The resistance of a photo resistor decreases
with the increasing incident light intensity; in other words, it exhibits photoconductivity. A photo
resistor can be applied in light-sensitive detector circuits.
A photo resistor is made of a high resistance semiconductor. In the dark, a photoresistor can have
a resistance as high as a few megohms (MΩ), while in the light, a photo resistor can have a
resistance as low as a few hundred ohms. If incident light on a photo resistor exceeds a certain
frequency, photons absorbed by the semiconductor give bound electrons enough energy to jump
into the conduction band. The resulting free electrons (and their whole partners) conduct
electricity, thereby lowering resistance. The resistance range and sensitivity of a photo resistor
can substantially differ among dissimilar devices. Moreover, unique photo resistors may react
substantially differently to photons within certain wavelength bands.
Schematic:
40
Web: www.sunrobotics.co.in
Email:[email protected]
Procedure:
Step 1: Build the circuit
41
Web: www.sunrobotics.co.in
Email:[email protected]
Step 2 : Program
/***********************************************************
File name: 9 Seeing the light using photo resistor with an arduino Description:
Let, light using photo resistor
******************** *******************************************/
const int sensorPin = 0;
const int ledPin = 9;
int lightCal;
int lightVal;
void setup() {
pinMode(ledPin, OUTPUT);
lightCal = analogRead(sensorPin);
}
void loop() {
lightVal = analogRead(sensorPin);
if (lightVal < lightCal - 50)
{
digitalWrite(9, HIGH);
}
else {
digitalWrite(9, LOW);
}
}
Step 3: Compile the program and upload to Arduino UNO board
42
Web: www.sunrobotics.co.in
Email:[email protected]
Lesson 10 – LCD 1602 Display
Overview:
In this lesson, we will learn how to use a character display device - LCD1602 on the Arduino
platform. We first make the LCD1602 display a string "Hello world!"
Components
1 x Arduino UNO
1 x USB Cable
1 x potentiometer
1 x LCD(16 x 2) Display
1 x BreadBoard
Jumper Wires
Principle
LCD1602 is a kind of character LCD display. The LCD has a parallel interface, meaning that the
microcontroller has to manipulate several interface pins at once to control the display. The
interface consists of the following pins:
● A register select (RS) pin that controls where in the LCD's memory you're writing data to. You
can select either the data register, which holds what goes on the screen, or an instruction
register, which is where the LCD's controller looks for instructions on what to do next.
● A Read/Write (R/W) pin that selects reading mode or writing mode
● An Enable pin that enables writing to the registers
● 8 data pins (D0-D7). The state of these pins (high or low) is the bits that you're writing to a
register when you write, or the values when you read.
● There are also a display contrast pin (Vo), power supply pins (+5V and Gnd) and LED Backlight
(Bklt+ and BKlt-) pins that you can use to power the LCD, control the display contrast, and turn
on or off the LED backlight respectively.
Schematic:
43
Web: www.sunrobotics.co.in
Email:[email protected]
Procedure:
Step 1: Build the circuit
Step 2: Program: Open /Copy the code from the “CODE” Folder
/***********************************************************
File name: 10 LCD1602 Display arduino.ino Description:
Let, LCD display print hello world.
****************************************************************/
44
Web: www.sunrobotics.co.in
Email:[email protected]
// include the library code:
#include <LiquidCrystal.h>
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);
}
45
Web: www.sunrobotics.co.in
Email:[email protected]
Lesson 11 – HC-SR04 Project
Overview:
In this lesson, we will learn how to measure the distance by the ultrasonic distance sensor.
Component:
1 x Arduino UNO
1 x USB Cable
1 x Ultrasonic sensor
1 x Breadboard
Jumper wire
Principle:
The HC-SR04 uses sound instead of light as the GP2D12 module does. The HC-SR04 sends a ping
as a submarine does and measure the time between sending and receiving anything back when
an object is in front of the sensor. Because using sound for its measurements we can reach up to
4 meters. The module is about 45x20x15 mm in size and has a 4 pin connection. Two pins are
needed to power the module with 5 Volts. The working current is about 15 mA. One pin is the
trigger ping and the last one is used to read the result of the measurements, the echo pin. The
measuring angle from the HC-SR04 is 15 degree. At 4 meter distance this should be a beam of
about 1 meter. At 1 meter this is 26 cm so we have to keep this in mind when using this
information.
Schematic:
46
Web: www.sunrobotics.co.in
Email:[email protected]
Procedure:
Step 1: Build the circuit
Step 2: Program
/***********************************************************
File name: 11 – HC-SR04 Project .ino Description:
Let, Distance measure with ultrasonic sensor.
***********************************************************/
#include <HCSR04.h>
const int TriggerPin = 8; //Trig pin
const int EchoPin = 9; //Echo pin
long Duration = 0;
void setup() {
pinMode(TriggerPin,OUTPUT); // Trigger is an output pin
pinMode(EchoPin,INPUT); // Echo is an input pin
Serial.begin(9600); // Serial Output
}
void loop() {
digitalWrite(TriggerPin, LOW);
delayMicroseconds(2);
digitalWrite(TriggerPin, HIGH); // Trigger pin to HIGH
47
Web: www.sunrobotics.co.in
Email:[email protected]
delayMicroseconds(10); // 10us high
digitalWrite(TriggerPin, LOW); // Trigger pin to HIGH
Duration = pulseIn(EchoPin,HIGH); // Waits for the echo pin to get high
long Distance_mm = Distance(Duration); // Use function to calculate the distance
48
Web: www.sunrobotics.co.in
Email:[email protected]
Lesson – 12 PIR sensor
Overview:
In this tutorial I will show you how to make basic interfacing of PIR sensor with the arduino.
Components
1 x Arduino UNO
1 x USB Cable
1 x PIR sensor
1 x BreadBoard
Several jumper wires
Principle
PIR sensor detects a human being moving around within approximately 10m from the sensor.
This is an average value, as the actual detection range is between 5m and 12m.PIR are
fundamentally made of a pyro electric sensor, which can detect levels of infrared radiation. This
PIR sensor is connected to the arduino pin 2 that is dedicated for interrupt 0.The interrupt will
be triggered at the rising edge of the input. And after receiving the interrupt. It will call a function
(ISR) alarm ON.
Schematic
49
Web: www.sunrobotics.co.in
Email:[email protected]
Procedure:
Step 1: Build the circuit
Step 2: Program: Open /Copy the code from the “CODE” Folder
50
Web: www.sunrobotics.co.in
Email:[email protected]
/***********************************************************
File name: 12. PIR sensor .ino Description:
Let, PIR sensor motion detected LED will blinks.
**********************************************************/
int led = 13; // the pin that the LED is atteched to
int sensor = 2; // the pin that the sensor is atteched to
int state = LOW; // by default, no motion detected
int val = 0; // variable to store the sensor status (value)
void setup() {
pinMode(led, OUTPUT); // initalize LED as an output
pinMode(sensor, INPUT); // initialize sensor as an input
Serial.begin(9600); // initialize serial
}
void loop(){
val = digitalRead(sensor); // read sensor value
if (val == HIGH) { // check if the sensor is HIGH
digitalWrite(led, HIGH); // turn LED ON
delay(100); // delay 100 milliseconds
if (state == LOW) {
Serial.println("Motion detected!");
state = HIGH; // update variable state to HIGH
}
}
else {
digitalWrite(led, LOW); // turn LED OFF
delay(200); // delay 200 milliseconds
if (state == HIGH){
Serial.println("Motion stopped!");
state = LOW; // update variable state to LOW
}
}
}
Step 3: Compile the program and upload to Arduino UNO board .After compile the code we can
see that PIR sensor detected the movement.
51
Web: www.sunrobotics.co.in
Email:[email protected]
Lesson 13 - Showing the temperature and humidity
sensor in using arduino
Overview:
In this tutorial we have to learn about the data from DHT11 sensor send to Arduino UNO and
then the humidity and temperature.
COMPONENTS:
1 x Arduino UNO
1 x USB Cable
1 x DTH11 Temperature Sensor
1 x 10kΩ Resistor
1 x BreadBoard
Jumper Wires
Schematic:
52
Web: www.sunrobotics.co.in
Email:[email protected]
Procedure:
Step 1: Build the circuit
Step 2: Program: Open /Copy the code from the “CODE” Folder
/***********************************************************
File name: 13 Showing the temperature and humidity sensor in display using arduino.ino
Description: Let, Showing the temperature using DHT.
***********************************************************/
#include <SimpleDHT.h>
int pinDHT11 = 2;
SimpleDHT11 dht11;
void setup()
{
Serial.begin(9600);
}
void loop() {
Serial.println("=================================");
Serial.println("Sample DHT11...");
byte temperature = 0;
byte humidity = 0;
byte data[40] = {0};
53
Web: www.sunrobotics.co.in
Email:[email protected]
if (dht11.read(pinDHT11, &temperature, &humidity, data)) {
Serial.print("Read DHT11 failed");
return;
}
Serial.print("Sample RAW Bits: ");
for (int i = 0; i < 40; i++) {
Serial.print((int)data[i]);
if (i > 0 && ((i + 1) % 4) == 0) {
Serial.print(' ');
}
}
Serial.println("");
Serial.print ("Sample OK: ");
Serial.print((int)temperature); Serial.print(" *C, ");
Serial.print((int)humidity); Serial.println(" %");
delay(1000);
}
Step 3: Compile the program and upload to Arduino UNO board.
54
Web: www.sunrobotics.co.in
Email:[email protected]
Lesson 14 - Touch Sensor arduino Interface
Overview:
In this project I made a touch sensor using a coin that works based on Arduino.
Components:
1 x Arduino UNO
1 x USB Cable
1 x Touch Sensor
1 x BreadBoard
Jumper Wires
Principle
This device uses your body as part of the circuit. When you touch the sensor pad, the capacitance of the
circuit is changed and is detected. That detected change in capacitance results in the output changing
states.
When I first got this, I expected a glitch device, that while functional, would occasionally have
unpredictable output results.
I may have been wrong. After playing for a few hours, I can’t seem to get it to do anything other than
what I expected it to do. If you’re looking for robust user input, this might do the trick.
Schematic:
55
Web: www.sunrobotics.co.in
Email:[email protected]
Procedure:
Step 1: Build the circuit
Step 2: Program: Open /Copy the code from the “CODE” Folder
/***********************************************************
File name: 14 Touch Sensor arduino Interface .ino Description:
Let, Touch sensor using.
***********************************************************/
#define sensorPin 2
void loop() {
int senseValue = digitalRead(sensorPin);
if (senseValue == HIGH){
digitalWrite(ledPin, HIGH);
Serial.println("TOUCHED");
}
else{
digitalWrite(ledPin,LOW);
Serial.println("not touched");
}
delay(500);
}
Step 3: Compile the program and upload to Arduino UNO board.
56
Web: www.sunrobotics.co.in
Email:[email protected]
Lesson 15 – Magnetic Reed Switch
Overview:
This tutorial demonstrates how to use a magnetic reed switch.
Components:
1 x Arduino UNO
1 x USB Cable
1 x 220Ω Resistor
1 x 1kΩ Resistor
1 x RED LED
1 x Magnetic Reed Switch
1 x BreadBoard
Jumper Wires
Principle
A magnetic contact switch is basically a reed switch encased in a plastic shell so that you can
easily apply them in a door, a window or a drawer to detect if the door is open or closed. The
electrical circuit is closed when a magnet is near the switch (less than 13 mm (0.5’’) away). When
the magnet is far away from the switch, the circuit is open
Schematic:
57
Web: www.sunrobotics.co.in
Email:[email protected]
Procedure:
Step 1: Build the circuit
Step 2: Program: Open /Copy the code from the “CODE” Folder
/***********************************************************
File name: 15 Magnetic Reed Switch.ino Description:
Let, Demonstrates how to use a magnetic reed switch .
**********************************************************/
#define LED 13
#define REED 2
void setup() {
pinMode(LED, OUTPUT);
pinMode(REED, INPUT);
}
void loop() {
digitalWrite(LED, digitalRead(REED));
}
Step 3: Compile the program and upload to Arduino UNO board.
58
Web: www.sunrobotics.co.in
Email:[email protected]
Lesson 16 - IR_Receiver using arduino
Overview:
Using an IR Remote is a great way to have wireless control of your project.
Components:
1 x Arduino UNO
1 x USB cable
1 x IR receiver
1 x Remote
1 x Breadboard
Jumper wires
Principle
IR detectors are little microchips with a photocell that are tuned to listen to infrared light. They
are almost always used for remote control detection - every TV and DVD player has
One of these in the front to listen for the IR signal from the clicker. Inside the remote control is a
matching IR LED, which emits IR pulses to tell the TV to turn on, off or change channels. IR light
is not visible to the human eye, which means it takes a little more work to test a setup.
Schematic:
Procedure:
Step 1: Build the circuit
59
Web: www.sunrobotics.co.in
Email:[email protected]
Step 2: Program
/***********************************************************
File name: 16- IR_Receiver using arduino .ino Description:
Let,IR Remote is a great way to have wireless control
***************************************************/
#include <IRremote.h> // Include the lib
int RECV_PIN = 2;
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
}
void loop() {
if (irrecv.decode(&results)) {
Serial.println(results.value, HEX);
irrecv.resume(); // Receive the next value
}
delay(100);
}
Step 3: Compile the program and upload to Arduino UNO board
60
Web: www.sunrobotics.co.in
Email:[email protected]