Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
394 views
Arduino - Projects
Uploaded by
Josip S. Kličinović
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save Arduino - Projects For Later
Download
Save
Save Arduino - Projects For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
0 ratings
0% found this document useful (0 votes)
394 views
Arduino - Projects
Uploaded by
Josip S. Kličinović
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save Arduino - Projects For Later
Carousel Previous
Carousel Next
Save
Save Arduino - Projects For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download
You are on page 1
/ 175
Search
Fullscreen
Measurement Projects for Beginners Unis inchsted lr deweinading sentches and Creal diagram fo practicContents Basics of E ‘ LED Programming Structure Structure Functions Variable Getting Started with Arduino Basic Proj - Serial Monitor LED-Digital Write Push Button Switch POT-Analog Read Arduino Measurement Projects ano Capaci M Proj Arduino Resistance (ohm) Measurement Project Measurement of Distance using ultrasonic Sensor Measurement of Light using LDR (LUX meter) aera ot distance usin sharp Sensor 1 ing V Measurement of current using current sensor Measurement of Pressure using GY-68 BMP 180 Dust Measurement using DSM501A Sensor PDF link and Source Files of this book© Copyright 2020 by STEMedu - All rights reserved. This document is geared towards providing exact and reliable information in regards to the topic and issue covered. The publication is sold with the idea that the publisher is not required to render an accounting, officially permitted, or otherwise, qualified services. If advice is necessary, legal or professional, a practiced individual in the profession should be ordered. = From a Declaration of Principles which was accepted and approved equally by a Committee of the American Bar Association and a Committee of Publishers and Associations. In no way is it legal to reproduce, duplicate, or transmit any part of this document in either electronic means or in printed format, Recording of this publication is strictly prohibited, and any storage of this document is not allowed unless with written permission from the publisher. All rights reserved. The information provided herein is stated to be truthful and consistent, in that any liability, in terms of inattention or otherwise, by any usage ot abuse of any policies, processes, or directions contained w ithin is, the sole and utter responsibility of the recipient reader. Under no circumstances will any legal responsibility or blame be held against the publisher for any reparation, damages, or monetary loss due to the information herein, either directly or indirectly. Respective authors own all copyrights not held by the publisher. The information herein is offered for informational purposes solely and is universal as so. The presentation of the information is without a contract or any type of guarantee assurance. ‘The trademarks that are used are without any consent, and the publication of the trademark is without permission or backing by the trademark owner. All trademarks and brands within this book are for clarifying purposes only and are owned by the owners themselves, not affiliated with this document.Basics of ElectronicsElectronics Primer Before jumping into the Arduino Completely, we present the foundations of electricity and electronics and Introduce critical concepts used. Here provides a broad overview of electronics to readers who have litte t0 hho experience with electronics and electricity. If you're already comfortable with some of the topics in this chapter, you can skip these and go to the programming page. If you're new to electronics or just want a refresher, we suggest reading this webpage in full. While it’s not a complete guide to electronics (there are whole books, classes, and degrees on the subject), this chapter is a handy reference designed to arm you with basic concepts and vocabulary. What Is Electricity? To understand electricity, you first need to understand the structure of an atom, Atoms are the building blocks of everything around you. An atom is made up of protons, neutrons, and electrons. The electrons have a negative charge, and the protons have a positive charge. A typical atom has the same number of electrons a5 protons and therefore is neutral in charge. Electricity is a form of energy that involves the movement or storage of charges; it is the phenomenon that occurs when we push or force charges to move in a prescribed manner or a defined path, In simple terms, electricity is a form of energy that we can hamess and convert into heat, light, movement, and power. Electricity has three main properties that will be important to us as we build projects: current, voltage, and power.Current ‘The flow of electrical energy through a circuit is called the current. Electrical current flows through a circuit from the positive side of a power source, such as a battery, to the negative side of the power source. This is known as direct current (DC).In some circuits; the negative side is called ground (GND). Current is measured in amperes or “amps” (A). Small amounts of current are measured in milliamps (mA), where 41,000 milliamps equal 1 amp.Voltage Voltage is a measure of the difference in potential energy between a circuit’s positive and negative ends, This is measured in volts (V). The higher the voltage, the faster the current moves through a circu.Power Power is a measurement of the rate at which an electrical device converts energy from one form to another. Power is measured in watts (W). For example, a 100 W light bulb is much brighter than a 60 W bulb because the higher-wattage bulb converts more electrical energy into light. A simple mathematical relationship exists among voltage, current, and power: Power (W) = Voltage (V) x Current (A)What Is a Circuit? Even with the electrical forces pushing them, charges need a path to follow from a point of higher potential to the point of lower potential. The path by which charges move from the positive (~) side of a battery (high potential) to the negative (-) side of the battery (low potential) is called a circuit. A circuit consists of a closed path from the positive terminal to the negative terminal through a device such as a light-emitting diode (LED), resistor, ight, or motor. In order for charges to move, the path must be made out of a material that is conductive, Conductivity is not an absolute measure but mote of a continuum. In other words, some materials allow charges to move more freely than others. Ohm's Law As you may already have guessed, there is a relationship between current, voltage, and resistance, This relationship is commonly called Ohm’s Law, and itis represented mathematically as follows: ve xR In this equation, V represents the voltage; I represent the current, and R is the resistance,‘Schematics battery switch push button switch ground resistor transistor Schematics ate simplified drawings of circuits. We sometimes also call these wiring diagrams or circuit blueprints. schematic shows what is connected to what and which components to use in building the circuit.Analog VS Digital With the concepts of circuits, components, voltage, current, and resistance defined, we can now talk about two different approaches to electronics: analog and digital. These approaches are not mutually exclusive, and you can’t really understand the circuits you build without understanding both concepts. 5v SV Tie —* TIME — DIGITAL SIGNAL ANALOG SIGNAL Digital versus analog signals Analog deals with values that vary within a set range, Think of the dimmer switch in some dining rooms; that is analog. Analog values can be on, off, and anything in between. Digital values, on the other hand, have only two. States: on or off. Digital electronics tend to include a microcontroller or microprocessor that is programmed to turn things on and off in response to conditions, whereas analog circuits tend to use components to vary the current, voltage, and resistance of a circuit to achieve the same result. There ate advantages and disadvamtages to both ways of thinking, but you can’t solely use one and not the other. For example, you couldn’t read the temperature using a microcontroller without using a number of analog components as wel What is Microcontroller? A microcontroller is a small computer that you can program by uploading a program or set of instructions. Microcontrollers are used to automate simple tasks, like controlling the temperature of your house or ‘watering your lawn when it’s dry LED An LED is an acronym for Light Emitting Diode; it is a type of diode that illuminates when electricity passes through it. Their voltage drop is higher than a standard diode, from1.2v for an infrared LED, up to 3.5v for blue and ultraviolet LED. These LED’s comes in different size and different colors. If you take a closer look to that LED picture, one lead (leg) of the LED’s shorter and another one is longer. The shorter one is known as a cathode (negative (-) symbol), and the longer one is known as an anode (positive (+) symbol). If the current passing through the LED is too high, you will lose LED. A LED can withstand up to 3.5y, the output voltage from the Arduino pins are 5V to step down this voltage,a resistor in series with LED should use to prevent the LED from hurt. rantResistors Resist the flow of electrical current in the circuit, in other words, they limit the flow of electrons. The SI unit of resistance is Ohms, written as the Greek letter omega (Q). They are often used with the unit prefixes kilo (k) and mega (M). The value of resistor indicated by 4 or 5 color band bands, using the resistor color code: The first 2 bands are the first digits of the value, and the 3° band is the power of ten that comes after those 2 digits. This is also called the multiplier and is just the number of zeros you have to add. The last band is the tolerance and mostly it will be silver or gold color. FE EF & “BB ROY Great Britain Very Good Wife,” try to memorize this sentence which allows you to remember 9 color bands in the resistor. First b represents black, the second b represents brown, R represents Red, O represents Orange, Y represents yellow, first word in Great G represents Green, first word in Britain B represents Blue, first word in Very V represents violet, the first letter in G represents Grey and, the first letter in Wife W represents White. Color 1% Band (1%} 2" Band] 3" Band J 4" Band digit) (2 digit) | (Multiplier) | (tolerance)Orange 1000 or 1kQ Yellow 10kQ White 9 9 Gold 0.12 25% Silver 0.012 +10% Eg: The first resistor toward right, in the above picture, shows Brown RED RED color, First band is Brown look up the table to find 1S digital value for this color,value for the brown color in the first digit is ‘1’, second color is Red, if you look up the table for the 2"¢ digit value color for the Red is 2 and the third color is also red, if you look up the table for 3° Band it is multiplier and the value is 100 ohms If we join all the value together, 1 2 * 100 And the final value will be 1200; the resistance value is 1200 Q. Capacitors These components store and release electrical energy in a circuit, It behaves like a small rechargeable battery. Capacitors are used in filters. The SI unit of capacitance is farad, of F. This is a huge unit, and most often, you will see prefixes like pico(p), nano (n) or micro (y). Often placed across power and ground close to a sensor or motor to help fluctuation in voltage. e & Transistor A wansistor is a semiconductor device, which is used to switch or amplify a signal. You can think of it as a switch that can be operated by using a feeble signal, a current controlled switch. A transistor has three terminals: they are called the base (B), the emitter (E) and the collector (C). The emitter ‘emits’ electrons, and they are ‘collected’ by the collector. The base is used to control this flow of electrons. If a small current flows from the base to the emitter, a much larger current will flow from the collector to the emitter. How much larger this C-E current is, depends on a constant, specific to the type of transistor. This constant is called the DC current gain and has the symbol of the Greek letter béta ( 3 ) or Hfe.E.g,, if you have a transistor with B = 100, and your B-E current = 10mA, your C-E current will be 1A. This principle is used in amplifiers. However, a transistor cannot keep on amplifying forever: at a certain point, the transistor will just act like a switch. Diode Just like a transistor, a diode is a semiconductor device. One of the unusual properties of a diode is that they only conduct electricity in one direction. For example, Arduino boards have a diode in series with their power input jack, to prevent you from reversing the power, and damaging the chip. Diodes have a forward voltage drop ranging from 0.5v to 0.7v. This means that if you measure the voltage before the diode, it will be about 600mV higher than after the Diode, a diode has its limits: if the reverse voltage is too high, it will break, causing it to let current pass in the wrong direction. In some diodes, this is done in a controlled way. These diodes are called zener diodes. They will only conduct if the voltage is higher than an absolute value, specific to the zener. This value is constant, so zener diodes are used as a reference in voltage regulators. fetVariable Resistor We have seen about Resistors previously, and the resistor value in those resistors cannot be changed, but in this resistor, it is possible to change the resistance value. These resistors come with three pins. Two pins are connected to the ends of a fixed resistor. The middle pin or wiper moves across the resistor dividing it into two halves. When the external sides of the potentiometer are connected to the voltage and ground the middle leg will give the difference in voltage as you tum the knob. This type of resistor also called potentiometer or Pot. For example, if you have a 10k ohms variable resistor, you can vary the resistance from 0 to 10k by rotating the knob. Mostly these type of resistors used with Arduino to control PWM pins available in the Arduino. Light Dependent Resistor ‘As the name suggests, these are the type of resistor where the resistance change depends on the amount of light falls on the resistor head. This is also known as a photo sensor or light sensor, most of the yesteryears smart products use this simple sensor to do some magic. If you want to make an automatic light control system, it is possible with this sensor. Resistance increase or decrease depends on the type of sensor.r DC Motor A simple motor allows us to experiment with Arduino and work with fun projects. This simple DC motor which cannot be used for making movable objects, this motor cannot produce necessary torque to move objects that’s the reason these motor coupled with gears to increase torque and do some useful work, A motor converts electrical energy into mechanical energy when electricity is applied to its leads.Push Button Push button or momentary switch used for giving inputs to Arduino. You can use this device to know how signal goes high or low based on the switch state. Temperature Sensor Lm35 is an Analog temperature sensor. This sensor can be used with any Arduino analog pins AO to AS. You have to do an analog read and do some mathematical calculation to change the analog value to Temperature in Celsius or Fahrenheit. You can use any analog type sensor to get a temperature value. Piezo Buzzer Piezo buzzer is an electronic device commonly used to produce sound.Servo Motor These are particular type of motor, these motor are capable of rotating to a precise degree, but these motor can move only from 0 to 180 degree. It is controlled by sending electrical pulses from Arduino. 16x2 LCD display Liquid display crystals are a type of alphanumeric or graphic display based on liquid crystals. These displays are available in many shapes and sizes, the most popular are the 16x2 type displays which have 2 rows and capable of display 16 characters on each row.Connecting wires These wires are very useful for connecting different components with Arduino. There are different types of wires available male to male, male to female, female to female. You should have 5 wires from each type for ease of connecting different components with Arduino. ae Breadboard The breadboard is the most critical component in any project. This board allows the user to build circuits. It’s like a patch panel, with rows of holes that allow you to connect wires and components together. This eliminates the need for soldering of components.Arduino An Arduino is an entirely open source DIY microcontroller become very famous among the maker community, Arduino is a programmable device that can add brain to non-intelligent things like a Robot. You can do wonders with this tiny device once you get your hands dirty with it. You can use an Arduino to blink some LED’s to run robots around you, and even you use it to create handheld gaming devices for you. We delve more into Arduino details in this chapter. There are loads of Arduino variants available in the market and Arduino Makers are catering to this board in many sizes and shapes that fit into their products or projects. Some of the Arduino that mainly used are listed Arduino Uno, Arduino Mega, Arduino Nano. Throughout the book, Arduino Uno used for doing projects and explaining with examples. ‘These boards come from authorized manufactures as well as others who copy the same design and sell in their brand name. You can buy a clone version of an Arduino for very less price compare to the official Arduino boards. Arduino Uno Arduino Uno is a famous and most used Variant of Arduino, this board based on the ATmega328p microcontroller. It has 14 digital input/output pins (Some cases when needed analog pins can also use as digital pins) Out of the leading 14 digital pins 6 can use as PWM outputs, and this board has 6 analog inputs, a 16 MHZ crystal oscillator, a power jack, a reset button, an ICSP header, and a USB connection. This board contains everything needed to support the microcontroller; This comes as a ready to use a device where it can be directly connected to a computer with a USB cable and start to program it and use with the project we have it in mind. This board can be powered with an external battery or power it with an AC-to-DC adapter. This development board is different from all the previous boards in that it does not use the FTDI USB to Serial driver chip. The Arduino UNO can be driven from an AC to DC adapter or from a USB cable, AC to DC adapter which is terminated in a barrel jack. In the picturebelow the USB connection is labeled (1) and the barrel jack is labeled (2). Note: Recommended Voltage supplied to Arduino should not exceed greater than 12v, the voltage should be supplied between Gv to 12v 543 Pins (Analog, Digital, PWM, AREF) These are the pins responsible for connecting wires and complete the circuit and make your dream project come true. ital Pins (labeled as 7): There are 14 digital pins in an Arduino Uno (0 to 13). These pins can be used to turn on/off a digital circuit and also used to take digital input from external devices, i.e., these pins can be configured and used as digital input as well as digital output. These pins can produce Two states: HIGH and LOW, i.e., the HIGH state produces 5v and LOW states produces Ov. Each of these digital pins can provide or receive a maximum of 40 mA and has an inbuilt internal pull-up resistor (by default these are disconnected from the pins internally) of 20-50k Ohms; Also, some pins have specialized functions that can programmatically be done as follows: © PWM (8): PWM expanded as (Pulse width Modulation) if you look closely in your Arduino Uno board you may notice asymbol (~) next to some of the digital pins ( 11, 10, 9, 6, 5, 3), These pins act as a standard digital pins and also used for PWM functions, Think of these pins as an analog signal producer AREF (9): AREF stands for Analog Reference pin. These pins are mostly not used, and it is sometimes used for setting a Voltage reference externally between Ov to 5v as the upper limit for the analog input pins. Serial (0 -RX) and (1 — TX). These are the essential pin and responsible for serial communication between the Arduino and a PC for wansferring of programs from the Arduino IDE to the Arduino board. Used to transmit and receive serial data. Analog Pins (Marked as 6 in the above picture) These pins are designed to receive analog signals and are labeled as Analog In in the Arduino Uno board. These pins receive an analog signal from sensors and convert it into a digital value that we can read programmatically. . Power (Sv, 3.3v, GND) * GND (Marked as 3 in the above Arduino Uno picture) There are 3 ground pins on the Arduino, any of the pins can be used to ground your circuit. © 5V (Marked as 4 in the above Arduino Uno Picture) The pin 5y supplies Sv of power, and this can be used for powering an external circuit. * 3.3V (Marked as 5 in the above Arduino Uno Picture) The pin 3.3v supplies 3.3v of power, and this can be used for powering an external circuit. Reset Button The Arduino has a reset button (Marked as 10 in the picture). The reset button in the Arduino does pretty much the same as switching off the board and switching it back in. It restarts your program from the beginning. When you Press the reset button on the Arduino board, the LED on pin 13 must flash some time while it's in the bootloader before it runs whatever program you have programmed in. If that LED doesn't flash when you press the reset button, then there is a serious fault with your board which will take further diagnostic. Power LED Indicator: (Marked as 11 in the picture) This LED is locatednear the ICSP pins. This LED should turn on when you plug the Arduino board to a power source. If this light does not turn on, there is something wrong with your Arduino board. TX, RX LEDs TX is short for the transmitter, RX is short for the receiver. These pins are responsible for serial communication. These LEDs (11, 12) will give us some excellent visual indications whenever our Arduino is receiving or transmitting data ATmega328p IC Each Arduino board has its IC, or Integrated Circuit (13) or the microcontroller is the main component or can be said as the brain of the Arduino. 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. Voltage Regulator The voltage regulator (14) controls the amount of voltage that is allowed into the Arduino board. Voltage regulators are acting as a gatekeeper; it will turn away an extra voltage that might harm the circuit. These voltage regulators have its limit, and it cannot control the voltage beyond its capacity, so don’t hook up your Arduino to anything higher than 20 volts.Introduction to the Arduino IDE © sketch_oct09b | Arduino 1.8.5 - Oo aK File Edit Sketch Tools Help sketch_oct09b PO ( Renee neers) In the last chapter, it’s full of Arduino hardware, and it's detailed, in thischapter, we will look into the Arduino IDE (Integrated Development Environment) that is used for Programming the Arduino Hardware. Note: This chapter deals with installing Arduino IDE in windows, another operating system may differ. It’s pretty straightforward to install Arduino IDE on a windows machine. Firstly Download the IDE, start by visiting the Arduino’s software page. https://www.arduino.cc/en/Main/Software) The Arduino IDE is available almost all the operating system including Linux, Mac OS, and window, make sure to download the right flavor of IDE that suitable to your operating system. If you are using an earlier version like windows 7 or older operating system, do not download the windows app version, as this needs Windows 8.1 or later. Once you downloaded the Arduino IDE, go ahead and install the IDE, enable all the options during installation, including libraries and any USB drivers and make sure to read the EULA. The Arduino IDE The Arduino IDE is a great tool provides a complete environment for all the Arduino-based projects. The IDE looks very minimalistic, but it provides all the necessary library and function to make any complicated Arduino projects. The top menu bar has standard options like File, Edit, Tools, Sketch, Help.(© sara dtone 169 - 0 x le de ech hp upload ~~ Write Your Code Here a cle ord and Com port The middle section of the Arduino IDE is like a text editor where all the programming coding is done here. The bottom section of the IDE called as Output console, that is used to see the status of the compilation, any errors in the program, how much memory has been used, and various useful messages are displayed in the console. The Arduino IDE in its default state Projects made using Arduino IDE are called as sketches, and these sketches are usually written in a short version of C++ (many features of C++ is not included in the Arduino IDE). Because programming a microcontroller is different from programming a computer, there are some libraries included in for Arduino hardware like — reading a pin, writing to a pin, reading analog values and other hardware specific functions, this often confuses many people, and they think Arduino is programmed in an “Arduino language.” However, the Arduino is programmed in C++ and uses some unique ArduinoHardware specific libraries. The SIX buttons Most projects in Arduino relay on these 6 buttons found below the menu bar. 1. veRwN The Tick mark icon is used to verify your Arduino Sketch. When you are done with your Arduino Program, you can click this once to verify the code you have written. . The Right arrow transfers the code to the Arduino . The dotted paper icon will create a new file. . The upward arrow icon is used to open an existing Arduino sketch. The downward arrow icon is used to save the current Arduino Sketch. . The far right button looks like a zoom glass is a serial monitor, which is very handy for sending and receiving data from the Arduino to the PC for debugging purposes.How to Install Arduino Libraries The Arduino IDE comes with several libraries inbuilt during the time of installation that can be used to do many projects, but, sometimes, specialized or new type of sensors requires special library functions that needed to be installed on the Arduino IDE, we will learn how to install extra libraries for our project in this chapter. There are three different ways available in practical to install an Arduino library 1) Manually installing the files 2) Installing using the library manager 3) Importing to Arduino using the zip file. The second and third option can be done using Arduino menu options. However, for manual installation, you have to locate the library’s files and place them inside the Arduino “libraries” folder. The manual way To install this way, we first need to download or find a specific library that we want to install manually. For this example, we will download a sound library for Arduino from Github. https://github.com/arduino-libraries/Audio the initial step is to download the required Arduino library as a zip file, click the green tab “clone or download” button on the GitHub page and then click “Download ZIP.”Once the zip file downloaded, open the zip file and unzip the libraries folder from the file, open the extracted file in a separate window and navigate to your Arduino folder. This is typically found in your “Documents,” folder and my case it is located at C:\Users\SimoneLaptop\Documents\Arduino. Open both the windows, the Arduino library you have downloaded and the Arduino main library folder side by side, Phim de. 6g entomingy twat ane Rte 14 ww " \ uw B étnn LW haus i as a lets iv nei) © 0 ita 4 1 ike ey ie Hine # Crane # te plan + [wags “hom pane Gri in i In the Arduino folder that located under the My Documents, open the “libraries” folder and then drag and drop the “sensor library” folder into the Arduino library folder.Drag and drop library folder into the Arduino library folder Restart the Arduino IDE and check the library and see if the library has detected by navigating to Sketch => Include Library. fat your sain code bess, Fun Pepeute iennannerbaInstalling using Library Manager This method is straightforward, unlike the previous method you don’t have to move away from your Arduino IDE to complete the task. The library manager can be loaded by navigating to Sketch => Include Library => Manage Libraries. © skatzh_vc:09b | Arduine 1.85 - o x File Edit|Sketch| Tools Help VerifyiCompile Cue Upload Ciel Skecll plead Using Programmer Ctil+ShifteU) | Export compiled Birary Ctl Alt S Manage Libraries. 4 * sense reir CtteK Ade ZIP Library bs Irlude Libnery Desist - Add Fite. Pridge pat v FF3OM Feploa , Ethernet Firmata om HD Keyooard LiquidCryetal Mouse Robot Control Robot IR Remote Robot Metor sp sri Softworeteisl SpozebrewYun Once the library manager loaded, you can see a window similar to the one looks belov‘The aary lew: wars to se nce Feature Derek ard matt, Includes come tel for He ESNERDE. Je2 2 1371 eo St tity ar te beeper Eesem see Porter acaase to Arcane, TFs ear eszones en sue sECO126. eee From here, you can search for many commonly used libraries and have the Arduino IDE automatically download and install them.Importing Zip libraries Libraries can be imported into Arduino library as a zip file, instead of the manual method, Importing zip libraries can be used if you are not finding a particular library in the Library Manager. To install the library, first, find the library that you want to include to the Arduino library. In this case, we are going to add the same library that we downloaded for adding the manual way. If you don’t have any library to add, follow the following steps, download the SD card library from Github from the following link https://github.com/arduino- libraries/SD first, download the library as a ZIP file, which can be done by clicking the green button “download or clone” button and then clicking “download ZIP.” Once downloaded the zip library, Open the Arduino IDE, and go to the Sketch => Include Library => Add .zip Library.Adding a ZIP library to Arduino Library ett 5 - ox ie a tH YesjCompe et ou S Ypetting hogan Cabo) fect os - i ‘Spor cempiet en, Vapi. When you click, the add ZIP Library... new dialogue windows that open find your downloaded Arduino library ZIP file. For me, this file was downloaded to s+ you guessed it . “Downloads.”The downloads folder Once you clicked the zip file and opened, the IDE will halt for a second or two, Later, you should receive a “Library Added” note, just above the debug window. The library has been added! Lastly, check that the installation was successful. To do this, click on Sketch => Include Library and look for the installed library.Which Arduino is Best for Your project Many variants of Arduino The word Arduino states to complete family of single board microcontroller development boards, which are used for building projects and prototypes. Almost all the Arduino boards carry ATMEL chips as their brain, and each IC has some different capabilities. Some microcontrollers have more input and output pins, some are faster, and some have more peripherals, and some are cheaper. When selecting a development board which one should you select for your project? Featured Devices ¢ Arduino Uno * Arduino Mega * Arduino Nano * Arduino Due¢ Arduino Yun © Arduino MKR Zero « Arduino Ethernet Rev 3 If you are a newbie to the Arduino world, you might have the confusion on which board to use for your projects. Then there are two devices which are suggested to everyone who is starting to the Arduino world: Arduino Uno and Arduino Nano The Arduino Uno is the most commonly available Arduino development board at the moment, and it has some accessible features, including Jumper pins for secure connectivity between other sensor and the Arduino board, onboard LEDs, USB connector for connecting to computers and laptop for programming and debugging, it has inbuilt Power handling which is very useful. On the other hand, Arduino Nano has most of the same features like Arduino Uno, (except it has a smaller USB port and has no DC power jack), it is better suited for breadboard based projects. This is an optimal board who has already played with electronic circuits using a breadboard. When to use the other boards? While the nano and Arduino Uno are more enough to complete many projects, in some cases you require more functionality from your Arduino, However merely choosing the more powerful Arduino board from the family is not the solution to your problem, so which board should you pick from the ocean of Arduino development boards. InpuvOutput If your project requires many I/O pins, then you should opt for Arduino Due or the Arduino Mega, which both the board has I/O pins up to 54. But not every project requires these many I/Os. You should not select a board based only on the Digital pins; you should also give same important to Analog pins also, Arduino Mega has 16 analog pins whereas the Arduino Due has only 12.Memory If you are planning to build complex and advanced projects using Arduino, it may require large program memory as these advance projects will have large programs that use a lot of memory. We have to consider both ROM and RAM, in the world of microcontrollers whenever the ROM size increases, the RAM. size automatically increases as well. The Arduino Due has 512KB of ROM and 96KB of RAM, and the Arduino Mega has a 256KB of ROM and 8KB of SRAM, but these two boards alone not rich in memory the Arduino MO, which is based on ARM Cortex-Mo+ has 256KB of ROM and 32KB of RAM. The Internet of Things Nowadays many projects require internet connectivity for remote monitoring and sending of necessary data to the internet for further analysis. If you are looking for adding WiFi capabilities to your Arduino board, there are few boards which have inbuilt wifi capability which can enable you to send and receive data over the Internet. The Arduino Yun has the WiFi chip in it, and Arduino Ethernet REV 3 has an Ethernet connection and a micro SD card reader, which makes this board ideal for loT projects.Programming Structure Overview The Arduino software is open-source. The source code for the Java environment is released under the GPL, and the C/C++ microcontroller libraries are under the LGPL. Sketch - The first new terminology is the Arduino program called “sketch.”Structure The primary structure of the Arduino Programming language is relatively simple and runs in at least two parts. These two required parts, of functions, enclose blocks of statements. Void sewup() { Program: } Void loop() { Program; } Let's discuss the Arduino Structure. The first line Void setup() is the preparation in the Arduino program. Loop() is the execution part. These are the two primary functions required for the Arduino program to work. The setup () function run only once when the Arduino powered. Any variable declaration should be declared at the very beginning of the program. Arduino development board has many I/O pins based on the model, these /O pins can be used as Input as well as output, we have to declare at the beginning of the program in the Setup() loop.If you plan to use Serial communication in the Arduino Program that needs to be declared in the Setup() loop.Setup() The setup() function in the Arduino IDE called only once during the execution of the program or when the Arduino board powered. Setup function used for initializing pin modes and serial communications to the Arduino board. Void Setup) { pinMode(pin,OUTPUT); } pinMode - is the syntax for setting a pin to input or output at the beginning of the program. Loop0) The loop function followed by the setup() function. Whatever the code we write inside the loop will continuously run until disturbed by an external interrupt. Void loop() { digitalWrite(pin, HIGH); delay(1000); digitalWrite(pin,LOW); delay(1000); }Functions A function is a block of code with a name and a block with instructions that are performed when the function is called. Custom functions can be written to execute repetitive tasks and reduce clutter in a program. Functions are indicated by first declaring the function type. This is the type of value that must be returned by the function, such as "int" for a function with an integer. If no value is to be returned, the function type is invalid. After type, declare the name given to the function, and in brackets, any parameters passed to the function. type functionname (parameters) { Program; The following integer type function delayVal () is used to set a delay value in a program by reading the value of the potentiometer. First, it declares a local variable v, sets v to the value of the potentiometer that gives a number between 0-1023, then divides that value by 4 for a final value between 0-255 and finally returns that value back to the main program. Int delayVal(Q) { Int v; // v-temporary variable V = analogRead(pot); // read the pot value v/= 4; //converts0-1023 to 0-255 return v; ( Curly BracesCurly braces (also called just "curly braces" or braces) define the start and end of function blocks and instruction blocks, such as the void loop () function and the for and IF instructions. Type function() Program;} An open brace {must always be followed by a closing accolade}. This is often called the alignment of the bracket. Unbalanced braces can often lead to cryptic, impenetrable compiler errors that are sometimes difficult to detect in an extensive program. ‘The Arduino environment contains a useful function to check the balance of braces. Merely select a brace or even click on the insertion point immediately after a brace, and the corresponding logic is highlighted. 3 Semicolon A semicolon must be used to end a statement and individual elements of the program. A semicolon is also used to separate elements in a “for loop.” Int x =13; Note: If you forget to end a line in a semicolon, this results in a compiler error. The error text may be distinct and refer to a missing semicolon, or maybe not. If an impenetrable or seemingly illogical compilation error occurs, one of the first things to check is a missing semicolon, near the line where the compiler complained. * ssseesseeeen/ block Comments block comments or multi-line comments are text areas that are ignored by the program and used for extensive text descriptions of code or comments that help others understand parts of the program. They start with / and end with / and can span multiple lines /* here we can type anything And the compiler will not consider these linesBypass the code Don’t forget to close the comment. */ comments are ignored by the program and do not occupy memory space, they must be used generously and can also be used to "omit" code blocks for debugging purposes. Note: although it is possible to place single line comments within a block comment, it is not allowed to add a second block comment. // LINE comments Single line comments start with // and end with the next line of code. Just like block notes, they are ignored by the program and do not take up memory space. // whatever comes after this line will be ignored Single line comments are often used after a valid statement to provide more information about what the statement reaches or to give a future reminder.Variable A variable is a way to give a numerical value a name and save it for later use by the program. As their name giver suggests, variables are numbers that can be changed continuously as opposed to constants whose value never changes. A variable must be declared and optionally assigned to the value to be stored for later use. The code shown below declares a variable called intVariable and then assigns the value obtained on analog input pin 2: Int intVariable = 0; intVariable = analogRead(2); ‘IntVariable’ is the variable itself. The first line states that it will contain an integer. The 2"¢ line in the program sets the variable to the value on analogpin 2. This makes the value of pin 2 available elsewhere in the code. Once a variable has been allocated or reassigned, you can check its value to see if it meets certain conditions, or you can use its value directly. As an example for illustrating three useful operations with variables, the following code tests whether the inputVariable is less than 100 if true assigns the value 100 to inputVariable and then sets a delay based on inputVariable that is now at least 10! If (intVariable < 100) // tests variable if less than 100 { intVariable = 100; // if true assigns value of 100 } Delay (intVariable); // uses variables as delay . Note: Variables must be given descriptive names to make the code more readable. Variables name such as a tilt sensor or pushButton help the programmer and anyone who reads the code to realize what the variable represents. Variable names such as var or value, on the other hand, do little to make the code clear and are only used here as an example. A variable can be called any word that is not yet one of the keywords in the Arduino language.Variable Declaration All variables need to be declared before they can be used. Declaring a variable means defining the value type as in int, long, float, etc., setting a specified name and optionally assigning it as an initial value. This only requires to be done once in a program, but the value can be altered at any time using arithmetic and different assignments. The following example explains that inputVariable is an int or integer type and that the initial value is zero. This is called a simple assignment. Int inputVariable A variable can be declared at a number of locations in the program and where this identification takes place determines which parts of the program the variable can use.Variable Scope A variable can be stated at the beginning of the program before void setup (), locally within functions and sometimes within an instruction block, such as for loops, is declared. Where the variable is declared, the variable range or power of certain parts of a program determines the use of the variable. A global variable is one that can be seen and used by any function and statement in a program. This variable is declared at the beginning of the program before the setup () function. A local variable is one that is defined within a function or as part of a for loop. It is only visible and can only be used within the function in which it has been declared. It is, therefore, possible to have two or more variables with the same name in different parts of the same program that contain different values. By ensuring that only one function has access to the variables, the program is simplified and the chance of programming errors decreases. The following example explains how to declare a number of different types of variables and show the visibility of each variable. int value; // value is visible void setup) { // setup is needed for this program } Void loop() { For (int i=0; i<20;) // { is;Float f; // ‘f" is only visible } //inside loopData types in C denotes to a widespread system used for declaring variables or functions of different types. The type of a variable decides how much space it occupies in the storage and how the bit pattem stored is interpreted. Data Types Each variable in C has an associated data type. Each data type requires different amounts of memory and has some specific operations which can be performed over it. Let us briefly describe them one by one: Following are the examples of some widespread data types used in Arduino programming: Byte Byte stores a bit numerical value without decimal points. They have a range of 0-255. byte someVariable = 180; //int Integers are the primary datatype for storage of numbers without decimal points and store a 16-bit value with a range of 32,767 to -32,768. Int someVariable = 1500; // declares ‘somevariable’ as an integer type Note: Integer variables will roll over if forced past their maximum or minimum values by an assignment or comparison. For example, if x = 2767 and a following statement adds 1 to x, x = x+1 or x++, x will then roll over and equal to -32768Long Extended size datatype for long integers, short of decimal points, stored in a 32-bit value with a range of 2,147,483,647 to -2,147,483,648. Long Variable = 80000; //.Float A datatype for floating-point numbers, or numbers that have a decimal point. Floating-point numbers have greater resolution than integers and are stored as a 32-bit value with a range of 3.4028235E+38 to -3.4028235E+38 Float someVariable =3.14; //declares ‘someVariable’ as a floating-point type Note: Floating-point numbers are not exact, and may yield strange results when compared. Floating point math is also much slower than integer math in performing calculations, so should be avoided if possible.Arrays An array is a collection of values that are accessed with an index number. Any value in the array may be called upon by calling the name of the array and the index number of the value. Arrays are zero indexed, with the first value in the array beginning at index number 0. An array needs to be declared and optionally assigned values before they can be used. int myArray[] = {value0, valuel, value2...} int myArray[5]; // declares integer array w/ 6 positions myAmay[3] = 10; // assigns the 4th index the value 10char A data type that takes up 1 byte of memory that stores a character value. Character literals are written in single quotes, like this: 'A' (for multiple characters - strings - use double quotes: "ABC"). char myChar ='A’; char myChar = 65; —_// both are equivalent Note: The char datatype is a signed type, meaning that it encodes numbers from -128 to 127. For an unsigned, one-byte (8 bit) data type, use the byte data type.Loops Overview Programming languages provide various control structures that allow for more complicated execution paths. A loop statement allows us to execute a statement or group of statements multiple times and following is the general form of a loop statement in most of the programming languages dition True ConditionLoops and Descriptionfor Loop A for loop executes statements a predetermined number of times. The control expression for the loop is initialized, tested and manipulated entirely within the for loop parentheses. 1/ syntax for for loop for (initialization; condition; expression) { dosomething;while Loop while loops will loop continuously, and infinitely, until the expression inside the parenthesis, becomes false. Something must change the tested variable, or the while loop will never exit. 7/ syntax for while loop while ( somevariable ?? value) / dosomething;‘do while Loop The do...while loop is similar to the while loop. In the while loop, the loop- continuation condition is tested at the beginning of the loop before performed the body of the loop. The// syntax for doing while loop do { dosomething; } while (some variable ?? value)Arithmetic Arithmetic operators include addition, subtraction, multiplication, and division. They return the sum, difference, product, or quotient (respectively) of two operands. Z=2+3; The operation is conducted using the data type of the operands, so, for example, 9 / 4 results in 2 instead of 2.25 since 9 and 4 are ints and are incapable of using decimal points. This also means that the operation can overflow if the result is larger than what can be stored in the data type. If the operands are of different types, the larger type is used for the calculation. For example, if one of the numbers (operands) are of the type float and the other of type integer, floating point math will be used for the calculation. Choose variable sizes that are large enough to hold the most significant results from your calculations. Know at what point your variable will roll over and also what happens in the other direction, e.g. (0 - 1) OR (0 - - 32768). For math that requires fractions, use float variables, but be aware of their drawbacks: large size and slow computation speeds.Comparison operators Comparisons of one variable or constant against another are often used in if a statement to test if a specified condition is true. Different types of condition used are: x == // x is equal to y x !=y // x is not equal to y x < y // x is less than y x > y // x is greater than y x <=y // x is less than or equal to y x >= y // x is greater than or equal to yLogical operators Logical operators are usually a way to compare two expressions and return a TRUE or FALSE depending on the operator. There are three logical operators, AND, OR, and NOT, that are often used in if statements: Logical AND: if (x > 0 && x <5) // true only if both expressions are true Logical OR: if (x > 0 || y > 0) // tue if either expression is true Logical NOT: if (1x > 0) // tue only if expression is falseConstants The Arduino language has a few predefined values, which are called constants. They are used to make the programs more comfortable to read. Constants are classified in groups. True/False These are Boolean constants that define logic levels. FALSE is easily defined as 0 (zero) while TRUE is often defined as 1, but can also be anything else except zero. So in a Boolean sense, -1, 2, and -200 are all also defined as TRUE. if (b == TRUE); { doSomething; }Control StatementsOverview Decision making structures require that the programmer specify one or more conditions to be evaluated or tested by the program. It should be along with a statement or statements to be executed if the condition is determined to be true, and optionally, other statements to be executed if the condition is determined to be false. Control Statement & Description If statement It takes an expression in parenthesis and a statement or block of statements. If the expression is true then the statement or block of statements gets executed otherwise these statements are skipped. // syntax for if statement if (condition) { do something; } If ...else statement An if statement can be followed by an optional else statement, which executes when the expression is false. // syntax for If ...else statement if (condition) { do something; } else do something; } switch case statement Similar to the if statements, switch...case controls the flow of programs by allowing the programmers to specify different codes that should be executed in various conditions // syntax for switch case statementswitch (variable) { case label: { // statements break; } case labe2: { // statements break; }Digital Input -Output Functions The digital inputs and outputs (digital I/O) on the Arduino are what allow you to connect the Arduino sensors, actuators, and other ICs. Learning how to use them will allow you to use the Arduino to do some beneficial things, such as reading switch inputs, lighting indicators, and controlling relay outputs. Etc ‘ital Signal Digital signals may not take any values within the range. Digital signals have two distinct values HIGH or 1 and LOW or 0. You use digital signals in situations where the input or output will have one of those two values.Function The Arduino functions associated with digital signals that we will be using in this tutorial are 1. pinMode (pin_number, mode) 2. digitalWrite(pin_number,value) 3. digitalRead(pin_number)pinMode (pin_number, mode) Because the Arduino digital /O pins can be used for either input or output, you should first configure the pins you intend to use for digital I/O with this function. the pin is the number of the pin you wish to configure. mode must be one of three values: INPUT, OUTPUT, our INPUT_PULLUP. When the mode is set to INPUT_PULLUP, a 20 k ohm pull-up resistor is internally connected to the pin to force the input HIGH if there is nothing connected to the pin. pinMode(pin,OUTPUT); // set pin as OUTPUT pinMode(pin,INPUT); // set pin as INPUT Note: INPUT/OUTPUT Constants used with pinMode() function to define the model of a digital pin as INPUT or OUTPUT. digitalWrite(pin_number,value) This function writes a digital value to a pin. pin specifies which Arduino pin the digital value will be written to, and value is the digital value to which the pin is set. The value must be either HIGH or LOW. digitalWrite(pin,HIGH);__//set pin as HIGHdigitalRead(pin_number) int reads = digitalRead(pin); //read the digital value on pin This function reads a digital value from a pin. the pin is the number of the digital /O pin you want to read. This function retums one of two values: HIGH or LOW. Note: HIGH/LOW These constants defined pin level as HIGH or LOW and used when reading or writing to digital pins.HIGH is defined as logic level 1, ON or 5 volts while LOW is logic level 0,OFF or 0 volts Analog Input-Output Functions ‘An analog signal is one that can take on any number of values, unlike a digital signal which has only two values: HIGH and LOW. To measure the value of analog signals, the Arduino has a built-in analog-to-digital converter (ADC). The ADC tums the analog voltage into a digital value. The function that you use to obtain the value of an analog signal is analogRead(pin). This function converts the value of the voltage on an analog input pin and returns a digital value from 0 to 1023, relative to the reference value. The reference is SV on most Arduino Function The Arduino functions associated with Analog signals that we will be using in this tutorial are 1. analogWrite(pin_number, value) 2. anlogRead(pin_number) analogWrite(pin_number,value) This function writes a analog value to a pin. Here in Arduino there are 6 Analog pins so use the same to write Value. Value must be range of 0 to 1023 analogWrite(Analogpin,255); //set Analogpin as 255 analogRead(pin_number) int reads = analogRead(Analogpin); //read the analog value on pin This function reads a analog value from a pin. Analogpin is the number of the analog /O pin you want to read. This function returns values from a range of 0 to 1023.Additonal Notes The Arduino does not have a built-in digital-to-analog converter (DAC), but it can pulse-width modulate (PWM) a digital signal to achieve some of the functions of an analog output. The function used to output a PWM signal is analogWrite(pin, value). pin is the pin number used for the PWM output. Value is a number proportional to the duty cycle of the signal. When value = 0, the signal is always off. When value = 255, the signal is always on. On most Arduino boards, the PWM function is available on pins 3, 5, 6, 9, 10, and 11. The frequency of the PWM signal on most pins is approximately 490 Hz. On the Uno and similar boards. To map an analog input value, which ranges from 0 to 1023 to a PWM output signal, which ranges from 0 - 255, you can use the map(value, fromLow, fromHigh, toLow, toHigh) function. This function has five parameters, one is the variable in which the analog value is stored, while the others are 0, 1023, 0 and 255 respectively. delay(ms) Pauses a program for the amount of time as specified in milliseconds, where 1000 equals 1 second. {delay(1000); 7 waits for one second] millis() Returns the number of milliseconds since the Arduino board began running the current program as an unsigned long value. value = millis();_// sets ‘value’ equal to millis() Note: This number will overflow (reset back to zero), after approximately 9 hours. map() This function is used to change covert a value in a particular range to other range. for example, if we read a value from analog port AO is 25, its between a range of 0-1023 in order to cover the value of analog port AO to a range of 0-255 we use the map function map(value, fromLow, fromHigh, toLow, toHigh) // example analogValue = map(analogValue, 0, 1023, 0, 255); random() The random() function returns a semi-random number up to the parametersspecified. If no parameters are specified, it will return a value in the signed long data type, with a range of -2,147,483,648 to 2,147,483,647. Its syntax follows: random(min, max) // "min" minimum possible value expected from the random() // "max" maximum value expected from the random() functionGetting Started with Arduino So, you bought yourself an Arduino; you understood you felt where to start with it. Do not fear, for help is at hand! In this chapter, we will look at how to get in progress with Arduino development boards. This chapter covers software installation once more if you have not followed the software installing from the previous chapter, as well as connecting and setting the Arduino IDE.You Will Need * Arduino Uno or any other Arduino + USB Cable and connecting wires « Windows or any other operating system Step 1: Download Arduino IDE and install it. The Arduino IDE can download the IDE from the official Arduino website. (https://www.arduino.cc/en/Main/Software) Since the Arduino development board uses a USB to serial converter, the Arduino board is well-matched with most PCs that have a USB port. Luckily, the Arduino inventors have released multiple versions of the IDE for different operating systems, including, Linux, Mac, and Windows, In this tutorial, we will use Window 10, to confirm that you download the correct type of IDE if you do not have Windows 10. Download the Arduino IDE Once downloaded the Arduino IDE, install the Arduino IDE and confirm that you enable most (if not all) of the options, WITH the drivers during the installation process. Step 2: Check for the Arduino COM Port Number (You can find it in your Arduino COM ports) Next, you'll require to connect the Arduino Uno or any other variant of Arduinoboard to the PC or to your laptop. This is done via a USB connection. Thanks to the beautiful world of USB, we do not need to provide power supply to the Arduino, as the USB provides 5V up to 2A. When the Arduino is connected, the operating system should identify the board as a generic COM port (for example, my Arduino Uno uses a CH340G,(clone version) which is an RS-232 serial to USB converter). Once it’s accepted, we will need to find out what port number it has been allocated. The easiest way to do this is to type “device manager” into Windows Search and select Device Manager when it shows.How to find Device manager in windows 10 =o e Fates V best match Device = Manager Settings FR Update device drivers Search suggestions 2 device manager 2 device manager In the Device Manager Window, check for a device under “Ports (COM & LPT) and chances are the Arduino will be the only device on the list. In my Device Manager, the Arduino shows up as COM? (I know this because CH340 is in the device name). The Arduino in my case is a CH340, and it shows on COM7 (port 7). @ WAN Miniport (SSTP) v §F Ports (COM & LPT) §@ USB-SERIAL CH340 (COM7) i Print queues n= Drinterc Be warned; the Arduino won’t constantly be recognized automatically. If your Arduino is not identified by the windows. Then uninstall the driver, remove theArduino, reinsert the Arduino, find the unrecognized device, right click “Update driver,” and then click “Search automatically.” This should fix 99 out of 100 problems. If the Arduino is not recognized, update the driver. a Ports (COM & LPT) Be A 8 ca FR Print queues : eu Plated Disable device Di Processors Uninstall device BB SO host adapters Scan for hardware char Hy Security devices mee oe B Sensors Properties Bl Software devices In the window that appears, click “Search automatically.” Il Update Drivers ~ USB-SERIAL CH340 (COM7) How do you want to search for drivers? > Search automatically for updated driver software Windows will search your computer and the internet for the latest driver software for your device, unless you've disabled this feature in your device installation settings. —> Browse my computer for driver software Locate and install driver software manually. Windows can be a real discomfort sometimes with COM ports, as it can magically change their numbers between connections. In other words, one day, your Arduino may be on port 7 (as shown here), but then on other days, ‘Windows may shift it to a different port number. As I understand it, this happens when you connect other COM ports to your system (which I frequently do).So, if you can’t find your Arduino on the port that you usually use, just go to your Device Manager and check what port it’s actually on and, if necessary, update your driver. Step 3: Configure the IDE Now that we have determined the COM port that the Arduino is on, it’s time to load the Arduino IDE and configure it to use the same device and port. Start by loading the IDE. Once it’s loaded, navigate to Tools > Board > Arduino Uno. However, if you are using a different board (i.e., not the Arduino Uno), you must select the proper board! Tell the IDE which board you are using. © seetch jen jen 185 Fle Ede Shtch To Help ‘te Format ech Sod Fu trceding 8 Read Set enter Seoul Pieter Coben, |_lesds Manages (R01 Fema Upsier a Pot Ardune Duerlnove Deca Get Board Adare Nine Ardune/ Gene Mage cr Mega 256) Progemeer AVR mis etn Wega 3 um Becticader mi Ardure leerade Ardine eerade ETH Arduce/Genane bre Ard apne edie Mis eduee tenet Ardea io Arde BT Pod Arbon USB UnPad bedane Jrduec Prot Pre Mew Arduee NG ot er Arduce Rbet Cort |Next, you must tell the IDE which COM port the Arduino is on. To do this, navigate to Tools > Port > COM7. Obviously, if your Arduino is on a different port, select that port instead. © sketch jonds | Fle Edit Sketch Arduino 1.8.5 - ao x Tools Help Auto Format CtrleT Archive Sketch Fax Encoding & Relood Serial Monitor CtiteShiftem Seria Plotter Clete Shifts WiFi101 Firmware Updater Board: "Arduine/Genuine Uno > Port: "COMT j Get Board info com Programmer: “AVRISP mii > Burn Bootloader Step 4: Loading a Basic Example For the sake of simpli ty, we will load an example project that the Arduino IDE comes with. This example will make the onboard LED blink for a second continuously. To load this example, click File > Examples > 01.Basics > Blink.Load the blink example. © sin jtiano 183 Bie sath Too the New GN Open cee Open Recent ams 09e ction Banden ine (4Comenmicion geaentent scot ase taser Aeactnsogonaye Dem, , tase : cus ‘se acta Naehines? Adatnt Cacut Paygeund bdr tapos hema oat drys abet Contr With the example loaded, it’s time to verify and upload the code. The verify stage checks the code for errors, then compiles the ready-for-uploading code to the Arduino. The upload stage actually takes the binary data, which was created from the code, and uploads it to the Arduino via the serial port. To verify and compile the code, press the check mark button in the upper left window. The “Verify” button will compile the Arduino code.© Blink | Arduino 1.8.5 File Edit Sketch Tools Help Blink If the compilation stage was successful, you should see the following message in the output window at the bottom of the IDE. You might also see a similar Message—just it’s one that does not have words like “ERROR” and “WARNING.” This is a successful compilation. With the code compiled, you must now upload it the Arduino Uno. To do this, click the arrow next to the check mark. The “Upload” button will program the Arduino with your code, pe [© ont aravino 125 Eile Edit_ Sketch Jools HelpConclusion The Arduino is a powerful prototyping tool for many reasons, including its lack of a dedicated programmer, its wide range of available libraries, and the simplicity of its IDE. While we only got a light to blink in this project, you can expect much more in the future. Try your hand at interfacing with displays, taking measurements, talking over the internet, and possibly even working with Al Now try few more examples from next chapters before you begin with real projects.Basic Projects with Arduino Now we have little bit idea about Arduino, how to program using C etc. Here we are talking about practical sections of basic programming with examples. Does it ina continuous way it will help you lean basic programming of Arduino. Connect your Arduino to the computer with the USB cable. You do not need the battery for now. The green PWR LED will light. If there was already a program bumed into the Arduino, it would run. Warning: Do not put your board down on a conductive surface; you will short out the pins on the back! Serial Monitor ‘The serial monitor is the ‘tether’ between the computer and your Arduino - it lets you send and receive text messages, handy for debugging and also controlling the Arduino from a keyboard! Serial.begin(rate) Opens serial port and set baud rate for serial data transmission. Typically baud rate for communication with the computer is 96000 although other speeds are supported. Note:when using serial communication digital pins (RX) and 1(TX) cannot be used at the same time Serial.printin(data) Print data to the serial port followed by an automatic carriage return and line feed .This command takes the same form as Serial.print() but is easier for reading data on the Serial monitor. Serial.printin(Anything);Arduino Code Open the Arduino IDE and Copy paste the Arduino Code below (You can find all the code is source file you can find at the end of this book) void setup() { Serial.begin(9600); initiate Serial communication Serial.printIn("Hello World"); // Print hello world in serial monitor void loop()© Serial Monitor Example | Arduino 1.8.5, - o me File Edit Sketch Tools Help Serial_Monitor_Example § a setup() S { Serial -begin (9600); /(Initiate Serial communicat Serial.printin("Hello World"); // Print hello world in seri ) oid loop () 0 v « > v < > Open the Serial Monitor Icon (Zoom Glass on the right side of the Arduino IDE) you can find the result for the program.LED-Digital WriteOverview LEDs make great indicator lights. They use very little electricity, and they pretty much last forever. The most common of all LEDs a Smm red LED. 5mm refers to the diameter of the LED and as well as 5mm, other standard sizes are 3mm and the large fun 10mm LEDs. You cannot directly connect an LED to a battery or voltage source. Firstly, because the LED has a positive and a negative lead and will not light if they are the wrong way around and secondly, an LED must be used with a resistor to limit the amount of current flowing through the LED - otherwise the LED could burn out If you do not use a resistor with an LED, then it may well be destroyed almost immediately, as too much current will flow through the LED, heating it and destroying the ‘junction’ where the light is produced. ‘There are two ways to tell which is the positive lead of the LED and which the negative. + Firstly, the positive lead is longer. + Secondly, where the negative lead enters the body of the LED, there isa flat edge to the case of the LED.How to Connect with Arduino Bread Board Layout Components Required 1) Arduino with cable 2) Breadboard 3) LED 4) 220 Qor 1KQArduino Code-Blink LED /*Blink,Turns on an LED on for one second, then off for one second, repeatedly.*/ // Pin 8 has an LED connected on most Arduino boards. int led = 8; // the setup routine rms once when you press reset: void setup() { pinMode(led, OUTPUT); // initialize the digital pin as an output. } // the loop routine runs over and over again forever: void loop() { digitalWrite(led, HIGH); —_// turn the LED on (HIGH is the voltage level) delay(1000); // wait for a second digitalWrite(led, LOW); // turn the LED off by making the voltage LOW delay(1000); // wait for a second } Push Button SwitchOverview Pushbuttons or switches connect two points in a circuit when you press them. This example turns on the built-in LED on pin 13 when you press the button. How to Connect with Arduino Bread Board LayoutComponents Required 1) Arduino with cable 2) Breadboard 3)push button 4) 220 Q or 1K QConnect three wires to the board. The first two, green and red, connect to the two long vertical rows on the side of the breadboard to provide access to the 5 volt supply and ground. The third wire goes from digital pin 2 to one leg of the pushbutton. That same leg of the button connects through a pull-down resistor (here 10K ohm) to ground. The other leg of the button connects to the 5 volt supply. When the pushbutton is open (unpressed) there is no connection between the two legs of the pushbutton, so the pin is connected to ground (through the pull- down resistor), and we read a LOW. When the button is closed (pressed), it makes a connection between its two legs, connecting the pin to 5 volts, so that we read a HIGH. You can also wire this circuit the opposite way, with a pull-up resistor keeping the input HIGH, and going LOW when the button is pressed. If so, the behavior of the sketch will be reversed, with the LED usually on and turned off when you press the button. If you disconnect the digital /O pin from everything, the LED may blink erratically. This is because the input is "floating" - that is, it will randomly return either HIGH or LOW. That's why you need a pull-up or pull-down resistor in the circuit. Arduino Code-Button Read const int buttonPin = 2; — // the number of the pushbutton pin const int ledPin= 13; — // the number of the LED pin int buttonState = 0; ut variable for reading the pushbutton status void setup() { pinMode(ledPin, OUTPUT); // initialize the LED pin as an output: pinMode(buttonPin, INPUT); // initialize the pushbutton pin as an input: } void loop() { buttonState = digitalRead(buttonPin); // read the state of the pushbutton value: if (buttonState == HIGH) // check if the pushbutton is pressed. If it is, the buttonState is HIGH: { digitalWrite(ledPin, HIGH); // turn LED on: } else {
You might also like
Getting Started 3.5 Inch
PDF
No ratings yet
Getting Started 3.5 Inch
24 pages
Arduino Inventors Kit Manual
PDF
100% (2)
Arduino Inventors Kit Manual
108 pages
Control Algorithm For A Biped Robot Based On Servo-Motors Controlled by An Android Application
PDF
No ratings yet
Control Algorithm For A Biped Robot Based On Servo-Motors Controlled by An Android Application
7 pages
Micropython On ESP8266 Workshop Documentation: Release 1.0
PDF
No ratings yet
Micropython On ESP8266 Workshop Documentation: Release 1.0
35 pages
Arduino Nano User Manual
PDF
100% (2)
Arduino Nano User Manual
5 pages
MECH 3032 Arduino - LED Finite State Machine Part 1: LED Finite State Machine, Random States Arduino Code
PDF
No ratings yet
MECH 3032 Arduino - LED Finite State Machine Part 1: LED Finite State Machine, Random States Arduino Code
4 pages
Interfacing RGB LED With Arduino Nano
PDF
No ratings yet
Interfacing RGB LED With Arduino Nano
8 pages
555 Timer Pinout
PDF
No ratings yet
555 Timer Pinout
1 page
Arduino Adxl335 Accelerometer Interfacing With Arduino Uno
PDF
No ratings yet
Arduino Adxl335 Accelerometer Interfacing With Arduino Uno
4 pages
Technoblogy - ATtiny85 Bargraph Voltmeter
PDF
No ratings yet
Technoblogy - ATtiny85 Bargraph Voltmeter
6 pages
Piu102 Piu201 Piu102 Piu201
PDF
100% (2)
Piu102 Piu201 Piu102 Piu201
2 pages
P R O T E U S: (1-Digit Up Counter)
PDF
No ratings yet
P R O T E U S: (1-Digit Up Counter)
29 pages
Power Supply Learning Kit For UNO
PDF
50% (2)
Power Supply Learning Kit For UNO
104 pages
Arduino Wifi Shield Schematic
PDF
No ratings yet
Arduino Wifi Shield Schematic
1 page
Advanced View Arduino Projects List - Use Arduino For Projects
PDF
No ratings yet
Advanced View Arduino Projects List - Use Arduino For Projects
107 pages
IoT Project Using ESP32 Blynk Google Assistant Wit
PDF
No ratings yet
IoT Project Using ESP32 Blynk Google Assistant Wit
33 pages
Arduino 101 Pt1
PDF
100% (1)
Arduino 101 Pt1
6 pages
Working With Displays - Book 2 of The Arduino Short Reads Series
PDF
No ratings yet
Working With Displays - Book 2 of The Arduino Short Reads Series
87 pages
1 8 TFT Display
PDF
No ratings yet
1 8 TFT Display
77 pages
The 74HC164 Shift Register and Your Arduino
PDF
100% (2)
The 74HC164 Shift Register and Your Arduino
13 pages
ESP8266 ESP-01 USB Serial Programmer With CH340
PDF
No ratings yet
ESP8266 ESP-01 USB Serial Programmer With CH340
15 pages
Arduino Poster High-Resolution
PDF
No ratings yet
Arduino Poster High-Resolution
1 page
Hallberg Gary - First Steps With Arduino (Arduino Short Reads. Book 1) - 2020
PDF
No ratings yet
Hallberg Gary - First Steps With Arduino (Arduino Short Reads. Book 1) - 2020
93 pages
270 Mini Electronics Project With Circuit Diagram
PDF
No ratings yet
270 Mini Electronics Project With Circuit Diagram
224 pages
Tutorial Myrio
PDF
100% (1)
Tutorial Myrio
57 pages
Learn Arduino Sensor With Projects For Beginners
PDF
No ratings yet
Learn Arduino Sensor With Projects For Beginners
85 pages
دستگاه سیستم چرخدنده ای
PDF
No ratings yet
دستگاه سیستم چرخدنده ای
8 pages
007 en
PDF
No ratings yet
007 en
13 pages
Adafruit Optical Fingerprint Sensor: Created by Lady Ada
PDF
100% (1)
Adafruit Optical Fingerprint Sensor: Created by Lady Ada
26 pages
Ardx Eg Adaf Web
PDF
No ratings yet
Ardx Eg Adaf Web
36 pages
LVGL Library
PDF
No ratings yet
LVGL Library
1,091 pages
ArduinoTrafficLight Download 032020
PDF
No ratings yet
ArduinoTrafficLight Download 032020
20 pages
Arduino Programming - A Beginners Guide of How Best To Program Arduino Step by Step in 2020
PDF
0% (1)
Arduino Programming - A Beginners Guide of How Best To Program Arduino Step by Step in 2020
103 pages
ARDUINO Super Learning Kit PDF
PDF
No ratings yet
ARDUINO Super Learning Kit PDF
167 pages
NodemcudevkitusingArduinoI MageshJayakumar
PDF
100% (1)
NodemcudevkitusingArduinoI MageshJayakumar
73 pages
30 Smart Project Microcontroller Arduino
PDF
No ratings yet
30 Smart Project Microcontroller Arduino
105 pages
Building and Running Micropython On The Esp8266
PDF
No ratings yet
Building and Running Micropython On The Esp8266
12 pages
Stm32cube Ecosystem Overview
PDF
No ratings yet
Stm32cube Ecosystem Overview
65 pages
Automation Home With Arduino UNO and APP Inventor 2 by Guillermo Perez
PDF
No ratings yet
Automation Home With Arduino UNO and APP Inventor 2 by Guillermo Perez
28 pages
Arduino PPT Akhil
PDF
No ratings yet
Arduino PPT Akhil
15 pages
Arduino: A Technical Reference
PDF
25% (4)
Arduino: A Technical Reference
3 pages
Arduino Playground - Matlab
PDF
No ratings yet
Arduino Playground - Matlab
3 pages
Esp32 Cam
PDF
No ratings yet
Esp32 Cam
6 pages
Getting Started With Arduino and Go by Agus Kurniawan
PDF
No ratings yet
Getting Started With Arduino and Go by Agus Kurniawan
79 pages
Contents - Programming With Node-RED
PDF
100% (1)
Contents - Programming With Node-RED
8 pages
2015 New Uno Ultimate Starter Kit R套件
PDF
No ratings yet
2015 New Uno Ultimate Starter Kit R套件
139 pages
Esp32-H2 Technical Reference Manual en
PDF
100% (1)
Esp32-H2 Technical Reference Manual en
1,160 pages
Spinning - Rotating LED Display Using Arduino POV
PDF
No ratings yet
Spinning - Rotating LED Display Using Arduino POV
23 pages
Arduino Inductance
PDF
100% (2)
Arduino Inductance
4 pages
Advanced View of Atmega Microcontroller Projects List - Projects Tutorials Code Library For Atmels Atmega32 AVR
PDF
No ratings yet
Advanced View of Atmega Microcontroller Projects List - Projects Tutorials Code Library For Atmels Atmega32 AVR
144 pages
Arduino Modules L298N
PDF
No ratings yet
Arduino Modules L298N
4 pages
Microcontroller Programming With Arduino and Python
PDF
100% (1)
Microcontroller Programming With Arduino and Python
152 pages
Bräunl, Thomas - Robot Adventures in Python and C
PDF
No ratings yet
Bräunl, Thomas - Robot Adventures in Python and C
185 pages
TB6600 Stepper Motor Driver BM3D v1.1
PDF
No ratings yet
TB6600 Stepper Motor Driver BM3D v1.1
8 pages
Arduino Part 1: Topics: Microcontrollers Programming Basics: Structure and Variables Digital Output
PDF
No ratings yet
Arduino Part 1: Topics: Microcontrollers Programming Basics: Structure and Variables Digital Output
30 pages
Arduino LCD 2
PDF
100% (2)
Arduino LCD 2
8 pages
Arduino Measurement Projects For Beginners
PDF
100% (5)
Arduino Measurement Projects For Beginners
175 pages
Letter of Request
PDF
No ratings yet
Letter of Request
27 pages
Electronic Workbench AND TOOLS
PDF
100% (1)
Electronic Workbench AND TOOLS
44 pages