1. 1
Arduino Based Applications
By
Jawaher A.Fadhil
B.SC in Electronics Engineering
M.Tech in Computer Engineering
University of Duhok
College of Science
CS Department
3. Blinking led
Open: File -> Examples -> Digital -> Blink
void setup()
{
// initialize digital pin 13 as an output.
pinMode(13, OUTPUT);
}
void loop()
{
// turn the LED on by making the voltage HIGH
digitalWrite(13, HIGH);
// wait for a second
delay(1000);
// turn the LED off by making the voltage LOW
digitalWrite(13, LOW);
delay(1000);
}
3
7. Enter the code
void setup()
{
// initialize digital pin 10 as an output.
pinMode(10, OUTPUT);
}
void loop()
{
// turn the LED on by making the voltage HIGH
digitalWrite(10, HIGH);
// wait for a second
delay(1000);
// turn the LED off by making the voltage LOW
digitalWrite(10, LOW);
delay(1000);
}
7
9. PWM
Pulse Width Modulation, or PWM, is a technique for getting
analog results with digital means. Digital control is used to
create a square wave, a signal switched between on and off.
This on-off pattern can simulate voltages in between full on (5
Volts) and off (0 Volts) by changing the portion of the time the
signal spends on versus the time that the signal spends off.
The duration of "on time" is called the pulse width. To get
varying analog values, you change, or modulate, that pulse
width. If you repeat this on-off pattern fast enough with an
LED for example, the result is as if the signal is a steady voltage
between 0 and 5v controlling the brightness of the LED.
9
11. PWM
In the previous graphic, the green lines represent a regular
time period. This duration or period is the inverse of the PWM
frequency. In other words, with Arduino's PWM frequency at
about 500Hz, the green lines would measure 2 milliseconds
each. A call to analogWrite() is on a scale of 0 - 255, such that
analogWrite(255) requests a 100% duty cycle (always on), and
analogWrite(127) is a 50% duty cycle (on half the time) for
example.
11
12. PWM
To build such application, you need the
following components:
Arduino Uno
USB cable
LED
Resistor 1k
Jumper wires
12
15. What is RGB LED?
The RGB LED can emit different colors by mixing the 3 basic
colors red, green and blue. So it actually consists of 3 separate
LEDs red, green and blue packed in a single case. That’s why it
has 4 leads, one lead for each of the 3 colors and one
common cathode or anode depending of the RGB LED type.
15
16. RGB LED
Components needed
• RGB LED
• 3x 220 Ohms Resistors
• Arduino Board
• Breadboard and Jump Wires
16
The cathode will be connected to the ground and the 3 anodes
will be connected through 220 Ohms resistors to 3 digital pins
on the Arduino Board that can provide PWM signal. We will use
PWM for simulating analog output which will provide different
voltage levels to the LEDs so we can get the desired colors.
19. RGB LED
19
int redPin= 11;
int greenPin = 10;
int bluePin = 9;
void setup() {
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
}
void loop() {
setColor(255, 0, 0); // Red Color
delay(1000);
setColor(0, 255, 0); // Green Color
delay(1000);
Enter The Code
20. Con…
20
setColor(0, 0, 255); // Blue Color
delay(1000);
setColor(255, 255, 255); // White Color
delay(1000);
setColor(170, 0, 255); // Purple Color
delay(1000);
}
void setColor(int redValue, int greenValue, int blueValue) {
analogWrite(redPin, redValue);
analogWrite(greenPin, greenValue);
analogWrite(bluePin, blueValue);
}
22. 7 - Segment Display
• How many TV shows and movies
have you seen with some mysterious
electronic device counting down to
zero on one of those 7 segment LED
displays.
• The seven segment display is a pretty
simple device. It is actually 8 LEDs
.Seven LEDs are the main, the 8st is
the dot. So we have 7 input pins for
the main LEDs, one input pin for the
dot and the other two are for
common anode or cathode.
22
23. 7 - Segment Display
23
There are two types of displays – with common anode or common
Cathode.
24. 7 - Segment Display
24
A to Pin 2
B to Pin 3
C to Pin 4
D to Pin 5
E to Pin 6
F to Pin 7
G to Pin 8
Dot to Pin 9
In this example ,we will use an 7-segment display with common
cathode. Use your solder less breadboard to make the
connections between the seven segment LED and your Arduino
board: