0% found this document useful (0 votes)
8 views

Arduino Presentation

Uploaded by

infopritam62
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Arduino Presentation

Uploaded by

infopritam62
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 49

IOT

EDUCATIONAL
BOARD

This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 United States License.
TOPICS TO BE DISCUSSED
 Arduno uno & pin
configuration
 Input output pins
 Analog & Digital Pins
 How to install arduino IDE
 Discuss basic C language
 Led blink projecT
 Error debugging in Arduino

This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 United States License.
ARDUINO
Introduction:-
Arduino is an open-source platform
used for building electronics projects.
Arduino consists of both a physical
programmable circuit board (often
referred to as a microcontroller) and a
piece of software, or IDE (Integrated
Development Environment) that runs on
your computer, used to write and upload
computer code to the physical board

This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 United States License.
PWR IN USB
(to Computer)

RESET

SCL\SDA
(I2C Bus)

POWER
5V / 3.3V / GND
Digital I\O
PWM(3, 5, 6, 9, 10, 11)

Analog
INPUTS

This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 United States License.
USB
(to Computer) PWR IN

Analog PIN Digital I\O


PWM(A1,A2,A3,
A4,A5,) PWM(SDA,SCL
8,9,10,11,12,13 )

SCL\SDA
(I2C Bus)

Digital PIN
PWM(0,1,2,3,4,5,6,7 )

Analog
INPUTS

POWER
5V / 3.3V / GND RESET
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 United States License.
Go ahead and plug your board in!

This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 United States License.
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 United States License.
Concepts: INPUT vs. OUTPUT

Referenced from the perspective of the microcontroller (electrical board).

Inputs is a signal / information Output is any signal exiting the


going into the board. board.

Almost all systems that use physical computing will have


some form of output

What are some examples of Outputs?


This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 United States License.
Concepts: INPUT vs. OUTPUT

Referenced from the perspective of the microcontroller (electrical board).

Inputs is a signal / information Output is any signal exiting the


going into the board. board.

Examples: Buttons Switches, Light Examples: LEDs, DC motor, servo


Sensors, Flex Sensors, Humidity motor, a piezo buzzer, relay, an RGB
Sensors, Temperature Sensors… LED

This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 United States License.
Concepts: Analog vs. Digital
Microcontrollers are digital devices – ON or OFF. Also
called – discrete.

analog signals are anything that can be a full range of


values. What are some examples? More on this later…

5V 5V

0V 0V

This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 United States License.
Open up Arduino

Hints:
For PC Users  For Mac Users 
1.Let the installer copy and 1. Move the Arduino
move the files to the executable to the dock
appropriate locations, or for ease of access.
2.Create a folder under C:\ 2. Resist the temptation to
Program Files (x86) called run these from your
Arduino. Move the entire desktop.
Arduino program folder here.

This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 United States License.
Arduino
Integrated Development Environment (IDE)

Two required functions /


methods / routines:

void setup()
{
// runs once
}

void loop()
{
// repeats
}

error & status messages


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.

This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 United States License.
Settings: Tools  Board

Next, double-check that the proper board is selected under the


ToolsBoard menu.

This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 United States License.
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 United States License.
Serial communication
analogRead()
if() statements / Boolean
digitalRead()
analogWrite() BIG 6 CONCEPTS
digitalWrite()
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….
*/

This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 United States License.
comments

This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 United States License.
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

This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 United States License.
Project #1: Wiring Diagram

Move the green


wire from the power
bus to pin 13 (or
any other Digital
I/O pin on the
Arduino board.

Image created in Fritzing

This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 United States License.
A few simple challenges
Let’s make LED#13 blink!

Challenge 1a – blink with a 200 ms second


interval.

Challenge 1b – blink to mimic a heartbeat

Challenge 1c – find the fastest blink that the


human eye can still detect…
1 ms delay? 2 ms delay? 3 ms delay???

This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 United States License.
Try adding other LEDs

This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 United States License.
Programming Concepts: Variables

Variable Scope

Global
---
Function-level

This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 United States License.
Programming Concepts: Variable Types

Variable Types:

8 bits 16 bits 32 bits

byte int long


char unsigned int unsigned long
float

This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 United States License.
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)

This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 United States License.
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)

This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 United States License.
Project #2 – Fading
Introducing a new command…

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

This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 United States License.
Move one of your LED pins over to Pin 9

In Arduino, open up:


File  Examples  01.Basics  Fade

This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 United States License.
Fade - Code Review

This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 United States License.
Fade - Code Review

This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 United States License.
RGB LED Color Mixing

int redPin = 5;
int greenPin = 6;
int bluePin = 9;

void setup()
{
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
}

This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 United States License.
RGB LED Color Mixing

void loop()
{
analogWrite(redPin, 255);
analogWrite (greenPin, 255);
analogWrite (bluePin, 255);
}

This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 United States License.
Project #4 – Digital Input

In Arduino, open up:


File  Examples  02.Digital  Button

This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 United States License.
Digital Sensors (a.k.a. Switches)
Pull-up Resistor (circuit)

to Digital Pin 2

This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 United States License.
Digital Sensors (a.k.a. Switches)
Add an indicator LED to Pin 13
This is just like our
1st circuit!

This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 United States License.
Digital Input

• Connect digital input to your Arduino using Pins # 0 – 13


(Although pins # 0 & 1 are also used for programming)

• Digital Input needs a pinMode command:


pinMode (pinNumber, INPUT);
Make sure to use ALL CAPS for INPUT

• To get a digital reading:


int buttonState = digitalRead
(pinNumber);

• Digital Input values are only HIGH (On) or LOW (Off)


This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 United States License.
Digital Sensors

• Digital sensors are more straight forward than Analog

• No matter what the sensor there are only two settings: On


and Off

• Signal is always either HIGH (On) or LOW (Off)

• Voltage signal for HIGH will be a little less than 5V on


your Uno

• Voltage signal for LOW will be 0V on most systems

This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 United States License.
http://opensourcehardwarejunkies.com/tutorial-03-digitalread-and-
serial-port-communication/
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 United States License.
Programming: Conditional Statements
if()

This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 United States License.
Programming: Conditional Statements
if()

void loop()
{
int buttonState = digitalRead(5);
if(buttonState == LOW)
{ // do something DIG
INPUT
}
else
{ // do something else
}
}
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 United States License.
analogRead()

Arduino uses a 10-bit A/D Converter:


• this means that you get input values from 0 to
1023
• 0V0
• 5 V  1023
Ex:
int sensorValue = analogRead(A0);

This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 United States License.
Using Serial Communication

Method used to transfer data between two devices.

Data passes between the computer and Arduino


through the USB cable. Data is transmitted as zeros
(‘0’) and ones (‘1’) sequentially.

Arduino dedicates Digital I/O pin # 0 to


receiving and Digital I/O pin #1 to transmit.

This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 United States License.
Serial Monitor & analogRead()

Initializes the Serial


Communication

9600 baud data rate


prints data to serial bus
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 United States License.
Serial Monitor & analogRead()

Opens up a
Serial Terminal
Window

This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 United States License.
Analog Sensors
2 Pin Analog Sensors = var. resistor

Take two sensors -- Use the


Serial Monitor and find the
range of input values you get
for each sensor.

MaxAnalogRead = _________

MinAnalogRead = _________

This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 United States License.
Analog Sensors

Examples:
Sensors Variables
Mic soundVolume
Photoresistor lightLevel
Potentiometer dialPosition
Temp Sensor temperature
Flex Sensor bend
Accelerometer tilt/acceleration

This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 United States License.
Additional Serial Communication
Sending a Message

void loop ( )
{
Serial.print(“Hands on “) ;
Serial.print(“Learning ”) ;
Serial.println(“is Fun!!!”) ;

}
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 United States License.
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 United States License.
Serial Communication:
Serial Debugging

void loop()
{
int xVar = 10;
Serial.print ( “Variable xVar is “ ) ;
Serial.println ( xVar ) ;
}

This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 United States License.
Serial Communication:
Serial Troubleshooting

void loop ( )
{
Serial.print (“Digital pin 9: “);
Serial.println (digitalRead(9));
}

This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 United States License.

You might also like