SlideShare a Scribd company logo
Lesson-4-Arduino-Programming-dsBasics.pdf
WHAT IS A PROGRAM
 is a written programming language which enables a computer to
perform its function. Therefore, a program is a written instruction that
process input, manipulate data, and output a result.
Arduino uses C / C++ Programming language. C was created by
Dennis Ritchie between 1969 -1973 and in 1979, Bjarne Stroustrup
created C with classes known as C++.
Both programming languages are still popular in programming
microcontrollers. In programming, we use a combination of letters,
words, and symbols, which are known as Tokens. All written codes will
go through a compiler to convert it to machine language.
Transducers
A Transducer is a device that converts energy from one form to
another. These devices are often used for automation,
measurement, and control system.
Sensors - are transducers that receive signals or stimulus from an
environment or physical system. Converts stimulus into electrical
signal.
Actuators - are transducers that actuate or move something -
converting electrical signal into actions.
Types of Signal
Analog - It can take up any number of values
or readings (Ex. Temperature)
Digital - It is represented by 2 values: either High
or Low or On or Off
Programming Syntax
Syntax refers to a set of rules used to determine if a
certain group of words forms a valid sentence - which is
also true in computer programming.
Arduino follows the C/C++ language. These two
programming languages use the same syntax.
void setup{ }
Void setup is technically a function that you create at the
top of each program. Inside the curly brackets is the
code that you want to run one time as soon as the
program starts running. You set things like pinMode in this
section.
void loop { }
The void loop is a function that Arduino integrates as a part of its
structure. Every command that is inside the loop will run
continuously as long as the microcontroller is turned on.
; (semicolon)
Signifies an end on the command line. Since the compiler does
not read spaces in the program, it looks for semicolons to read
every end of the statements.
{ } curly braces
A group of code statements. When troubleshooting your
program, always check first the curly braces if all opening curly
braces have partner closing curly braces.
() parentheses
A group of arguments for a function, a method, or a code
statement. Since programming languages follow PEMDAS
(Parenthesis, Equation, Multiplication, Division, Addition,
Subtraction), you can also use it to group math within equations.
Ex. random( (5-2), (480 - 220));With the example above, the result
will be: random(3,260);
Lesson-4-Arduino-Programming-dsBasics.pdf
// single line comment
When you type two forward slashes, the compiler ignores the
code from that point until the end of the line. Use comments to
clarify what the code does, to remember how the hardware is
connected, or to delete code from the software without
removing it entirely.
/* multi-line comment */
A multi-line comment needs to have /* as its opening and */ as
its closing. All characters between the symbols will be
considered as a comment. When you have a lot to type, use a
multi-line comment to make it easier to group the information
together.
Lesson-4-Arduino-Programming-dsBasics.pdf
Variables
A variable can store data from a sensor or results in a calculation.
These variables can then be called for later use in the program.
Lesson-4-Arduino-Programming-dsBasics.pdf
Using and Naming a Variable
Creating a Variable; To create a variable in C/C++. We must follow
these basic steps:
Declaration - before a variable is used, we need to declare it first to
inform the compiler about the data type and size. The syntax in
declaring a variable is simple:
Type the data type - for example, "int" for integer type of data.
Followed by the identifier or the name of the variable
In naming a variable, we must be mindful of the following:
Its name must start with a letter.
It may contain letters, numbers, and the underscore character.
It should not be a reserved word in the Arduino IDE.
It should not contain white spaces.
 Initialization of Variables - after declaring the variable, its value is set to default unless we assign
value to it. It is also possible to place value on the variable from the moment that it is declared.
 We created 1 variable to store pin number of the LED that we will use for the activity – led_1
Programming a circuit
Void setup is technically a function that you create at the top of
each program. Every code that is inside the curly braces will run
once as soon as the program starts running.
The pinMode command is usually placed here so that the
microcontroller reads the pin assignment first before running
other commands.
The setup() runs once when the Arduino is first powered on.
 The pinMode() function is used to configure a specific pin to behave either as an input or an output.
 Since the variable led1 is initialized with the value 2, we are configuring pin 2 as an Output.
 Note: We can directly put pin 2 to the setup without having a variable for it. It is also beneficial if we
are saving Arduino's memory.
 Void loop is another function that Arduino uses as part of its structure. The code inside the loop
function runs over and over if the Maker Board is turned on.
digitalWrite();
digitalWrite() is the command that allows you to send 5V or 0V
to an output pin. It takes two arguments: what pin to control,
and what value to set that pin, HIGH or LOW.
delay();
The delay() function lets you stop the Arduino from executing
anything for a period of time. delay() takes an argument that
determines the number of milliseconds before it executes the
next set of code. There are 1000 milliseconds in one second,
delay (250) will pause for a quarter of a second.
Lesson-4-Arduino-Programming-dsBasics.pdf

More Related Content

PPTX
Introduction to Arduino Microcontroller
PPTX
Ch_2_8,9,10.pptx
PDF
Arduino for Beginners
PPT
Arduino Platform with C programming.
PDF
Arduino IDE
PDF
Arduino - Module 1.pdf
PDF
Intro to Arduino Programming.pdf
PDF
arduino
Introduction to Arduino Microcontroller
Ch_2_8,9,10.pptx
Arduino for Beginners
Arduino Platform with C programming.
Arduino IDE
Arduino - Module 1.pdf
Intro to Arduino Programming.pdf
arduino

Similar to Lesson-4-Arduino-Programming-dsBasics.pdf (20)

PDF
Ardx eg-spar-web-rev10
PDF
4 IOT 18ISDE712 MODULE 4 IoT Physical Devices and End Point-Aurdino Uno.pdf
PPTX
Arduino board program for Mobile robotss
PPSX
Arduino by yogesh t s'
PDF
[Apostila] programação arduíno brian w. evans
PPT
Arduino Section Programming - from Sparkfun
PPTX
Programming with arduino
PDF
Syed IoT - module 5
DOCX
Arduino and Circuits.docx
PPTX
KEY
Hello Arduino.
PPTX
Introduction to the Arduino
PDF
aurduino-200107075953.pdf
PPTX
Arduino: On-board components description, IDE and Programming
PPTX
Introduction to Arduino Hardware and Programming
PDF
Arduino programming
PPT
Arduino_CSE ece ppt for working and principal of arduino.ppt
PPT
Arduino section programming slides
Ardx eg-spar-web-rev10
4 IOT 18ISDE712 MODULE 4 IoT Physical Devices and End Point-Aurdino Uno.pdf
Arduino board program for Mobile robotss
Arduino by yogesh t s'
[Apostila] programação arduíno brian w. evans
Arduino Section Programming - from Sparkfun
Programming with arduino
Syed IoT - module 5
Arduino and Circuits.docx
Hello Arduino.
Introduction to the Arduino
aurduino-200107075953.pdf
Arduino: On-board components description, IDE and Programming
Introduction to Arduino Hardware and Programming
Arduino programming
Arduino_CSE ece ppt for working and principal of arduino.ppt
Arduino section programming slides
Ad

More from unicaeli2020 (10)

PDF
gen chem.pdf gen chem.pdfgen chem.pdfgen chem.pdf
PPTX
GENDER ROLEpptxd d d d d d d d d d d d d d d
PPTX
Lesson-2-Earth-Subsystem.pptxnnn nn nn jn
PDF
Lesson-3-Advance-Spreadsheet (1).pdfmmm mmm
PDF
Lesson-2-Cyber-Security.pdf"Chemistry: The Invisible Force Shaping Our World."
PPT
Biological-Macromolecules-Week-7 b b .ppt
PPTX
TEST ON ANALOGY.pptx dd dd dd d d d d d
PPTX
Presentation1 (1).pptx englishy.........
PPTX
Noli-Me-Tangere-Kabanata-51-at-52.pptx
PPTX
Pollution and Road Safety Grade 10 Health 2nd Grading
gen chem.pdf gen chem.pdfgen chem.pdfgen chem.pdf
GENDER ROLEpptxd d d d d d d d d d d d d d d
Lesson-2-Earth-Subsystem.pptxnnn nn nn jn
Lesson-3-Advance-Spreadsheet (1).pdfmmm mmm
Lesson-2-Cyber-Security.pdf"Chemistry: The Invisible Force Shaping Our World."
Biological-Macromolecules-Week-7 b b .ppt
TEST ON ANALOGY.pptx dd dd dd d d d d d
Presentation1 (1).pptx englishy.........
Noli-Me-Tangere-Kabanata-51-at-52.pptx
Pollution and Road Safety Grade 10 Health 2nd Grading
Ad

Recently uploaded (20)

PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Sensors and Actuators in IoT Systems using pdf
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
madgavkar20181017ppt McKinsey Presentation.pdf
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
PDF
CIFDAQ's Market Wrap: Ethereum Leads, Bitcoin Lags, Institutions Shift
PDF
Chapter 2 Digital Image Fundamentals.pdf
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
KodekX | Application Modernization Development
PDF
Modernizing your data center with Dell and AMD
Review of recent advances in non-invasive hemoglobin estimation
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
MYSQL Presentation for SQL database connectivity
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Reach Out and Touch Someone: Haptics and Empathic Computing
Diabetes mellitus diagnosis method based random forest with bat algorithm
“AI and Expert System Decision Support & Business Intelligence Systems”
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Sensors and Actuators in IoT Systems using pdf
Spectral efficient network and resource selection model in 5G networks
madgavkar20181017ppt McKinsey Presentation.pdf
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Advanced methodologies resolving dimensionality complications for autism neur...
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
CIFDAQ's Market Wrap: Ethereum Leads, Bitcoin Lags, Institutions Shift
Chapter 2 Digital Image Fundamentals.pdf
20250228 LYD VKU AI Blended-Learning.pptx
KodekX | Application Modernization Development
Modernizing your data center with Dell and AMD

Lesson-4-Arduino-Programming-dsBasics.pdf

  • 2. WHAT IS A PROGRAM  is a written programming language which enables a computer to perform its function. Therefore, a program is a written instruction that process input, manipulate data, and output a result. Arduino uses C / C++ Programming language. C was created by Dennis Ritchie between 1969 -1973 and in 1979, Bjarne Stroustrup created C with classes known as C++. Both programming languages are still popular in programming microcontrollers. In programming, we use a combination of letters, words, and symbols, which are known as Tokens. All written codes will go through a compiler to convert it to machine language.
  • 3. Transducers A Transducer is a device that converts energy from one form to another. These devices are often used for automation, measurement, and control system. Sensors - are transducers that receive signals or stimulus from an environment or physical system. Converts stimulus into electrical signal. Actuators - are transducers that actuate or move something - converting electrical signal into actions.
  • 4. Types of Signal Analog - It can take up any number of values or readings (Ex. Temperature) Digital - It is represented by 2 values: either High or Low or On or Off
  • 5. Programming Syntax Syntax refers to a set of rules used to determine if a certain group of words forms a valid sentence - which is also true in computer programming. Arduino follows the C/C++ language. These two programming languages use the same syntax. void setup{ } Void setup is technically a function that you create at the top of each program. Inside the curly brackets is the code that you want to run one time as soon as the program starts running. You set things like pinMode in this section.
  • 6. void loop { } The void loop is a function that Arduino integrates as a part of its structure. Every command that is inside the loop will run continuously as long as the microcontroller is turned on.
  • 7. ; (semicolon) Signifies an end on the command line. Since the compiler does not read spaces in the program, it looks for semicolons to read every end of the statements.
  • 8. { } curly braces A group of code statements. When troubleshooting your program, always check first the curly braces if all opening curly braces have partner closing curly braces. () parentheses A group of arguments for a function, a method, or a code statement. Since programming languages follow PEMDAS (Parenthesis, Equation, Multiplication, Division, Addition, Subtraction), you can also use it to group math within equations. Ex. random( (5-2), (480 - 220));With the example above, the result will be: random(3,260);
  • 10. // single line comment When you type two forward slashes, the compiler ignores the code from that point until the end of the line. Use comments to clarify what the code does, to remember how the hardware is connected, or to delete code from the software without removing it entirely. /* multi-line comment */ A multi-line comment needs to have /* as its opening and */ as its closing. All characters between the symbols will be considered as a comment. When you have a lot to type, use a multi-line comment to make it easier to group the information together.
  • 12. Variables A variable can store data from a sensor or results in a calculation. These variables can then be called for later use in the program.
  • 14. Using and Naming a Variable Creating a Variable; To create a variable in C/C++. We must follow these basic steps: Declaration - before a variable is used, we need to declare it first to inform the compiler about the data type and size. The syntax in declaring a variable is simple: Type the data type - for example, "int" for integer type of data. Followed by the identifier or the name of the variable In naming a variable, we must be mindful of the following: Its name must start with a letter. It may contain letters, numbers, and the underscore character. It should not be a reserved word in the Arduino IDE. It should not contain white spaces.
  • 15.  Initialization of Variables - after declaring the variable, its value is set to default unless we assign value to it. It is also possible to place value on the variable from the moment that it is declared.  We created 1 variable to store pin number of the LED that we will use for the activity – led_1
  • 16. Programming a circuit Void setup is technically a function that you create at the top of each program. Every code that is inside the curly braces will run once as soon as the program starts running. The pinMode command is usually placed here so that the microcontroller reads the pin assignment first before running other commands. The setup() runs once when the Arduino is first powered on.
  • 17.  The pinMode() function is used to configure a specific pin to behave either as an input or an output.  Since the variable led1 is initialized with the value 2, we are configuring pin 2 as an Output.  Note: We can directly put pin 2 to the setup without having a variable for it. It is also beneficial if we are saving Arduino's memory.  Void loop is another function that Arduino uses as part of its structure. The code inside the loop function runs over and over if the Maker Board is turned on.
  • 18. digitalWrite(); digitalWrite() is the command that allows you to send 5V or 0V to an output pin. It takes two arguments: what pin to control, and what value to set that pin, HIGH or LOW.
  • 19. delay(); The delay() function lets you stop the Arduino from executing anything for a period of time. delay() takes an argument that determines the number of milliseconds before it executes the next set of code. There are 1000 milliseconds in one second, delay (250) will pause for a quarter of a second.