Lecture22 - Arduino - CSE 1
Lecture22 - Arduino - CSE 1
Arduino
Agenda
• Introduction to Arduino Boards
• Getting started with Arduino IDE
• Arduino Programming and Proteus designs
• Interfacing Output (LED) & Input (Key) devices
• Working with IR Sensor, LDR and its Interfacing
• Serial Communication feature of Arduino
• Working with DHT11/22 and its interfacing
• Ultrasonic Sensor Interfacing
• Microprocessor vs Microcontroller: Key Difference
• Microprocessor consists of only a Central Processing Unit, whereas Micro
Controller contains a CPU, Memory, I/O all integrated into one chip.
• Microprocessor is used in Personal Computers whereas Micro Controller is
used in an embedded system.
• Microprocessor uses an external bus to interface to RAM, ROM, and other
peripherals, on the other hand, Microcontroller uses an internal
controlling bus.
• Microprocessors are based on Von Neumann model Micro controllers are
based on Harvard architecture
• Microprocessor is complicated and expensive, with a large number of
instructions to process but Microcontroller is inexpensive and
straightforward with fewer instructions to process.
Microcontroller vs. Arduino
•The difference between an Arduino development board and a
microcontroller chip is that the development board contains almost
every essential part needed to start a project on the board itself.
•It has a microcontroller chip and ports for connection or extension.
•On the other hand, for a single microcontroller chip (such as
Atmega328 microcontroller), you need a lot of things. First, you need to
buy a separate programmer board to program the chip. For building a
project or experimentation with the chip, you need a breadboard for
circuit wiring/connections with other components, a DC power supply,
jumper wires, etc. You also need to search for program examples from
various sources, books, and the Internet.
What is Arduino?
• A microcontroller board, contains on-board power supply,
USB port to communicate with PC, and an Atmel
microcontroller chip.
• It simplify the process of creating any control system by
providing the standard board that can be programmed
and connected to the system without the need to any
sophisticated PCB design and implementation.
•Robotics. ...
•Wearable Technology. ...
•Educational Teaching. ...
•IoT. ...
•Data Logging. ...
•3D Mapping & Printing. ...
•Automated Gardening
Different types of Arduino boards:
https://getintopc.com/softwares/3d-cad/proteus-professional-2020-free-download/
Getting Started (Installing Arduino IDE and Setting up Arduino Board)
IDE =
Integrated Development
Environment
http://www.arduino.cc/en/Guide/Environ
ment
Arduino IDE (Cont..)
Two required functions /
methods / routines:
void setup()
{
// runs once
}
void loop()
{
// repeats
}
Arduino IDE (Cont..)
Your computer
communicates to the
Arduino microcontroller via a
serial port → through a USB-
Serial adapter.
pinMode(pin, mode);
Sets pin to either INPUT or OUTPUT
Eg1. pinMode(13, OUTPUT);
digitalRead(pin);
Reads HIGH or LOW from a pin
Eg3. digitalRead(2);
digitalWrite(pin, value);
Writes HIGH or LOW to a pin
Eg2. digitalWrite(13, HIGH);
Our first Arduino Sketch/Program
/*
* Arduinos ketch to toggle the LED connected to pin-13 with a rate/delay of 1sec
*/
void setup()
{
// put your setup code here, to run once: -->I*
pinMode(13, OUTPUT); //pin-13 configures as o/p -->II
}
void loop()
{
// put your main code here, to run repeatedly: -->1*
digitalWrite(13, HIGH); //HIGH Value or Bunary-1 send to pin-13 -->2
//delay(x); //x-ms second(s) delay -->3*
//delayMicroseconds(y); //y-us second(s) delay -->4*
delay(1000); //1000-milliseconds=1second delay -->5
digitalWrite(13, LOW); //LOW Value or Bunary-1 send to pin-13 -->6
delay(1000); //1000-milliseconds=1second delay -->7
//Toggling rate of led connected to pin-13 is of 1second -->8*
}
Uploading and Running the blink sketch
In Arduino, open up:
File → Examples → 01.Basics → Blink
const int ledPin = 13; // choose the pin for the LED
const int inputPin = 2; // choose the input pin (for a pushbutton)
void setup()
{
pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(inputPin, INPUT); // declare pushbutton as input
}
void loop()
{
int val = digitalRead(inputPin); // read input value
if (val == HIGH) // check if the input is HIGH
{
digitalWrite(ledPin, HIGH); // turn LED on if switch is pressed
}
else
{
digitalWrite(ledPin, LOW); // turn LED off
}
}
Proteus design (with external resister)
Using a key/push button with external resistor
The digitalRead function monitors the voltage on the input pin (inputPin),
and it returns a value of HIGH if the voltage is high (5 volts) and LOW if
the voltage is low (0 volts).
Actually, any voltage that is greater than 2.5 volts (half of the voltage
powering the chip) is considered HIGH and less than this is treated as LOW.
If the pin is left unconnected (known as floating) the value returned from
digitalRead is indeterminate (it may be HIGH or LOW, and it cannot be
reliably used).
The resistor shown in Figure shown in previous slide ensures that the
voltage on the pin will be low when the switch is not pressed, because the
resistor “pulls down” the voltage to ground.
When the switch is pushed, a connection is made between the pin and +5
volts, so the value on the pin interpreted by digital Read changes from LOW
to HIGH.