Important Announcement
PubHTML5 Scheduled Server Maintenance on (GMT) Sunday, June 26th, 2:00 am - 8:00 am.
PubHTML5 site will be inoperative during the times indicated!

Home Explore CU-BCA-Sem VI-IOT Based Applications

CU-BCA-Sem VI-IOT Based Applications

Published by Teamlease Edtech Ltd (Amita Chitroda), 2022-11-12 07:10:45

Description: CU-BCA-Sem VI-IOT Based Applications

Search

Read the Text Version

["Fig 5.22 Power source switching mechanism. Click to enlarge. The LP2985-33DBVR is the 3V3 regulator. Both the 3V3 and 5V regulators are LDO (Low Dropout), which means that they can regulate voltage even if the input voltage is close to the output voltage. This is an improvement over older linear regulators, such as the 7805. The last thing I'll talk about is the power protection that is provided in Arduino UNO. As mentioned above, VIN from a DC jack is protected from reverse polarity by using a serial M7 diode in the input. Be aware that the VIN pin in the power header is not protected. This is because it is connected after the M7 diode. Personally, I don\u2019t know why they decided to do that when they could connect it before the diode to provide the same protection. 101 CU IDOL SELF LEARNING MATERIAL (SLM)","Fig 5.23 VIN pin from power header. Click to enlarge. When you use USB as a power source, and to provide protection for your USB port, there is a PTC (positive temperature coefficient) fuse (MF-MSMF050-2) in series with the USBVCC. This provides protection from overcurrent, 500mA. When an overcurrent limit is reached, the PTC resistance increases a lot. Resistance decreases after the overcurrent is removed. 102 CU IDOL SELF LEARNING MATERIAL (SLM)","5.5 SUMMARY \uf0b7 Arduino is an open-source electronics platform based on easy-to-use hardware and software. Arduino boards are able to read inputs - light on a sensor, a finger on a button, or a Twitter message - and turn it into an output - activating a motor, turning on an LED, publishing something online \uf0b7 Arduino is an open-source platform used for building electronics projects. Arduino consists of both a physical programmable circuit board (often referred to as a microcontroller) and a piece of software, or IDE (Integrated Development Environment) that runs on your computer, used to write and upload computer code to the physical board. \uf0b7 The Arduino platform has become quite popular with people just starting out with electronics, and for good reason. Unlike most previous programmable circuit boards, the Arduino does not need a separate piece of hardware (called a programmer) in order to load new code onto the board -- you can simply use a USB cable. Additionally, the Arduino IDE uses a simplified version of C++, making it easier to learn to program. Finally, Arduino provides a standard form factor that breaks out the functions of the micro-controller into a more accessible package. 5.6 KEYWORDS \uf0b7 API Application Programming Interface: the interface used to interact programmatically with a piece of software. The API of an Arduino library is the public functions exposed to the user. The library may contain many other functions that are only used internally, but it is only necessary to understand the API in order to use the library. \uf0b7 AREF Analog REFerence : the reference max voltage for the Analog to Digital converter. Changing the AREF allows to use the resolution of the ADC at its best, especially for low voltages. Usually AREF can\u2019t be greater than the supply voltage of the ADC circuit. \uf0b7 ATSAMW25 The SAM W25 module is based on Atmel\u2019s WINC1500 Wi-Fi core combined with Atmel\u2019s ARM\u00ae Cortex\u00ae -M0+ based microcontroller technology. It allows to build low power solutions for Internet of Things. \uf0b7 Accelerometer A sensor that measures acceleration. Sometimes, they are used to detect orientation, or tilt. 103 CU IDOL SELF LEARNING MATERIAL (SLM)","\uf0b7 Access Point A WiFi device that connects to the physical network and allows to access the LAN through the wireless connection. Usually it takes care of the authentication and the assignment of an IP address. \uf0b7 Actuator A type of component that changes an energy into motion. Motors are a type of electrical actuator. \uf0b7 Alternating current A type of current where electricity changes its direction periodically. This is the sort of electricity that comes out of a wall socket. Amperage (Amps or Amperes) The amount of electrical charge flowing past a specific point in your circuit. Describes the current as it flows through a conductor, like a wire. \uf0b7 Analog Something that can continuously vary over time. \uf0b7 Analog-to-Digital Converter (ADC) A circuit that converts an analog voltage into a digital number representing that voltage. This circuit is built-in to the microcontroller, and is connected to the analog input pins of the Arduino board. \uf0b7 Anode The positive end of a diode (remember that an LED is a type of diode). \uf0b7 Argument A type of data supplied to a function as an input. For example, for digitalRead() to know what pin to check, it takes an argument in the form of a pin number. \uf0b7 Array In programming, this is a group of variables that are identified by one name, and accessed by an index number. 5.7 LEARNING ACTIVITY 1. In Arduino-speak, what is a shield? Identify at least two shields, where you can get them from and how much they cost. 104 CU IDOL SELF LEARNING MATERIAL (SLM)","2. What processor family does Arduino primarily use? Name another programming environment that is commonly used to program that family. What are the pros and cons of Arduino compared to that environment? 5.8UNIT END QUESTIONS A. Descriptive questions Short Questions 1. What is Arduino? 2. What is the stable version of Arduino software? 3. Who is the developer of Arduino? 4. Why we should use Arduino? 5. In which language Arduino software was written? Long Questions 1. What are the advantages of Arduino? 2. What are the IDE toolbar of Arduino? 3. Explain the advantage of Open source community 4. Draw and explain the functional block diagram of Arduino UNO? A. Multiple Choice Questions 105 1. What is Arduino? a) Programming language b) Image editing software c) Open-source electronics platform d) Text editor Answer: c 2. How many types of Arduino do we have? a) 4 b) 8 c) 12 CU IDOL SELF LEARNING MATERIAL (SLM)","d) 16 Answer: b 3. What language is a typical Arduino code based on? a) Assembly Code b) Python c) Java d) C\/C++ Answer: d 4. Arduino shields are also called as _________ a) Another Arduinos b) Extra peripherals c) Add on modules d) Connectivity modules Answer: c 5. What language is the Arduino IDE built on? a) Java b) HTML c) C\/C++ d) Python Answer: a 5.9 REFERENCES Text Books: - 1. Internet of Things (A Hands on Approach), By ArshdeepBahga (Author),VijayMadisetti(Author). Edition: Second Edition, Illustrated, Reprint (2014) Publisher: VPT, 2017 2. \u201cBeginning Arduino\u201d by Michael McRobetrs(Author). Publisher:Technology in Action 106 CU IDOL SELF LEARNING MATERIAL (SLM)","Reference Books: - 1. Tim Cox, Dr. Steven Lawrence Fernandes, Sai Yamanoor, Srihari Yamanoor, Prof. DiwakarVaish,\u201d Getting Started with Python for the Internet of Things: Leverage the full potential of Python to prototype and build IoT projects using the RaspberryPi Edition: First Edition Publisher:Packt Publisher-2019 107 CU IDOL SELF LEARNING MATERIAL (SLM)","UNIT - 6INTRODUCTION TO ARDUINO 2 STRUCTURE 6.0 Learning Objectives 6.1 Introduction 6.2 Classification of Arduino Functions of each Pin of Arduino UNO 6.3 Designing of 1st sketch 6.4 Programming of an Arduino 6.5 Summary 6.6 Keywords 6.7 Learning Activity 6.8 Unit End Questions 6.9 References 6.0LEARNING OBJECTIVES After studying this unit, you will be able to: \uf0b7 Learn about the functions of pins in Arduino \uf0b7 How to design \uf0b7 Know how to program in Arduino 6.1 INTRODUCTION Arduino is an open-source electronics platform based on easy-to-use hardware and software. Arduino boards are able to read inputs - light on a sensor, a finger on a button, or a Twitter message - and turn it into an output - activating a motor, turning on an LED, publishing something online. Arduino is an open-source platform used for building electronics projects. Arduino consists of both a physical programmable circuit board (often referred to as a microcontroller) and a piece of software, or IDE (Integrated Development Environment) that runs on your computer, used to write and upload computer code to the physical board. 108 CU IDOL SELF LEARNING MATERIAL (SLM)","The Arduino platform has become quite popular with people just starting out with electronics, and for good reason. Unlike most previous programmable circuit boards, the Arduino does not need a separate piece of hardware (called a programmer) in order to load new code onto the board -- you can simply use a USB cable. Additionally, the Arduino IDE uses a simplified version of C++, making it easier to learn to program. Finally, Arduino provides a standard form factor that breaks out the functions of the micro-controller into a more accessible package. 6.2 CLASSIFICATION OF ARDUINO FUNCTIONS OF EACH PIN OF ARDUINO UNO pin configuration of the following models: 1. Arduino Uno(R3) 2. Arduino Mega (R3) 3. Arduino Nano 4. Arduino Leonardo 5. Arduino Due 6. LilyPad Arduino 7. Arduino Micro 8. Arduino Pro Mini Arduino Uno (R3) As we discussed we know that Arduino Uno is the most standard board available and probably the best choice for a beginner. We can directly connect the board to the computer via a USB Cable which performs the function of supplying the power as well as acting as a serial port. 109 CU IDOL SELF LEARNING MATERIAL (SLM)","Fig 6.1 Arduino Uno (R3) Image Source: diyi0t.com Vin: This is the input voltage pin of the Arduino board used to provide input supply from an external power source. 5V: This pin of the Arduino board is used as a regulated power supply voltage and it is used to give supply to the board as well as onboard components. 3.3V: This pin of the board is used to provide a supply of 3.3V which is generated from a voltage regulator on the board GND: This pin of the board is used to ground the Arduino board. Reset: This pin of the board is used to reset the microcontroller. It is used to Resets the microcontroller. Analog Pins: The pins A0 to A5 are used as an analog input and it is in the range of 0-5V. Digital Pins: The pins 0 to 13 are used as a digital input or output for the Arduino board. 110 CU IDOL SELF LEARNING MATERIAL (SLM)","Serial Pins: These pins are also known as a UART pin. It is used for communication between the Arduino board and a computer or other devices. The transmitter pin number 1 and receiver pin number 0 is used to transmit and receive the data resp. External Interrupt Pins: This pin of the Arduino board is used to produce the External interrupt and it is done by pin numbers 2 and 3. PWM Pins: This pins of the board is used to convert the digital signal into an analog by varying the width of the Pulse. The pin numbers 3,5,6,9,10 and 11 are used as a PWM pin. SPI Pins: This is the Serial Peripheral Interface pin, it is used to maintain SPI communication with the help of the SPI library. SPI pins include: 1. SS: Pin number 10 is used as a Slave Select 2. MOSI: Pin number 11 is used as a Master Out Slave In 3. MISO: Pin number 12 is used as a Master In Slave Out 4. SCK: Pin number 13 is used as a Serial Clock LED Pin: The board has an inbuilt LED using digital pin-13. The LED glows only when the digital pin becomes high. AREF Pin: This is an analog reference pin of the Arduino board. It is used to provide a reference voltage from an external power supply. Arduino Mega (R3) 111 CU IDOL SELF LEARNING MATERIAL (SLM)","The most important thing about this board is that the board has more input-output pins so it is very beneficial for the Advanced Users or the people who want more pins for their projects. Fig 6.2 Arduino Mega (R3) Image Source: diyi0t.com Vin: This is the input voltage pin of the Arduino board used to provide input supply from an external power source. 5V: This pin of the Arduino board is used as a regulated power supply voltage and it is used to give supply to the board as well as onboard components. 3.3V: This pin of the board is used to provide a supply of 3.3V which is generated from a voltage regulator on the board GND: This pin of the board is used to ground the Arduino board. Reset: This pin of the board is used to reset the microcontroller It is used to Resets the microcontroller. 112 CU IDOL SELF LEARNING MATERIAL (SLM)","Analog Pins: The pins A0 to A15 are used as an analog input and it is in the range of 0-5V. The analog pins on this board can be used as a digital Input or Output pins. Serial pins: It is used for communication between the Arduino board and a computer or other devices. The TXD and RXD are used to transmit & receive the serial data resp. It includes serial 0, Serial 1, serial 2, Serial 3 as follows: 1. Serial 0: It consists of Transmitter pin number 1 and receiver pin number 0 2. Serial 1: It consists of Transmitter pin number 18 and receiver pin number 19 3. serial 2: It consists of Transmitter pin number 16 and receiver pin number 17 4. Serial 3: It consists of Transmitter pin number 14 and receiver pin number 15 External Interrupts pins: This pin of the Arduino board is used to produce the External interrupt and it is done by the pin numbers 0,3,21,20,19,18. I2C: This pin of the board is used for I2C communication. 1. Pin number 20 signifies Serial Data Line (SDA)and it is used for holding the data. 2. Pin number 21 signifies Serial Clock Line (SCL) and it is used for offering data synchronization among the devices. SPI Pins: This is the Serial Peripheral Interface pin, it is used to maintainSPI communication with the help of the SPI library. SPI pins include: 1. MISO: Pin number 50 is used as a Master In Slave Out 2. MOSI: Pin number 51 is used as a Master Out Slave In 3. SCK: Pin number 52 is used as a Serial Clock 4. SS: Pin number 53 is used as a Slave Select LED Pin: The board has an inbuilt LED using digital pin-13. The LED glows only when the digital pin becomes high. AREF Pin: This is an analog reference pin of the Arduino board. It is used to provide a reference voltage from an external power supply. Arduino Nano 113 CU IDOL SELF LEARNING MATERIAL (SLM)","The Arduino Uno and nano are similar, but the only difference is that its size. The UNO size is 2 times the nano size, so the Arduino nano is more breadboard friendly. It is used for portable projects. The board has a mini USB cable slot. Fig 6.3 Arduino Mega (R3) Image Source: diyi0t.com Vin: This is the input voltage pin of the Arduino board used to provide input supply from an external power source. 5V: This pin of the Arduino board is used as a regulated power supply voltage and it is used to give supply to the board as well as onboard components. 3.3V: This pin of the board is used to provide a supply of 3.3V which is generated from a voltage regulator on the board GND: This pin of the board is used to ground the Arduino board. Reset: This pin of the board is used to reset the microcontroller. It is used to Resets the microcontroller. Analog Pins: The pins A0 to A7 are used as an analog input and it is in the range of 0-5V. 114 CU IDOL SELF LEARNING MATERIAL (SLM)","Digital Pins: The pins D0 to D13 are used as a digital input or output for the Arduino board. Serial Pins: This pin is also known as a UART pin. It is used for communication between the Arduino board and a computer or other devices. The transmitter pin number 1 and receiver pin number 2 is used to transmit and receive the data resp. External Interrupt Pins: This pin of the Arduino board is used to produce the External interrupt and it is done by pin numbers 2 and 3. PWM Pins: This pins of the board is used to convert the digital signal into an analog by varying the width of the Pulse. The pin numbers 3,5,6,9,10 and 11 are used as a PWM pin. SPI Pins: This is the Serial Peripheral Interface pin, it is used to maintainSPI communication with the help of the SPI library. SPI pins include: 1. SS: Pin number 10 is used as a Slave Select 2. MOSI: Pin number 11 is used as a Master Out Slave In 3. MISO: Pin number 12 is used as a Master In Slave Out 4. SCK: Pin number 13 is used as a Serial Clock I2C: This pin of the board is used for I2C communication. 1. Pin A4 signifies Serial Data Line (SDA)and it is used for holding the data. 2. Pin A5 signifies Serial Clock Line (SCL) and it is used for offering data synchronization among the devices. LED Pin: The board has an inbuilt LED using digital pin-13. The LED glows only when the digital pin becomes high. AREF Pin: This is an analog reference pin of the Arduino board. It is used to provide a reference voltage from an external power supply. Arduino Leonardo The Arduino Leonardo has more number of digital input\/ output and analog input pins. The Arduino Leonardo can be powered via the micro USB connection or with an external power supply. 115 CU IDOL SELF LEARNING MATERIAL (SLM)","Fig 6.4 Arduino Leonardo Source: electroschematics.com Vin: This is the input voltage pin of the Arduino board used to provide input supply from an external power source. 5V: This pin of the Arduino board is used as a regulated power supply voltage and it is used to give supply to the board as well as onboard components. 3.3V: This pin of the board is used to provide a supply of 3.3V which is generated from a voltage regulator on the board GND: This pin of the board is used to ground the Arduino board. Reset: This pin of the board is used to reset the microcontroller. It is used to Resets the microcontroller. Analog Pins: The pins A0 to A11 are used as an analog input and it is in the range of 0-5V. Digital Pins: The pins 4, 6, 8, 9, 10, and 12 are used as a digital input or output for the Arduino board. Serial Pins: This pin is also known as a UART pin. It is used for communication between the Arduino board and a computer or other devices. The transmitter pin number 1 and receiver pin number 0 is used to transmit and receive the data resp. 116 CU IDOL SELF LEARNING MATERIAL (SLM)","External Interrupt Pins: This pin of the Arduino board is used to produce the External interrupt and it is done by pin numbers 2 and 3. I2C: This pin of the board is used for I2C communication. 1. Pin number 2 signifies Serial Data Line (SDA)and it is used for holding the data. 2. Pin number 3 signifies Serial Clock Line (SCL) and it is used for offering data synchronization among the devices. LED Pin: The board has an inbuilt LED using digital pin-13. The LED glows only when the digital pin becomes high. AREF Pin: This is an analog reference pin of the Arduino board. It is used to provide a reference voltage from an external power supply. Arduino Due Arduino Due is more preferable when there are many peripherals that need to connect the board. This board has many numbers of PWM and ADC outputs so it can be more beneficial to use the Due board where you will need more PWM and ADC pins. It is the perfect board for powerful larger scale Arduino projects like designing complex systems like CNC or 3D printer. Fig 6.5 Arduino Due Image Source: javatpoint.com 117 CU IDOL SELF LEARNING MATERIAL (SLM)","Vin: This is the input voltage pin of the Arduino board used to provide input supply from an external power source. 5V: This pin of the Arduino board is used as a regulated power supply voltage and it is used to give supply to the board as well as onboard components. 3.3V: This pin of the board is used to provide a supply of 3.3V which is generated from a voltage regulator on the board IOREF: It stands for Input-Output voltage REFerence. It allows the shields to check the operating voltage of the board. GND: This pin of the board is used to ground the Arduino board. Reset: This pin of the board is used to reset the microcontroller. It is used to Resets the microcontroller. Analog Pins: The pins A0 to A11 are used as an analog input and it is in the range of 0-5V. Digital Pins: The pins 0 to 53 are used as a digital input or output for the Arduino board. PWM Pins: This pins of the board is used to convert the digital signal into an analog by varying the width of the Pulse. The pin numbers 2 to 13 are used as PWM pins. SPI Pins: This pin is also known as a UART pin. It is used for communication between the Arduino board and a computer or other devices. The transmitter pin and receiver pin are used to transmit and receive the data resp. I2C Communication: This pin of the board is used for I2C communication. 1. Serial Data Line (SDA): It is used for holding the data. 2. Serial Clock Line (SCL): It is used for offering data synchronization among the devices. Voltage for ADC: This pin of the Arduino board is used to map the voltage value to the integer value. The voltage from 0 to 5 is mapped into the integer value from 0 to 1023. Erase Button: This pin of the board is used to erase the Flash Memory of the microcontroller. To erase, on the power of the board press and hold the Erase button for a few seconds. LilyPad Arduino 118 CU IDOL SELF LEARNING MATERIAL (SLM)","Arduino Lilypad is very unique in its shape and applications among the other Arduino boards. This Arduino Lilypad is based on the circular PCB with the wide holes at the corner and is optimized for the e-textiles and wearable projects. The Arduino Lilypad does not have built-in USB to UART converter as it is present in other Arduino modes. Fig 6.6 LilyPad Arduino Image Source: projectiot123.com VCC: This pin of the Arduino board is connected to +5V or +3.3V for providing supply to the board GND: This pin of the board is used to ground the Arduino board. Reset: This pin of the board is used to reset the microcontroller. It is used to Resets the microcontroller. Analog Pins: The pins A0 to A5 are used as an analog input and it is in the range of 0-5V. Digital Pins: The board contains 14 digital pins that can be used as an input or output. Serial Pins: This pin is also known as a UART pin. It is used for communication between the Arduino board and a computer or other devices. The transmitter and are used to transmit and receive the data resp. PWM: These pins of the board are used to convert the digital signal into an analog by varying the width of the Pulse. The pin numbers 9, 10, 15, 16, and 17 are used as PWM pins. SPI Pins: This is the Serial Peripheral Interface pin, it is used to maintainSPI communication with the help of the SPI library. SPI pins include: 119 CU IDOL SELF LEARNING MATERIAL (SLM)","1. SS: Pin number 16 is used as a Slave Select 2. MOSI: Pin number 17 is used as a Master Out Slave In 3. MISO: Pin number 18 is used as a Master In Slave Out 4. SCK: Pin number 19 is used as a Serial Clock I2C Communication: This pin of the board is used for I2C communication. 1. Serial Data Line (SDA): It is used for holding the data. 2. Serial Clock Line (SCL): It is used for offering data synchronization among the devices. Arduino Micro Arduino Micro is the smallest board in the Arduino Community. The Arduino Micro has more number of analog input pins than the UNO board. It is essentially a shrunk-down version of the Arduino Leonardo Fig 6.7 Arduino Micro Image Source: javatpoint.com 120 CU IDOL SELF LEARNING MATERIAL (SLM)","Vin: This is the input voltage pin of the Arduino board used to provide input supply from an external power source. 5V: This pin of the Arduino board is used as a regulated power supply voltage and it is used to give supply to the board as well as onboard components. 3.3V: This pin of the board is used to provide a supply of 3.3V which is generated from a voltage regulator on the board GND: This pin of the board is used to ground the Arduino board. Reset: This pin of the board is used to reset the microcontroller. It is used to Resets the microcontroller. Analog Pins: The pins A0 to A11 are used as an analog input and it is in the range of 0-5V. Digital Pins: The pins 4, 6, 8, 9, 10, and 12 are used as a digital input or output for the Arduino board. External Interrupt Pins: This pin of the Arduino board is used to produce the External interrupt and it is done by pin number 0, 1, 2, and 3. PWM Pins: This pins of the board is used to convert the digital signal into an analog by varying the width of the Pulse. The pin numbers 3, 5, 6, 9, 10, 11, and 13 are used as PWM pins. Serial Pins: This pin is also known as a UART pin. It is used for communication between the Arduino board and a computer or other devices. The transmitter pin number 1 and receiver pin number 0 is used to transmit and receive the data resp. I2C: This pin of the board is used for I2C communication. 1. Pin number 2 signifies Serial Data Line (SDA)and it is used for holding the data. 2. Pin number 3 signifies Serial Clock Line (SCL) and it is used for offering data synchronization among the devices. SPI Pins: This is the Serial Peripheral Interface pin, it is used to maintainSPI communication with the help of the SPI library. SPI pins include: 1. SS: It is used as a Slave Select 2. MOSI: It is used as a Master Out Slave In 3. MISO: It is used as a Master In Slave Out 121 CU IDOL SELF LEARNING MATERIAL (SLM)","4. SCK: It is used as a Serial Clock LED Pin: The board has an inbuilt LED using digital pin-13. The LED glows only when the digital pin becomes high. AREF Pin: This is an analog reference pin of the Arduino board. It is used to provide a reference voltage from an external power supply. Arduino Pro Mini The Arduino Pro mini has the new pin called the RAW pin. The RAW PIN is the input to the on-board regulator. You can connect up to 12V to the RAW pin and VCC will remain at a constant voltage. This Arduino board is preferred by advanced users for greater flexibility and small size. Fig 6.8 Arduino Pro Mini Image Source: javatpoint.com Vin: This is the input voltage pin of the Arduino board used to provide input supply from an external power source. 122 CU IDOL SELF LEARNING MATERIAL (SLM)","VCC: This pin of the Arduino board is connected to +5V or +3.3V for providing supply to the board GND: This pin of the board is used to ground the Arduino board. Reset: This pin of the board is used to reset the microcontroller. It is used to Resets the microcontroller. Analog Pins: The pins A0 to A7 are used as an analog input and it is in the range of 0-5V. Digital Pins: The pins 2 to 13 are used as a digital input or output for the Arduino board. External Interrupt Pins: This pin of the Arduino board is used to produce the External interrupt and it is done by the pin number 4 and 5 PWM Pins: This pin of the board is used to convert the digital signal into an analog by varying the width of the Pulse. The pin numbers 3, 5, 6,9,10, and 12 are used as a PWM pin. Analog Comparator: Pin number 6 -AIN0 and pin number 7- AIN1 are connected to the internal comparator. SPI Pins: This is the Serial Peripheral Interface pin, it is used to maintainSPI communication with the help of the SPI library. SPI pins include: 1. SS: Pin number 10 is used as a Slave Select 2. MISO: Pin number 11 is used as a Master In Slave Out 3. MOSI: Pin number 12 is used as a Master Out Slave In 4. SCK: Pin number 13 is used as a Serial Clock 6.3 DESIGNING OF 1ST SKETCH Once you have the basics, you can now complete your first sketch. In front of you now should be an Arduino Uno R3, a USB cable, and a computer running your choice of operating system (Windows, Mac OS, or Linux). Find the Blink Sketch To make sure that the Arduino software is talking to the hardware, you upload a sketch. What is a sketch, you ask? Arduino was created as a device that allows people to quickly prototype 123 CU IDOL SELF LEARNING MATERIAL (SLM)","and test ideas using little bits of code that demonstrate the idea \u2014 kind of like how you might sketch out an idea on paper. For this reason, programs written for Arduino are referred to as sketches. Although a device for quick prototyping was its starting point, Arduino devices are being used for increasingly complex operations. So don't infer from the name sketch that an Arduino program is trivial in any way. The specific sketch you want to use here is called Blink. It's about the most basic sketch you can write, a sort of \u201cHello, world!\u201d for Arduino. Click in the Arduino window. From the menu bar, choose File\u2192Examples\u219201.Basics\u2192Blink. Fig 6.9 Blink Sketch A new window opens in front of your blank sketch. 124 CU IDOL SELF LEARNING MATERIAL (SLM)","Fig 6.10 Blank sketch. Identify your board Before you can upload the sketch, you need to check a few things. First you should confirm which board you have. You can choose from a variety of Arduino devices and several variations on the USB board. The latest generation of USB boards is the Uno R3. If you bought your device new, you can be fairly certain that this is the type of board you have. To make doubly sure, check the back of the board. You should see details about the board's model. 125 CU IDOL SELF LEARNING MATERIAL (SLM)","Fig 6.11 Identify your board Also worth checking is the ATMEL chip on the Arduino. The ATMEL chip is the brains of the Arduino and is similar to the processor in your computer. Because the Uno and earlier boards allow you to replace the chip, there is always a chance, especially with a used board, that the chip has been replaced with a different one. Although the ATMEL chip looks quite distinctive on an individual board, if you compare it to an older Arduino, telling them apart at first glance would be difficult. The important distinguishing feature is written on the surface of the chip. In this case, you are looking for ATmega328P-PU. 126 CU IDOL SELF LEARNING MATERIAL (SLM)","Fig 6.12 ATMEL Configure the software After you confirm the type of board you are using, you have to provide that information to the software. From the Arduino main menu bar (at the top of the Arduino window on Windows and at the top of the screen on Mac OS X), choose Tools\u2192Board. You should see a list of the different kinds of boards supported by the Arduino software. Select your board from the list. 127 CU IDOL SELF LEARNING MATERIAL (SLM)","Fig 6.13 Configure the software Next, you need to select the serial port. The serial port is the connection that enables your computer and the Arduino device to communicate. Serial describes the way that data is sent, one bit of data (0 or 1) at a time. The port the physical interface, in this case a USB socket. To determine the serial port, choose Tools\u2192Serial Port. A list displays of devices connected to your computer. This list contains any device that can talk in serial, but for the moment, you're only interested in finding the Arduino. If you've just installed Arduino and plugged it in, it should be at the top of the list. For OS X users, this is shown as \/dev\/tty.usbmodemXXXXXX (where XXXXXX is a randomly signed number). On Windows, the same is true, but the serial ports are named COM1, COM2, COM3, and so on. The highest number is usually the most recent device. 128 CU IDOL SELF LEARNING MATERIAL (SLM)","Fig 6.14 Arduino and plugged After you find your serial port, select it. It should appear in the bottom right of the Arduino GUI, along with the board you selected. 129 CU IDOL SELF LEARNING MATERIAL (SLM)","Fig 6.15 Arduino GUI Upload the sketch Now that you have told the Arduino software what kind of board you are communicating with and which serial port connection it is using, you can upload the Blink sketch. First click the Verify button. Verify checks the code to make sure it makes sense. This doesn't necessarily mean your code will do what you are anticipating, but it verifies that the syntax is written in a way Arduino can understand. You should see a progress bar and the text Compiling Sketch for a few seconds, followed by the text Done compiling after the process has finished. Fig 6.16 Upload the sketch If the sketch compiled successfully, you can click the Upload button next to the verify button. A progress bar appears, and you see lots of activity on your board from the two LEDs marked RX and TX. These show that the Arduino is sending and receiving data. After a few seconds, the RX and TX LEDs stop blinking, and a Done Uploading message appears at the bottom of the window. 130 CU IDOL SELF LEARNING MATERIAL (SLM)","Fig 6.17 Arduino is sending and receiving data You should see the LED marked L blinking away reassuringly: on for a second, off for a second. If that is the case, give yourself a pat on the back. You've just uploaded your first piece of Arduino code and entered the world of physical computing! 6.4 PROGRAMMING OF AN ARDUINO Here's how to use the physical Arduino Uno board. The Arduino Uno is one among the several development boards. It has 14 digital input\/output pins, 6 analog input pins, a power jack, a reset button, a USB connection, an ICSP header. 131 CU IDOL SELF LEARNING MATERIAL (SLM)","Fig 6.18 Programming of an Arduino 1. Download & install the Arduino environment (IDE) If you just got your Arduino Uno board, you\u2019ll first have to install the Arduino IDE (Integrated Development Environment) on another computer. The code is typed into the IDE and sent to the Arduino via a USB cable. Visit arduino.cc to download the most recent Arduino IDE version for your computer. There are different versions for Mac, Windows, and Linux OS. \uf0b7 At the download page, click on the \u201cInstaller\u201d option for the easiest installation then \uf0b7 Save the .exe file to your disk drive. \uf0b7 Open the .exe file. \uf0b7 Click the button to agree to the licensing agreement \uf0b7 Decide which components to put in, then click \u201cNext\u201d \uf0b7 Select which folder to put in the program to, then click \u201cInstall\u201d \uf0b7 Wait for the program to complete installing, then click \u201cClose\u201d 2. Launch the Arduino IDE After your Arduino IDE software is downloaded, unzip the folder. To do so, double-click on the Arduino shortcut on your Desktopt. The IDE will open up and you\u2019ll see the code editor. 132 CU IDOL SELF LEARNING MATERIAL (SLM)","3. If needed, install the drivers If you used the Installer, it'll install drivers automatically as soon as you connect your board. 4. Connect the board to your computer via the USB cable To power up your board, connect your Arduino board with the pc via USB cable. The green color power LED should glow on the board. 5. Select your board Next, make sure the software is ready up for your particular Arduino board. Go to the \u201cTools\u201d computer menu from the menu bar. Select the \u201cBoard\u201d option and another menu will appear, where you'll select your Arduino model from the list. Fig 6.19 Select your board 6. Select your serial port 133 CU IDOL SELF LEARNING MATERIAL (SLM)","Select the serial device of the Arduino board. Go to Tools, and then the serial port menu. You might see COM3 or higher (COM1 and COM2 are usually reserved for hardware serial ports). To find out which port your Arduino board is connected to, disconnect your Arduino board and re-open the menu. The entry that disappears should be the Arduino board. Reconnect the board and choose that serial port. Fig 6.20 Arduino board 7. Open the blink example We'll start with the LED Blink example that comes with the Arduino IDE. Just go to File- >Examples->Basics->Blink. 134 CU IDOL SELF LEARNING MATERIAL (SLM)","Fig 6.21 Open the blink example (a) Fig 6.21 Open the blink example (b) 135 Here are the few things to keep in mind while writing the code: CU IDOL SELF LEARNING MATERIAL (SLM)","\uf0b7 Code is case sensitive \uf0b7 All the statements must end with a semicolon \uf0b7 Comments follow a \/\/ or begin with \/* and end with *\/ \uf0b7 Void loop() and void setup() are two mandatory functions. The setup section of the code is simply run once when the Arduino board is first turned on or reset. Once the setup is complete, the loop runs over and over. It keeps on running until the board continues to stay powered. \uf0b7 The status bar shows that the program is compiled or uploaded. \uf0b7 Program notification area shows error(s) within the code if any. 8. Upload the program Now it is time to upload your first sketch(code). Confirm the Arduino is plugged in, and the green light is on - therefore the correct board and port is chosen. Select Upload from the Sketch drop-down menu. Fig 6.22 Upload the program After a few seconds, you will get this screen, with the message \\\"Done uploading.\\\" 136 CU IDOL SELF LEARNING MATERIAL (SLM)","You've done it! Fig 6.23 Done uploading 6.5 SUMMARY \uf0b7 The Arduino Programming Language is basically a framework built on top of C++. You can argue that it's not a real programming language in the traditional term, but I think this helps avoiding confusion for beginners. \uf0b7 A program written in the Arduino Programming Language is called sketch. \uf0b7 The Arduino UNO is a standard board of Arduino. Here UNO means 'one' in Italian. It was named as UNO to label the first release of Arduino Software. \uf0b7 It was also the first USB board released by Arduino. It is considered as the powerful board used in various projects. Arduino.cc developed the Arduino UNO board. \uf0b7 Arduino UNO is based on an ATmega328P microcontroller. It is easy to use compared to other boards, such as the Arduino Mega board, etc. The board consists of digital and analog Input\/Output pins (I\/O), shields, and other circuits. 6.6 KEYWORDS \uf0b7 Calibration The process of making adjustments to certain numbers or components to get the best results from a circuit or program. In Arduino projects, this is often used when sensors in the real world may give different values in different circumstances, for instance the amount of light on a photoresistor. Calibration can be automatic or manual. 137 CU IDOL SELF LEARNING MATERIAL (SLM)","\uf0b7 Capacitance The ability of a material to hold an electrical charge. \uf0b7 Cathode The negative end of a diode. \uf0b7 Circuit A circular path from a power supply, through a load, and then back again to the other end of the power supply. Current flows in a circuit only if it is closed, that is, if the outgoing and return path are both uninterrupted (or closed). If either path is interrupted (or open) then current will not flow through the circuit. \uf0b7 Common cathode LED Types of LEDs that have multiple colors in one fixture, with one cathode and multiple anodes. \uf0b7 Conductor A material that allows electricity to flow, like a copper wire. \uf0b7 Constant A named identifier that cannot change its value in a program. \uf0b7 Cryptochip CryptoChip it\u2019s an hardware chip that take care of all the calculations required by the modern cryptographic standards. They work with any MCU, are extremely cost-effective, require only a single GPIO, and use very little power. Advanced protocols like ECDSA sign-verify (asymmetric authentication) and ECDH (key agreement in encryption\/decryption settings) are built-in which makes adding sophisticated security easy. \uf0b7 Current The flow of electrical charge through a closed circuit. Measured in Amps. 6.7 LEARNING ACTIVITY 1. List the Pin used in Arduino 2. Define the structure of Arduino program. 138 CU IDOL SELF LEARNING MATERIAL (SLM)","6.8UNIT END QUESTIONS A.Descriptive questions Short Questions 1. Where is Arduino used in real life? 2. What is the use of the RESET button on the Arduino UNO? ... 3. What is the use of the Vin pin present on some Arduino Boards? ... 4. What does the analogRead() function do physically when invoked in a code? ... 5. What is the use for the 2 serial pins on the Arduino Diecimila? Long Questions 1. What are pins used for in Arduino? 2. How many pin are there in Arduino? 3. What are the 3 main pin sections on the Arduino board? 4. What are the 14 pins in Arduino Uno? 5. Design a sketch for your Arduino program. A. Multiple Choice Questions 1) How many numbers of the element in the open IoT architecture? a. Four elements b. Five elements c. Six elements d. Seven elements 2) Which of the following is the way in which an IoT device is associated with data? a. Internet b. Cloud c. Automata 139 CU IDOL SELF LEARNING MATERIAL (SLM)","d. Network 140 3) Which of the following IoT networks has a very short range? a. Short Network b. LPWAN c. SigFox d. Short-range Wireless Network 4) What is the full form of the LPWAN? a. Low Protocol Wide Area Network b. Low Power Wide Area Network c. Long Protocol Wide Area Network d. Long Power Wide Area Network 5) An IoT network is a collection of ______ devices. a. Signal b. Machine to Machine c. Interconnected d. Network to Network 6) Which one of the following is not an IoT device? a. Amazon echo voice controller b. Google Home c. Nest Smoke Alarm d. None of these Answers: 1- (d), 2-(b) ,3-(d) ,4-(b) ,5-(c), 6-(d) CU IDOL SELF LEARNING MATERIAL (SLM)","6.9 REFERENCES Text Books: - 1. Internet of Things (A Hands on Approach), By ArshdeepBahga (Author),VijayMadisetti(Author). Edition: Second Edition, Illustrated, Reprint (2014) Publisher: VPT, 2017 2. \u201cBeginning Arduino\u201d by Michael McRobetrs(Author). Publisher:Technology in Action Reference Books: - 1. Tim Cox, Dr. Steven Lawrence Fernandes, Sai Yamanoor, Srihari Yamanoor, Prof. DiwakarVaish,\u201d Getting Started with Python for the Internet of Things: Leverage the full potential of Python to prototype and build IoT projects using the RaspberryPi Edition: First Edition Publisher:Packt Publisher-2019 141 CU IDOL SELF LEARNING MATERIAL (SLM)","UNIT - 7BASIC INTERFACING AND I\/O CONCEPT STRUCTURE 7.0 Learning Objectives 7.1 Introduction 7.2 Digital vs. Analog 7.3 Voltage 7.4 Denouncing 7.5 PWM using Arduino Uno with programming 7.6 Summary 7.7 Keywords 7.8 Learning Activity 7.9 Unit End Questions 7.10References 7.0 LEARNING OBJECTIVES After studying this unit, you will be able to: \uf0b7 Differentiate between Digital vs. Analog \uf0b7 Understand the concept of Voltage \uf0b7 Know about Denouncing \uf0b7 Implement PWM using Arduino Uno with programming 7.1 INTRODUCTION With digital input, 5V can be read as HIGH and 0V as LOW. You can determine whether a switch is on based on which state it is in. However, electricity is not only 5V and 0V, but various voltages. For example, one AA battery is 1.5V, and a household outlet is 100V. Arduino supports analog inputs to read these various voltages. Analog inputs enable you to read the state of electronic components that change gradually. For example, you can use 142 CU IDOL SELF LEARNING MATERIAL (SLM)","volume to adjust brightness or loudness or a temperature sensor to get the current temperature. Fig 7.1 Arduino supports analog 7.2 DIGITAL VS. ANALOG Most of our sketches have been using digital electrical signals, with just two discrete levels. Specifically, we used digitalWrite(pin, HIGH) and digitalWrite(pin, LOW) to blink an LED and digitalRead() to measure whether a digital pin had a voltage applied to it (HIGH) or not (LOW). With our Arduino UNO, high is closer to 5 V and low is closer to 0 V, or GND. Analog signals on the other hand can vary with an indefinite number of steps between high and low. We can measure the voltage values of an analog signal with our Arduino using the six analog inputs shown on the left. These analog inputs can safely measure voltages from 0 (GND) to no more than 5V and all of the values in between. If you use the function analogRead(), then the Arduino will return a number between 0 and 1,023 in proportion to the voltage applied to the analog pin. Example: You might use analogRead() to store the value of analog pin zero in the integer variable a: 143 CU IDOL SELF LEARNING MATERIAL (SLM)","a = analogRead(0); \/\/ read analog input pin 0 (A0) returns 0 to 1023 which is usually 0.000 to 4.995 volts FADING SKETCH EXAMPLE Demonstrates the use of the analogWrite() function in fading an LED off and on. AnalogWrite uses pulse width modulation (PWM), turning a digital pin on and off very quickly, to create a fading effect. Hardware Required \u2022 Arduino board \u2022 Breadboard \u2022 a LED \u2022 a 220 ohm resistor Circuit Connect the anode (the longer, positive leg) of your LED to digital output pin 9 on your Arduino through a 220-ohm resistor. Connect the cathode (the shorter, negative leg) directly to ground. Code After declaring pin 9 to be your ledPin, there is nothing to do in the setup() function of your code. The analogWrite() function that you will be using in the main loop of your code requires two arguments: One telling the function which pin to write to, and one indicating what PWM value to write. 144 CU IDOL SELF LEARNING MATERIAL (SLM)","In order to fade your LED off and on, gradually increase your PWM value from 0 (all the way off) to 255 (all the way on), and then back to 0 once again to complete the cycle. In the sketch below, the PWM value is set using a variable calledbrightness. Each time through the loop, it increases by the value of the variable fadeAmount. If brightness is at either extreme of its value (either 0 or 255), then fadeAmount is changed to its negative. In other words, if fadeAmount is 5, then it is set to -5. If it's 55, then it's set to 5. The next time through the loop, this change causesbrightness to change direction as well. analogWrite() can change the PWM value very fast, so the delay at the end of the sketch controls the speed of the fade. Try changing the value of the delay and see how it changes the program. \/* Fade This example shows how to fade an LED on pin 9 using the analogWrite() function. This example code is in the public domain. *\/ int led = 9; \/\/ the pin that the LED is attached to int brightness = 0; \/\/ how bright the LED is int fadeAmount = 5; \/\/ how many points to fade the LED by \/\/ the setup routine runs once when you press reset: 145 void setup() { \/\/ declare pin 9 to be an output: CU IDOL SELF LEARNING MATERIAL (SLM)","pinMode(led, OUTPUT); } \/\/ the loop routine runs over and over again forever: void loop() { \/\/ set the brightness of pin 9: analogWrite(led, brightness); \/\/ change the brightness for next time through the loop: brightness = brightness + fadeAmount; \/\/ reverse the direction of the fading at the ends of the fade: if (brightness == 0 || brightness == 255) { fadeAmount = -fadeAmount ; } \/\/ wait for 30 milliseconds to see the dimming effect delay(30); } 7.3 VOLTAGE A simple but very useful module which uses a potential divider to reduce any input voltage by a factor of 5. This allows you to use the analogue input of a microcontroller to monitor voltages much higher than it capable of sensing. For example with a 0-5V analogue input range you are able to measure a voltage up to 25V. The module also includes convenient screw terminals for easy and secure connection of a wire. If you want to measure external voltages using Arduino, you have to make use of the Analog Input pins of the Arduino Board. If you recall a little bit about the Arduino Analog Pins, their 146 CU IDOL SELF LEARNING MATERIAL (SLM)","input voltage is limited to 5V i.e. you can measure up to 5V directly using the Analog Input Pins of the Arduino. But what if you want to measure voltages that are greater than 5V? You cannot directly use the Analog Input Pins of the Arduino as you might fry the ATmega328P IC on the Arduino UNO board (or the relevant Microcontroller IC depending on the Arduino Board you are using). Here comes the Voltage Sensor Module to the rescue. Using this Voltage Sensor Module, you can measure voltages up to 25V. PINS OF THE VOLTAGE SENSOR Before going into the details of the Voltage Sensor like its functionality and schematic, let me give you an overview of the available Pins of the Voltage Sensor Module. Basically, a 25V Voltage Sensor, like the one used here, has 5 pins in total. Two of them are on the two-pin screw terminal and three are male header pins. The Screw Terminal pins are marked as VCC and GND and they must be connected to the external source of voltage i.e. the voltage that needs to be measured. Coming to the three male headers, they are marked as S, + and \u2013. The S pin is the \u201cSense\u201d pin and it must be connected to the Analog Input of the Arduino. The \u201c\u2013\u201d pin must be connected to the GND of the Arduino. The pin marked as \u201c+\u201d is not connected to anything (it is an N\/C Pin). The following image shows the pins of a Voltage Sensor Module. Fig 7.2 Voltage Sensor Module Inputs \uf0b7 GND \u2013 This is where you connect the low side of the voltage you are measuring. Caution! : This is the same electrical point as your Arduino ground. \uf0b7 VCC: The is where you connect the high side of the voltage you are measuring 147 CU IDOL SELF LEARNING MATERIAL (SLM)","Outputs \uf0b7 S: This connects to your Arduino analog input. \uf0b7 \u2013 (or minus): This connects to your Arduino ground. \uf0b7 +: This is not connected. . SCHEMATIC OF VOLTAGE SENSOR Now, let us talk about the important thing about the voltage sensor: its schematic. The Voltage Sensor is basically a Voltage Divider consisting of two resistors with resistances of 30K\u03a9 and 7.5K\u03a9 i.e. a 5 to 1 voltage divider. The following image shows the schematic of the Voltage Sensor Module with an input voltage limit of 25V. Fig 7.3 Voltage Sensor Module Make your Own Voltage Sensor Using a pre-built voltage sensor module is very easy and if you don\u2019t have one then you can easily build one yourself. All you need are two resistors. If you want to make your own voltage sensor that can measure voltages up to 25V like this Voltage Sensor Module, then you have to get a 30K\u03a9 and a 7.5K\u03a9 resistor. APPLICATIONS \uf0b7 DC measurement \uf0b7 Power measurement 148 CU IDOL SELF LEARNING MATERIAL (SLM)","\uf0b7 Power quality measurement 7.4 DENOUNCING Anti-bounce or debouncing logic prevents the detection of parasitic changes of state of a sensor. When using sensors returning discrete states, such as a push button, it can happen, for mechanical or other reasons, that changes of state are detected that do not correspond to what we want to detect. We can improve the reliability of these measurements by using anti- bounce logic which we will see in this tutorial. Hardware \uf0b7 Computer \uf0b7 Arduino UNO \uf0b7 USB cable A Male to B Male \uf0b7 A push button (or other on\/off sensor) Principle of operation When a physical system changes state, there are often oscillations during the transition period for physical reasons (mechanical, response time, etc.). Sufficient time must therefore be allowed for the state to stabilise. This can be made possible by electronic or mechanical filtering or digitally through the programme processing the measurement. 149 CU IDOL SELF LEARNING MATERIAL (SLM)","Fig 7.4 Principle of operation Schematic The anti-bounce strategy can be used to improve the detection of the state of a button for example. To test the code, we place a button between pins GND and 2. 150 CU IDOL SELF LEARNING MATERIAL (SLM)"]


Like this book? You can publish your book online for free in a few minutes!
Create your own flipbook