SlideShare ist ein Scribd-Unternehmen logo
1 von 41
Department of Electrical and Electronic
Engineering
Khulna University of Engineering & Technology
Khulna-9203
Course code : EE 3214
Sessional on
Microprocessors, Micro-controllers and Peripherals
Presented By
Amit Kumer Podder
Experiment No. 09
(a) Introduction to Arduino board and Arduino IDE
(b) Design and implementation of blinking LED,
analog voltage measurement, string operation and
traffic controller projects in Arduino environment
Experiment Name
Arduino is a prototype platform (open-source) based on an easy-
to-use hardware and software. It consists of a circuit board,
which can be programed (referred to as a microcontroller) and a
ready-made software called Arduino IDE (Integrated
Development Environment), which is used to write and upload
the computer code to the physical board.
Arduino
Arduino & Arduino Compatible Boards
Arduino Family
Arduino Pin Diagram
Arduino Software Outlet
Settings: Tools  Serial Port
•Your computer communicates
to the Arduino microcontroller
via a serial port  through a
USB-Serial adapter.
•Check to make sure that the
drivers are properly installed.
•Next, double-check that the proper board is selected under the
ToolsBoard menu.
Settings: Tools  Board
Arduino
Integrated Development Environment (IDE)
Two required functions /
methods / routines:
void setup()
{
// runs once
}
void loop()
{
// repeats
}error & status messages
Comments, Comments, Comments
• Comments are for you – the programmer and your
friends…or anyone else human that might read your code.
• // this is for single line comments
• // it’s good to put a description at
the top and before anything ‘tricky’
• /* this is for multi-line comments
• Like this…
• And this….
• */
comments
Comments, Comments, Comments
digitalWrite()
analogWrite()
digitalRead()
if() statements / Boolean
analogRead()
Serial communication
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 United States License.
BIG6CONCEPTS
Three commands to know…
• pinMode(pin, INPUT/OUTPUT);
• ex: pinMode(13, OUTPUT);
• digitalWrite(pin, HIGH/LOW);
• ex: digitalWrite(13, HIGH);
• delay(time_ms);
• ex: delay(2500); // delay of 2.5
sec.
• // NOTE: -> commands are CASE-
sensitive
Programming Concepts: Variables
Variable Scope
•Global
•---
•Function-level
Programming Concepts: Variable Types
• Variable Types:
8 bits 16 bits 32 bits
byte
char
int
unsigned int
long
unsigned long
float
Fading in and Fading Out (Analog or Digital?)
• A few pins on the Arduino allow for us to
modify the output to mimic an analog signal.
• This is done by a technique called:
• Pulse Width Modulation (PWM)
Concepts: Analog vs. Digital
•To create an analog signal, the microcontroller uses a
technique called PWM. By varying the duty cycle, we
can mimic an “average” analog voltage.
•Pulse Width Modulation (PWM)
•analogWrite(pin, val);
•
•pin – refers to the OUTPUT pin
(limited to pins 3, 5, 6, 9, 10, 11.) –
denoted by a ~ symbol
•val – 8 bit value (0 – 255).
• 0 => 0V | 255 => 5V
Introducing a new command…
Move one of your LED pins over to Pin
9
• In Arduino, open up:
• File  Examples  01.Basics  Fade
Fade - Code Review
Fade - Code Review
Programming: Conditional Statements
if()
• void loop()
• {
• int buttonState =
digitalRead(5);
• if(buttonState == LOW)
• { // do something
• }
• else
• { // do something else
• }
• }
Programming: Conditional
Statements
if()
DIG
INPUT
Boolean Operators
<Boolean> Description
( ) == ( ) is equal?
( ) != ( ) is not equal?
( ) > ( ) greater than
( ) >= ( ) greater than or equal
( ) < ( ) less than
( ) <= ( ) less than or equal
analogRead()
• Arduino uses a 10-bit A/D Converter:
• this means that you get input values from 0
to 1023
• 0 V  0
• 5 V  1023
•Ex:
• int sensorValue = analogRead(A0);
Using Serial Communication
Method used to transfer data between two devices.
Arduino dedicates Digital I/O pin # 0 to
receiving and Digital I/O pin #1 to transmit.
Data passes between the computer and Arduino
through the USB cable. Data is transmitted as zeros
(‘0’) and ones (‘1’) sequentially.
Serial Monitor & analogRead()
Initializes the Serial
Communication
9600 baud data rate
prints data to serial bus
Serial Monitor & analogRead()
Opens up a Serial
Terminal Window
Additional Serial Communication
Sending a Message
void loop ( )
{
Serial.print(“Hands on “) ;
Serial.print(“Learning ”) ;
• Serial.println(“is Fun!!!”) ;
}
Serial Communication:
Serial Debugging
void loop()
{
int xVar = 10;
Serial.print ( “Variable xVar is “ ) ;
Serial.println ( xVar ) ;
}
Serial Communication:
Serial Troubleshooting
void loop ( )
{
Serial.print (“Digital pin 9: “);
Serial.println (digitalRead(9));
}
Fritzing View of Breadboard Circuit
•What happens
when you break the
circuit?
•What if you
wanted to add
more than one
LED?
Now Let’s Play With
Arduino
Program 1
Blinking of LED
void loop() {
digitalWrite(13, HIGH); // turn the LED
on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(13, LOW); // turn the LED
off by making the voltage LOW
delay(1000); // wait for a second }
void setup() {
// initialize digital pin 13 as an output.
pinMode(13, OUTPUT);
}
Program 2
Serial Blinking of LEDs
Program 3
Fading of LED
Program 4
Analog Voltage Measurement
Program 5
Traffic Signal Controller

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (20)

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
 
(D/A) and (A/D)conversion
(D/A) and (A/D)conversion(D/A) and (A/D)conversion
(D/A) and (A/D)conversion
 
Arduino: On-board components description, IDE and Programming
Arduino: On-board components description, IDE and Programming Arduino: On-board components description, IDE and Programming
Arduino: On-board components description, IDE and Programming
 
Arduino Workshop Day 1 - Basic Arduino
Arduino Workshop Day 1 - Basic ArduinoArduino Workshop Day 1 - Basic Arduino
Arduino Workshop Day 1 - Basic Arduino
 
1. Introduction to Embedded Systems & IoT
1. Introduction to Embedded Systems & IoT1. Introduction to Embedded Systems & IoT
1. Introduction to Embedded Systems & IoT
 
Embedded System Basics
Embedded System BasicsEmbedded System Basics
Embedded System Basics
 
8051 interfacing
8051 interfacing8051 interfacing
8051 interfacing
 
Pic 18 microcontroller
Pic 18 microcontrollerPic 18 microcontroller
Pic 18 microcontroller
 
Communication Interface of The Embedded Systems
Communication Interface of The Embedded Systems Communication Interface of The Embedded Systems
Communication Interface of The Embedded Systems
 
IoT sensing and actuation
IoT sensing and actuationIoT sensing and actuation
IoT sensing and actuation
 
DIGITAL SIGNAL PROCESSING
DIGITAL SIGNAL PROCESSINGDIGITAL SIGNAL PROCESSING
DIGITAL SIGNAL PROCESSING
 
Sensors in IOT
Sensors in IOTSensors in IOT
Sensors in IOT
 
Introduction to Arduino
Introduction to ArduinoIntroduction to Arduino
Introduction to Arduino
 
Arduino Uno Pin Description
Arduino Uno Pin DescriptionArduino Uno Pin Description
Arduino Uno Pin Description
 
VLSI Testing Techniques
VLSI Testing TechniquesVLSI Testing Techniques
VLSI Testing Techniques
 
RS 232
RS 232RS 232
RS 232
 
Serial buses
Serial busesSerial buses
Serial buses
 
Microcontroller presentation
Microcontroller presentationMicrocontroller presentation
Microcontroller presentation
 
TinyOS
TinyOSTinyOS
TinyOS
 
Arduino
ArduinoArduino
Arduino
 

Ähnlich wie Arduino Programming Familiarization

arduinocourse-180308074529 (1).pdf
arduinocourse-180308074529 (1).pdfarduinocourse-180308074529 (1).pdf
arduinocourse-180308074529 (1).pdf
ssusere5db05
 
Arduino Workshop (3).pptx
Arduino Workshop (3).pptxArduino Workshop (3).pptx
Arduino Workshop (3).pptx
HebaEng
 
teststststststLecture_3_2022_Arduino.pptx
teststststststLecture_3_2022_Arduino.pptxteststststststLecture_3_2022_Arduino.pptx
teststststststLecture_3_2022_Arduino.pptx
ethannguyen1618
 

Ähnlich wie Arduino Programming Familiarization (20)

Arduino
ArduinoArduino
Arduino
 
Starting with Arduino
Starting with Arduino Starting with Arduino
Starting with Arduino
 
Arduino Slides With Neopixels
Arduino Slides With NeopixelsArduino Slides With Neopixels
Arduino Slides With Neopixels
 
IOT beginnners
IOT beginnnersIOT beginnners
IOT beginnners
 
IOT beginnners
IOT beginnnersIOT beginnners
IOT beginnners
 
Fun with arduino
Fun with arduinoFun with arduino
Fun with arduino
 
Introduction to Arduino Microcontroller
Introduction to Arduino MicrocontrollerIntroduction to Arduino Microcontroller
Introduction to Arduino Microcontroller
 
arduinocourse-180308074529 (1).pdf
arduinocourse-180308074529 (1).pdfarduinocourse-180308074529 (1).pdf
arduinocourse-180308074529 (1).pdf
 
Arduino workshop
Arduino workshopArduino workshop
Arduino workshop
 
Basics of arduino uno
Basics of arduino unoBasics of arduino uno
Basics of arduino uno
 
Arduino Workshop (3).pptx
Arduino Workshop (3).pptxArduino Workshop (3).pptx
Arduino Workshop (3).pptx
 
teststststststLecture_3_2022_Arduino.pptx
teststststststLecture_3_2022_Arduino.pptxteststststststLecture_3_2022_Arduino.pptx
teststststststLecture_3_2022_Arduino.pptx
 
Introduction of Arduino Uno
Introduction of Arduino UnoIntroduction of Arduino Uno
Introduction of Arduino Uno
 
Arduino اردوينو
Arduino اردوينوArduino اردوينو
Arduino اردوينو
 
Embedded systems optimization memory requirments.pptx
Embedded systems optimization memory requirments.pptxEmbedded systems optimization memory requirments.pptx
Embedded systems optimization memory requirments.pptx
 
arduinoedit.pptx
arduinoedit.pptxarduinoedit.pptx
arduinoedit.pptx
 
INT4073 L07(Sensors and AcutTORS).pdf
INT4073 L07(Sensors and AcutTORS).pdfINT4073 L07(Sensors and AcutTORS).pdf
INT4073 L07(Sensors and AcutTORS).pdf
 
ARDUINO AND ITS PIN CONFIGURATION
 ARDUINO AND ITS PIN  CONFIGURATION ARDUINO AND ITS PIN  CONFIGURATION
ARDUINO AND ITS PIN CONFIGURATION
 
Introduction to Arduino Hardware and Programming
Introduction to Arduino Hardware and ProgrammingIntroduction to Arduino Hardware and Programming
Introduction to Arduino Hardware and Programming
 
Arduino Workshop Slides
Arduino Workshop SlidesArduino Workshop Slides
Arduino Workshop Slides
 

Mehr von Amit Kumer Podder

Mehr von Amit Kumer Podder (13)

Power Amplifier
Power AmplifierPower Amplifier
Power Amplifier
 
Familiarization of electronic equipment
Familiarization of electronic equipmentFamiliarization of electronic equipment
Familiarization of electronic equipment
 
Transducer
Transducer Transducer
Transducer
 
Arduino Programming on Motor Control
Arduino Programming on Motor ControlArduino Programming on Motor Control
Arduino Programming on Motor Control
 
8254 Programmable Interval Timer
8254 Programmable Interval Timer8254 Programmable Interval Timer
8254 Programmable Interval Timer
 
Dot Matrix LED Interfacing using 8255 PPI
Dot Matrix LED Interfacing using 8255 PPIDot Matrix LED Interfacing using 8255 PPI
Dot Matrix LED Interfacing using 8255 PPI
 
8086 Assembly Language and Serial Monitor Operation of 8086 Trainer Kit
8086 Assembly Language and Serial Monitor Operation of 8086 Trainer Kit8086 Assembly Language and Serial Monitor Operation of 8086 Trainer Kit
8086 Assembly Language and Serial Monitor Operation of 8086 Trainer Kit
 
8086 Micro-processor and MDA 8086 Trainer Kit
8086 Micro-processor and MDA 8086 Trainer Kit8086 Micro-processor and MDA 8086 Trainer Kit
8086 Micro-processor and MDA 8086 Trainer Kit
 
Traffic Light Controller using 8255
Traffic Light Controller using 8255Traffic Light Controller using 8255
Traffic Light Controller using 8255
 
8255 Programmble Peripheral Interface
8255 Programmble Peripheral Interface8255 Programmble Peripheral Interface
8255 Programmble Peripheral Interface
 
8085 Microprocessor Programming and Instruction set
8085 Microprocessor Programming and Instruction set8085 Microprocessor Programming and Instruction set
8085 Microprocessor Programming and Instruction set
 
Micro-processor, Micro-controller and Peripherals
Micro-processor, Micro-controller and PeripheralsMicro-processor, Micro-controller and Peripherals
Micro-processor, Micro-controller and Peripherals
 
Lecture on wire splicing and termination
Lecture on wire splicing and terminationLecture on wire splicing and termination
Lecture on wire splicing and termination
 

Kürzlich hochgeladen

Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Christo Ananth
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Christo Ananth
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
MsecMca
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
dharasingh5698
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
dollysharma2066
 

Kürzlich hochgeladen (20)

PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELLPVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
 
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)
 
Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...
 
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank  Design by Working Stress - IS Method.pdfIntze Overhead Water Tank  Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
 

Arduino Programming Familiarization

  • 1. Department of Electrical and Electronic Engineering Khulna University of Engineering & Technology Khulna-9203 Course code : EE 3214 Sessional on Microprocessors, Micro-controllers and Peripherals Presented By Amit Kumer Podder Experiment No. 09
  • 2. (a) Introduction to Arduino board and Arduino IDE (b) Design and implementation of blinking LED, analog voltage measurement, string operation and traffic controller projects in Arduino environment Experiment Name
  • 3. Arduino is a prototype platform (open-source) based on an easy- to-use hardware and software. It consists of a circuit board, which can be programed (referred to as a microcontroller) and a ready-made software called Arduino IDE (Integrated Development Environment), which is used to write and upload the computer code to the physical board. Arduino
  • 4. Arduino & Arduino Compatible Boards
  • 8. Settings: Tools  Serial Port •Your computer communicates to the Arduino microcontroller via a serial port  through a USB-Serial adapter. •Check to make sure that the drivers are properly installed.
  • 9. •Next, double-check that the proper board is selected under the ToolsBoard menu. Settings: Tools  Board
  • 10. Arduino Integrated Development Environment (IDE) Two required functions / methods / routines: void setup() { // runs once } void loop() { // repeats }error & status messages
  • 11. Comments, Comments, Comments • Comments are for you – the programmer and your friends…or anyone else human that might read your code. • // this is for single line comments • // it’s good to put a description at the top and before anything ‘tricky’ • /* this is for multi-line comments • Like this… • And this…. • */
  • 13. digitalWrite() analogWrite() digitalRead() if() statements / Boolean analogRead() Serial communication This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 United States License. BIG6CONCEPTS
  • 14. Three commands to know… • pinMode(pin, INPUT/OUTPUT); • ex: pinMode(13, OUTPUT); • digitalWrite(pin, HIGH/LOW); • ex: digitalWrite(13, HIGH); • delay(time_ms); • ex: delay(2500); // delay of 2.5 sec. • // NOTE: -> commands are CASE- sensitive
  • 15. Programming Concepts: Variables Variable Scope •Global •--- •Function-level
  • 16. Programming Concepts: Variable Types • Variable Types: 8 bits 16 bits 32 bits byte char int unsigned int long unsigned long float
  • 17. Fading in and Fading Out (Analog or Digital?) • A few pins on the Arduino allow for us to modify the output to mimic an analog signal. • This is done by a technique called: • Pulse Width Modulation (PWM)
  • 18. Concepts: Analog vs. Digital •To create an analog signal, the microcontroller uses a technique called PWM. By varying the duty cycle, we can mimic an “average” analog voltage. •Pulse Width Modulation (PWM)
  • 19. •analogWrite(pin, val); • •pin – refers to the OUTPUT pin (limited to pins 3, 5, 6, 9, 10, 11.) – denoted by a ~ symbol •val – 8 bit value (0 – 255). • 0 => 0V | 255 => 5V Introducing a new command…
  • 20. Move one of your LED pins over to Pin 9 • In Arduino, open up: • File  Examples  01.Basics  Fade
  • 21. Fade - Code Review
  • 22. Fade - Code Review
  • 23.
  • 25. • void loop() • { • int buttonState = digitalRead(5); • if(buttonState == LOW) • { // do something • } • else • { // do something else • } • } Programming: Conditional Statements if() DIG INPUT
  • 26. Boolean Operators <Boolean> Description ( ) == ( ) is equal? ( ) != ( ) is not equal? ( ) > ( ) greater than ( ) >= ( ) greater than or equal ( ) < ( ) less than ( ) <= ( ) less than or equal
  • 27. analogRead() • Arduino uses a 10-bit A/D Converter: • this means that you get input values from 0 to 1023 • 0 V  0 • 5 V  1023 •Ex: • int sensorValue = analogRead(A0);
  • 28. Using Serial Communication Method used to transfer data between two devices. Arduino dedicates Digital I/O pin # 0 to receiving and Digital I/O pin #1 to transmit. Data passes between the computer and Arduino through the USB cable. Data is transmitted as zeros (‘0’) and ones (‘1’) sequentially.
  • 29. Serial Monitor & analogRead() Initializes the Serial Communication 9600 baud data rate prints data to serial bus
  • 30. Serial Monitor & analogRead() Opens up a Serial Terminal Window
  • 31. Additional Serial Communication Sending a Message void loop ( ) { Serial.print(“Hands on “) ; Serial.print(“Learning ”) ; • Serial.println(“is Fun!!!”) ; }
  • 32.
  • 33. Serial Communication: Serial Debugging void loop() { int xVar = 10; Serial.print ( “Variable xVar is “ ) ; Serial.println ( xVar ) ; }
  • 34. Serial Communication: Serial Troubleshooting void loop ( ) { Serial.print (“Digital pin 9: “); Serial.println (digitalRead(9)); }
  • 35. Fritzing View of Breadboard Circuit •What happens when you break the circuit? •What if you wanted to add more than one LED?
  • 36. Now Let’s Play With Arduino
  • 37. Program 1 Blinking of LED void loop() { digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level) delay(1000); // wait for a second digitalWrite(13, LOW); // turn the LED off by making the voltage LOW delay(1000); // wait for a second } void setup() { // initialize digital pin 13 as an output. pinMode(13, OUTPUT); }