SlideShare uma empresa Scribd logo
1 de 43
Introduction to
Arduino
Wilson Wingston Sharon
cto@workshopindia.com
Physical computing
Developing solutions that implement a software to interact with
elements in the physical universe.

1. Sensors convert signals from the physical world to
   information to the computing device.

2. Processing this data via the computational device

3. Performing physical actions using actuators
Microcontrollers
• Microcontrollers are small computers integrated into a single chip.

• They contain
   1.   Processor core
   2.   Flash Memory for program
   3.   I/O peripherals
   4.   RAM
   5.   Peripherals such as clocks, timers, PWM etc


• Microprocessors are used for general purpose applications while
  microcontrollers are self sufficient and are used for specific tasks.

• MCU are an example of embedded systems.
Microcontroller architectures
• ATMEL – 32 bit RISC AVR architecture

• IBM PowerPC family – sold to AMCC

• Analogue Device – ARM architecture and Blackfin (DSP)

• Microchip – PIC architecture
Microcontroller components
Parts of an MCU
• CPU: central processing unit that may contain a 8-bit, 16-bit or
  32-bit processor.
• RAM: for volatile data storage.
• ROM, EPROM, EEPROM or Flash memory for program and
  operating parameter storage
• discrete input and output PINS
• serial input/output such as serial ports (UARTs)
• peripherals such as timers, event counters, PWM generators,
  and watchdog
• clock generator
• analog-to-digital converters
• digital-to-analog converters
• in-circuit programming and debugging support
Programming Microcontrollers
Programming microcontrollers is usually hard and expensive:

• Obtaining the microcontroller
• Making the programming circuit
• Writing the program into a target language and compiler
• Flashing the program onto the chip
• Removing the chip from programming circuit to application
  circuit
• Testing and debugging

• Proprietary technology is expensive
Enter the Arduino
• The Arduino is an open source development board for the
  AVR series of microcontrollers for physical computing.

• Can input a variety of sensor data.
• Can communicate with programs on computer easily.
• Can control a variety of motors, lights and other devices.

• Advantages
  1.   Cheap
  2.   Open source hardware and software
  3.   Easy learning curve
  4.   Extensible
Freeduino
• Exactly the same as the Arduino.
• Developed as a clone for IP purposes only as open hardware.
Arduino board layout
Microcontroller
Microcontroller           ATmega328p

Operating Voltage         5V

Digital I/O Pins          14 (of which 6 provide PWM output)

Analog Input Pins         6

DC Current per I/O Pin    40 mA

DC Current for 3.3V Pin   50 mA


Flash Memory              16 KB (of which 2 KB used by bootloader)


SRAM                      1 KB

EEPROM                    512 bytes

Clock Speed (via XTAL)    16 MHz
Arduino Pinout diagram
Powering it up
• Has a jumper that can switch between 5V from USB and a 9V
  input jack through a 7805.

• External power can be connected via a 2.1mm standard jack.
  Normal adaptors that fit and are 6V-12V can be used.

• If power supply is <5V, board may become unstable
• If power supply >12V, board may overheat

• GND, VIN, 5V and 3.3V are present for powering peripherals.
The bootloader
• Programming a microcontroller is usually done by specific
  programmer circuits like AVR-MKll, USBtiny
• ISP and JTAG are protocols to burn code onto microcontrollers

• The arduino comes preloaded with code called the bootloader
  ( taking 2K of memory) that looks for programs coming
  through the serial port and moves it into the program memory
  for execution.

• If bootloader is damaged for any reason it can be restored by
  an ICSP programmer.
FTDI serial to USB
• Microcontrollers like the atmega328 have only serial port
  using the USART for external communication.

• The arduino design includes a FTDI chip that acts as a Serial to
  USB link.

• The USB cable connected to the computer shows up as a
  virtual COM port and behaves exactly like a serial port.

• Latest Drivers can be found at the downloads section of the
  FTDI website. (use google)
Atmega328 to Arduino PIN
Important PINS on the board
• All arduino pins operate at 5V, 40mA.
                 DO NOT EXCEED THAT RATING!
• 0(RX) and 1(TX) are the serial port pins. These pins go to the FTDI
  chip also. You can tap the serial data from here if you want. These
  pins are also connected to LED so you can see when there is data
  being transferred.

• 2 & 3 : External Interrupts. These pins can be used as INT0 and INT1
  respectively for calling an externally generated interrupt.

• 3, 5, 6, 9, 10, and 11 : PWM : These pins can generate an 8-bit pulse
  width modulated output.

• LED: 13 an LED provided on the arduino board itself.

• AREF: used for external analogue signal reference for the ADC
The Arduino IDE
• The arduino is an open
  source IDE developed from
  wiring.

• Get the latest IDE (0022)
  from the website

• Extract it and double click
  arduino.exe

• Since the program is written
  in JAVA.. It might have some
  issues on win7 x64 systems.
  (to solve, just wait.. Its hangs
  for a bit occasionally)
The Arduino IDE
• The arduino is programmed in C language.

• The language is very simple and provides many abstraction for
  simplicity of reading and writing powerfull applications.

• The Arduino IDE can be used write the bootloader onto any
  MCU via ICSP making it an “arduino”.

• It provides a serial monitor to see the serial data from the USB
  virtual COM port.

• Allows ofr one click compiling, verification and burning of code
  onto the arduino.
Select the right board
Programming for Arduino
 This is the basic structure of any arduino program.
 Setup is for program setup and variable initialization
 Loop containg code for the working of the program.
//global declaration area for header files and such (none needed by default)

void setup()
{
         statements here get executed once;
}
void loop()
{
         statements here keep getting executed indefinitely;
}
Setup()
  • All code contained in this function is executed once.

  • REQUIRED function for an arduino program to compile




void setup()
{
          pinMode(pin, OUTPUT);         // sets the 'pin' as output
}
loop()
  • All code contained in this function is executed repeatedly.

  • This program is responsible for all the arduino boards
    functionality.

  • REQUIRED function for an arduino program to compile


void loop()
{
          digitalWrite(pin, HIGH);   // turns 'pin' on
          delay(1000);               // pauses for one second
          digitalWrite(pin, LOW);    // turns 'pin' off
          delay(1000);               // pauses for one second
}
Available data types in Arduino IDE
•   void
•   boolean
•   char ( 0 – 255)
•   byte - 8 bit data ( 0 – 255)
•   int - 16-bit data (32,767 - -32,768)
•   long – 32 bit data (2,147,483,647 to -2,147,483,648)
•   float
•   double
•   string - char array
•   String - object
•   array
Arithmetic
   • Arithmetic operators include addition, subtraction, multiplication,
     and division.

   • Remember the point of variable rollover and also what happens
     then: e.g. (0 - 1) OR (0 - - 32768).

   • For math that requires fractions, you can use float variables, if you
     can bear large size and slow computation speeds in your
     microcontroller.

y = y + 3;
x = x - 7;
i = j * 6;
r = r / 5;
Comparison operators
   • Comparisons of one variable or constant against another are
     often used in if statements to test if a specified condition is
     true.


x == y   // x is equal to y
x != y   // x is not equal to y
x<y      // x is less than y
x>y      // x is greater than y
x <= y   // x is less than or equal to y
x >= y   // x is greater than or equal to y
Logical operators
   • Logical operators are usually a way to logically combine two
     expressions and return a TRUE or FALSE depending on the operator.
   • There are three logical operators, AND, OR, and NOT.


Logical AND:
if (x > 0 && x < 5)               // true only if both expressions are true

Logical OR:
if (x > 0 || y > 0)               // true if either expression is true

Logical NOT:
if (!x > 0)                       // true only if expression is false
TRUE/FALSE
  • These are Boolean constants that define logic levels of the arduino.
  • FALSE is easily defined as 0 (zero)
  • TRUE is often defined as 1, but can also be anything else except
    zero. So in a Boolean sense, -1, 2, and -200 are all also defined as
    TRUE.


if (abcd== TRUE);
{
          DoSomethingNice;
}
else
{
          DoSomethingHorrible;
}
HIGH/LOW
  • These constants define pin levels as HIGH or LOW and are
    used when reading or writing to digital pins.
  • HIGH is defined as logic level 1, ON, or 5 volts
  • LOW is logic level 0, OFF, or 0 volts.




digitalWrite(13, HIGH);
INPUT/OUTPUT
  • These constants define pin levels as HIGH or LOW and are
    used when reading or writing to digital pins.
  • HIGH is defined as logic level 1, ON, or 5 volts
  • LOW is logic level 0, OFF, or 0 volts.




pinmode(13, OUTPUT);
Writing custom functions
  • Functions are named blocks of code that can be called
    repeatedly.
  • Use functions to reduce clutter and perform repeated tasks.

  • Functions can return datatypes as required.



int delayVal()
{
          int v;                 // create temporary variable 'v'
          v = analogRead(pot);   // read potentiometer value
          v /= 4;                // converts 0-1023 to 0-255
          return v;              // return final value
}
Arrays
   • An array is a collection of values that are accessed with an
     index number.
   • Arrays are zero indexed, with the first value in the array
     beginning at index number 0.



int myArray[5];    // declares integer array w/ 6 positions
myArray[3] = 10;   // assigns the 4th index the value 10
int x;
x = myArray[3];    // x now equals 10
int ledPin = 10;                                    // LED on pin 10
byte flikr[] = {160, 130, 5, 20, 100, 30, 110, 25};
       // above array of 8
void setup()
 {
         pinMode(ledPin, OUTPUT);                  // sets OUTPUT pin
}
void loop()
{
         for(int i=0; i<7; i++)                    // looping though array
         {
         analogWrite(ledPin, flikr[i]); // write index value
         delay(200);                               // pause 200ms
         }
}
Pinmode(pin,mode)
 • Used in void setup() to decide whether a specified pin must
   behave either as an INPUT or an OUTPUT pin.
 • Arduino digital pins are input by default, but still use
   pinmode() for brevity.
 • Pins configured as INPUT are said to be in a high-impedance
   state so don’t try to load this pin externally.. It’ll fry.

 • Pins configured as OUTPUT are said to be in a low-impedance
   state and can provide 40 mA of current to the load.
 • Can be used to brightly light up an LED sound a buzzer but not
   motors, solenoids etc..
pinMode(pin, INPUT);           // set ‘pin’ to input
digitalWrite(pin, HIGH);       // turn on pullup resistors
digitalRead(pin)
  • Reads the value from a specified digital pin with the result
    either HIGH or LOW.

  • The pin can be specified as either a variable or constant (0-13).




value = digitalRead(Pin);        // sets 'value' equal to the input pin
digitalwrite(pin,value)
• Outputs either logic level HIGH or LOW at (turns on or off) a
  specified digital pin. The pin can be specified as either a
  variable or constant (0-13).
     int led = 13;               // connect LED to pin 13
     int pin = 7;                // connect pushbutton to pin 7
     int value = 0;              // variable to store the read value
     void setup()
     {
                   pinMode(led, OUTPUT);                    // sets pin 13 as output
                   pinMode(pin, INPUT);                     // sets pin 7 as input
     }
     void loop()
     {
                   value = digitalRead(pin);                // sets 'value' equal to I/P pin
                   digitalWrite(led, value);                // sets 'led' to the
     }
analogread(pin)
• Reads the value from a specified analog pin with a 10-bit resolution.
  T
• his function only works on the analog in pins (0-5). The resulting
  integer values range from 0 to 1023.

• Analogue pins do not need to be set by using pinmode

• A0 – A6 are the analoge pins




value = analogRead(A0);            // sets 'value' equal to A0
analogwrite(pin,value)
• Writes a analog value using hardware enabled pulse width
  modulation (PWM) by internal timers to an output pin marked
  as PWM ONLY.


int led = 10;                 // LED with 220 resistor on pin 10
int pin = 0;                  // potentiometer on analog pin 0
int value;                    // value for reading
void setup(){}                // no setup needed
void loop()
{
           value = analogRead(pin);      // sets 'value' equal to 'pin'
           value /= 4;                   // converts 0-1023 to 0-255
           analogWrite(led, value);      // outputs PWM signal to led
}
Serial.begin(rate)
• Opens serial port and sets the baud rate for serial data
  transmission.
• The typical baud rate for communicating with the computer is
  9600.

• If you get garbage values, check if baude rate matches.
• Always in setup()

void setup()
{
Serial.begin(9600); // opens serial port
}
Serial.println(data)
• Prints data to the serial port, followed by an automatic
  carriage return and line feed.
• This command takes the same form as Serial.print(), but is
  easier for reading data on the Serial Monitor.




Serial.println(analogread(A0));   //sends A0 value to serial port
Other available functions
• Pointer access operators * &

• Random() and randomseed() for random number generation

• Sin(), cos() and tan() functions

• Delayms() and delay()

• Various math function, abs(), pow(), sqrt() etc

• Attachinterrupt() and Detachinterrupt() for interrupt programming

• All compund operators, structures and class functionality of C/C++
The arduino Sketch
• A sketch is the name that Arduino uses for a program. It's the
  unit of code that is uploaded to and run on an Arduino board.

• Sketches are stored in .pde format. Openable only by the
  arduino IDE.



• If you have issues burning code onto the arduino, check
  http://arduino.cc/en/Guide/Troubleshooting for tips.
Steps in Arduino programming.
• Open the IDE

• Write code and logic

• Click the verify/compile button to check your program for
  errors.
• Attach the arduino via USB to the PC.
• Install drivers if first time.
• Set up serial port being used.
• Set up board you are programming.
• Click upload code to send code to arduino.

Mais conteúdo relacionado

Mais procurados

Introduction to Arduino
Introduction to ArduinoIntroduction to Arduino
Introduction to ArduinoRichard Rixham
 
Arduino presentation by_warishusain
Arduino presentation by_warishusainArduino presentation by_warishusain
Arduino presentation by_warishusainstudent
 
Esp8266 NodeMCU
Esp8266 NodeMCUEsp8266 NodeMCU
Esp8266 NodeMCUroadster43
 
Nodemcu - introduction
Nodemcu - introductionNodemcu - introduction
Nodemcu - introductionMichal Sedlak
 
Arduino Workshop Day 1 - Basic Arduino
Arduino Workshop Day 1 - Basic ArduinoArduino Workshop Day 1 - Basic Arduino
Arduino Workshop Day 1 - Basic ArduinoVishnu
 
Arduino for beginners- Introduction to Arduino (presentation) - codewithgauri
Arduino for beginners- Introduction to Arduino (presentation) - codewithgauriArduino for beginners- Introduction to Arduino (presentation) - codewithgauri
Arduino for beginners- Introduction to Arduino (presentation) - codewithgauriGaurav Pandey
 
Arduino Lecture 1 - Introducing the Arduino
Arduino Lecture 1 - Introducing the ArduinoArduino Lecture 1 - Introducing the Arduino
Arduino Lecture 1 - Introducing the ArduinoEoin Brazil
 
Arduino slides
Arduino slidesArduino slides
Arduino slidessdcharle
 
lesson2 - Nodemcu course - NodeMCU dev Board
 lesson2 - Nodemcu course - NodeMCU dev Board lesson2 - Nodemcu course - NodeMCU dev Board
lesson2 - Nodemcu course - NodeMCU dev BoardElaf A.Saeed
 
Introduction to Arduino
Introduction to ArduinoIntroduction to Arduino
Introduction to Arduinoyeokm1
 
Arduino Workshop Day 2 - Advance Arduino & DIY
Arduino Workshop Day 2 - Advance Arduino & DIYArduino Workshop Day 2 - Advance Arduino & DIY
Arduino Workshop Day 2 - Advance Arduino & DIYVishnu
 
Arduino Workshop
Arduino WorkshopArduino Workshop
Arduino Workshopatuline
 
Raspberry Pi (Introduction)
Raspberry Pi (Introduction)Raspberry Pi (Introduction)
Raspberry Pi (Introduction)Mandeesh Singh
 

Mais procurados (20)

Introduction to Arduino
Introduction to ArduinoIntroduction to Arduino
Introduction to Arduino
 
Arduino presentation by_warishusain
Arduino presentation by_warishusainArduino presentation by_warishusain
Arduino presentation by_warishusain
 
Esp8266 NodeMCU
Esp8266 NodeMCUEsp8266 NodeMCU
Esp8266 NodeMCU
 
Nodemcu - introduction
Nodemcu - introductionNodemcu - introduction
Nodemcu - introduction
 
Arduino Workshop Day 1 - Basic Arduino
Arduino Workshop Day 1 - Basic ArduinoArduino Workshop Day 1 - Basic Arduino
Arduino Workshop Day 1 - Basic Arduino
 
Arduino for beginners- Introduction to Arduino (presentation) - codewithgauri
Arduino for beginners- Introduction to Arduino (presentation) - codewithgauriArduino for beginners- Introduction to Arduino (presentation) - codewithgauri
Arduino for beginners- Introduction to Arduino (presentation) - codewithgauri
 
Arduino Lecture 1 - Introducing the Arduino
Arduino Lecture 1 - Introducing the ArduinoArduino Lecture 1 - Introducing the Arduino
Arduino Lecture 1 - Introducing the Arduino
 
Arduino slides
Arduino slidesArduino slides
Arduino slides
 
Arduino presentation
Arduino presentationArduino presentation
Arduino presentation
 
Introduction to Arduino
Introduction to ArduinoIntroduction to Arduino
Introduction to Arduino
 
lesson2 - Nodemcu course - NodeMCU dev Board
 lesson2 - Nodemcu course - NodeMCU dev Board lesson2 - Nodemcu course - NodeMCU dev Board
lesson2 - Nodemcu course - NodeMCU dev Board
 
Introduction to Arduino
Introduction to ArduinoIntroduction to Arduino
Introduction to Arduino
 
Aurdino presentation
Aurdino presentationAurdino presentation
Aurdino presentation
 
Arduino
ArduinoArduino
Arduino
 
Arduino Workshop Day 2 - Advance Arduino & DIY
Arduino Workshop Day 2 - Advance Arduino & DIYArduino Workshop Day 2 - Advance Arduino & DIY
Arduino Workshop Day 2 - Advance Arduino & DIY
 
Arduino Workshop
Arduino WorkshopArduino Workshop
Arduino Workshop
 
Arduino
ArduinoArduino
Arduino
 
Arduino uno
Arduino unoArduino uno
Arduino uno
 
What is Arduino ?
What is Arduino ?What is Arduino ?
What is Arduino ?
 
Raspberry Pi (Introduction)
Raspberry Pi (Introduction)Raspberry Pi (Introduction)
Raspberry Pi (Introduction)
 

Destaque

DIY! Introduction to Arduino (Development Board)
DIY! Introduction to Arduino (Development Board) DIY! Introduction to Arduino (Development Board)
DIY! Introduction to Arduino (Development Board) Dignitas Digital Pvt. Ltd.
 
Getting Started with Arduino
Getting Started with ArduinoGetting Started with Arduino
Getting Started with ArduinoWee Keat Chin
 
20150826 Introduction to Arduino
20150826 Introduction to Arduino20150826 Introduction to Arduino
20150826 Introduction to ArduinoSyuan Wang
 
Introducing... Arduino
Introducing... ArduinoIntroducing... Arduino
Introducing... Arduinozvikapika
 
Arduino Introduction Guide 1
Arduino Introduction Guide 1Arduino Introduction Guide 1
Arduino Introduction Guide 1elketeaches
 
Arduino Introduction (Blinking LED) Presentation (workshop #5)
Arduino  Introduction (Blinking LED)  Presentation (workshop #5)Arduino  Introduction (Blinking LED)  Presentation (workshop #5)
Arduino Introduction (Blinking LED) Presentation (workshop #5)UNCG University Libraries
 
Getting started with arduino
Getting started with arduinoGetting started with arduino
Getting started with arduinoDr. Pranav Rathi
 
Intro arduino English
Intro arduino EnglishIntro arduino English
Intro arduino EnglishSOAEnsAD
 
Introduction to arduino
Introduction to arduinoIntroduction to arduino
Introduction to arduinoMohamed Essam
 
Introduction to Arduino
Introduction to ArduinoIntroduction to Arduino
Introduction to ArduinoKarim El-Rayes
 
Introduction to Arduino and Circuits
Introduction to Arduino and CircuitsIntroduction to Arduino and Circuits
Introduction to Arduino and CircuitsJason Griffey
 
Introduction to arduino!
Introduction to arduino!Introduction to arduino!
Introduction to arduino!Makers of India
 
Introduction to Arduino
Introduction to ArduinoIntroduction to Arduino
Introduction to ArduinoYong Heui Cho
 
Introduction to Arduino & Raspberry Pi
Introduction to Arduino & Raspberry PiIntroduction to Arduino & Raspberry Pi
Introduction to Arduino & Raspberry PiAhmad Hafeezi
 
Intro to Arduino
Intro to ArduinoIntro to Arduino
Intro to Arduinoavikdhupar
 
Introduction To Arduino
Introduction To ArduinoIntroduction To Arduino
Introduction To Arduinounsheffield
 
Introduction to arduino
Introduction to arduinoIntroduction to arduino
Introduction to arduinoAhmed Sakr
 
My Top 10 slides on presentations
My Top 10 slides on presentationsMy Top 10 slides on presentations
My Top 10 slides on presentationsAlexei Kapterev
 
Introduction to Arduino Programming
Introduction to Arduino ProgrammingIntroduction to Arduino Programming
Introduction to Arduino ProgrammingJames Lewis
 

Destaque (19)

DIY! Introduction to Arduino (Development Board)
DIY! Introduction to Arduino (Development Board) DIY! Introduction to Arduino (Development Board)
DIY! Introduction to Arduino (Development Board)
 
Getting Started with Arduino
Getting Started with ArduinoGetting Started with Arduino
Getting Started with Arduino
 
20150826 Introduction to Arduino
20150826 Introduction to Arduino20150826 Introduction to Arduino
20150826 Introduction to Arduino
 
Introducing... Arduino
Introducing... ArduinoIntroducing... Arduino
Introducing... Arduino
 
Arduino Introduction Guide 1
Arduino Introduction Guide 1Arduino Introduction Guide 1
Arduino Introduction Guide 1
 
Arduino Introduction (Blinking LED) Presentation (workshop #5)
Arduino  Introduction (Blinking LED)  Presentation (workshop #5)Arduino  Introduction (Blinking LED)  Presentation (workshop #5)
Arduino Introduction (Blinking LED) Presentation (workshop #5)
 
Getting started with arduino
Getting started with arduinoGetting started with arduino
Getting started with arduino
 
Intro arduino English
Intro arduino EnglishIntro arduino English
Intro arduino English
 
Introduction to arduino
Introduction to arduinoIntroduction to arduino
Introduction to arduino
 
Introduction to Arduino
Introduction to ArduinoIntroduction to Arduino
Introduction to Arduino
 
Introduction to Arduino and Circuits
Introduction to Arduino and CircuitsIntroduction to Arduino and Circuits
Introduction to Arduino and Circuits
 
Introduction to arduino!
Introduction to arduino!Introduction to arduino!
Introduction to arduino!
 
Introduction to Arduino
Introduction to ArduinoIntroduction to Arduino
Introduction to Arduino
 
Introduction to Arduino & Raspberry Pi
Introduction to Arduino & Raspberry PiIntroduction to Arduino & Raspberry Pi
Introduction to Arduino & Raspberry Pi
 
Intro to Arduino
Intro to ArduinoIntro to Arduino
Intro to Arduino
 
Introduction To Arduino
Introduction To ArduinoIntroduction To Arduino
Introduction To Arduino
 
Introduction to arduino
Introduction to arduinoIntroduction to arduino
Introduction to arduino
 
My Top 10 slides on presentations
My Top 10 slides on presentationsMy Top 10 slides on presentations
My Top 10 slides on presentations
 
Introduction to Arduino Programming
Introduction to Arduino ProgrammingIntroduction to Arduino Programming
Introduction to Arduino Programming
 

Semelhante a Introduction to Arduino Microcontrollers

introductiontoarduino-111120102058-phpapp02.pdf
introductiontoarduino-111120102058-phpapp02.pdfintroductiontoarduino-111120102058-phpapp02.pdf
introductiontoarduino-111120102058-phpapp02.pdfHebaEng
 
Arduino_Beginner.pptx
Arduino_Beginner.pptxArduino_Beginner.pptx
Arduino_Beginner.pptxshivagoud45
 
Arduino_Beginner.pptx
Arduino_Beginner.pptxArduino_Beginner.pptx
Arduino_Beginner.pptxaravind Guru
 
arduinocourse-180308074529 (1).pdf
arduinocourse-180308074529 (1).pdfarduinocourse-180308074529 (1).pdf
arduinocourse-180308074529 (1).pdfssusere5db05
 
Arduino Platform with C programming.
Arduino Platform with C programming.Arduino Platform with C programming.
Arduino Platform with C programming.Govind Jha
 
Introduction to Arduino Microcontroller
Introduction to Arduino MicrocontrollerIntroduction to Arduino Microcontroller
Introduction to Arduino MicrocontrollerMujahid Hussain
 
Arduino by yogesh t s'
Arduino by yogesh t s'Arduino by yogesh t s'
Arduino by yogesh t s'tsyogesh46
 
Introduction to Arduino.pptx
Introduction to Arduino.pptxIntroduction to Arduino.pptx
Introduction to Arduino.pptxAkshat Bijronia
 
Arduino.pptx
Arduino.pptxArduino.pptx
Arduino.pptxAadilKk
 
Micro_Controllers_lab1_Intro_to_Arduino.pptx
Micro_Controllers_lab1_Intro_to_Arduino.pptxMicro_Controllers_lab1_Intro_to_Arduino.pptx
Micro_Controllers_lab1_Intro_to_Arduino.pptxGaser4
 
Embedded system design using arduino
Embedded system design using arduinoEmbedded system design using arduino
Embedded system design using arduinoSantosh Verma
 
Introduction to Arduino Webinar
Introduction to Arduino WebinarIntroduction to Arduino Webinar
Introduction to Arduino WebinarFragiskos Fourlas
 
Internet of Things Unit 3 notes-Design and Development and Arduino.pptx
Internet of Things Unit 3 notes-Design and Development and Arduino.pptxInternet of Things Unit 3 notes-Design and Development and Arduino.pptx
Internet of Things Unit 3 notes-Design and Development and Arduino.pptxDinola2
 

Semelhante a Introduction to Arduino Microcontrollers (20)

introductiontoarduino-111120102058-phpapp02.pdf
introductiontoarduino-111120102058-phpapp02.pdfintroductiontoarduino-111120102058-phpapp02.pdf
introductiontoarduino-111120102058-phpapp02.pdf
 
Arduino
ArduinoArduino
Arduino
 
Arduino_Beginner.pptx
Arduino_Beginner.pptxArduino_Beginner.pptx
Arduino_Beginner.pptx
 
Arduino_Beginner.pptx
Arduino_Beginner.pptxArduino_Beginner.pptx
Arduino_Beginner.pptx
 
Arduino course
Arduino courseArduino course
Arduino course
 
arduinocourse-180308074529 (1).pdf
arduinocourse-180308074529 (1).pdfarduinocourse-180308074529 (1).pdf
arduinocourse-180308074529 (1).pdf
 
Arduino Platform with C programming.
Arduino Platform with C programming.Arduino Platform with C programming.
Arduino Platform with C programming.
 
Introduction to Arduino Microcontroller
Introduction to Arduino MicrocontrollerIntroduction to Arduino Microcontroller
Introduction to Arduino Microcontroller
 
Arduino Programming Basic
Arduino Programming BasicArduino Programming Basic
Arduino Programming Basic
 
Arduino by yogesh t s'
Arduino by yogesh t s'Arduino by yogesh t s'
Arduino by yogesh t s'
 
Introduction to Arduino.pptx
Introduction to Arduino.pptxIntroduction to Arduino.pptx
Introduction to Arduino.pptx
 
IOT beginnners
IOT beginnnersIOT beginnners
IOT beginnners
 
IOT beginnners
IOT beginnnersIOT beginnners
IOT beginnners
 
Introduction of Arduino Uno
Introduction of Arduino UnoIntroduction of Arduino Uno
Introduction of Arduino Uno
 
Arduino.pptx
Arduino.pptxArduino.pptx
Arduino.pptx
 
arduinoedit.pptx
arduinoedit.pptxarduinoedit.pptx
arduinoedit.pptx
 
Micro_Controllers_lab1_Intro_to_Arduino.pptx
Micro_Controllers_lab1_Intro_to_Arduino.pptxMicro_Controllers_lab1_Intro_to_Arduino.pptx
Micro_Controllers_lab1_Intro_to_Arduino.pptx
 
Embedded system design using arduino
Embedded system design using arduinoEmbedded system design using arduino
Embedded system design using arduino
 
Introduction to Arduino Webinar
Introduction to Arduino WebinarIntroduction to Arduino Webinar
Introduction to Arduino Webinar
 
Internet of Things Unit 3 notes-Design and Development and Arduino.pptx
Internet of Things Unit 3 notes-Design and Development and Arduino.pptxInternet of Things Unit 3 notes-Design and Development and Arduino.pptx
Internet of Things Unit 3 notes-Design and Development and Arduino.pptx
 

Mais de Wingston

OpenCV @ Droidcon 2012
OpenCV @ Droidcon 2012OpenCV @ Droidcon 2012
OpenCV @ Droidcon 2012Wingston
 
05 content providers - Android
05   content providers - Android05   content providers - Android
05 content providers - AndroidWingston
 
04 activities - Android
04   activities - Android04   activities - Android
04 activities - AndroidWingston
 
03 layouts & ui design - Android
03   layouts & ui design - Android03   layouts & ui design - Android
03 layouts & ui design - AndroidWingston
 
02 hello world - Android
02   hello world - Android02   hello world - Android
02 hello world - AndroidWingston
 
01 introduction & setup - Android
01   introduction & setup - Android01   introduction & setup - Android
01 introduction & setup - AndroidWingston
 
OpenCV with android
OpenCV with androidOpenCV with android
OpenCV with androidWingston
 
C game programming - SDL
C game programming - SDLC game programming - SDL
C game programming - SDLWingston
 
C programming - Pointers
C programming - PointersC programming - Pointers
C programming - PointersWingston
 
Introduction to Basic C programming 02
Introduction to Basic C programming 02Introduction to Basic C programming 02
Introduction to Basic C programming 02Wingston
 
Introduction to Basic C programming 01
Introduction to Basic C programming 01Introduction to Basic C programming 01
Introduction to Basic C programming 01Wingston
 
Linux – an introduction
Linux – an introductionLinux – an introduction
Linux – an introductionWingston
 
Embedded linux
Embedded linuxEmbedded linux
Embedded linuxWingston
 
04 Arduino Peripheral Interfacing
04   Arduino Peripheral Interfacing04   Arduino Peripheral Interfacing
04 Arduino Peripheral InterfacingWingston
 
03 analogue anrduino fundamentals
03   analogue anrduino fundamentals03   analogue anrduino fundamentals
03 analogue anrduino fundamentalsWingston
 
02 General Purpose Input - Output on the Arduino
02   General Purpose Input -  Output on the Arduino02   General Purpose Input -  Output on the Arduino
02 General Purpose Input - Output on the ArduinoWingston
 
4.content mgmt
4.content mgmt4.content mgmt
4.content mgmtWingston
 
8 Web Practices for Drupal
8  Web Practices for Drupal8  Web Practices for Drupal
8 Web Practices for DrupalWingston
 
7 Theming in Drupal
7 Theming in Drupal7 Theming in Drupal
7 Theming in DrupalWingston
 
6 Special Howtos for Drupal
6 Special Howtos for Drupal6 Special Howtos for Drupal
6 Special Howtos for DrupalWingston
 

Mais de Wingston (20)

OpenCV @ Droidcon 2012
OpenCV @ Droidcon 2012OpenCV @ Droidcon 2012
OpenCV @ Droidcon 2012
 
05 content providers - Android
05   content providers - Android05   content providers - Android
05 content providers - Android
 
04 activities - Android
04   activities - Android04   activities - Android
04 activities - Android
 
03 layouts & ui design - Android
03   layouts & ui design - Android03   layouts & ui design - Android
03 layouts & ui design - Android
 
02 hello world - Android
02   hello world - Android02   hello world - Android
02 hello world - Android
 
01 introduction & setup - Android
01   introduction & setup - Android01   introduction & setup - Android
01 introduction & setup - Android
 
OpenCV with android
OpenCV with androidOpenCV with android
OpenCV with android
 
C game programming - SDL
C game programming - SDLC game programming - SDL
C game programming - SDL
 
C programming - Pointers
C programming - PointersC programming - Pointers
C programming - Pointers
 
Introduction to Basic C programming 02
Introduction to Basic C programming 02Introduction to Basic C programming 02
Introduction to Basic C programming 02
 
Introduction to Basic C programming 01
Introduction to Basic C programming 01Introduction to Basic C programming 01
Introduction to Basic C programming 01
 
Linux – an introduction
Linux – an introductionLinux – an introduction
Linux – an introduction
 
Embedded linux
Embedded linuxEmbedded linux
Embedded linux
 
04 Arduino Peripheral Interfacing
04   Arduino Peripheral Interfacing04   Arduino Peripheral Interfacing
04 Arduino Peripheral Interfacing
 
03 analogue anrduino fundamentals
03   analogue anrduino fundamentals03   analogue anrduino fundamentals
03 analogue anrduino fundamentals
 
02 General Purpose Input - Output on the Arduino
02   General Purpose Input -  Output on the Arduino02   General Purpose Input -  Output on the Arduino
02 General Purpose Input - Output on the Arduino
 
4.content mgmt
4.content mgmt4.content mgmt
4.content mgmt
 
8 Web Practices for Drupal
8  Web Practices for Drupal8  Web Practices for Drupal
8 Web Practices for Drupal
 
7 Theming in Drupal
7 Theming in Drupal7 Theming in Drupal
7 Theming in Drupal
 
6 Special Howtos for Drupal
6 Special Howtos for Drupal6 Special Howtos for Drupal
6 Special Howtos for Drupal
 

Último

Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 

Último (20)

Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 

Introduction to Arduino Microcontrollers

  • 1. Introduction to Arduino Wilson Wingston Sharon cto@workshopindia.com
  • 2. Physical computing Developing solutions that implement a software to interact with elements in the physical universe. 1. Sensors convert signals from the physical world to information to the computing device. 2. Processing this data via the computational device 3. Performing physical actions using actuators
  • 3. Microcontrollers • Microcontrollers are small computers integrated into a single chip. • They contain 1. Processor core 2. Flash Memory for program 3. I/O peripherals 4. RAM 5. Peripherals such as clocks, timers, PWM etc • Microprocessors are used for general purpose applications while microcontrollers are self sufficient and are used for specific tasks. • MCU are an example of embedded systems.
  • 4. Microcontroller architectures • ATMEL – 32 bit RISC AVR architecture • IBM PowerPC family – sold to AMCC • Analogue Device – ARM architecture and Blackfin (DSP) • Microchip – PIC architecture
  • 6. Parts of an MCU • CPU: central processing unit that may contain a 8-bit, 16-bit or 32-bit processor. • RAM: for volatile data storage. • ROM, EPROM, EEPROM or Flash memory for program and operating parameter storage • discrete input and output PINS • serial input/output such as serial ports (UARTs) • peripherals such as timers, event counters, PWM generators, and watchdog • clock generator • analog-to-digital converters • digital-to-analog converters • in-circuit programming and debugging support
  • 7. Programming Microcontrollers Programming microcontrollers is usually hard and expensive: • Obtaining the microcontroller • Making the programming circuit • Writing the program into a target language and compiler • Flashing the program onto the chip • Removing the chip from programming circuit to application circuit • Testing and debugging • Proprietary technology is expensive
  • 8. Enter the Arduino • The Arduino is an open source development board for the AVR series of microcontrollers for physical computing. • Can input a variety of sensor data. • Can communicate with programs on computer easily. • Can control a variety of motors, lights and other devices. • Advantages 1. Cheap 2. Open source hardware and software 3. Easy learning curve 4. Extensible
  • 9. Freeduino • Exactly the same as the Arduino. • Developed as a clone for IP purposes only as open hardware.
  • 11. Microcontroller Microcontroller ATmega328p Operating Voltage 5V Digital I/O Pins 14 (of which 6 provide PWM output) Analog Input Pins 6 DC Current per I/O Pin 40 mA DC Current for 3.3V Pin 50 mA Flash Memory 16 KB (of which 2 KB used by bootloader) SRAM 1 KB EEPROM 512 bytes Clock Speed (via XTAL) 16 MHz
  • 13. Powering it up • Has a jumper that can switch between 5V from USB and a 9V input jack through a 7805. • External power can be connected via a 2.1mm standard jack. Normal adaptors that fit and are 6V-12V can be used. • If power supply is <5V, board may become unstable • If power supply >12V, board may overheat • GND, VIN, 5V and 3.3V are present for powering peripherals.
  • 14. The bootloader • Programming a microcontroller is usually done by specific programmer circuits like AVR-MKll, USBtiny • ISP and JTAG are protocols to burn code onto microcontrollers • The arduino comes preloaded with code called the bootloader ( taking 2K of memory) that looks for programs coming through the serial port and moves it into the program memory for execution. • If bootloader is damaged for any reason it can be restored by an ICSP programmer.
  • 15. FTDI serial to USB • Microcontrollers like the atmega328 have only serial port using the USART for external communication. • The arduino design includes a FTDI chip that acts as a Serial to USB link. • The USB cable connected to the computer shows up as a virtual COM port and behaves exactly like a serial port. • Latest Drivers can be found at the downloads section of the FTDI website. (use google)
  • 17. Important PINS on the board • All arduino pins operate at 5V, 40mA. DO NOT EXCEED THAT RATING! • 0(RX) and 1(TX) are the serial port pins. These pins go to the FTDI chip also. You can tap the serial data from here if you want. These pins are also connected to LED so you can see when there is data being transferred. • 2 & 3 : External Interrupts. These pins can be used as INT0 and INT1 respectively for calling an externally generated interrupt. • 3, 5, 6, 9, 10, and 11 : PWM : These pins can generate an 8-bit pulse width modulated output. • LED: 13 an LED provided on the arduino board itself. • AREF: used for external analogue signal reference for the ADC
  • 18. The Arduino IDE • The arduino is an open source IDE developed from wiring. • Get the latest IDE (0022) from the website • Extract it and double click arduino.exe • Since the program is written in JAVA.. It might have some issues on win7 x64 systems. (to solve, just wait.. Its hangs for a bit occasionally)
  • 19. The Arduino IDE • The arduino is programmed in C language. • The language is very simple and provides many abstraction for simplicity of reading and writing powerfull applications. • The Arduino IDE can be used write the bootloader onto any MCU via ICSP making it an “arduino”. • It provides a serial monitor to see the serial data from the USB virtual COM port. • Allows ofr one click compiling, verification and burning of code onto the arduino.
  • 21. Programming for Arduino This is the basic structure of any arduino program. Setup is for program setup and variable initialization Loop containg code for the working of the program. //global declaration area for header files and such (none needed by default) void setup() { statements here get executed once; } void loop() { statements here keep getting executed indefinitely; }
  • 22. Setup() • All code contained in this function is executed once. • REQUIRED function for an arduino program to compile void setup() { pinMode(pin, OUTPUT); // sets the 'pin' as output }
  • 23. loop() • All code contained in this function is executed repeatedly. • This program is responsible for all the arduino boards functionality. • REQUIRED function for an arduino program to compile void loop() { digitalWrite(pin, HIGH); // turns 'pin' on delay(1000); // pauses for one second digitalWrite(pin, LOW); // turns 'pin' off delay(1000); // pauses for one second }
  • 24. Available data types in Arduino IDE • void • boolean • char ( 0 – 255) • byte - 8 bit data ( 0 – 255) • int - 16-bit data (32,767 - -32,768) • long – 32 bit data (2,147,483,647 to -2,147,483,648) • float • double • string - char array • String - object • array
  • 25. Arithmetic • Arithmetic operators include addition, subtraction, multiplication, and division. • Remember the point of variable rollover and also what happens then: e.g. (0 - 1) OR (0 - - 32768). • For math that requires fractions, you can use float variables, if you can bear large size and slow computation speeds in your microcontroller. y = y + 3; x = x - 7; i = j * 6; r = r / 5;
  • 26. Comparison operators • Comparisons of one variable or constant against another are often used in if statements to test if a specified condition is true. x == y // x is equal to y x != y // x is not equal to y x<y // x is less than y x>y // x is greater than y x <= y // x is less than or equal to y x >= y // x is greater than or equal to y
  • 27. Logical operators • Logical operators are usually a way to logically combine two expressions and return a TRUE or FALSE depending on the operator. • There are three logical operators, AND, OR, and NOT. Logical AND: if (x > 0 && x < 5) // true only if both expressions are true Logical OR: if (x > 0 || y > 0) // true if either expression is true Logical NOT: if (!x > 0) // true only if expression is false
  • 28. TRUE/FALSE • These are Boolean constants that define logic levels of the arduino. • FALSE is easily defined as 0 (zero) • TRUE is often defined as 1, but can also be anything else except zero. So in a Boolean sense, -1, 2, and -200 are all also defined as TRUE. if (abcd== TRUE); { DoSomethingNice; } else { DoSomethingHorrible; }
  • 29. HIGH/LOW • These constants define pin levels as HIGH or LOW and are used when reading or writing to digital pins. • HIGH is defined as logic level 1, ON, or 5 volts • LOW is logic level 0, OFF, or 0 volts. digitalWrite(13, HIGH);
  • 30. INPUT/OUTPUT • These constants define pin levels as HIGH or LOW and are used when reading or writing to digital pins. • HIGH is defined as logic level 1, ON, or 5 volts • LOW is logic level 0, OFF, or 0 volts. pinmode(13, OUTPUT);
  • 31. Writing custom functions • Functions are named blocks of code that can be called repeatedly. • Use functions to reduce clutter and perform repeated tasks. • Functions can return datatypes as required. int delayVal() { int v; // create temporary variable 'v' v = analogRead(pot); // read potentiometer value v /= 4; // converts 0-1023 to 0-255 return v; // return final value }
  • 32. Arrays • An array is a collection of values that are accessed with an index number. • Arrays are zero indexed, with the first value in the array beginning at index number 0. int myArray[5]; // declares integer array w/ 6 positions myArray[3] = 10; // assigns the 4th index the value 10 int x; x = myArray[3]; // x now equals 10
  • 33. int ledPin = 10; // LED on pin 10 byte flikr[] = {160, 130, 5, 20, 100, 30, 110, 25}; // above array of 8 void setup() { pinMode(ledPin, OUTPUT); // sets OUTPUT pin } void loop() { for(int i=0; i<7; i++) // looping though array { analogWrite(ledPin, flikr[i]); // write index value delay(200); // pause 200ms } }
  • 34. Pinmode(pin,mode) • Used in void setup() to decide whether a specified pin must behave either as an INPUT or an OUTPUT pin. • Arduino digital pins are input by default, but still use pinmode() for brevity. • Pins configured as INPUT are said to be in a high-impedance state so don’t try to load this pin externally.. It’ll fry. • Pins configured as OUTPUT are said to be in a low-impedance state and can provide 40 mA of current to the load. • Can be used to brightly light up an LED sound a buzzer but not motors, solenoids etc.. pinMode(pin, INPUT); // set ‘pin’ to input digitalWrite(pin, HIGH); // turn on pullup resistors
  • 35. digitalRead(pin) • Reads the value from a specified digital pin with the result either HIGH or LOW. • The pin can be specified as either a variable or constant (0-13). value = digitalRead(Pin); // sets 'value' equal to the input pin
  • 36. digitalwrite(pin,value) • Outputs either logic level HIGH or LOW at (turns on or off) a specified digital pin. The pin can be specified as either a variable or constant (0-13). int led = 13; // connect LED to pin 13 int pin = 7; // connect pushbutton to pin 7 int value = 0; // variable to store the read value void setup() { pinMode(led, OUTPUT); // sets pin 13 as output pinMode(pin, INPUT); // sets pin 7 as input } void loop() { value = digitalRead(pin); // sets 'value' equal to I/P pin digitalWrite(led, value); // sets 'led' to the }
  • 37. analogread(pin) • Reads the value from a specified analog pin with a 10-bit resolution. T • his function only works on the analog in pins (0-5). The resulting integer values range from 0 to 1023. • Analogue pins do not need to be set by using pinmode • A0 – A6 are the analoge pins value = analogRead(A0); // sets 'value' equal to A0
  • 38. analogwrite(pin,value) • Writes a analog value using hardware enabled pulse width modulation (PWM) by internal timers to an output pin marked as PWM ONLY. int led = 10; // LED with 220 resistor on pin 10 int pin = 0; // potentiometer on analog pin 0 int value; // value for reading void setup(){} // no setup needed void loop() { value = analogRead(pin); // sets 'value' equal to 'pin' value /= 4; // converts 0-1023 to 0-255 analogWrite(led, value); // outputs PWM signal to led }
  • 39. Serial.begin(rate) • Opens serial port and sets the baud rate for serial data transmission. • The typical baud rate for communicating with the computer is 9600. • If you get garbage values, check if baude rate matches. • Always in setup() void setup() { Serial.begin(9600); // opens serial port }
  • 40. Serial.println(data) • Prints data to the serial port, followed by an automatic carriage return and line feed. • This command takes the same form as Serial.print(), but is easier for reading data on the Serial Monitor. Serial.println(analogread(A0)); //sends A0 value to serial port
  • 41. Other available functions • Pointer access operators * & • Random() and randomseed() for random number generation • Sin(), cos() and tan() functions • Delayms() and delay() • Various math function, abs(), pow(), sqrt() etc • Attachinterrupt() and Detachinterrupt() for interrupt programming • All compund operators, structures and class functionality of C/C++
  • 42. The arduino Sketch • A sketch is the name that Arduino uses for a program. It's the unit of code that is uploaded to and run on an Arduino board. • Sketches are stored in .pde format. Openable only by the arduino IDE. • If you have issues burning code onto the arduino, check http://arduino.cc/en/Guide/Troubleshooting for tips.
  • 43. Steps in Arduino programming. • Open the IDE • Write code and logic • Click the verify/compile button to check your program for errors. • Attach the arduino via USB to the PC. • Install drivers if first time. • Set up serial port being used. • Set up board you are programming. • Click upload code to send code to arduino.