Beruflich Dokumente
Kultur Dokumente
The Arduino Starter Kit is the primary tool we use to start learning Electronics and Programming. The
kit includes the main microcontroller board the Arduino UNO R3 based on ATmega328. It has 14 digital
input/output pins (6 of which can be PWM outputs), 6 analog inputs, a 16 MHz crystal oscillator, a USB
connection, a power jack, an ISP header, and a reset button.
Microcontroller = ATmega328
Operating Voltage = 5V
Input Voltage (recommended) = 7-12V
1. Download the Arduino IDE (Integrated Development Environment) by opening your Internet
browser and going to https://www.arduino.cc/en/Main/Software
By default we use Windows Operating System, Click the link on the red box. After downloading
locate the file and place it in your preferred computer disk storage.
If you are having trouble downloading and installing the hardware and software, go to
https://www.arduino.cc/en/Guide/Windows for a step by step guide.
2. Connect your Arduino board to your computer using the included USB cable. When you connect
your Arduino board to your computer, it automatically installs the Arduino DRIVERS and the board is
recognized as Arduino UNO board by your computer.
4. Now our Software and Hardware is ready, we prepare the Starter Kit Materials.
Materials Needed:
1x Arduino UNO board
1x Breadboard (half-size)
1x Red LED
1x 330 ohm Resistor
Connecting wires
Construct the circuit with correct connections and part orientation by following the graphical
representation shown in Fig. 1.1. Your actual circuit will look like in Fig. 1.2.
After assembly, copy the Arduino code from Sample Code 1.1 found in the next part and paste it in
the Arduino IDE.
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin 13 as an output.
pinMode(13, OUTPUT);
}
*Choose the correct board where we will upload the Arduino Code. In
the Arduino IDE go to Tools > Board > click Arduino UNO.
The Output
After successfully Uploading the code to the Arduino board, you should see the LED blinking ON and OFF
repeatedly every 1 second (1000ms).
Other things to do
Make the LED blink faster or slower by changing the codes delay() value. Change the delay(1000) to
delay(200) to make the LED blink faster or any value you desire to make the blink faster or slower.
Materials Needed:
1x Arduino UNO board 2x 10k Ohm Resistor
1x Breadboard (half-size) 1x 330 ohm Resistor
2x Push Button Switch Connecting wires
1x Red LED
Construct the circuit with correct connections and part orientation by following the graphical
representation shown in Fig. 2.1. Your actual circuit will look like in Fig. 2.2.
2.1
/*
Buttons and DIGITAL Inputs
*/
void setup() {
pinMode(ledRedPin, OUTPUT); // set Arduino pin 3 as output for LED
pinMode(buttonLeftPin, INPUT); // set Left button as a Digital Input
pinMode(buttonRightPin, INPUT); // set Right button as a Digital Input
}
void loop() {
if (digitalRead(buttonLeftPin) == LOW) // if Left Button is Pressed
{
digitalWrite(ledRedPin, HIGH); // turn ON the LED
}
if (digitalRead(buttonRightPin) == LOW) // if Right Button is Pressed
{
digitalWrite(ledRedPin, LOW); // tun OFF the LED
}
}
The Output
The Red LED should be OFF when the circuit starts after uploading the code. Now Press the Left Button
on the breadboard and you should see the Red LED light up (ON). Now Press the Right Button and the
Red LED will turn OFF.
Other things to do
Add additional LEDs and Buttons to create a Push Button controlled Traffic Light Switch.
Construct the circuit with correct connections and part orientation by following the graphical
representation shown in Fig. 3.1. Your actual circuit will look like in Fig. 3.2.
After assembly, copy the Arduino code fro m Sample Code 3.1 found in the next part and paste it in
the Arduino IDE. Complie and Upload the code to your Arduino board by following the same steps
we did in Project number 1 with STEPS TO UPLOAD CODE to the Arduino board.
/*
RGB LED and Analog Outputs
*/
void setup()
{
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
}
void loop()
{
setColor(255, 0, 0); // red
delay(1000);
setColor(0, 255, 0); // green
delay(1000);
setColor(0, 0, 255); // blue
delay(1000);
setColor(255, 255, 0); // yellow
delay(1000);
setColor(80, 0, 80); // purple
delay(1000);
setColor(255, 255, 255); // white
delay(1000);
}
The Output
The RGB LED will change colors every second following the sequence Red, Green, Blue, Yellow, Purple,
White as defined in the Sample Code.
Materials Needed:
1x Arduino UNO board
1x Breadboard (half-size)
1x 10k Ohm Potentiometer
Connecting wires
4.1
/*
Potentiometer and Analog Inputs
*/
void setup(){
Serial.begin(9600); // set baudrate to use in the Serial Monitor
}
void loop(){
// analogRead translates the potentiometer voltage from GND 0V to VCC 5V
// into 0 to 1023 and assign it to readInput variable
readInput = analogRead(potentiometerPin);
The Output
We will use a built in application included in Arduino IDE, the Serial Monitor. It is used to emulate a
communication channel for sending and receiving datas back and forth from an electronic device
connected to a computer. In this part, we will see the value of the potentiometer reading display in the
Serial Monitor.
After uploading the code Open the Serial Monitor by clicking the button shown below.
Materials Needed:
1x Arduino UNO board 1x Red LED
1x Breadboard (half-size) 1x 330 ohm resistor (orange-orange-brown)
1x LDR (Photocell/Photoresistor) Connecting wires
1x 10k ohm resistor (brown-black-orange)
Copy the Arduino code from Sample Code 5.1 and paste it in the Arduino IDE. Compile and Upload
the code to your Arduino board by following the same steps we did in Project number 1.
// The reading will not reach 0 or 1024, it will be from around 16 (brightest) and 970 (darkest)
// because of the internal resistance of the resistor and LDR.
// Compare light and dark conditions to turn ON and OFF the LED
if (lightValue > 500) {
digitalWrite(ledPin, HIGH);
}
else {
digitalWrite(ledPin, LOW);
}
The Output
Upload the program to your Arduino board and open the Serial Monitor the same step from the previous
project. You will see the values changing (shown in the image below) as you move the circuit with the LDR
on dark and bright light. You will also see the red LED turn ON when it starts to get darker and it will turn
OFF when the environment get brighter lights.
Other things to do
Change the value in the programs if condition to a lower or higher value and you will have an automatic
light detector for bright and dark environment of your own place!
Materials Needed:
1x Arduino UNO board
1x Breadboard (half-size)
1x Buzzer (passive type)
Connecting wires
Copy the Arduino code from Sample Code 6.1 and paste it in the Arduino IDE. Compile and Upload
the code to your Arduino board by following the same steps we did in Project number 1.
void setup() {
//we do not need to put any code initialization here.
}
void loop() {
// A "for" loop function is used to make a count from 0 to 9 using a variable "i".
// This "i" corresponds to the tone sequences listed like
// for i = 0 is for 261 and for i = 9 is for 440.
for (int i = 0; i < listTones; i++)
{
// The "tone" command from the Arduino library need only 2 parameters
// first parameter is the pin for the buzzer (buzzerPin)
// and second the tones we wish to play (tones)
tone(buzzerPin, tones[i]);
delay(500);
}
The program starts to play the tones that we put in the tone[] array. 10 tones will be played
simultaneously with a 1 second delay after the last tone and the program plays back the first tone.
Other things to do
Add some other tone values to play different musical tones. You may also connect the LDR from the
previous project and program the Arduino that equivalent values read by the LDR will be played on the
speaker!
Project #7: Temperature Sensing _
Construct the circuit with correct connections and part orientation by following the graphical
representation shown in Fig. 7.1. Your actual circuit will look like in Fig. 7.2.
Copy the Arduino code from Sample Code 7.1 and paste it in the Arduino IDE. Compile and Upload the
code to your Arduino board by following the same steps.
/*
Project 7 - Temperature Sensing with LM35
*/
//assign variable to use for the program float tempReading; // use a float
variable tempReading for decimal reading
float correctTemperature; // use a float variable correctTemperature for decimal reading int
temperaturesensorPin = 0; // use Arduino Analog pin 0 for temprature reading
void setup(){
The Output
Run the program and open the Serial Monitor. You should see the values of the temperature in degrees
Celsius print out in the Serial monitor. From the code above, the value will be printed every 1 second.
Other things to do
Put your circuit board near a fan or air condition unit and you should see that the value will slowly go
down since the temperature sensor detects a colder environment. You should see in the serial monitor
some data the same as in the image below.
Example output values from the temperature sensor IC, you will see a decrease in value when you point
the temperature sensor near a fan or air condition unit or any cold places.
Materials Needed:
1x Arduino UNO board
1x Breadboard (half-size)
1x 330 ohm resistor (orange-orange-brown)
1x 10k potentiometer
1X LCD module 16x2 character
Connecting wires
Construct the circuit with correct connections and part orientation by following the graphical
representation shown in Fig. 8.1. Your actual circuit will look like in Fig. 8.2.
Copy the Arduino code from Sample Code 8.1 and paste it in the Arduino IDE. Compile and Upload the
code to your Arduino board by following the same steps we did in Project number 1.
Sample Schematic
void setup() {
// To start using the LCD, we first need to set up the LCD's number of columns and rows:
// thus, put (16 columns and 2 rows) using the "lcd.begin(x,y)" command
lcd.begin(16, 2);
// Now, we can 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);
// We test out by printing the number of seconds since the time we start or reset the Arduino
lcd.print(millis() / 1000);
}
The Output
Compile and Upload the program. Start and you will see on the first line a text Hello, World! and on the
second line is an increasing count of number in seconds from which you starter or reset the Arduino board.
Other things to do
Try changing the text on the LCD with your decide text. Make the text move from left to right and display
the temperature and light values of the LM35 temperature sensor and the LDR.
Materials Needed:
1x Arduino UNO board
1x Breadboard (half-size)
1x Servo Motor
Construct the circuit with correct connections and part orientation by following the graphical
representation shown in Fig. 9.1. Your actual circuit will look like in Fig. 9.2.
Copy the Arduino code from Sample Code 9.1 and paste it in the Arduino IDE. Compile and Upload
the code to your Arduino board by following the same steps we did in Project number 1.
// include the "Servo.h" Arduino library for the servo motor commands
#include <Servo.h>
// we create our own name ( or called "object" in programming) to use for calling servo commands
Servo myservo;
//assign a variable for storing the value of the servo position from 0 to 180 degrees
int pos = 0;
void setup()
{
// use this command and put the Arduino pin number where we connect our servo motor input
// in this case we connect the servo motor on pin 9
// connection: orange wire to pin 9, red wire to 5V+, brown wire to GND
myservo.attach(9);
}
void loop()
{
// use a "for" loop function to count from 0 to 180 degrees
// the servo turns with a 1 degree per step
for (pos = 0; pos <= 180; pos += 1)
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
// use another "for" loop to reverse the spin of the servo from 180 to 0 degrees
for (pos = 180; pos >= 0; pos -= 1)
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
The Output
Run the program and you should see that the servo motor turns from 0 to 180 degrees and then turns
back to 180 to 0 degrees.
Materials Needed:
1x Arduino UNO board 1x Transistor NPN (BC547)
1x Breadboard (half-size) 1x 330 ohm resistor (orange-orange-brown)
1x DC Motor Connecting wires
1x Diode
Construct the circuit with correct connections and part orientation by following the graphical
representation shown in Fig. 10.1. Your actual circuit will look like in Fig. 10.2.
Copy the Arduino code from Sample Code 10.1 and paste it in the Arduino IDE. Compile and Upload
the code to your Arduino board by following the same steps we did in Project number 1.
void loop()
{
// We use "if" statement to check if a value (speed from 0 to 255) is entered in the serial monitor.
// If there is, we use parseInt() function to get all the numbers.
// Then, use analogWrite() function to use that value to drive the DC motor speed.
if (Serial.available())
{
int motorSpeed = Serial.parseInt();
if (motorSpeed >= 0 && motorSpeed <= 255)
{
analogWrite(motorPin, motorSpeed);
}
}
}
The Output
Run the program and open the Serial Monitor. Type a value to set a speed for the dc motor.
Theoretically we can use from 0, but some motors we use have higher specification, so typically we can
start to use a value from 150 to 255 (maximum). Type in value from 150 to 255 then hit Enter or Send
button. You will see that the DC motor turns faster when the value is at 255 and get slower turn if set to
255 below.
Copy and upload the code below. This program will make the DC motor start and stop from turning for
every 2 seconds. Try to play with the Run and Stop values to make the motor spin longer or shorter.
void setup()
{
pinMode(motorPin, OUTPUT); // set the motorPin to output
}
void loop()
{
// Call the function "motorRunandStop()" to run repeatedly in
motorRunandStop();
}
// We create an outside function to make the DC motor Run and Stop for 2 seconds
void motorRunandStop()
{
int Run = 2000; // milliseconds to turn the motor on
int Stop = 2000; // milliseconds to turn the motor off
Going further Check out the other Example Codes, Projects, Circuits and Guides from the following links.
https://www.arduino.cc/en/Tutorial/HomePage
https://www.arduino.cc/en/Reference/HomePage
https://www.arduino.cc/en/Guide/HomePage