You are on page 1of 14

ARDUINO

POLYTECHNIC UNIVERSITY OF THE PHILIPPINES


ELECTRONICS ENGINEERING DEPARTMENT

MYRNA ANOT-CABRERA
TERMS USED IN ARDUINO
• Arduino - is an open-source electronics platform based on easy-to-
use hardware and software. It's intended for anyone making
interactive projects.

• Open source software (OSS) - is computer software with


its source code made available with a license in which the copyright
holder provides the rights to study, change and distribute the
software to anyone and for any purpose.

• Sketch – is what we call the arduino program

• Shields- are boards that can be plugged on top of the Arduino PCB
extending its capabilities.
Some Samples of Shields:
 Wifi shield – for wireless comm
 Motor shield – for dc motor control
 rMP3 shield – play sounds/music and read/write data from SD cards.
PARTS OF ARDUINO
Starting clockwise from the top center:
Analog Reference pin (orange)
Digital Ground (light green)
Digital Pins 2-13 (green)
Digital Pins 0-1/Serial In/Out - TX/RX
(dark green) - These pins cannot be used
for digital i/o (digitalRead and digitalWrite)
if you are also using serial communication
(e.g. Serial.begin).
Reset Button - S1 (dark blue)
In-circuit Serial Programmer (blue-green)
Analog In Pins 0-5 (light blue)
Power and Ground Pins (power: orange,
grounds: light orange)
External Power Supply In (9-12VDC) - X1
(pink)
Toggles External Power and USB Power
(place jumper on two pins closest to
desired supply) - SV1 (purple)
In-system programming (ISP), also called In-Circuit Serial USB (used for uploading sketches to the
Programming (ICSP), is the ability of some programmable logic
devices, microcontrollers, and other embedded devices to be
board and for serial communication
programmed while installed in a complete system, rather than between the board and the computer; can
requiring the chip to be programmed prior to installing it into the be used to power the board) (yellow)
system
Arduino AT mega 328 specifications

• Digital I/O Pins14 (of which 6 provide PWM


output)
• Analog Input Pins6 (DIP) or 8 (SMD)
• DC Current per I/O Pin40 mA
• Flash Memory 32 kilobytes
• RAM2 KB
• EEPROM1KB
Sample of Arduino Program
• /*
Blink
Turns on an LED on for one second, then off for one
second, repeatedly.
This example code is in the public domain.
*/
// Pin 13 has an LED connected on most Arduino
boards.
// give it a name:
int led = 13;
// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(led, OUTPUT);
}
// the loop routine runs over and over again forever:
void loop() {
digitalWrite(led, HIGH); // turn the LED on (HIGH
is the voltage level)
delay(1000); // wait for a second
digitalWrite(led, LOW); // turn the LED off by
making the voltage LOW
delay(1000); // wait for a second
}

How to do it
• Create the sketch in the computer
• Connect all the needed components or shields
( if there is any )to your arduino .
• Connect the usb cable to your arduino and
computer. ( *** always disconnect this cable
or external supply if there will be changes in
the connection)
• Upload the sketch to your arduino.
• Simulate .
Common Functions in Arduino
1. Basics
 BareMinimum: The bare minimum of code needed to
start an Arduino sketch.
 Blink: Turn an LED on and off.
 DigitalReadSerial: Read a switch, print the state out
to the Arduino Serial Monitor.
 AnalogReadSerial: Read a potentiometer, print its
state out to the Arduino Serial Monitor.
 Fade: Demonstrates the use of analog output to fade
an LED.
 ReadAnalogVoltage : Reads an analog input and
prints the voltage to the serial monitor
2. Digital
• Blink Without Delay: blinking an LED without using the delay()
function.
• Button: use a pushbutton to control an LED.
• Debounce: read a pushbutton, filtering noise.
• Button State Change: counting the number of button pushes.
• Input Pullup Serial: Demonstrates the use of INPUT_PULLUP with
pinMode().
• Tone: play a melody with a Piezo speaker.
• Pitch follower: play a pitch on a piezo speaker depending on an
analog input.
• Simple Keyboard: a three-key musical keyboard using force sensors
and a piezo speaker.
• Tone4: play tones on multiple speakers sequentially using the tone()
command.
3. Analog
• AnalogInOutSerial: Read an analog input pin, map the
result, and then use that data to dim or brighten an
LED.
• Analog Input: Use a potentiometer to control the
blinking of an LED.
• AnalogWriteMega: Fade 12 LEDs on and off, one by
one, using an Arduino Mega board.
• Calibration: Define a maximum and minimum for
expected analog sensor values.
• Fading: Use an analog output (PWM pin) to fade an
LED.
• Smoothing: Smooth multiple readings of an analog
input.
RUN AWAY ROBOT

Is your robot bumping into walls? This quickly solves that problem.
By attaching a ultrasonic rangefinder, the robot can find out if
it's too close to obstacles, and turn around to avoid collision.
Hardware Required
• Arduino Robot
• ultrasonic rangefinder
• cable to plug the Ultrasonic sensor
Instruction
• Connect the Ultrasonic ranger to TK1
• Fix the sensor to the front of the robot
• Upload the example, unplug USB and turn on power
• Put the robot on the floor
• The robot will move around, avoiding obstacles in front
of it
• If you want to change the detection range, in the code
below, find the line @@while (getDistance()<20)**, 20
here means 20cm; change it to another value to try out
other sensitivities.
• You can also change the robot speed, look at
motorWrite() for a hint on how to do that.
int sensorPin = M1; // pin is used by the sensor
}
void setup() {
// initialize the Robot, SD card, and display // return the distance in cm
Serial.begin(9600); float getDistance() {
Robot.begin(); // read the value from the sensor
Robot.beginTFT(); int sensorValue = Robot.analogRead(sensorPin
Robot.beginSD(); );
Robot.displayLogos(); //Convert the sensor input to cm.
float distance_cm = sensorValue*1.27;
// draw a face on the LCD screen return distance_cm;
setFace(true); }
}
// make a happy or sad face
void loop() { void setFace(boolean onOff) {
// If the robot is blocked, turn until free if(onOff) {
while(getDistance() < 40) { // If an obstacle is // if true show a happy face
less than 20cm away Robot.background(0, 0, 255);
setFace(false); //shows an unhappy face Robot.setCursor(44, 60);
Robot.motorsStop(); // stop the motors Robot.stroke(0, 255, 0);
delay(1000); // wait for a moment Robot.setTextSize(4);
Robot.turn(90); // turn to the right and try Robot.print(":)");
again }else{
setFace(true); // happy face // if false show an upset face
} Robot.background(255, 0, 0);
// if there are no objects in the way, keep Robot.setCursor(44, 60);
moving Robot.stroke(0, 255, 0);
Robot.motorsWrite(255, 255); Robot.setTextSize(4);
delay(100); Robot.print("X(");
} }
}
Assignment
Bring the following materials:
 1 - Breadboard
 4 - Red, green , yellow leds
 Connecting wires
 1 – 9 volts battery
 Push button switch
 2 – 10 kiloohms ½ watt resistor
 16 –1000 ohms ½ w resistor
 1 – arduino
 1 - serial USB Cable
 1 – laptop with Arduino software

You might also like