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)
4 views
Assignment-5es & Iot
Iot
Uploaded by
sri296315
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save Assignment-5es & Iot For Later
Download
Save
Save Assignment-5es & Iot For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
0 ratings
0% found this document useful (0 votes)
4 views
Assignment-5es & Iot
Iot
Uploaded by
sri296315
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save Assignment-5es & Iot For Later
Carousel Previous
Carousel Next
Save
Save Assignment-5es & Iot For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download
You are on page 1
/ 7
Search
Fullscreen
Gil Arduino Programming Structure ected to a computer via USB, where it connects with the Arduino Development Environment (IDE). The user writes the Arduino code in the IDE, then uploads it to the microcontroller which executes the code, interacting with inputs and outputs such as sensors, motors and lights. © The Arduino board is conn ® fuses aceEmbedded Systems and loT 5-14 JOT and Arduing Program, nr AA ‘ ~~ en in C++ with an addition of special methods and fy, “ is writt Arduino code the Arduino IDE, it should be uploadeg “* on ‘After the sketch is written in Arduino board for execution. Libraries : Arduino provides built-in libraries, which provide basic functional is also possible to import other libraries and expand the Arduing an capabilities and features. These libraries are roughly divided into libraries a interact with a specific component or those that implement new functions, t © The Arduino programming language is based on a very simple hardware programming language called processing, which is similar to the C language, aj, the sketch is written in the Arduino IDE, it should be uploaded on the Arduing board for execution. The first step in programming the Arduino board is downloading and installing the Arduino IDE. The open source Arduino IDE runs on Windows, Mac OS X ang Linux. Downloaded the Arduino software (depending on your OS) from the official website and follow the instructions to install. ‘The Arduino board is connected to a computer via USB, where it connects with the Arduino development environment (IDE). The user writes the Arduino code in the IDE, then uploads it to the microcontroller which executes the code, interacting with inputs and outputs such as sensors, motors and lights. To get it started with Arduino Uno board and blink the built-in LED, load the example code by selecting Files>Examples>Basics>Blink. Once the example code is loaded into IDE, click on the ‘upload’ button given on the top bar. Once the upload is finished, we should see the Arduino built-in LED blinking. Below is the example code for blinking : // the setup function nuns once when we press reset or power the board void setup() { // initialize digital pin LED_BUILTIN as an output. pinMode(LED_BUILTIN, OUTPUT); } // the loop function runs over and over again forever void loop() { digitalWrite(LED_BUILTIN, HIGH); // tum the LED on (HIGH is the // voltage level) // wait for a second // tam the LED off by making the ae // voltage LOW } // wait for a second delay(1000); digitalWrite(LED_BUILTIN, Low); TECHNICAL PUBLICATIONS® . an thrust for knowledge ICATIOL sp-thrus o. ledgejoa ane [ol 5-16 Jo and Arduino Programming sya ms OTE AVOID. SPOT EOINTUL yal te! ‘ty to connect to a sensor, display, +A eae, eles Hor example, the bulltinLiquidCryotal library makes it easy to talk to " rele LCD dlaplays. there are hundreds of additional libraries available on the ; jorniet fOr download, le vw ate are acollyetion of code that makes ite wil skotchos «A programy written In the Arduino Programming Language is called sketch, A gheteh is normally saved with the “ino” extension (from Arduino). yhe Arduino program can be divided in three main parts : Structure, Values (variables and constants) and Functions, | Structure setup( ), loop( ) 2, Control structure + if, if....else, for, switeh case, while, do....while, break, continue. 3. Variables ; Constants —» HIGHILOW, INPUTIOUTPUT, truel false, integer constants, floating point constants, Data types —> void, boolean, char, byte, unsigned char 4, Functions : Digital 1/O — pinMode( ), digitalWrite( ), digitalRead( ), Analog 1/O — analogReference( ), analogRead( ), analogWrite( ). Strucutra | | Functions Values | [ Set-up wan | [ vention | [ Variables | E conan | Fig. 5.5.1 iti duino + * Remarks for writing a program for Ar E 1. To complete the statement a semicolon "7" is used at the end of the statement. 2. To enclose the block parenthesis "()" are used. aaa in a program contains some statements, declaration of the variables, functions, or loops, ° 1 knows TECHNIGAL PUBLICATIONS® - an upIMust for knowledge5-16 foT and Ary Embedded Systems and loT = ; tatement in the code to better und, written for each u erst 3. Soames ae pai It can be done by using double forward stag, =)" a, Seer ec ymont if there is only 2 single line comment. However ip “t, start of the ees in a row, a forward slash asterisk "/*" at the start and ee pa line eo my" at the end of the comment, Comments can also py wert forware fo Jude any statement. ° Fig 5.5.2 shows basic Arduino Sketch Structure. Fig. 5.5.2 Arduino sketch structure * Variable declaration section : In the variable declaration section, usually contains variables that we must declare. To declare is to indicate that something will be used or specified for a particular use a + Here we setup the “actions” of what the program is going to do © make the final product function. This could inchade describing which pins will be TECHNICAL PuBUCA Tions® 87 up-thrust for kmowteageoT and Ardui Ege which mathematical elegant rig a ve . ations wi . ation of the i ‘ will 6 ais i tlie a libraries, Variables useq f pean Setup() function on’, of the Arduino are also declared in this fun es e code, Similarly, pin ction. : \e 000 ati ‘ a ynunication between the Arduino board and the com, Tt also initializes the section : The Loop section tells puter. It only runs once, writing the sketch : yoid setup() { gerial-begin(9600); serial.printin("Hello, worldl"); } yoid loop() { } + Running the sketch : Plug Arduino into PC using a USB cable. Click the Upload putton to load the program to the Arduino. «+ Now open the Arduino IDE Serial Monitor Window to see the sketch run and print the text message. Opens serial monitor window no . le in jal monitor window. apie in the serial monitor win« id be visibl ts shoul tpt «The text that the program outP! Tions® - a” tp-thrust for knowledge TECHNICAL PUBLICA’ ‘ci ileEmbedded Systems and loT a 5-10 oT and Arduino Progr min BEF Pins = . To use the Arduino pins, you need to define which pin is being used , functionality. A convenient way to define the used pins is by using ; ‘#dofino pinNamo pinNumber’ The functionality is either input or output and is defined by using the pinMo, ey method in the setup section. o ‘The pins on the Arduino can be configured as either inputs or outputs. Arduing (Atmega) pins default to inputs, so they don't need to be explicitly declared a5 inputs with pinMode() when we are using them as inputs. Pins configured this way are said to be in a high-impedance state. Input ping make extremely small demands on the circuit that they are sampling, equivalent to a series resistor of 100 MQ in front of the pin. This means that it takes very little current to move the input pin from one state to another and can make the pins useful for such tasks as implementing a capacitive touch sensor, reading an LED as a photodiode, or reading an analog sensor with a scheme such as RCTime. Each pin operates at 5 V at HIGH and 0 V at LOW. It can provide or receive a maximum current of 40 mA, but only 20 mA continuous, which is merely sufficient to drive a single - color LED @ 20 mA for full brightness continuously. Total current for the chipset shall not exceed 200 mA, ie., driving 10 single - color LEDs @ 20 mA. Pin 13 : There is a built-in LED connected to Pin 13, under Pin 13. It is useful for debugging. PWM Output : 6 of the pins (pins 3, 5, 6, 9, 10 and 11, marked with ~) can produce PWM (Pulse Width Modulated) output Digital input pins can be configured as pinMode(pin, INPUT), where the pin is the digital pin number we want to initialize. Often it is useful to steer an input pin to a known state if no input is present. This can be done by adding a pull-up resistor (to +5 V), or a pulldown resistor (resistor to ground) on the input. A 10K resistor is a good value for a pull - up or pulldown resistor. If the pin is configured as INPUT_PULLUP during initialization, it inverts the behavior of the INPUT mode, where HIGH means the sensor is OFF and LOW means the sensor is ON. It is because there are 20 K pull-up resistors built into the Atmega chip that can be accessed from software. Pins can be configured as OUTPUT with pinMode(pin, OUTPUT), where the P# is the digital pin number we want to initialize as output. These pins are also in ® low - impedance state. This means that they can provide a substantial amount of current to other circuits. nd ity TECHNICAL PUBLICATIONS® - an up-thrust for knowledge5-19 oT werd brduina Progremnenitig eM) gsi function in Arduino IDE, » URS GH o LOW value. If the pin has bem paved its voltage will be set to the correspo digital pin, to a OUTPUT with Y for HIGH, OV of (LOW) the internal pull-up on he input pin It is recom -Mode() to INPUT_PULLUP to enable the internal pull-up re , The analog input pins can also be used as digital pins, referred to 25 AD, Al, ete duino program for LED blink : ‘2 LED =13; // The digital pin to ‘yoid savup () which the LED is comected pinMMode (LED, OUTPUT); //Declaring pin 12 az output pin } eid loop) // The loop function runs again and again { digitalWrite (LED, HIGH); //Tum ON the LED delay(1000); //Wait for 1 see digitalRead (LED, LOW); // Tum off the LED delay(1000); // Wait for 1 sec i Here, LED is declared globally and is set to pin number 13. This will reduce the number of iterations required to update the pin number in the program when we connect the LED to the other digital pin. * A pin on Arduino can be set as input or output by using pinMode function. PinMede(12, OUTPUT); —_// sets pin 13 as output pin pinMode(13, INPUT); // sets pin 13 as input pin ReadingMWriting digital values digitalWrrite(13, LOW); // Makes the output voltage on pin 13,0 V digitalWrite(13, HIGH); // Makes the output voltage on pin 13,5 V itbuttonState=digitalRead(2); // reads the value of pin 2 in buttonState —_
You might also like
The Subtle Art of Not Giving a F*ck: A Counterintuitive Approach to Living a Good Life
From Everand
The Subtle Art of Not Giving a F*ck: A Counterintuitive Approach to Living a Good Life
Mark Manson
4/5 (6125)
Principles: Life and Work
From Everand
Principles: Life and Work
Ray Dalio
4/5 (627)
The Gifts of Imperfection: Let Go of Who You Think You're Supposed to Be and Embrace Who You Are
From Everand
The Gifts of Imperfection: Let Go of Who You Think You're Supposed to Be and Embrace Who You Are
Brené Brown
4/5 (1148)
Never Split the Difference: Negotiating As If Your Life Depended On It
From Everand
Never Split the Difference: Negotiating As If Your Life Depended On It
Chris Voss
4.5/5 (932)
The Glass Castle: A Memoir
From Everand
The Glass Castle: A Memoir
Jeannette Walls
4/5 (8214)
Grit: The Power of Passion and Perseverance
From Everand
Grit: The Power of Passion and Perseverance
Angela Duckworth
4/5 (631)
Sing, Unburied, Sing: A Novel
From Everand
Sing, Unburied, Sing: A Novel
Jesmyn Ward
4/5 (1253)
The Perks of Being a Wallflower
From Everand
The Perks of Being a Wallflower
Stephen Chbosky
4/5 (8365)
Shoe Dog: A Memoir by the Creator of Nike
From Everand
Shoe Dog: A Memoir by the Creator of Nike
Phil Knight
4.5/5 (860)
Her Body and Other Parties: Stories
From Everand
Her Body and Other Parties: Stories
Carmen Maria Machado
4/5 (877)
Hidden Figures: The American Dream and the Untold Story of the Black Women Mathematicians Who Helped Win the Space Race
From Everand
Hidden Figures: The American Dream and the Untold Story of the Black Women Mathematicians Who Helped Win the Space Race
Margot Lee Shetterly
4/5 (954)
The Hard Thing About Hard Things: Building a Business When There Are No Easy Answers
From Everand
The Hard Thing About Hard Things: Building a Business When There Are No Easy Answers
Ben Horowitz
4.5/5 (361)
Steve Jobs
From Everand
Steve Jobs
Walter Isaacson
4/5 (2922)
Elon Musk: Tesla, SpaceX, and the Quest for a Fantastic Future
From Everand
Elon Musk: Tesla, SpaceX, and the Quest for a Fantastic Future
Ashlee Vance
4.5/5 (484)
The Emperor of All Maladies: A Biography of Cancer
From Everand
The Emperor of All Maladies: A Biography of Cancer
Siddhartha Mukherjee
4.5/5 (277)
A Man Called Ove: A Novel
From Everand
A Man Called Ove: A Novel
Fredrik Backman
4.5/5 (4972)
Angela's Ashes: A Memoir
From Everand
Angela's Ashes: A Memoir
Frank McCourt
4.5/5 (444)
Brooklyn: A Novel
From Everand
Brooklyn: A Novel
Colm Tóibín
3.5/5 (2061)
The Art of Racing in the Rain: A Novel
From Everand
The Art of Racing in the Rain: A Novel
Garth Stein
4/5 (4281)
The Yellow House: A Memoir (2019 National Book Award Winner)
From Everand
The Yellow House: A Memoir (2019 National Book Award Winner)
Sarah M. Broom
4/5 (100)
The Little Book of Hygge: Danish Secrets to Happy Living
From Everand
The Little Book of Hygge: Danish Secrets to Happy Living
Meik Wiking
3.5/5 (447)
The World Is Flat 3.0: A Brief History of the Twenty-first Century
From Everand
The World Is Flat 3.0: A Brief History of the Twenty-first Century
Thomas L. Friedman
3.5/5 (2283)
Bad Feminist: Essays
From Everand
Bad Feminist: Essays
Roxane Gay
4/5 (1068)
Yes Please
From Everand
Yes Please
Amy Poehler
4/5 (1987)
Devil in the Grove: Thurgood Marshall, the Groveland Boys, and the Dawn of a New America
From Everand
Devil in the Grove: Thurgood Marshall, the Groveland Boys, and the Dawn of a New America
Gilbert King
4.5/5 (278)
The Outsider: A Novel
From Everand
The Outsider: A Novel
Stephen King
4/5 (1993)
The Woman in Cabin 10
From Everand
The Woman in Cabin 10
Ruth Ware
3.5/5 (2641)
A Tree Grows in Brooklyn
From Everand
A Tree Grows in Brooklyn
Betty Smith
4.5/5 (1936)
The Sympathizer: A Novel (Pulitzer Prize for Fiction)
From Everand
The Sympathizer: A Novel (Pulitzer Prize for Fiction)
Viet Thanh Nguyen
4.5/5 (125)
A Heartbreaking Work Of Staggering Genius: A Memoir Based on a True Story
From Everand
A Heartbreaking Work Of Staggering Genius: A Memoir Based on a True Story
Dave Eggers
3.5/5 (692)
Team of Rivals: The Political Genius of Abraham Lincoln
From Everand
Team of Rivals: The Political Genius of Abraham Lincoln
Doris Kearns Goodwin
4.5/5 (1912)
Wolf Hall: A Novel
From Everand
Wolf Hall: A Novel
Hilary Mantel
4/5 (4074)
Fear: Trump in the White House
From Everand
Fear: Trump in the White House
Bob Woodward
3.5/5 (830)
On Fire: The (Burning) Case for a Green New Deal
From Everand
On Fire: The (Burning) Case for a Green New Deal
Naomi Klein
4/5 (75)
Rise of ISIS: A Threat We Can't Ignore
From Everand
Rise of ISIS: A Threat We Can't Ignore
Jay Sekulow
3.5/5 (143)
Manhattan Beach: A Novel
From Everand
Manhattan Beach: A Novel
Jennifer Egan
3.5/5 (901)
John Adams
From Everand
John Adams
David McCullough
4.5/5 (2530)
The Light Between Oceans: A Novel
From Everand
The Light Between Oceans: A Novel
M L Stedman
4.5/5 (790)
The Unwinding: An Inner History of the New America
From Everand
The Unwinding: An Inner History of the New America
George Packer
4/5 (45)
Little Women
From Everand
Little Women
Louisa May Alcott
4/5 (105)
The Constant Gardener: A Novel
From Everand
The Constant Gardener: A Novel
John le Carré
3.5/5 (109)
Related titles
Click to expand Related Titles
Carousel Previous
Carousel Next
The Subtle Art of Not Giving a F*ck: A Counterintuitive Approach to Living a Good Life
From Everand
The Subtle Art of Not Giving a F*ck: A Counterintuitive Approach to Living a Good Life
Principles: Life and Work
From Everand
Principles: Life and Work
The Gifts of Imperfection: Let Go of Who You Think You're Supposed to Be and Embrace Who You Are
From Everand
The Gifts of Imperfection: Let Go of Who You Think You're Supposed to Be and Embrace Who You Are
Never Split the Difference: Negotiating As If Your Life Depended On It
From Everand
Never Split the Difference: Negotiating As If Your Life Depended On It
The Glass Castle: A Memoir
From Everand
The Glass Castle: A Memoir
Grit: The Power of Passion and Perseverance
From Everand
Grit: The Power of Passion and Perseverance
Sing, Unburied, Sing: A Novel
From Everand
Sing, Unburied, Sing: A Novel
The Perks of Being a Wallflower
From Everand
The Perks of Being a Wallflower
Shoe Dog: A Memoir by the Creator of Nike
From Everand
Shoe Dog: A Memoir by the Creator of Nike
Her Body and Other Parties: Stories
From Everand
Her Body and Other Parties: Stories
Hidden Figures: The American Dream and the Untold Story of the Black Women Mathematicians Who Helped Win the Space Race
From Everand
Hidden Figures: The American Dream and the Untold Story of the Black Women Mathematicians Who Helped Win the Space Race
The Hard Thing About Hard Things: Building a Business When There Are No Easy Answers
From Everand
The Hard Thing About Hard Things: Building a Business When There Are No Easy Answers
Steve Jobs
From Everand
Steve Jobs
Elon Musk: Tesla, SpaceX, and the Quest for a Fantastic Future
From Everand
Elon Musk: Tesla, SpaceX, and the Quest for a Fantastic Future
The Emperor of All Maladies: A Biography of Cancer
From Everand
The Emperor of All Maladies: A Biography of Cancer
A Man Called Ove: A Novel
From Everand
A Man Called Ove: A Novel
Angela's Ashes: A Memoir
From Everand
Angela's Ashes: A Memoir
Brooklyn: A Novel
From Everand
Brooklyn: A Novel
The Art of Racing in the Rain: A Novel
From Everand
The Art of Racing in the Rain: A Novel
The Yellow House: A Memoir (2019 National Book Award Winner)
From Everand
The Yellow House: A Memoir (2019 National Book Award Winner)
The Little Book of Hygge: Danish Secrets to Happy Living
From Everand
The Little Book of Hygge: Danish Secrets to Happy Living
The World Is Flat 3.0: A Brief History of the Twenty-first Century
From Everand
The World Is Flat 3.0: A Brief History of the Twenty-first Century
Bad Feminist: Essays
From Everand
Bad Feminist: Essays
Yes Please
From Everand
Yes Please
Devil in the Grove: Thurgood Marshall, the Groveland Boys, and the Dawn of a New America
From Everand
Devil in the Grove: Thurgood Marshall, the Groveland Boys, and the Dawn of a New America
The Outsider: A Novel
From Everand
The Outsider: A Novel
The Woman in Cabin 10
From Everand
The Woman in Cabin 10
A Tree Grows in Brooklyn
From Everand
A Tree Grows in Brooklyn
The Sympathizer: A Novel (Pulitzer Prize for Fiction)
From Everand
The Sympathizer: A Novel (Pulitzer Prize for Fiction)
A Heartbreaking Work Of Staggering Genius: A Memoir Based on a True Story
From Everand
A Heartbreaking Work Of Staggering Genius: A Memoir Based on a True Story
Team of Rivals: The Political Genius of Abraham Lincoln
From Everand
Team of Rivals: The Political Genius of Abraham Lincoln
Wolf Hall: A Novel
From Everand
Wolf Hall: A Novel
Fear: Trump in the White House
From Everand
Fear: Trump in the White House
On Fire: The (Burning) Case for a Green New Deal
From Everand
On Fire: The (Burning) Case for a Green New Deal
Rise of ISIS: A Threat We Can't Ignore
From Everand
Rise of ISIS: A Threat We Can't Ignore
Manhattan Beach: A Novel
From Everand
Manhattan Beach: A Novel
John Adams
From Everand
John Adams
The Light Between Oceans: A Novel
From Everand
The Light Between Oceans: A Novel
The Unwinding: An Inner History of the New America
From Everand
The Unwinding: An Inner History of the New America
Little Women
From Everand
Little Women
The Constant Gardener: A Novel
From Everand
The Constant Gardener: A Novel