Você está na página 1de 15

O que um what is an arduino?

arduino?

uma plataforma de cdigo its an opensource e hardware livre para electronics prototyping prototipao. platform. O que isto significa? what does that mean?

open source

resources can be used, redistributed or rewritten free of charge. "RECURSOS DEthat HARDWARE E SOFTWARE QUE PODEM SER USADOS, ADAPTADOS E often software or hardware. DISTRIBUDOS SEM CUSTO"

electronics Prototype Platform

"TECNOLOGIA QUE FAZ USO DO FLUXO DE ELTRONS EM DIVERSOS TIPOS DE technology which makes use of the controlled motion of electrons MATERIAIS PARA OS MAIS DIVERSOS FINS" through different media.

"UMA MONTAGEM NO DEFINITIVA DE UM COMPROVAR O other FUNCIONAMENTO" an original Form that can serve asPROJETO a basis PARA or standard for things.

"UM CONJUNTO DE HARDWARE E SOFTWARE QUE POSSIBILITA REALIZAR PROJETOS hardware architecture with software framework on which other software DE ELETRNICA" Can run.

photocell microchip

led

breadboard
O Arduino um microprocessador montado com alguns acessrios para poder funcionar como um minsculo computador que pode ser An Arduino is a microchip, which is a very small computer that you can program to respond to programado. Ele pode responder aos estmulos (eletricidade) vindos de sensores (fotoclula) e usar estes dados para medir things. It acan measure conditions (like how much there is o in the room). It can control condies como luz em um ambiente e, assim, controlar um interruptor para light acender a luz quando ambiente fica escuro. how other objects react to those conditions (room gets dark and an led turns on).

ON

OFF

a mouse is a common O mouse um sensor ligado input device ao seu computador, com ele for a desktop computer, voc interage com seu a monitor is a common microprocessador. output device.

Or it can to um something O arduino poderespond reagir ao se ligar interruptor! as simple as the press of a switch.

Microcontrollers use inputs and outputs Like any Microprocessadores usam inputs e outputs como qualquer computer. Inputs capture information From the user computador. Inputs capturam informao do usurio ou do ambiente or the environment while Outputs do something with enquanto os outputs fazem alguma coisa com a informao capturada. the information that has been captured.

momentary switch

force sensitive resisitor

DC Motor
Qualquer objeto que queira ligar desligar pode ser um output any object wese want to e turn on and off and do arduino, eles podembe ser An simples motores It ou at um control could output. could be a computador. motor or even a computer.

Um ou um sensor sofisticado podem ser os inputs do arduino A boto switch or A sensor could be An input into the Arduino.

the Qual whats a diferena entre difference between inputs e outputs analgicos e digitais? and analog digital inputs and outputs?

Digital information Informao digital pode ter is estados. discrete and dois finite . all 0 ou 1. Ligado ou desligado, information is Quando a luz est ligada 1, quando est desligada described in two zero. states, 1 or 0, on or off.

Analog information is characterized Informao analgica mais by its continuous como um fluxo contnuo e pode ter it infinitos valores. nature. can have an infinite number of possible values.

Inputs e outputs ser analgicos ou digitais. inputs and podem outputs can be digital or analog. Informao digital tem o formato binrio e pode ser tanto verdadeira Digital information is binary it is either true como falsa, zero ou 1. Informao analgica por exemplo, or false. Analog information is continuous, it a variao de uma corrente eletrica. can hold a range of values.

a boto switch is adigital, digital input, sensor is an O um input s pode ter doisa valores. Um sensor um input analgico que pode em muitos sensor analog input. the range ofvariar an analog valores diferentes. is limited by its conversion to digital data.

VOLTAGEM? voltage? CORRENTE? current? RESISTNCIA? resistance? LEI DE OHM? Ohms law?

VOLTAGEM (V) A MEDIDA DO is a measure POTENCIAL of electrical ELTRICO


potential.

Voltage (V)

CORRENTE Current(I)(I) O QUANTIDADE of flow DO FLUXO EM UM through a MATERIAL conductive CONDUTIVO


material. It is measured SUA UNIDADE O AMPRE OU in amperes AMP or Amps. is the amount

RESISTNCIA (R) Resistance (R)


isAa material's CAPACIDADE opposition to QUE UM MATERIAL TEM DE RESISTIR the flow of A CORRENTE electric ELTRICA

It isUNIDADE measured SUA O

volts. in (V) VOLT

SUA UNIDADE O OHM


It is measured in ohms.

current.

Antes de ligar Arduinoin the Arduino, Before we oplug vamos revisar alguns termos we will review a few terms e princpios que tem athat ver comhave to and principles a forma como a eletricidade ( e eletrnica) do with how electricity (and funcionam. therefore electronics) works.

ELETRICIDADE O FLUXO ENERGIA POR UM MATERIAL CONDUTIVO. Electricity is theflow ofDE energy through a conductive material.

the speed of flow A VELOCIDADE DO FLUXO is determinedPELA by voltage DETERMINADA VOLTAGEM

A RESISTNCIA AUMENTA resistance increases or flow OU decreases DIMINUI O FLUXO

amount of flow moving through A QUANTIDADE DO FLUXO CORRENDO pipes is current PELO TUBO A CORRENTE
Athe ANALOGIA COM A GUA CORRENDO POR UM TUBO to UMA DAS FORMAS UTILIZADAS ILUSTRAR ESTE PROCESSO water analogy is commonly used explain these terms. PARA Heres one model.

OHMs law LEI DE OHM


corrente = voltagem/resistncia current = voltage/resistance (i = v/r) (i = v/r) ou or Resistncia = voltagem/corrente Resistance = voltage/current (r = v/i) (r = v/i) ou or Voltagem = Resistncia * corrente Voltage = Resistance * current (v = r*i) (v = r*i)

EXISTE UMA ENTRE VOLTAGEM, There is RELAO a relationship between CORRENTE voltage, E RESISTNCIA. ESTA RELAO FOIdiscovered DESCOBERTAby PELO current and resistance, Georg Ohm, ALEMO a German physicist. FSICO GEORG OHM.

POR for EXEMPLO, example,AO Increase AUMENTAR A RESISTNCIA the resistance, less O FLUXO DIMINUI... flow.

AO AUMENTAR POTENCIAL or increase O the potential, more flow. O FLUXO AUMENTA

Lamp

Switch DC power source

VAMOS OBSERVAR UM a CIRCUITO now lets look at simple SIMPLES. circuit. every Todo o circuito um cculo fechado que tem uma fonte de circuit is a closed loop that has an energy energia (bateria) e uma carga source (battery) and (lmpada). a load (lamp). The load A carga converte a elecrical energia eletrica e a utiliza (gera luzbattery converts the energy of the e calor). Esteit circuito tem um interruptor. and uses up. tambm this one has a switch too.

ESTE O ESQUEMA ELETRNICO DO MESMO CIRCUITO. Thisis a schematic of the same circuit (it uma representao que utiliza smbolos cada um for dos the represents the circuit usingpara symbols componentes eletrnicos. Quando o interruptor fechado a corrente electronic components). When the switch is flui da fonte (bateria) at a carga (lmpada). closed, current flows from the power source and lights the lamp.

I
Direct Current (DC)

Now that reviewed some Agora que jweve revisamos os conceitos basics of how electricity bsicos de eletricidade, vamos works, Lets get back t0 voltar ao Arduino..... the arduino.

Alternating Current (AC)

Existem dois tipos comuns de circutos eltricos. There are two Common types of circuits, Corrente Contnua (CC) e Corrente Alternada (CA). A corrente . Direct Current and Alternating Current contnua a circuit, eletricidadethe que vem de uma bateria, gerada In a Dc current always flows in quimicamente. A corrente a eletricidade que vem one direction. In alternada AC, thecurrent flows in da tomada em directions sua casa, gerada mecanicamente. opposite in regular cycles. We will Vamos a corrente contnua em nossos exemplos. onlyusar talk about Dc circuits here.

The arduino will need power to PARA run. FUNCIONAR, we will O ARDUINO PRECISA DE ELETRICIDADE need to attach itAO to a computer to program it. VAMOS CONECT-LO COMPUTADOR.

download CARREGUE NO SITE DOhere: ARDUINO:


http://arduino.cc/en/Main/Software

CONECTAR O the ARDUINO AO COMPUTADOR PELA PORTA Attaching arduino to a computer with USB VAI NOS DAR OS 5 VOLTS NECESSRIOS PARA SEU a usb cable will supply The 5 volts of power FUNCIONAMENTO E PARA PROGRAM-LO. we need and allow us to start programming.

VOC PRECISA CARREGAR E INSTALAR O SOFTWARE youll have to download and install software PARA PODER PROGRAMAR O ARDUINO. O softwarefrom livre e to program the arduino. it is available existem verses para windows, mac e linux. O software chamado the URL above Free of charge. the ARduino de IDE (Integrated Development Environment), um software runs on the Mac os X, Windows and linux Platforms. ambiente integrado para desenvolvimento.

for instructions on how to install arduino software on a mac: PARA INSTRUES SOBRE A INSTALAO EM http://www.arduino.cc/en/Guide/MacOSX PORTUGUS VISITE: For Instructions on how to install http://www.labdegaragem.com.br/wiki/index.php?title=Sobre_Arduino on Windows: PARA INSTRUES DE INSTALAO EM INGLS VISITE:

http://www.arduino.cc/en/Guide/Windows

Mac: http://www.arduino.cc/en/Guide/MacOSX For Instructions on how to install Windows: http://www.arduino.cc/en/Guide/Windows on Linux: Linux: http://www.arduino.cc/playground/Learning/Linux

http://www.arduino.cc/playground/Learning/Linux
SE DIFICULDADES NA INSTALAO FREQUENTE AS NOITES DO ARDUINO goTIVER to the URLS above for detailed instructions on NO GAROA HACKER AS LISTAS DISCUSSO OU O LAB DE GARAGEM. installing the CLUBE, software on DE these platforms.

When you have installed the software, DEPOIS DE INSTALAR O SOFTWARE E CONECTAR O ARDUINO AO COMPUTADOR LED DEmarked "POWER" ON DEVE Connect the arduino. O An led ACENDER. should light up on the board.

INICIE O SOFTWARE. Launch the arduino software. in the tools menu, NO MENU "TOOLS" SELECIONE A PLACA QUE VOC EST USANDO select the board you are using (tools > board). (TOOLS>BOARD) COMO POR EXEMPLO, ARDUINO UNO for example, Arduino Uno. OU DUEMILENOVE.

Next select the SELECIONAR serial port. DEPOIS NECESSRIO A PORTA SERIAL. (Tools > serial port On a ser mac it como will be Use o menu (Tools> Serial port) no ) windows algo COM3 ou outra. No maclike e linux algo parecido com "/dev/tty.usbmodem". something /dev/tty.usbmodem . On a Se no houver nada neste it menu... revise conexo instalao windows machine, will be sua com3 oresomething de drivers. like that.

whats an O que um ambiente Integrated integrado de Development desenvolvimento? environment?

Ao carregar e instalar o software do Arduino, When you downloaded the voc instalou uma IDE. Um editor de Arduino software, you textos especial aonde realizada a programao downloaded an seus IDE. it combines e que ajuda a carregar programas a text editor with a para dentro do chip instalado emcompiler seu Arduino. and other features to help A IDE tem um software chamado programmers software. "COMPILADOR" quedevelop faz este trabalho.

A IDE do Arduino permite que voc crie os to programas chamados de "SKETCH" The Arduino IDE allows you write Sketches , or programs e que eles sejam carregados no Arduino. Abra o exemplo Blink no menu: File > Examples > and upload them to the Arduino board. open the blink example 1.Basics > Blink. in the file menu. File > Examples > 1.Basics > Blink.

int ledPin = 13; void setup() { pinMode(ledPin, OUTPUT); } void loop() { Upload button

Depois de qabrir the o exemplo blink, clique no boto UPLOADboard, ToSerial.println(analogRead(A0); upload sketch to the arduino para este programabutton ou "SKETCH" no the Arduino. click the upload on strip of } carregar Algumas mensagens vo aparecer partewindow. inferior da tela e caso buttons at the top ofna the some tudo tenha corrido bem appear voce vai ver a the bottom of the messages will in mensagem "Done Uploading". window, finally Done Uploading.

O LED VAI COMEAR A PISCAR !! the led NO at SEU pin ARDUINO 13 on the arduino starts blinking.

void setup() { // initialize the digital pin as an output. // Pin 13 has LED connected on most Arduino boards: pinMode(13, OUTPUT); } void loop() { digitalWrite(13, HIGH); delay(1000); digitalWrite(13, LOW); delay(1000); } // // // // set the LED on wait for a second set the LED off wait for a second

SETUP: ACONTECE VEZ QUANDO setup: happensUMA one time when O PROGRAMA COMEA A SER EXECUTADO program starts to run

Loop: repeats over and LOOP: REPETE INFINITAMENTE over again O ARDUINO) (AT DESLIGAR OU REINICIAR

Um como um a programa escrito em qualquer a sketch, sketch, like program writen in any linguagem de programao, um conjunto de language, is a Set of instructions for the instrues. computer. If we look closely at the Blink we detalhe see there are 2 major parts, Sesketch, olharmos em no sketch blink veremos que setup and loop . ele tem duas partes principais: SETUP e LOOP
http://arduino.cc/en/Reference/HomePage

EstesAre dois both blocos blocks de cdigoof socode chamados de These called funes e aparecem em todos os sketches. functions that every sketch will have. They Note que as instrues so separadas por are blocked out by curly Braces {{ }.}
//DeClares block of code void setup() { pinMode(13, OUTPUT); //sets pin 13 to output } //End block of code

Visite o site do Arduino na seo "reference" check out the arduino website para for the aprender mais sobre a linguagem deand programao. arduino reference guide many other Use os exemplos quelearn vem na IDE. resources to the language.

//declares block of code void loop() { digitalWrite(13, HIGH); //sets pin 13 high delay(1000); //pause 1 second digitalWrite(13, LOW); //sets pin 13 low delay(1000); //pause 1 second } //End block of code

Por enquanto vamos ver este exemplo e entender o que For now, lets look at this simple script line cada linha faz. by line & see what each line does.

holes FUROSconnected CONECTADOS


HORIZONTALMENTE horizontally

holes connected FUROS CONECTADOS


VERTICALMENTE vertically

Como controlamos objetos que no esto conectados How do we control objects that are no Arduino? Vamos ligar o Arduino em uma placa de not on the arduino board? we will connect prottipos chamada Proto-board ou Breadboard. the arduino to solderless .e This Isto a vai nos ajudar a ligar breadboard tudo rapidamente testarwill allow us to quickly set up and test circuits. nossos circuitos.

Esta proto-board tem 2 linhas furos que This breadboard has de 2 rows of holes running vo por toda a exteno vertical na esquerda e diversas down the left and right direira side,eand 5 rows of linhas de 5 furos em toda a superfcie holes on either side of a middle indentation. na horizontal. As duas linhas verticais so conectadas eletricamente the side rows are connected vertically , na vertical e as linhas horizontais each Row of 5 holes in the middle are so conectadas eletricamente na horizontal. connected horizontally .
ANODO anode CONECTA NA (connects FORA(POWER)

to power)

O LED TEM UMA "PERNA" MAIOR E OUTRA MENOR!

CATODO cathode CONECTA NO TERRA (connects (GROUND)

to ground)

Ns conectar a fora (power) e o terra (ground) de we vamos will connect power and ground from the nossa placa board arduino aos da proto-board. arduino to furos the verticais vertically connected Desta forma todos osleft componentes que ligarmos strips on the and right with 22 gauge nos furos horizontais podero ser alimentados pela wire. other components can be attached to the Arduino. holes in the middle and to power and placa ground as needed.

When a current flows through a led de (Light Quando corrente flui por um LED ( Diodo Emissor Luz) na direo correta Diode) ele se acende. Nsright vamos conectar um led na emitting in the direction, it proto-board e nowell Arduinoattach para que possamos lights up. an LEd to the breadboard, then to the arduino so we can controlar o LED com nossa programao. control it with code.

void setup() { pinMode(2, OUTPUT); } void loop() { digitalWrite(2, HIGH); delay(500); digitalWrite(2, LOW); delay(500); }
Na SETUP vamos o pino in funo setup , we setdefinir pin 2 to 2be an como sendo um output. Na funo LOOP output. in loop, first we set pin 2 vamos definir o pino 2 como "high" ou ligado high which lights the led. Delay para acender o LED. Logo abaixo vamos definir pauses 500 milliseconds, or half a que o estado ligado dure 500 milissegundos (meio segundo) second. when pin ou 2 desligado. is set Pausamos low, the e ento mude para "low" mais led segundo goes e off, we pause another half meio repetimos. second.

O anodo vai conectado ao pino 2 do Arduino com2 um resistor de 220 Ohm. through the anode is connected to pin on the arduino O catodo vai conectado ao terra. pinos de 2 a 13 podem ser configurados como a 220 ohm resistor . Os The cathode is connected to inputs ou outputs digitais. ground . pins 2 through 13 can be configured as digital Clique no boto "new" para comear seu prprio sketch. inputs or outputs. click New button to start a sketch.

verify button

upload button

Clique no boto "verify" para verificar seu cdigo no tem erros. click verify on the menu se to check your code. if Se tudo estiver certo, clique no boto "upload" carregar seu there arent any errors, click para upload to put programa para a placa Arduino. your program on the arduino.

O LED led vai piscar... aceso durante segundo e apagado durante the blinks on for meio half a second, then meio segundo e apagado durante meio segundo... at and voc desligar blinks off for half a second, over over ou mudar a programao. again.

Agora ns vamos usar um boto, um input a digital, para Next we will add a switch, digital controlar led. we can turn the LED off input,o so and on.

Conecte um terminal do boto ao momentary pino 4 do arduino com Connect one end of a switch to pin 4 on the um resistor de 10 k conectado ao terra e ligado ao mesmo terminal. Arduino, with a 10k resistor connected to ground Conecte agora o outro terminal naend. fora. O led fica no mesmo pino end to attached to the same Attach the other do arduino. power. We will leave the LED attached to the same pin.

void setup() { pinMode(2, OUTPUT); pinMode(4, INPUT); } void loop() { if(digitalRead(4)){ digitalWrite(2, HIGH); }else{ digitalWrite(2, LOW); } }
Next well write code. In setup, we declare Vamos escrever o cdigo.the No setup declaramos o pin an output and pin 4 an No input. in loop, we pino 2 2 como output e o pino 4 como input. loop vamos use an statement, if we pin 4 nos asligamos high, owe usar um IFif (SE), se a leitura do pino 4 forread High (ligado), pino do led, em qualquer outro caso ns mantemos o we pino set do led the set the led pin to high, otherwise LOW pin (desligado). led to low, turning it off.

The LED lights the switch is held down. O LED ACENDEwhen QUANDO APERTAMOS O BOTO

a potentiometer, or pot, is a Um potnciometro um resistor varivel. variable resistor. the amount A resistncia muda quando giramos o of resistance changes as it boto, aumentando ou diminuindo de is turned, increasing or acordo com a direo. decreasing depending on which direction it is turned.

Agora vamos utilizar um input analgico, uminput. Now we will set up an analog potencimetro. Well use a potentiometer.

Conecte o terminal do centro do potencimentro na porta analgica 0 to do arduino (A0). pin Attach the middle pin on the potentiometer Analog Conecte um dos outros ao terra pot e o outros fora. A0. attach one terminais end of the to a power, the other to ground.

void setup() { Serial.begin(9600); } void loop() { Serial.println(analogRead(A0)); }

Serial Monitor

click to open serial window

First will look at the Primeirowe vamos verificar os valores que range obtemos of values we get by turning the pot using the Serial girando o potencimetro por meio do terminal serial. monitor . in our code, we serial initialize the serial No cdigo vamos inicializar a leitura e determinar uma object setup, setting a ler baud rate 9600. velocidade in de 9600 bps. No loop, vamos o valor obtidoof do pino A0 In loop,este Wevalor read the value from a analog pin a0 e escrever no terminal serial utilizando funo printLn. and print it to the serial object using the printLn function,

after you have uploaded the script the Depois de carregar o script para a placa arduino, clique to no boto arduino, click thea Serial Monitor button in "Serial Monitor" para abrir nova janela e ver os valores. Os valores exibidos gama entre e 1024 enquanto order to see tero the uma values as 0 you turn the pot. giramos o potencimetro A window will open, and you will see values ranging from 0 to 1024 as the pot is turned.

5V 0V

0% Duty Cycle - analogWrite(0)

50% Duty Cycle - analogWrite(127) 5V 0V 100% Duty Cycle - analogWrite(255) 5V 0V

Agora vamos usar os valores variveis do potencimetro para Lets use the changing values we receive from the pot aumentar e diminuir a luminosidade led (dimmer). as a dimmer to light ando LED. put the led back into the Coloque led conectado ao pino do arduino. at pin 3. board,um attached to the3 Arduino

Para isso vamos usar um mtodo modulation chamado de Well use pulse width PWM ( pulse width ou Modulao por (PWM). This is modulation) a method of simulating largura de pulso (MlP). an analog value by manipulating the Este mtodo simula um valor a voltage, turning it analgico on andutilizando off at variao de voltagem em ciclos regulares. different rates, or duty cycles. you As portas 3, 5, 6, 9, 10, e 11 do arduino can use pwm with pins 3, 5, 6, 9, 10, podem ser usadas com PWM. and 11.

int sensorValue = 0; void setup() { pinMode(3,OUTPUT); } void loop() { sensorValue = analogRead(A0); analogWrite(3, sensorValue/4); }
First create variable to store the value Primeiro we vamos criar umaa varivel para estocar of the pot. In setup we make pin 3 an output. o valor do potencimetro. No setup declaramos o pino 3 como output. In loop, we store the we have read No loop, estocamos o valor lido do value potencimetro (A0) em nossa from pin a0 Ento, in our variable. Then we write the value varivel. escrevemos este valor para o pino 3 (pino do led). to pin 3, our led obtido pin. por we4 have tovalores divide the Temos que dividir o valor para obter de 0 a 255 variable ou um byte. by 4, so we will have a range of values from 0 to 255, or a byte.

The brightness of the LED changes, ranging Mudamos a intesidade da luz variando a posio do pontecimetro. from completely off to very bright as you turn the pot.

Thats it! This is a very brief intro. in the next Panels, there are links and other resources. check them all out, youll find more!

Links
Software
Software Download http://www.arduino.cc/en/Main/Software Language Reference http://arduino.cc/en/Reference/HomePage

Supplies
Sparkfun Electronics http://www.sparkfun.com/ Adafruit Industries http://adafruit.com/ Maker Shed http://www.makershed.com/ Jameco Electronics http://www.jameco.com/

Tutorials
Arduino site Tutorials http://www.arduino.cc/en/Tutorial/HomePage Lady Ada http://www.ladyada.net/learn/arduino/ Instructables http://www.instructables.com/tag/typeid/ categorytechnology/channelarduino/

all text and drawings by Jody Culkin for more, check out jodyculkin.com
Special Thanks to Tom Igoe, Marianne petit, Calvin Reid, The faculty and staff of the interactive telecommunications program at nyu, particularly Dan osullivan, Danny rozin and Red burns. thanks to Cindy karasek, chris Stein, sarah teitler, kathy goncharov & zannah marsh. many, many thanks to the Arduino team for bringing us this robust and flexible open source platform. and thanks to the lively, active and ever growing arduino community.
Introduction to Arduino by Jody Culkin is licensed under a Creative Commons AttributionNonCommercialShareAlike 3.0 Unported License.

books
Getting Started with Arduino by Massimo Banzi Making Things Talk: Using Sensors, Networks, and Arduino to see, hear, and feel your world by Tom Igoe Physical Computing: Sensing and Controlling the Physical World with Computers by Dan O'Sullivan & Tom Igoe Arduino Cookbook by Michael Margolis

TRADUZIDO PARCIALMENTE PARA O PORTUGUS BRASILEIRO POR CLUDIO MIKLS COM AUTORIZAO DO AUTOR PARA O WORKSHOP "ARDUINO 100 NOO" REALIZADO NO GAROA HACKER CLUBE - WWW.GAROA.NET.BR

Você também pode gostar