Introduction to Arduino PDF

Summary

This document provides a comprehensive introduction to the Arduino platform, including its history, features, and use cases. It explores the fundamentals of embedded systems programming using Arduino's core concepts and components. The document is a valuable resource for beginners looking to start their embedded systems development journey.

Full Transcript

Creating EMBEDDED SYSTEMS using ARDUINO What is Arduino Open Source electronic prototyping platform based on flexible easy to use hardware and software. Arduino platform - A physical Input/Output board (I/O) with a programmable Integrated Circuit (...

Creating EMBEDDED SYSTEMS using ARDUINO What is Arduino Open Source electronic prototyping platform based on flexible easy to use hardware and software. Arduino platform - A physical Input/Output board (I/O) with a programmable Integrated Circuit (IC). HISTORY Arduino project was made by a team of students and teachers from the Interaction Design Institute Ivrea (IDII). http://interactionivrea.org/en/index.asp HISTORY Gianluca Martino, David Mellis, David Cuartielles, Tom Igoe, Massimo Banzi et Nicholas Zambetti. HISTORY The inspiration come from processing, a programation language developed in 2001 by Casey Reas and Ben Fry, two students of John Maeda from M.I.T. ADVANTAGES Simple to use Cheap Open Source Multi-platforms PHILOSOPHY & COMMUNITY Arduino project is based on a principle of open Source which has help it to have a quick development. Thanks to a community who work on the software and hardware. There are several tools to share and learn: - Blog (http://blog.Arduino.cc/) - Forum (http://forum.Arduino.cc/) Arduino IDE How to get started? Arduino IDE Go to Arduino Website and download it. http://arduino.cc/en/Main/Software Arduino IDE Scroll down then you will see this Arduino IDE Extract the file then double click the arduino.exe Arduino IDE Arduino IDE splash screen Arduino IDE menus Verify: This allows you to compile your code to code the Arduino understands. Any mistakes you have made in the syntax of your code will be show in the info panel Upload: This does the same as verify but will then send your code to your Arduino if the code is verified successfully Serial Monitor: This will open a window that allows you to send text to and from an Arduino. We will use this feature in later lectures. Serial Monitor Code area: This is where you will type all your code Info panel: This will show any errors during compiling or uploading code to your Arduino  By far one of the most valuable part of the Arduino software is its vast library of example programs. All features of the Arduino are demonstrated in these.  Optional libraries usually add their own examples on how to use them.  Arduino shields will often come with their own libraries and therefore their own examples.  If these examples don’t cover what you need….Google it! Before we begin coding Arduino Language  A program or code written for Arduino is called a "sketch”.  Arduino programs are written in C or C++. Structure of an Arduino “sketch” Example int onBoardLED; void setup() { //Arduinos have an on-board LED on pin 13 onBoardLED = 13; pinMode(onBoardLED, OUTPUT); } void loop() { digitalWrite(onBoardLED, HIGH); delay(500); //delay measured in milliseconds digitalWrite(onBoardLED, LOW); delay(500); } Arduino Sketch  Users only need to define two functions to make a runnable cyclic executive program:  setup(): a function run once at the start of a program that can initialize settings  loop(): a function called repeatedly until the board powers off How Arduino sketch Works? Terminologies  pinMode() – Define your pin as an input or output.  digitalWrite() – Send a binary value (high/low) to a pin.  digitalRead() – Read a binary value (high/low) from a pin.  analogRead() – Read an analogic value (from 0 to 1024)  analogWrite() – Send an analogic value (from 0 to 255) to a pin.  delay() – Arduino clock with an interval count in milliseconds. Basic Electrical Knowled ge Basic Electrical Knowlege  Each electronic component has a schematic symbol, which is a simplified drawing of the part. For resistors the symbol looks like this: Basic Electrical Knowlege The LED symbol has an arrow thing going on. This is the direction in which current flows. The little arrows that are coming out of the symbol indicate that this is a diode that emits light. Basic Electrical Knowlege The only thing we need to do now is indicate how the LED and resistor are hooked up and show the 5V and ground connections. Next to symbols, we often write important information like what the resistor value is, what color and size the LED should be, and the voltage associated with the power supply. LED BREADBOARD External LEDs PWM – Pulse width modulation PWM allows you to create a fake analogue signal by toggling a pin high and low. The amount of overall time the pin spends high effects the average voltage of the signal. This works well for dimming LEDs so long as the frequency of pulses is faster than the eye can pick up An Arduino UNO can only do PWM on pins: 3, 5, 6, 9, 10 and 11 PWM Example int ledPin; void setup() { ledPin = 10; //Note that PWM doesn't need a pinMode } void loop() { analogWrite(ledPin, 50); delay(500); analogWrite(ledPin, 255); delay(500); } First Interaction  Plug your LED just like the image as shown below and connect the USB connector from Arduino board to your computer. Writing a Code pinMode() Configures the specified pin to behave either as an input or an output. Syntax pinMode(pin, mode); Parameters pin: the number of the pin whose mode you wish to set. mode: INPUT, OUTPUT, or INPUT_PULLUP. digitalWrite() Write a HIGH or a LOW value to a digital pin If the pin has been configured as an OUTPUT with pinMode(), its voltage will be set to the corresponding value: 5V (or 3.3V on 3.3V boards) for HIGH, 0V (ground) for LOW. digitalWrite() Syntax digitalWrite(pin, value) Parameters pin: the pin number digitalRead() If the pin is configured as an INPUT, reading a HIGH value with digitalRead() will enable an internal 20K pull-up resistor. Reading LOW will disable the pull-up. digitalRead() Syntax digitalRead(pin, value) Parameters pin: the pin number delay() Pauses the program for the amount of time (in miliseconds) specified as parameter. (There are 1000 milliseconds in a second.)  Syntax delay(ms);  Parameters ms: the number of milliseconds to pause (unsigned long)  Returns none Blink w/o Delay This sketch will cause the LED to turn ON and OFF every 1 second without using delay func. millis() Returns the number of milliseconds since the Arduino board began running the current program. This no. will overflow (go back to zero), after approximately 50 days.  Syntax millis();  Parameters None  Returns Number of milliseconds since the program started (unsigned long) micros() Returns the number of microseconds since the Arduino board began running the current program. This no. will overflow (go back to zero), after approximately 70 minutes.  Syntax micros();  Parameters None  Returns Number of microseconds since the program started (unsigned long) millis() and micros() Note: there are 1,000 microseconds in a millisecond and 1,000,000 microseconds in a second. 4. Fade In This sketch will gradually light up the LED 5. Fade Out This sketch will gradually fade the light of LED Fade in and out This sketch will fade in and out the LED like a HeartBeat. analogWrite() Writes an analog value ( PWM wave) to a pin. Can be used to light a LED at varying brightnesses or drive a motor at various speeds. The frequency of the PWM signal on most pins is approximately 490 Hz. analogWrite() On the Uno and similar boards, pins 5 and 6 have a frequency of approximately 980 Hz. Pins 3 and 11 on the Leonardo also run at 980 Hz. analogWrite()  On most Arduino boards (those w/ the ATmega168 or ATmega328), this function works on pins 3, 5, 6, 9, 10, and 11. On the Arduino Mega, it works on pins 2 - 13 and 44 - 46. Older Arduino boards with an ATmega8 only support analogWrite() on pins 9, 10, and 11. analogWrite() You do not need to call pinMode() to set the pin as an output before calling analogWrite().  Syntax analogWrite(pin, value)  Parameters pin: the pin to write to. value: the duty cycle: between 0 (always off) and 255 (always on). Serial Used for communication between the Arduino board and a computer or other devices. All Arduino boards have at least one serial port (also known as a UART or USART): Serial. It communicates on digital pins 0 (RX) and 1 (TX) as well as with the computer via USB. 7. Hello World (Serial) You may open your Serial Monitor to check the data/char being sent. 7. Hello World (Serial) This sketch will send characters to the pc via Serial. Exercises

Use Quizgecko on...
Browser
Browser