Basics of Arduino uno BY RAHAT SOOD B.TECH (ECE) 6 TH SEM ROLL NO – 14BTD5060237
Contents: WHAT IS MICROCONTROLLER ? WHAT IS ARDUINO ? ARDUINO UNO BOARD ANALOG TO DIGITAL CONVERSION GETTING STARTED WITH ARDUINO PROGRAMMING PRACTICAL APPLICATIONS
INTRODUCTION
MICROCONTROLLER : A small microcontroller on a single chip containing a Central Processor Unit (CPU), Flash Memory, RAM and input/output interface. Used for control purposes ,and for data analysis. Popular manufacturers are Intel, Atmel, Microchip.
What is the Arduino todbot.com/blog/bionicarduino
An open source Electronics Platform based on easy-to-use hardware (electronic board) and software(IDE).www.Arduino.ccd. A Electronic Board , with on-board regulated power supply,USB port to communicate with PC , and an Atmel microcontroller chip. Anyone can details of its design and modify it or make his own.
Arduino Uno BOARD
Sample Specs: Arduino Uno Microcontoller: 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 Flash Memory 32 KB (of which 0.5 KB used by bootloader) SRAM 2 KB (ATmega328) EEPROM 1 KB (ATmega328) Clock Speed 16 MHz
What is analog ? It is continuous range of voltage values (not just 0 or 5V) Why convert to digital ? Because our microcontroller only understands digital . Analog to Digital Coversion
ADC in Arduino Uno
Converting Analog Value to Digital
Quantanization the signal
The Arduino Uno board contains 6 pins for ADC 10-bit analog to digital converter This means that it will map input voltages between 0 and 5 volts into integer values between 0 and 1023 ADC in Arduino
analogRead (A0); // used to read the analog value from the pin A0 analogWrite (2,128 ); Reading/Writing Analog Values
Getting started with Programming
C++ libs C++ libs C++ libs Arduino C/C++ (READABLE CODE) ASSEMBLY (READABLE CODE) MACHINE LANGUAGE (BINARY CODE)
Integer : used with integer variables with value between 2147483647 and -2147483647. Ex: int x=1200; Character : used with single character, represent value from - 127 to 128. Ex. char c=‘r’; 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. Ex. long u=199203 ; 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. Ex. float num =1.291; Data Types and operators
Statement represents a command, it ends with ; Ex: int x; x=13; Operators are symbols that used to indicate a specific function: - Math operators: [ +,-,*,/,%,^ ] - Logic operators: [ ==, !=, &&, || ] - Comparison operators: [ ==, >, <, !=, <=, >= ] Syntax: ; Semicolon, {} curly braces, // single line comment, /* Multi-line comments */ Statement and operators:
Switch case: switch ( var ) { case 1: //do something when var equals 1 break; case 2: //do something when var equals 2 break; default: // if nothing else matches, do the default // default is optional } Control statements:
Do… while: do { Statements; } while(condition); // the statements are run at least once. While: While(condition) {statements ;} for for (int i=0; i <= val ; i++){ statements; } Loop statements :
void setup () { // put your setup code here, to run once: } void loop () { // put your main code here, to run repeatedly: } Bare minimum code
setup : It is called only when the Arduino is powered on or reset. It is used to initialize variables and pin modes. loop : The loop functions runs continuously till the device is powered off. The main logic of the code goes here. Similar to while (1) for micro-controller programming. Bare minimum code
A pin on arduino can be set as input or output by using pinMode function. pinMode(13, OUTPUT); // sets pin 13 as output pin pinMode(13, INPUT); // sets pin 13 as input pin PinMode
digitalWrite(13, LOW); // Makes the output voltage on pin 13 , 0V digitalWrite(13, HIGH); // Makes the output voltage on pin 13 , 5V int buttonState = digitalRead(2); // reads the value of pin 2 in buttonState Reading/writing digital values
Arduino IDE See: http://arduino.cc/en/Guide/Environment for more information
PRACTICAL APPLICATIONS LIGHT CONTROL MOTOR CONTROL AUTOMATION ROBOTICS NETWORKING CUSTOM PROTOCOLS