SlideShare a Scribd company logo
1 of 11
Download to read offline
Programming the
    Arduino
CS4062 - Eoin Brazil - Semester 2 - 2009




        http://www.flickr.com/photos/collinmel/2317520331/
Programming an
   Arduino
         Write program

          Compile (check for
       errors)

         Reset board

         Upload to board
An Arduino “Sketch”
       Declare variables at top



       Initialize
              setup() – run once at beginning, set pins




       Running
              loop() – run repeatedly, after setup()
An Arduino “Sketch”
                   int ledPin = 13; – led
                   connected to control pin 13

                   int aSensor = 0; – setup
Global Variables
                   sensor 'aSensor' on analog pin 0

                   int statePin = LOW; – use this
                   to hold the state of a pin
An Arduino “Sketch”

          pinMode() – set a pin as input
          or output
setup()
          serial.Begin() – setup to `talk'
          to the computer
An Arduino “Sketch”

          pinMode(ledPin, Output); –
          set the pin `ledPin' as an output
setup()
          serial.Begin(9600); – talk to
          the computer at 9600 baud rate
An Arduino “Sketch”

          digitalWrite() – set a digital pin high/low
          digitalRead() – read a digital pin’s state
          analogRead() – read an analog pin
 loop()
          analogWrite() – write an “analog” PWM value
          delay() – wait an amount of time
          millis() – get the current tim
`C’ language
  char - ascii character, 8 bits
  short - short integer, 16 bits, -32768 to
32767
  int - default integer, 16 or 32 bits
  long - large integer, at least 32 bits
  float - 32 bit floating point (e.g. 3.13)
  double, long double - 64 bit or greater
Character constants
  `A’ - upper case A

  `n’ - newline character

  `t’ - tab character

  `0’ - null character (it is digit not char)

  `012’ - character with octal value of 12
which is decimal 10
Commenting and
    Operators
`//’ - single line comment

`/* .... */’ - multiline comment

 + Addition - Subtraction * Multiplication

/ Division % Remander (mod)

== != <= >= < >

= is not ==
More Operators
   Boolean operators ! - not && - and || - or

  if (<statement>) { <statement/s> }

  if - else

  while (<statement>) { <statements/s> }

  Essential C - http://cslibrary.stanford.edu/
101/

More Related Content

What's hot

Introduction to the Arduino
Introduction to the ArduinoIntroduction to the Arduino
Introduction to the Arduino
Wingston
 

What's hot (20)

Arduino Platform with C programming.
Arduino Platform with C programming.Arduino Platform with C programming.
Arduino Platform with C programming.
 
Arduino Workshop Day 2
Arduino  Workshop Day 2Arduino  Workshop Day 2
Arduino Workshop Day 2
 
2015-10-21 - Arduino workshop
2015-10-21 - Arduino workshop2015-10-21 - Arduino workshop
2015-10-21 - Arduino workshop
 
Lesson sample introduction to arduino
Lesson sample   introduction to arduinoLesson sample   introduction to arduino
Lesson sample introduction to arduino
 
Arduino technical session 1
Arduino technical session 1Arduino technical session 1
Arduino technical session 1
 
Getting Started With Arduino_Tutorial
Getting Started With Arduino_TutorialGetting Started With Arduino_Tutorial
Getting Started With Arduino_Tutorial
 
Arduino experimenters guide hq
Arduino experimenters guide hqArduino experimenters guide hq
Arduino experimenters guide hq
 
Intro to Arduino
Intro to ArduinoIntro to Arduino
Intro to Arduino
 
Aurdino presentation
Aurdino presentationAurdino presentation
Aurdino presentation
 
Arduino Development For Beginners
Arduino Development For BeginnersArduino Development For Beginners
Arduino Development For Beginners
 
Introduction to Arduino
Introduction to ArduinoIntroduction to Arduino
Introduction to Arduino
 
Arduino Robotics workshop Day1
Arduino Robotics workshop Day1Arduino Robotics workshop Day1
Arduino Robotics workshop Day1
 
Introduction to the Arduino
Introduction to the ArduinoIntroduction to the Arduino
Introduction to the Arduino
 
Intro to Hardware Programming with the Arduino Uno
Intro to Hardware Programming with the Arduino UnoIntro to Hardware Programming with the Arduino Uno
Intro to Hardware Programming with the Arduino Uno
 
Arduino 101
Arduino 101Arduino 101
Arduino 101
 
Introduction to Arduino and Circuits
Introduction to Arduino and CircuitsIntroduction to Arduino and Circuits
Introduction to Arduino and Circuits
 
Intro to Arduino
Intro to ArduinoIntro to Arduino
Intro to Arduino
 
Introduction to Arduino
Introduction to ArduinoIntroduction to Arduino
Introduction to Arduino
 
Introducing the Arduino
Introducing the ArduinoIntroducing the Arduino
Introducing the Arduino
 
Arduino Workshop Day 1 - Basic Arduino
Arduino Workshop Day 1 - Basic ArduinoArduino Workshop Day 1 - Basic Arduino
Arduino Workshop Day 1 - Basic Arduino
 

Viewers also liked

Arduino Full Tutorial
Arduino Full TutorialArduino Full Tutorial
Arduino Full Tutorial
Akshay Sharma
 
Introduction to arduino
Introduction to arduinoIntroduction to arduino
Introduction to arduino
Ahmed Sakr
 

Viewers also liked (20)

Arduino Lecture 1 - Introducing the Arduino
Arduino Lecture 1 - Introducing the ArduinoArduino Lecture 1 - Introducing the Arduino
Arduino Lecture 1 - Introducing the Arduino
 
Arduino Full Tutorial
Arduino Full TutorialArduino Full Tutorial
Arduino Full Tutorial
 
Arduino Lecture 3 - Interactive Media CS4062 Semester 2 2009
Arduino Lecture 3 - Interactive Media CS4062 Semester 2 2009Arduino Lecture 3 - Interactive Media CS4062 Semester 2 2009
Arduino Lecture 3 - Interactive Media CS4062 Semester 2 2009
 
Introduction to arduino
Introduction to arduinoIntroduction to arduino
Introduction to arduino
 
Serial 8 Channel AC 230V SSR and Dimmer Bluetooth Interface
Serial 8 Channel AC 230V SSR and Dimmer  Bluetooth InterfaceSerial 8 Channel AC 230V SSR and Dimmer  Bluetooth Interface
Serial 8 Channel AC 230V SSR and Dimmer Bluetooth Interface
 
Digital Dimmer Module
Digital Dimmer ModuleDigital Dimmer Module
Digital Dimmer Module
 
Mobile Services from Concept to Reality - Case Studies at the Mobile Service ...
Mobile Services from Concept to Reality - Case Studies at the Mobile Service ...Mobile Services from Concept to Reality - Case Studies at the Mobile Service ...
Mobile Services from Concept to Reality - Case Studies at the Mobile Service ...
 
Introduction to Machine Learning using R - Dublin R User Group - Oct 2013
Introduction to Machine Learning using R - Dublin R User Group - Oct 2013Introduction to Machine Learning using R - Dublin R User Group - Oct 2013
Introduction to Machine Learning using R - Dublin R User Group - Oct 2013
 
Arduino 1 jose m. ruiz
Arduino 1   jose m. ruizArduino 1   jose m. ruiz
Arduino 1 jose m. ruiz
 
Mindstorms Arduino En Phidgets
Mindstorms Arduino En PhidgetsMindstorms Arduino En Phidgets
Mindstorms Arduino En Phidgets
 
Arduino Lecture 2 - Electronic, LEDs, Communications and Datasheets
Arduino Lecture 2 - Electronic, LEDs, Communications and DatasheetsArduino Lecture 2 - Electronic, LEDs, Communications and Datasheets
Arduino Lecture 2 - Electronic, LEDs, Communications and Datasheets
 
Pragmatic Analytics - Case Studies of High Performance Computing for Better B...
Pragmatic Analytics - Case Studies of High Performance Computing for Better B...Pragmatic Analytics - Case Studies of High Performance Computing for Better B...
Pragmatic Analytics - Case Studies of High Performance Computing for Better B...
 
Arduino Lecture 3 - Interactive Media CS4062 Semester 2 2009
Arduino Lecture 3 - Interactive Media CS4062 Semester 2 2009Arduino Lecture 3 - Interactive Media CS4062 Semester 2 2009
Arduino Lecture 3 - Interactive Media CS4062 Semester 2 2009
 
Arduino Lecture 2 - Interactive Media CS4062 Semester 2 2009
Arduino Lecture 2 - Interactive Media CS4062 Semester 2 2009Arduino Lecture 2 - Interactive Media CS4062 Semester 2 2009
Arduino Lecture 2 - Interactive Media CS4062 Semester 2 2009
 
The Fab Lab Life Cycle; Report of the FAB10 workshops; Pieter van der Hijden ...
The Fab Lab Life Cycle; Report of the FAB10 workshops; Pieter van der Hijden ...The Fab Lab Life Cycle; Report of the FAB10 workshops; Pieter van der Hijden ...
The Fab Lab Life Cycle; Report of the FAB10 workshops; Pieter van der Hijden ...
 
Dimmer digital con Arduino
Dimmer digital con ArduinoDimmer digital con Arduino
Dimmer digital con Arduino
 
humidity sensor
humidity sensorhumidity sensor
humidity sensor
 
Programming with arduino
Programming with arduinoProgramming with arduino
Programming with arduino
 
Arduino Home Automation Hacks
Arduino Home Automation HacksArduino Home Automation Hacks
Arduino Home Automation Hacks
 
Report On Arduino
Report On  ArduinoReport On  Arduino
Report On Arduino
 

Similar to Arduino Lecture 4 - Interactive Media CS4062 Semester 2 2009

4 IOT 18ISDE712 MODULE 4 IoT Physical Devices and End Point-Aurdino Uno.pdf
4 IOT 18ISDE712  MODULE 4 IoT Physical Devices and End Point-Aurdino  Uno.pdf4 IOT 18ISDE712  MODULE 4 IoT Physical Devices and End Point-Aurdino  Uno.pdf
4 IOT 18ISDE712 MODULE 4 IoT Physical Devices and End Point-Aurdino Uno.pdf
Jayanthi Kannan MK
 
Getting Started With Raspberry Pi - UCSD 2013
Getting Started With Raspberry Pi - UCSD 2013Getting Started With Raspberry Pi - UCSD 2013
Getting Started With Raspberry Pi - UCSD 2013
Tom Paulus
 
Arduino Workshop (3).pptx
Arduino Workshop (3).pptxArduino Workshop (3).pptx
Arduino Workshop (3).pptx
HebaEng
 

Similar to Arduino Lecture 4 - Interactive Media CS4062 Semester 2 2009 (20)

Arduino intro.pptx
Arduino intro.pptxArduino intro.pptx
Arduino intro.pptx
 
4 IOT 18ISDE712 MODULE 4 IoT Physical Devices and End Point-Aurdino Uno.pdf
4 IOT 18ISDE712  MODULE 4 IoT Physical Devices and End Point-Aurdino  Uno.pdf4 IOT 18ISDE712  MODULE 4 IoT Physical Devices and End Point-Aurdino  Uno.pdf
4 IOT 18ISDE712 MODULE 4 IoT Physical Devices and End Point-Aurdino Uno.pdf
 
01_DIGITAL IO.pptx
01_DIGITAL IO.pptx01_DIGITAL IO.pptx
01_DIGITAL IO.pptx
 
Arduino Programming
Arduino ProgrammingArduino Programming
Arduino Programming
 
Programming arduino makeymakey
Programming arduino makeymakeyProgramming arduino makeymakey
Programming arduino makeymakey
 
Cassiopeia Ltd - standard Arduino workshop
Cassiopeia Ltd - standard Arduino workshopCassiopeia Ltd - standard Arduino workshop
Cassiopeia Ltd - standard Arduino workshop
 
Embedded system course projects - Arduino Course
Embedded system course projects - Arduino CourseEmbedded system course projects - Arduino Course
Embedded system course projects - Arduino Course
 
Arduino Programming Basic
Arduino Programming BasicArduino Programming Basic
Arduino Programming Basic
 
Getting Started With Raspberry Pi - UCSD 2013
Getting Started With Raspberry Pi - UCSD 2013Getting Started With Raspberry Pi - UCSD 2013
Getting Started With Raspberry Pi - UCSD 2013
 
Arduino cic3
Arduino cic3Arduino cic3
Arduino cic3
 
Arduino Programming Familiarization
Arduino Programming FamiliarizationArduino Programming Familiarization
Arduino Programming Familiarization
 
Arduino Foundations
Arduino FoundationsArduino Foundations
Arduino Foundations
 
Arduino Workshop (3).pptx
Arduino Workshop (3).pptxArduino Workshop (3).pptx
Arduino Workshop (3).pptx
 
How to use an Arduino
How to use an ArduinoHow to use an Arduino
How to use an Arduino
 
Day1
Day1Day1
Day1
 
ARUDINO UNO and RasberryPi with Python
 ARUDINO UNO and RasberryPi with Python ARUDINO UNO and RasberryPi with Python
ARUDINO UNO and RasberryPi with Python
 
Starting with Arduino
Starting with Arduino Starting with Arduino
Starting with Arduino
 
Introduction to Arduino
Introduction to ArduinoIntroduction to Arduino
Introduction to Arduino
 
Introduction to Arduino
Introduction to ArduinoIntroduction to Arduino
Introduction to Arduino
 
Getting Started with Raspberry Pi - USC 2013
Getting Started with Raspberry Pi - USC 2013Getting Started with Raspberry Pi - USC 2013
Getting Started with Raspberry Pi - USC 2013
 

More from Eoin Brazil

Ichec is vs-andthecloud
Ichec is vs-andthecloudIchec is vs-andthecloud
Ichec is vs-andthecloud
Eoin Brazil
 
Mixing Interaction, Sonification, Rendering and Design - The art of creating ...
Mixing Interaction, Sonification, Rendering and Design - The art of creating ...Mixing Interaction, Sonification, Rendering and Design - The art of creating ...
Mixing Interaction, Sonification, Rendering and Design - The art of creating ...
Eoin Brazil
 

More from Eoin Brazil (9)

Cloud Computing Examples at ICHEC
Cloud Computing Examples at ICHECCloud Computing Examples at ICHEC
Cloud Computing Examples at ICHEC
 
An example of discovering simple patterns using basic data mining
An example of discovering simple patterns using basic data miningAn example of discovering simple patterns using basic data mining
An example of discovering simple patterns using basic data mining
 
Bringing HPC to tackle your business problems
Bringing HPC to tackle your business problemsBringing HPC to tackle your business problems
Bringing HPC to tackle your business problems
 
Fat Nodes & GPGPUs - Red-shifting your infrastructure without breaking the bu...
Fat Nodes & GPGPUs - Red-shifting your infrastructure without breaking the bu...Fat Nodes & GPGPUs - Red-shifting your infrastructure without breaking the bu...
Fat Nodes & GPGPUs - Red-shifting your infrastructure without breaking the bu...
 
Example optimisation using GPGPUs by ICHEC
Example optimisation using GPGPUs by ICHECExample optimisation using GPGPUs by ICHEC
Example optimisation using GPGPUs by ICHEC
 
Ichec is vs-andthecloud
Ichec is vs-andthecloudIchec is vs-andthecloud
Ichec is vs-andthecloud
 
Mixing Interaction, Sonification, Rendering and Design - The art of creating ...
Mixing Interaction, Sonification, Rendering and Design - The art of creating ...Mixing Interaction, Sonification, Rendering and Design - The art of creating ...
Mixing Interaction, Sonification, Rendering and Design - The art of creating ...
 
Echoes, Whispers, and Footsteps from the Conflux of Sonic Interaction Design ...
Echoes, Whispers, and Footsteps from the Conflux of Sonic Interaction Design ...Echoes, Whispers, and Footsteps from the Conflux of Sonic Interaction Design ...
Echoes, Whispers, and Footsteps from the Conflux of Sonic Interaction Design ...
 
Arduino Lecture 3 - Making Things Move and AVR programming
Arduino Lecture 3 - Making Things Move and AVR programmingArduino Lecture 3 - Making Things Move and AVR programming
Arduino Lecture 3 - Making Things Move and AVR programming
 

Recently uploaded

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
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
vu2urc
 

Recently uploaded (20)

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
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
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)
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
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
 
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
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
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?
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
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
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
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
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 

Arduino Lecture 4 - Interactive Media CS4062 Semester 2 2009

  • 1. Programming the Arduino CS4062 - Eoin Brazil - Semester 2 - 2009 http://www.flickr.com/photos/collinmel/2317520331/
  • 2. Programming an Arduino Write program Compile (check for errors) Reset board Upload to board
  • 3. An Arduino “Sketch” Declare variables at top Initialize setup() – run once at beginning, set pins Running loop() – run repeatedly, after setup()
  • 4. An Arduino “Sketch” int ledPin = 13; – led connected to control pin 13 int aSensor = 0; – setup Global Variables sensor 'aSensor' on analog pin 0 int statePin = LOW; – use this to hold the state of a pin
  • 5. An Arduino “Sketch” pinMode() – set a pin as input or output setup() serial.Begin() – setup to `talk' to the computer
  • 6. An Arduino “Sketch” pinMode(ledPin, Output); – set the pin `ledPin' as an output setup() serial.Begin(9600); – talk to the computer at 9600 baud rate
  • 7. An Arduino “Sketch” digitalWrite() – set a digital pin high/low digitalRead() – read a digital pin’s state analogRead() – read an analog pin loop() analogWrite() – write an “analog” PWM value delay() – wait an amount of time millis() – get the current tim
  • 8. `C’ language char - ascii character, 8 bits short - short integer, 16 bits, -32768 to 32767 int - default integer, 16 or 32 bits long - large integer, at least 32 bits float - 32 bit floating point (e.g. 3.13) double, long double - 64 bit or greater
  • 9. Character constants `A’ - upper case A `n’ - newline character `t’ - tab character `0’ - null character (it is digit not char) `012’ - character with octal value of 12 which is decimal 10
  • 10. Commenting and Operators `//’ - single line comment `/* .... */’ - multiline comment + Addition - Subtraction * Multiplication / Division % Remander (mod) == != <= >= < > = is not ==
  • 11. More Operators Boolean operators ! - not && - and || - or if (<statement>) { <statement/s> } if - else while (<statement>) { <statements/s> } Essential C - http://cslibrary.stanford.edu/ 101/