2. 6/22/2018 2
Ahmed Elwali
BME 7022 & ECE 4610
Ahmed Elwali
BME 7022 & ECE 4610
Objectives
Introducing Arduino
Arduino UNO (Hardware & specs)
Arduino IDE
Variable & function declaration
Data types
Statement & operators
Control statements
Inputs and outputs
Oscilloscope software
3. 6/22/2018 3
Ahmed Elwali
BME 7022 & ECE 4610
Ahmed Elwali
BME 7022 & ECE 4610
Micro-Controller
A programmable device (chip)
Like a mini-computer as it has internal CPU,
RAM, ROM, and IOs interface.
Used for control purposes, and data analysis.
Famous microcontroller manufacturers are
MicroChip, Atmel, Intel, Motorola, and more.
4. 6/22/2018 4
Ahmed Elwali
BME 7022 & ECE 4610
Ahmed Elwali
BME 7022 & ECE 4610
Arduino
It is a Microcontroller board, contains microcontroller chip (Atmel), USB port to communicate
with PC, oscillator, regulator, wireless module, etc.
It makes our life easier with removing many sophisticated issues regarding PCB design and
implementation.
You can use it during development and testing but not for production.
It has a lot of predeveloped modules/sensors with their codes (life is much easier!)
It has a lot of versions, Uno, YUN, Mega, etc.
5. 6/22/2018 5
Ahmed Elwali
BME 7022 & ECE 4610
Ahmed Elwali
BME 7022 & ECE 4610
Arduino Uno (Hardware and Specs)
Microcontroller: ATmega 328
Operating Voltage 5V
Input Voltage (recommended) 7-12V
Input Voltage (limits) 6-20V
Digital I/O Pins 14 (of which 6 provide PWM output)
Analog Input Pins 6
DC Current per I/O Pin 40 mA
DC Current for 3.3V Pin 50 mA
Clock Speed 16 MHz
Reset pin 0 input
Analog sampling rate 10000 s/sec
6. 6/22/2018 6
Ahmed Elwali
BME 7022 & ECE 4610
Ahmed Elwali
BME 7022 & ECE 4610
Getting Started
Check out: http://arduino.cc/en/Guide/HomePage
1. Download & install the Arduino environment (IDE) (not needed in lab)
2. Connect the board to your computer via the USB cable
3. If needed, install the drivers (not needed in lab)
4. Launch the Arduino IDE
5. Select your board
6. Select your serial port
7. Open the blink example
8. Upload the program
9. Observe the results
7. 6/22/2018 7
Ahmed Elwali
BME 7022 & ECE 4610
Ahmed Elwali
BME 7022 & ECE 4610
Arduino IDE
Button Bar
Input/Edit area
Status bar
Program notification area
8. 6/22/2018 8
Ahmed Elwali
BME 7022 & ECE 4610
Ahmed Elwali
BME 7022 & ECE 4610
Select Serial Port, Board, and Example
11. 6/22/2018 11
Ahmed Elwali
BME 7022 & ECE 4610
Ahmed Elwali
BME 7022 & ECE 4610
Arduino Coding (Data Types)
•boolean (8 bit) - simple logical true/false
•byte (8 bit) - unsigned number from 0-255
•char (8 bit) - signed number from -128 to 127
•unsigned char (8 bit) - same as ‘byte’
•word (16 bit) - unsigned number from 0-65535
•unsigned int (16 bit)- the same as ‘word’.
•int (16 bit) - signed number from -32768 to 32767.
•unsigned long (32 bit) - unsigned number from 0-4,294,967,295.
•long (32 bit) - signed number from -2,147,483,648 to 2,147,483,647
•float (32 bit) - signed number from -3.4028235E38 to 3.4028235E38.
12. 6/22/2018 12
Ahmed Elwali
BME 7022 & ECE 4610
Ahmed Elwali
BME 7022 & ECE 4610
Statement and Operators
To get most of the useful information about Arduino:
◦ Login to www.Arduino.cc then press on the tab bar Learning then Reference
; (semicolon), {} (curly braces), // (single line comment), and
/* */ (multi-line comment)
Arithmetic Operators
= (assignment operator), + (addition), - (subtraction), * (multiplication), / (division), and % (modulo)
Comparison Operators
== (equal to), != (not equal to), < (less than), > (greater than), <= (less than or equal to), and >=
Boolean Operators
&& (and), || (or), and ! (not)
14. 6/22/2018 14
Ahmed Elwali
BME 7022 & ECE 4610
Ahmed Elwali
BME 7022 & ECE 4610
Input and outputs
pinMode(no. of the digital pin , status); // status (OUTPUT, INPUT) , setup
digitalWrite(no. of the digital pin , value); // value (HIGH, LOW)
digitalRead(no. of the digital pin);
analogRead(no. of the analog pin); // 10 bits ADC, with max sampling rate 10000 sample/sec. Read
Positive part only.
analogWrite(no. of the PWM pin , value); // (frequency ~= 500 Hz) and values from 0-255
// delay(value); // milliseconds. // delayMicroseconds(value);
// Activate the serial port:
Serial.begin(baud-Rate); // baud-Rate (bit per seconds), setup
Serial.println(value)
Serial.write(value) // serial.avilable() // serial.read()
15. 6/22/2018 15
Ahmed Elwali
BME 7022 & ECE 4610
Ahmed Elwali
BME 7022 & ECE 4610
Supplying (driving) outputs or inputs
Maximum current for each pin to sink or drain is 40 mA.
Motor
Pull down Pull up
High current consumption >40 mA
Out
Out
Out
16. 6/22/2018 16
Ahmed Elwali
BME 7022 & ECE 4610
Ahmed Elwali
BME 7022 & ECE 4610
Push button and bouncing problem
Noise due to mechanical vibrations
IN
17. 6/22/2018 17
Ahmed Elwali
BME 7022 & ECE 4610
Ahmed Elwali
BME 7022 & ECE 4610
Analog output (PWM)
analogWrite(no. of the PWM pin, value); // (frequency ~= 500 Hz) and values from 0-255
output voltage = (on_time / cycle_time) * 5V
PWMin
18. 6/22/2018 18
Ahmed Elwali
BME 7022 & ECE 4610
Ahmed Elwali
BME 7022 & ECE 4610
Reading an analog signal
Arduino can’t read negative signal so we need to shift the signal with a positive offset using
voltage divider.
Using the function generator produce a sinus signal with 4 VPP. Use a voltage divider to shift the
signal (Check with the oscilloscope).
Vref
2.5
Vin
19. 6/22/2018 19
Ahmed Elwali
BME 7022 & ECE 4610
Ahmed Elwali
BME 7022 & ECE 4610
Reading an analog signal (oscilloscope
software)
analogRead(no. of the analog pin); // 10 bits ADC, with max sampling rate 10000 sample/sec.
For the oscilloscope software: Check serial port, baud rate, Terminal, and signals.
For more than one signal