100% found this document useful (1 vote)
342 views14 pages

Unit-6: Arduino and Raspberry Pi

The document discusses programming the Arduino using the Arduino IDE software. It describes how to install the Arduino IDE, write code for a basic blinking LED example, compile and upload the code to an Arduino board. The code uses functions like pinMode(), digitalWrite(), and delay() to turn an LED on and off at one second intervals to make it blink. Uploading the code to the Arduino board causes the onboard LED to flash on and off every second, demonstrating a successful upload and run of the code.

Uploaded by

SAMPA
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
100% found this document useful (1 vote)
342 views14 pages

Unit-6: Arduino and Raspberry Pi

The document discusses programming the Arduino using the Arduino IDE software. It describes how to install the Arduino IDE, write code for a basic blinking LED example, compile and upload the code to an Arduino board. The code uses functions like pinMode(), digitalWrite(), and delay() to turn an LED on and off at one second intervals to make it blink. Uploading the code to the Arduino board causes the onboard LED to flash on and off every second, demonstrating a successful upload and run of the code.

Uploaded by

SAMPA
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/ 14

IOT and Applications

GTU # 3160716

Unit-6

Arduino and Raspberry Pi

Prof. Tushar J. Mehta


Computer Engineering Department
Darshan Institute of Engineering & Technology, Rajkot
[email protected]
8866756776
Arduino
Section - 1
Programming the Arduino
 Programming of Arduino is done in Arduino IDE – Integrated Development Environment.
 The software helps to connect, upload and communicate with Arduino hardware.
 The Arduino software is an open-source platform.
 The steps to install the Arduino software into the computer are as following:
 Download Arduino IDE from http://arduino.cc/en/Main/Software

Prof. Tushar J Mehta #3160716 (IoT and Applications)  Unit 6 – Arduino and Raspberry Pi 3
Installation process of Arduino
 After downloading the installer
double click and install the software
by agreeing to License Agreement.
 Select the components required to
be installed and click on next. Make
sure to have free space in hard drive
which is mentioned in the software.
 Select the path where you want to
install Arduino IDE and click on
“Install”
 Now wait for few minutes until
installation process gets completed.
 The dialogue box will show the
“Completed” status of the
installation. Click on “Close” button.

Prof. Tushar J Mehta #3160716 (IoT and Applications)  Unit 6 – Arduino and Raspberry Pi 4
Arduino IDE Explanation
 Open Arduino IDE software. Here, 4
we can find different sections. 3
1. Editor – It is the space where we can
write the code
2. A text Console – for displaying the
messages.
1
3. A toolbar with buttons – given for
common functions to perform.
4. Menu bar – A menu bar with series
of menus
 Note that, the name of the default
file is sketch_[currentdate] with the 2
alphabet ‘a’ and every new file has
consecutive alphabet.

Prof. Tushar J Mehta #3160716 (IoT and Applications)  Unit 6 – Arduino and Raspberry Pi 5
Arduino IDE Explanation – Cont.
 The functions of buttons in toolbar can be explained as following:

Verify Open
Checks your code for errors compiling it. Presents a menu of all the sketches in your
sketchbook. Clicking one will open it within the current
window overwriting its content.

Upload Save
Compiles your code and uploads it to the configured board. Saves your sketch.

New Serial Monitor


Creates a new sketch. Opens the serial monitor.

Prof. Tushar J Mehta #3160716 (IoT and Applications)  Unit 6 – Arduino and Raspberry Pi 6
Programming the First Code
 The IDE is already loaded with few basic examples. Let us take a basic example of LED blinking
which blinks built-in LED of Arduino UNO with a 1-second interval.
 Go to File > Examples > 01.Basics > Blink as shown in the figure.
 It will load the prewritten example in a new window with the title “Blink”.

Prof. Tushar J Mehta #3160716 (IoT and Applications)  Unit 6 – Arduino and Raspberry Pi 7
Code Explanation

Blink.ino
1 void setup() { Initialize digital pin LED_BUILTIN which is at pin 13
2   pinMode(LED_BUILTIN, OUTPUT); as an output.
3 }
4 void loop() { turn ON the LED by writing HIGH voltage level
5   digitalWrite(LED_BUILTIN, HIGH); 
6   delay(1000); A delay of 1000ms = 1 sec
7   digitalWrite(LED_BUILTIN, LOW); turn OFF the LED by writing LOW voltage level
8   delay(1000);
9 } A delay of 1000ms = 1 sec
 We should initialize the pin as input or output once only. Therefore the syntax for defining the
pin as output is written in void setup ( ) function.
 For blinking of LED, the LED should turn on and off at the regular interval of time. Hence, the
instructions for turning on, turning off and delay for both on time and off time are written in the
void loop ( ) function
Prof. Tushar J Mehta #3160716 (IoT and Applications)  Unit 6 – Arduino and Raspberry Pi 8
Code Explanation
 Arduino code is always written with two mandatory functions.
 void setup ( )
 void loop ( )
 The instructions which are to be performed once in the program are written in void setup ( )
function.
 The instructions written in void loop ( ) are executed infinite times until the next restart of
Arduino board.

 Comments are important for any programming language. They are ignored while execution of
the program
 Anything written after // in Arduino program is considered as a single line comment
 Anything written between /* and */ is considered as multiple line comments.

Prof. Tushar J Mehta #3160716 (IoT and Applications)  Unit 6 – Arduino and Raspberry Pi 9
Functions in Arduino IDE
 pinMode( ): Configures the specified pin to behave either as an input or an output.
 Syntax : pinMode(pin, mode)
 Parameters :
 pin: the Arduino pin number to set the mode of.
 Mode: INPUT or OUTPUT
 digitalWrite( ) : Write a HIGH or a LOW value to a digital pin.
 Syntax : digitalWrite(pin, value)
 Parameters :
 pin : the Arduino pin number.
 Mode : HIGH or LOW
 What is HIGH or LOW?
 HIGH: - Also considered as Logic ‘1’ or Logic High. It will set 5V on the configured pin of Arduino.
 LOW: - Also considered as Logic ‘0’ or Logic Low. It will set 0V on the configured pin of Arduino.

Prof. Tushar J Mehta #3160716 (IoT and Applications)  Unit 6 – Arduino and Raspberry Pi 10
Functions in Arduino IDE (Cont.)
 delay( ): It pauses the program for the amount of time (in milliseconds) specified as the
parameter. For example, if we want to hold the program for 1 second before executing the next
instruction. A delay of 1000ms = 1s is passed in the parameter.
 Syntax : delay(ms)
 Parameters :
 ms: the number of milliseconds to pause

Prof. Tushar J Mehta #3160716 (IoT and Applications)  Unit 6 – Arduino and Raspberry Pi 11
Compiling the Code
 To compile a code in Arduino click on
the “Verify” button in menu bar.
 While compiling the code, a message
“Compiling sketch” is shown with its
progress in the status bar.
 If there is no error in the code, the
message “Done compiling” is displayed
in the status bar.
 If an error is present in the code it will
show the message of error with
highlighted syntax where the error is
present.

Prof. Tushar J Mehta #3160716 (IoT and Applications)  Unit 6 – Arduino and Raspberry Pi 12
Upload the first code in Arduino Hardware
 Select the proper board type: First, we
need to select the appropriate board
type in which we need to upload the
program.
 Go to Tools > Board menu and select
the board which is used as the
hardware.
 Select port: Select the serial device of
the board from the Tools > Port menu.
 This is likely to be COM3 or higher
(COM1 and COM2 are usually reserved
for hardware serial ports).
 Upload the program: Now, simply click
the "Upload" button in the environment.

Prof. Tushar J Mehta #3160716 (IoT and Applications)  Unit 6 – Arduino and Raspberry Pi 13
Upload the first code in Arduino Hardware
 While uploading process, TX and RX
LED will be flashing.
 If uploading is done successfully, it will
show a message “Done uploading” in
the status bar.
 Once the program is uploaded, the built-
in LED of the Arduino board will flash
with one second delay.
 It means LED turns ON for 1 second and
LED turns OFF for 1 second.

Prof. Tushar J Mehta #3160716 (IoT and Applications)  Unit 6 – Arduino and Raspberry Pi 14

You might also like