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

chuong7 programing dasua

Chapter 7 introduces Arduino programming, focusing on the Arduino board as a microcontroller platform for the Internet of Things (IoT). It covers the components, functionalities, and programming environment of Arduino, emphasizing its affordability, cross-platform capabilities, and open-source nature. The chapter also outlines the steps to program an Arduino, detailing the structure of sketches and the process of uploading code to the board.

Uploaded by

23110282
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
17 views

chuong7 programing dasua

Chapter 7 introduces Arduino programming, focusing on the Arduino board as a microcontroller platform for the Internet of Things (IoT). It covers the components, functionalities, and programming environment of Arduino, emphasizing its affordability, cross-platform capabilities, and open-source nature. The chapter also outlines the steps to program an Arduino, detailing the structure of sketches and the process of uploading code to the board.

Uploaded by

23110282
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 32
Chapter 7 ARDUINO PROGRAMMING Introduction The Internet of Things (IoT) is a scenario in which objects, animals or people are provided with single identifiers and the capability to automatically transfer and the capability to automatically transfer data more to a network without requiring human-to-human or human-to-computer communication Arduino Board: > An Arduino is actually a microcontroller based kit. > Itis basically used in communications and in controlling or operating many devices. > Arduino UNO board is the most popular board in the Arduino board family. > Inaddition, it is the best board to get started with electronics and coding. > Some boards look a bit different from the one given below, but most Arduino’s have majority of these components in common. >” It consists of two memories- Program memory and the data memory. > The code is stored in the flash program memory, whereas the data is stored in the data memory. > Arduino Uno consists of 14 digital input/output pins (of which 6 can be used as PWM outputs), 6 analog inputs, a 16 MHz crystal oscillator, a USB connection, a power jack, an ICSP header, and a reset button WHAT IS ARDUINO? © ARDUINO Arduino is a tool for making computers that can sense and control more of the physical world than your desktop computer. It's an open-source physical computing platform based on a simple microcontroller board, and a development environment for writing software for the board & @erovect HUB oe Carive aHARAT os The word “Arduino” can mean 2 things A physical piece A programming of hardware environment E> @rrovect UB oe mec ea” WHY ARDUINO? © Inexpensive [ARDUINO Arduino boards are relatively inexpensive compared to other microcontroller platforms Cross-platform The Arduino software runs on Windows, and Linux operating systems. Open source and extensible software The Arduino software is published as open source tools, available for extension by experienced programmers Open source and extensible hardware ge . . . . PROJECT HUB Simple, clear programming environment Sg PORINNOVATIVE GHARAT a 0 TS OF THE ARDUINO e ATMegal 68/328 ° 16MHz crystal/filtering capacitors ¢ Onboard power regulators e FTDI USB <-> Serial Chip e Hardware C3 Beroyecr wus © ‘& NECESSARY PARTS FOR ARDUINO a MICROCONTROLLER UNIT ° ATMegal 68/328 The ‘brains’ of the Arduino Program is loaded onto the chip « Runs main loop until power is removed E> . SOPROWEST, HUB a =a 46MHZ CRYSTAL » 16Mhz Crystal © The ‘heartbeat’ of the ATMega chip ° Speed of crystal determines chip speed Possible to over/underclock depending on application « ATMega series has onboard oscillator; less precise E_PROsEST HUB ae! TDI USB CHIP rover nus ‘® « Allows your Arduino to communicate with your computer over a simple USB link ° Only necessary for communicating with USB a OER SUPPL eo. EQPROsECT HUB ‘@ « 5 Volt and 3.3 Volt Regulators « Filtering capacitors TO-220 « Automatic switching between GND external and USB Power aw Leave it out if you have a filtered f 5 Volt power supply WT? a Le 4 1. Input 1 2. GND 3. Output e Circuit Board ° Headers e USB port » Sockets Be PROJECT HUB &, fo @erovecr Hus ‘2 TYPES OF ARDUINO oe PES OF ARDUINO @® EQPROsEST HUB ‘® There are many different Arduino variations on the market, from small boards like the Arduino mini to large boards like the Arduino MEGA. All have certain features in common: Digital input/output pins (some double as PWM pins) Analog input/output pins *Serial communication pins eln-system programming pins (ISP) *Compatibility with Arduino software spun DEVELOPMENT BOARD Pin 013 LED a @prayecr wus &% —— Powerpins Analog VO pins ®@ , PROJECT HUB C like syntax, but simplified Abstracts the pin naming to numbers Easy to learn, yet powerful Lots of example code Easy to reuse C-code from other projects Libraries can be written in C++ Lots of libraries available rover HUB 17.Arduino Reset 15.Digital1/O. 14.7% and RX EDs o> ofan Regulator 2.Power (Barreljack) 5.Arduino Reset 10.Analog pins 6,7,8,9.Pins (3.3, 5, GND, Vin) = 1.Power USB Arduino board can be powered by using the USB cable from your computer. All you need to do is connect the USB cable to the USB connection (1). 2.Power (Barrel Jack) ‘Arduino boards can be powered directly from the AC mains power supply by connecting it to the Barrel Jack (2). 3.Voltage Regulator The function of the voltage regulator is to control the voltage given to the Arduino board and stabilize the DC voltages used by the processor and other elements. 4.Crystal Oscillator The crystal oscillator helps Arduino in dealing with time issues. How does Arduino calculate time? The answer is, by using the erystal oscillator. The number printed on top of the Arduino crystal is 16.000H9H. It tells us that the frequency is 16,000,000 Hertz or 16 MHz. 5,17.Arduino Reset You can reset your Arduino board, i.e., start your program from the beginning. You can reset the UNO board in two ways. First, by using the reset button (17) on the board. Second, you can connect an external reset button to the Arduino pin labelled RESET (5). = 6,7,8,9.Pins (3.3, 5, GND, Vin) + 3.3V (6) - Supply 3.3 output volt + 5V (7) - Supply 5 output volt + Most of the components used with Arduino board works fine with 3.3 volt and 5 volt. + GND (8)(Ground) - There are several GND pins on the Arduino, any of which can be used to ground your circuit. * Vin (9) - This pin also can be used to power the Arduino board from an external power source, like AC mains power supply 10.Analog pins The Arduino UNO board has six analog input pins AO through AS. These pins can read the signal from an analog sensor like the humidity sensor or temperature sensor and convert it into a digital value that can be read by the microprocessor = 11.Main microcontroller Each Arduino board has its own microcontroller (11). You can assume it as the brain of your board. The main IC (integrated circuit) on the Arduino is slightly different from board to board. The microcontrollers are usually of the ATMEL Company. You must know what IC your board has before loading up a new program from the Arduino IDE. This information is available on the top of the IC. For more details about the IC construction and functions, you can refer to the data sheet. = 12.1CSP pin Mostly, ICSP (12) is an AVR, a tiny programming header for the Arduino consisting of MOSI, MISO, SCK, RESET, VCC, and GND. It is often referred to as an SPI (Serial Peripheral Interface), which could be considered as an "expansion" of the output. Actually, you are slaving the output device to the master of the SPI bus. _ = 13.Power LED indicator This LED should light up when you plug your Arduino into a power source to indicate that your board is powered up correctly. If this light does not turn on, then there is something wrong with the connection. 14.TX and RX LEDs On your board, you will find two labels: TX (transmit) and RX (receive). They appear in two places on the Arduino UNO board. First, at the digital pins 0 and 1, to indicate the pins responsible for serial communication. Second, the TX and RX led (13). The TX led flashes with different speed while sending the serial data. The speed of flashing depends on the baud rate used by the board. RX flashes during the receiving process. _ = 15.Digital /O * The Arduino UNO board has 14 digital I/O pins (15) (of which 6 provide PWM (Pulse Width Modulation) output. These pins can be configured to work as input digital pins to read logic values (0 or 1) or as digital output pins to drive different modules like LEDs, relays, etc. The pins labeled “~” can be used to generate PWM. 16.AREF + AREF stands for Analog Reference. It is sometimes, used to set an external reference voltage (between 0 and 5 Volts) as the upper limit for the analog input pins. - Program an Arduino = > The most important advantage with Arduino is the programs can be directly loaded to the device without requiring any hardware programmer to burn the program. > This is done because of the presence of the 0.5KB of Bootloader which allows the program to be burned into the circuit. > All we have to do is to download the Arduino software and writing the code. >» The Arduino tool window consists of the toolbar with the buttons like verify, upload, new, open, save, serial monitor. > It also consists of a text editor to write the code, a message area which displays the feedback like showing the errors, the text console which displays the output and a series of menus like the File, Edit, Tools menu. - eps to program an Arduino = > Programs written in Arduino are known as sketches. A basic sketch consists of 3 parts 1. Declaration of Variables 2. Initialization: It is written in the setup () function. 3. Control code: It is written in the loop () function. > The sketch is saved with .ino extension. Any operations like verifying, opening a sketch, saving a sketch can be done using the buttons on the toolbar or using the tool menu. > The sketch should be stored in the sketchbook directory. > Chose the proper board from the tools menu and the serial port numbers. > Click on the upload button or chose upload from the tools menu. Thus the code is uploaded by the bootloader onto the microcontroller

You might also like