0% found this document useful (0 votes)
54 views19 pages

IOT Programing: Sketch The First New Terminology Is The

The document discusses Internet of Things (IoT) programming for Arduino. It covers key concepts like sketches, functions (setup and loop), data types (boolean, char, integers), variables, operators, and provides an example of blinking an LED using the Arduino IDE. The example connects an LED to Arduino with a resistor on a breadboard and uses the setup and loop functions with digitalWrite and delay commands to turn the LED on and off to create a blinking pattern.

Uploaded by

annaparthi divya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views19 pages

IOT Programing: Sketch The First New Terminology Is The

The document discusses Internet of Things (IoT) programming for Arduino. It covers key concepts like sketches, functions (setup and loop), data types (boolean, char, integers), variables, operators, and provides an example of blinking an LED using the Arduino IDE. The example connects an LED to Arduino with a resistor on a breadboard and uses the setup and loop functions with digitalWrite and delay commands to turn the LED on and off to create a blinking pattern.

Uploaded by

annaparthi divya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 19

IOT programing

Sketch − The first new terminology is the


Arduino program called “sketch”.

Arduino programs can be divided in three


main parts:
Structure,
Values
Functions.
Structure:
Software structure consist of two main functions
• Setup( ) function
• Loop( ) function
setup() function:
• The setup() function is called when a sketch
starts.
• Use it to initialize the variables, pin modes,
start using libraries, etc.
• The setup function will only run once, after
each power up or reset of the Arduino board.
Loop() function:
• After creating a setup() function, which
initializes and sets the initial values,
the loop() function does precisely what its
name suggests, and loops consecutively,
allowing your program to change and
respond.
• Use it to actively control the Arduino board.
Void:
The void keyword is used only in function declarations. It
indicates that the function is expected to return no
information to the function from which it was called.
Example:
Void loop ( )
{
// rest of the code
}
Boolean:
A Boolean holds one of two values, true or false. Each Boolean
variable occupies one byte of memory.
Example:
boolean val = false ;
boolean state = true ;
Char:
• A data type that takes up one byte of memory that stores a
character value.
• Character literals are written in single quotes like this: 'A' and for
multiple characters, strings use double quotes: "ABC".
Example:
Char chr_a = ‘a’ ;
Unsigned char:
It is an unsigned data type that occupies one byte of
memory.
The unsigned char data type encodes numbers from 0 to
255.
Example:
Unsigned Char chr_y = 121 ;
Byte:
A byte stores an 8-bit unsigned number, from 0 to 255.
Example:
byte m = 25 ;
Integers:
Integers are the primary data-type for number
storage.
Int stores a 16-bit (2-byte) value. This yields a range
of -32,768 to 32,767.
The int size varies from board to board. On the
Arduino Due, for example, an int stores a 32-bit (4-
byte) value.
Unsigned int:

• Unsigned integers are the same as int in the way


that they store a 2 byte value.
• Instead of storing negative numbers, however,
they only store positive values, yielding a useful
range of 0 to 65,535 (2^16) - 1).
• The Due stores a 4 byte (32-bit) value, ranging
from 0 to 4,294,967,295 (2^32 - 1).
Example:
Unsigned int counter = 60 ;
Word:
• On the Uno and other ATMEGA based boards, a word stores
a 16-bit unsigned number.
• On the Due and Zero, it stores a 32-bit unsigned number.
Example:
word w = 1000;
Long:
• Long variables are extended size variables for number
storage, and store 32 bits (4 bytes), from -2,147,483,648 to
2,147,483,647.
Example:
Long velocity = 102346
Unsigned long:
Unsigned long variables are extended size
variables for number storage and store 32 bits
(4 bytes).
Unlike standard longs, unsigned longs will not
store negative numbers, making their range
from 0 to 4,294,967,295 (2^32 - 1).
Example:
Unsigned Long velocity = 101006 ;
Short:
A short is a 16-bit data-type. On all Arduinos (ATMega and ARM
based), a short stores a 16-bit (2-byte) value. This yields a range of -
32,768 to 32,767 (minimum value of -2^15 and a maximum value of
(2^15) - 1).
Example:
short val = 13 ;
Float:
• Data type for floating-point number is a number that has a decimal
point.
• Floating-point numbers can be as large as 3.4028235E+38 and as
low as -3.4028235E+38. They are stored as 32 bits (4 bytes) of
information.
Example:
• float num = 1.352;
double:
• On the Uno and other ATMEGA based boards,
Double precision floating-point number occupies
four bytes. That is, the double implementation is
exactly the same as the float, with no gain in
precision.
• On the Arduino Due, doubles have 8-byte (64 bit)
precision.
Example:
double num = 45.352 ;
Variables:
• Inside a function or a block, which is
called local variables.
• In the definition of function parameters,
which is called formal parameters.
• Outside of all functions, which is called global
variables.
Operators:

• Arithmetic Operators
• Comparison Operators
• Boolean Operators
• Bitwise Operators
• Compound Operators
Arduino setup for led blinking:

Components Required:
You will need the following components
• 1 × Breadboard
• 1 × Arduino Uno R3
• 1 × LED
• 1 × 330Ω Resistor
• 2 × Jumper
Components like resistors need to have their
terminals bent into 90° angles in order to fit
the breadboard sockets properly. You can also
cut the terminals shorter.
Program for led blinking:
/* Blink Turns on an LED on for one second, then off for one second, repeatedly. */
// the setup function runs once when you press reset or power the board
void setup()
{
// initialize digital pin 13 as an output.
pinMode(2, OUTPUT);
}
// the loop function runs over and over again forever
void loop()
{
digitalWrite(2, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(2, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}

You might also like