0% found this document useful (0 votes)
10 views24 pages

Arduino 1

Arduino Lab

Uploaded by

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

Arduino 1

Arduino Lab

Uploaded by

Akbar Afridi
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
Lab-1: Introduction to the Arduino Arduino is an open-source single-board microcontroller, designed to make the process of using electronics in multidisciplinary projects more accessible. The hardzvare consists ofa simple open hardware board with an Atmel AVR processor. It has on-board analog and digital input/output support. The software consists of a standard programming language compiler and the boot loader that runs on the board. Knowledge of the Arduino gives a tangible application of Embedded systems. Lab Objective The objective of this lab is to explore the basic capabilities of the Arduino and its programming structure, and the Atmel AVR Atmeg328p details. Lab Background and Getting Knowledge of: 1. Basic Computer Skills. Student should be comfortable starting applications, opening, closing and saving files, cutting and pasting text, and locating files/folders. 2. Overview of the Arduino. After this lab, Student should have a basic knowledge of the components and capabilities of the Arduino board (Uno— R3), 3. Overview of the AVR Atmeg328P. After this lab, students should be familiar of the AVR microcontroller features and PINs descriptions. 4, Basic Programming Skills. Student should be familiar with creating simple programs in C/C++ as well as working in a programming development environment. Laboratory Pre-Exercise Tasks Overview: 1.1 Overview of Arduino: Arduino is a circuit board containing an ATMEL ATmega microcontroller preloaded with a boot loader program. A boot loader is a tiny program (e.g., 2 Kbytes on the Arduino) stored in non-volatile memory at a location such that when power is applied or the reset button is pressed the CPU jumps into it and executes its instructions. When you create an application, an embedded program you create to do something meaningful, you can send it to the target processor by uploading it. When you start the upload process, a special signal on the Arduino hardware causes the microcontroller to reset which forces the boot loader to run. It performs several steps to configure the controller to listen for incoming data on its serial communications port. Because the host computer initiated an upload of the application program which caused the reset, there is data being sent via the serial port. So the boot loader sees this data and responds by saving it to the non-volatile memory at a special location. When finished, the boot loader jumps to that application location in the flash and starts executing program instructions. In the event that the Arduino is manually reset or when power is first applied, the boot loader will not see any data on the serial port, and it will just jump to the application location in flash. 1.1.1 Components View of Arduino UNO R3.0: The components view of the Arudino (UNO 3.0) circuit board is shown in the Fig-1 below: uihip Le MADE. brary Pee POU Figure 1: Arduino UNO Circuit Board and Components are labeled. The details of components are below: ‘ Analog input pins ~ pins (A0-A5) that take-in analog values to be converted to be represented with a number range 0-1023 through an Analog to Digital Converter (ADO). + ATmega328 chip - 8-bit microcontroller that processes the sketch you programmed. “Built-in LED - in order to gain access or control of this pin, you have to change the configuration of pin 13 where it is connected to. ‘Crystal Oscillator - clock that has a frequency of 16MHz. “© DC Jack — where the power source (AC-to-DC adapter or battery) should be connected. It is limited to input values between 6-20V but recommended to be around 7-12V. + Digital /O pins — input and output pins (0-13) of which 6 of them (3, 5, 6, 9, 10 and 11) also provide PWM (Pulse Width Modulated) output by using the analogWrite() function. Pins (0 (RX) and 1 (TX)) are also used to transmit and receive serial data. ‘ ICSP Header - pins for “In-Circuit Serial Programming” which is another method of programming. “© ON indicator — LED that lights up when the board is connected to a power source. “ Power Pins — pins that can be used to supply a circuit with values VIN (voltage from DC Jack), 3.3V and 5V. ‘© Reset Button — a button that is pressed whenever you need to restart the sketch programmed in the board. “USB port — allows the user to connect with a USB cable the board to a PC to upload sketches or provide a voltage supply to the board. This is also used for serial communication through the serial monitor from the Arduino software. 1.1.2 Schematic Diagram of Arduino: Fig.2 shows the schematic diagram of the Arduino UNO R3. “GEee Figure 2: Schematic Diagram of Arduino UNO R3. 1.2 Overview of Atmeg328p Microcontroller: ‘The ATmega328P is a low-power CMOS 8-bit microcontroller based on the AVR enhanced RISC architecture. By executing powerful instructions in a single clock cycle, the ATmega328P achieves throughputs approaching 1 MIPS per MHz allowing the system designer to optimize power consumption versus processing speed. 1.2.1 Key features of Atmeg328p Microcontroller: “High Performance, Low Power Atmel®AVR® 84 “© Advanced RISC Architecture © 131 Powerful Instructions ~ Most Single Clock Cycle Execution Microcontroller © 32x 8 General Purpose Working Registers Fully Static Operation © Up to 20 MIPS Throughput at 20MHz ‘High Endurance Non-volatile Memory Segments © 32KBytes of In-System SelfProgrammable Flash program memory © 1KBytes EEPROM © 2KBytes Internal SRAM * Peripheral Features © Two 8 bit Timer/Counters with Separate Prescaler and Compare Mode © One 16-bit Timer/Counter with Separate Prescaler, Compare Mode ° and Capture Mode - Real Time Counter with Separate Oscillator Six PWM Channels 8-channel 10-bit ADC in TQFP and QFN/MLF package 6-channel 10-bit ADC in PDIP Package Programmable Serial USART Master/Slave SPT Serial Interface Byte-oriented 2-wire Serial Interface (I2C compatible) Programmable Watchdog Timer with Separate On-chip Oscillator ° ° ° ° ° © Interrupt and Wake-up on Pin Change ‘© Power Consumption at IMHz, 1.8V, 25°C © Active Mode: 0.2mA. © Power-down Mode: 0.14A © Power-save Mode: 0.75A (Including 32kHz RTC) 1.2.2 PINS of Atmeg328p Microcontroller: Fig.3 shows description of the 28 pins PDIP of ATmega328p microcontroller. These pins are similar to the pins on the Arduino UNO R3 boards. It is simply extended on the circuit board to easily interface with other system. (POINTIARESET) Pe [| (PCINTI6IRXD) POO C} (POINTI7/7x0) POI | (PCINTI@/NTO) PD2 Cf (PeINT19/0C2BANTI) PDA Cf (PCINT20/KCK/TO) PDs (| vee 4} ano | 'CINT/ATAL1/TOSC1) PES [} ‘CINTZxTALZTOSC2) PET [| (PciNT21/0C0B/T1) Pos Cf (PCINTZ2/OGoA/AINO) PDS C| (PCINTZs/AINT) PDT Cf (PCINTOICLKONGP?) PEO C} 8 10 1" 2 13 14 28 27 26 25 2 23 22 at 20 19 18 7 16 15 PCS (ADCSISCLIPCINT13) Fics (apcaispavpcint12) Fics (abcaPcinrs 1) Fipce (ADcaiPcintio) Fler (apctPoinrs) Feco (ApcoPoinra) eno Fianer Haves FlpBs (scK/PoInTs) Fires qmisomcinta) Fires (mosvocePcints) Free (ssiocie/ecinT2) Fat (ociacints) Figure 3: PINs description of ATmega328p Microcontroller installed at Arduino Circuit Board. 13 Setup and Installation of Arduino (IDE): 1.3.1 Installation of Arduino (IDE): This part will guide you through the set up and installation process of the Integrated Development Environment (IDE) that will be used throughout the development and experiments of labs. * Open your default internet browser and access the Arduino website. Download the latest Arduino IDE version. The software is compatible with Linux, Mac and Windows s0 just choose the one that matches your OS. The Arduino download page is at [Link] ftware Download Next steps Arduino 0022 (release notes), hosted by Google Code: Getting Started Reference ‘windows Environment Examples + Lisus: gait, 6apbit Foundations FAQ Also available from [Link]: Windows, Mac OS X, Linux (abit) (6gbit), Source Figure 4 A part of Arduino Website's download page. Arduino allows you to install, its IDE on several platforms (see encircled), 4 After downloading the compressed file, extract its contents to your preferred directory (C:\Program Files, your Desktop or etc...). Note that the whole folder size is around 200MB when completely extracted. fof, ate rand cs te Figure 4: Screenshot of attempt to extract the zipped Arduino folder. ‘Make sure you have an archive utility such as 7zip or WinRAR. ‘ Congratulations! Arduino IDE is installed on your computer. To use it, just navigate to your main folder directory and run the Arduino application. Figure 5: Screenshot of what's inside the Arduino folder. The application icon looks like an infinity symbol. 1.3.2 Installation of Arduino Drivers: This part will guide you through the set-up and installation process of the Arduino Uno board driver for the device to be recognized by the IDE % Connect the Arduino UNO to the computer via USB Cable (on Fig. 6) . Check if it is properly connected by observing the green LED labeled ON (on Fig. 6) on the board. Figure 6: Photo of Arduino Uno board connected to a Computer. Note that the board's USB-B port. “ Wait for Windows to try and install the device's driver until it fails, Navigate to the Device Manager through Start > Control Panel > Device Manager. Locate the Arduino Uno Device. Right-click it to choose Update Driver Software. Figure 7: Screenshot of the Device Manager. The Arduino Uno should have an exclamation point. * Choose to browse your computer for the driver by clicking Browse my computer for driver software. Figure 7: Screenshot of the options for searching the device driver. Anew window will open for you to indicate the location of the driver. Click Browse... r rien erie a sin Figure 8: Screenshot of the browse option menu, Choose the first option which is to look manually for the folder that contains the Arduino Uno board's driver. “© A Windows Security window sometimes pops up to confirm if you want to continue the installation. Just click, Install this driver software anyway. ‘> Don't instal this driver software ‘Yeushodd chek your manfacrers weiter voted diverse feryour dence ‘sal this diver software anyway” ove randaceswebiteo ures ray amor comps te Figure 9: Screenshot of pop-up window. Windows can't verify the publisher of the device software but we know that the software's publisher is Arduino. ‘Wait for Windows to finish installing the device driver. Upon completion, you should see an installation successful message Figure 10: Screenshot of successful completion of the Arduino Drivers. 1.4 Comparison of the Programming Structure of ANSI C and Arduino C: In any kind of C programming, a program is comprised primarily of subroutines. The ANSI C program structure is shown below (Fig. 11). ‘Decumentations. (Ciobal declarations Main () « Local declarations pas am siaierents y ee Main ( function Calling user defined functions (opton to user) ) User defined functions Functon 1 Prveod } ccoenosey Functon a Figure 11: ANSI C Program Structure Overview Every ANSI C program follows this structure, even the most simple. In the simple cases, some of the parts might be missing. Indeed, the simplest program in ANSI Cis shown. In this case, there are no declarations, no subroutines ete. Main() {} Figure 12: ANSI C Simple Program with no subroutine For the Arduino, we have a structure similar to that shown above, but we always have at least two subroutines. Te minimal Arduino program is shown below (Fig.13) Figure 13: ANSI C Simple Program with no subroutine 1.5 Writing an Example Program (Blinking of an LED) Using Arduino IDE and Circuit Board: This example aims to familiarize the student with the basic operation of the Arduino Uno board, and Integrated Development Environment (IDE). By the end of the exercise, the student should be able to know the basic functionalities of the IDE. The students will be able to answer the following 4 How do you compile and upload a sketch file into the Arduino Board using the IDE? 4 How can the configuration of the pins be specified in the programming? 4 What functions are always required in a sketch? Equipment required performing this task: “ 1x Arduino Uno board and USB cable “© 1x 5mm/3mm Red LED 1x 470Q resistor 1xbreadboard 1.5.1 Writing Program using Arudino IDE: ‘ Proceed to the Arduino Folder and double-click the arduino application to open the Arduino IDE which is also shown below: Tae rie oe atm Tee Figure 14: Screenshot of the Arduino IDE. The workspace is very simple and frequently used buttons are easy to access ‘> Type the following lines of code on the front panel. //the setup function runs once when you 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); // turn LED on (HIGH voltage level) delay(1000) I/-wait for a second digitalWrite(LED_BUILTIN, LOW); // turn LED off (making voltage LOW) delay(1000); I wait for a second } 4 Press Ctr1 + Bllor icon on the IDE to save your sketch (the term for a source code in Arduino). ‘ Click the Verify Button (A shown on Fig. below) to check if the sketch has no errors. At the bottom of the screen you should see if the sketch was successfully scanned free of problems (B on Fig. below). Moreover, the size of the sketch file (C on Fig. below) is also indicated on the black screen at the bottom to shows that it fits the flash memory of the Arduino Uno. Figure 15: Screenshot of the Blink code after compilation. The verify button looks just like a play button and is located at the upper left corner. Successful compiling will be indicated at the bottom. If an error or problem ‘occurred, it will be shown in the black screen. 15.2 Test your Program: 4 Connect an LED to a 4700 resistor. Note: that the longer leg of the LED is the positive (connected to one end of resistor and the shorter one is the negative (connected to the ground). The other end of the resistor should then be connected to the specified pin whicl Figure 15: Schematic Diagram of blinking LED circuit ° Check if the board selected in the IDE is the one you are using, the Arduino Uno board. Figure 16: Screenshot showing Arduino Uno as selected board. If you have a different type of Arduino board, just select it from this list Next, make sure that the Arduino board’s COM port is properly identified by the IDE. To do this, connect the board to the computer then from the IDE front panel go to Tools > Serial Port (A on Fig. 17). A list of COM’s should be there, choose the COM number associated with the microcontroller board. Note: the microcontroller board’s COM no. is found near the name of the device's driver in Device Manager (B on Fig. 17) Figure 17: Screenshot of both the Device Manager and Arduino IDE windows. Note that the COM number selected as Serial Port must be the same one found beside the device's name ‘Finally, upload the sketch made earlier into the board by clicking the icon Hilin the IDE. The status of the upload can be found near the bottom of the program Figure 17: Screenshot showing a successful upload. Sometimes an error occurs because the COM port of the Arduino UNO was not properly specified 1.6 In Lab Tasks to Perform: Control the LED ON/OFF operation using a push button or a switch “ Control the light bulb (LED) installed in Stairway using the following two buttons (switches) combinations Switch-1 Switch-2 LED Status 0 0 OFF 1 0 ON oO 1 ON 1 1 OFF. 1.7 Post Lab Tasks to Perform: “ Draw the schematic diagram of Arduino Nano Circuit Board (Handwritten Only) + Compare the features of AVR Atmega328p, PIC, and 8051 microcontrollers (at least 20 features Notes for In Lab Tasks Report: Your lab report should have the following bullets: Title of the task ~Task Objective (what are you doing and what you will get) “Flow chart of the Task -Block Diagram (Schematic Diagram) -Code of the task -Results Lab-2: Interfacing Sensors (Analog and Digital) with Arduino In this lab, you will connect a digital input circuit and a digital output circuit (Sensor having digital output) and an analog output circuit (analog sensor) to Arduino. Though this lab is about sensors interfacing with arduino. However, this interfacing concept and principles can 1 input (for digital sensor interfacing) and be applied to any microcontroller having digi analog input (for analog sensor interfacing). Digital input and output are the most fundamental physical connections for any microcontroller. The pins to which you connect the digital circuits are called General Purpose Input-Output, or GPIO, pins. The arudino has only analog inputs and there are no analog outputs. In mostly microcontrollers, the analog inputs and outputs are unavailable such as the 8051 microcontroller. Lab Objectives The objective of this lab is to explore the analog-to-digital convertor (ADC), various configurations of the built-in ADC of Arduino for various levels of resolutions, interfacing analog sensors with Arduino, and interfacing digital sensors with Arduino. Lab Background and Getting Knowledge of: 5. Basic Signals Conversion. Student will learn different type of signals and how an analog signal will be converted into encoded digital numbers (binary string). 6. Configuration Built-in ADC of Arduino. After this lab, Student should be able to configuration the ADC for 5 Volts, and how to measure smaller voltages with greater accuracy using the analogue input pins on your Arduino in conjunction with the AREF pin. Students will also learn how to acquire a signal if itis greater than 5 Volt. 7. Interfacing an Analog Sensor. Student will learn how to interface analog sensors with Arduino, We will use the IR sensor analog output and measure the distance between transmitter and obstacle. 8, Interfacing a Digital Sensor with Arduino. In this lab, student will learn how to interface digital sensor (single bit output) with Arduino. In this lab we will interface an IR sensor (digital sensor) to detect an obstacle. Laboratory Pre-Exercise Tasks Overview: 1.1 Basics of Signals Conversion: A signal as referred to in communication systems, signal processing and electrical engineering is a function that "conveys information about the behavior or attributes of some phenomenon’. The IEEE Transactions on Signal Processing states that the term "signal" includes audio, video, speech, image, communication, geophysical, sonar, radar, medical and musical signals. We categorize the signal into four main types. However, the two main types are analog signal and digital signal. The analog signal has both real number values on x-axis (time) and y-axis(amplitude), while the digital signal has discrete values. In computing systems, we can’t store the analog real number infinite values due to limited storage capabilities. So the analog is converted to digital using the mechanism of analog-to-digital conversion. The ADC has the following steps: Sampling: In signal processing, sampling is the conversion/reduction of a continuous-time to a discrete-time. Sampling is the process of recording an analog signal at regular discrete moments of time. The sampling rate (£_s) is the number of samples per second. The time interval between samples is called the sampling interval T_s f_s should be at least or greater the twice of the maximum frequency (f_max) of analog signal in order to recover the signal back to analog from the digital. Fig. 1 shows an analog, signal. Fig. 2a and Fig.2b shows the sampling of the signal in Fig.1 at T_s-0.5 and T_s-0.1 seconds respectively. /{_s. To sample a signal the @) Oy Figure 2: Pictorial Overview Sampling Phenomena (a). Sample interval is 0.5 seconds (b). Sample interval is 0.1 seconds. “© Quantization: Quantization, in mathematics and digital signal processing, is the process of mapping input values from a large set (often a continuous set) to output values in a (countable) smaller set. Rounding and truncation are typical examples of quantization processes. In our scenario, we define as the conversion of y-axis (Amplitude) real value into a discrete (integer) value is called as quantization. Eq. 1 is used to convert the real amplitude value into integer value. x=|@"-, a Where N is number of bits used to store the digital value, V is the desired amplitude value to change. However, using ADC the V_min value should be greater than or equal to zero. 1 os 1000 06 aie 500 o2 o @), © Figure 3: A portion of the sampled signal and its conversion to the discrete values (a). Sampled Signal (b). The quantized signal using Eq. (1) Facto “Encoding of the Quantized Signal: Encoding is the process of representing the quantized value in a binary sequence in which the number of bits will be equal to the ADC bits. For example, the value in Fig. 3b at point#1 is 860 and if we use an ADC of 10-bits its corresponding encoded value will be (1101011100). 1.2 Configuration of the Arduino Built-in ADC: ‘The Arduino has six ADC channels marked as (A0-A5, as shown on Fig. 4) and the default signal measured by these PINs are in range of 0-5 volts. The Arudino (AVR Atmega) has the following features Figure 4: Arduino Circuit Board showing the Analog (ADC) PINs (A0~A5) The ATmega328P features a 10-bit successive approximation ADC. + £2 LSB Absolute Accuracy ‘© 15 k samples per second (kSPS) at Maximum Resolution, to 76.9 kSPS (13 is Conversion Time) # 6 Multiplexed Single Ended Input Channels 1.2.1 Default Configuration of the Arduino Built-in ADC: Arudino rely on ADCs to obtain continuously variable (analog0 input data. By default, the reference voltage for the converter is the on-board five volt DC source. This represents the maximum input level that may be digitized. The minimum level is ground or zero volts (if negative signals are needed, some form of offset bias will be required). A 10 bit converter yields 1024 discrete levels. This means that each step will be slightly less than five millivolts. To use the ADC, a reference voltage/operating voltage must be set during the initialization routine. However, in default configuration case we do not set that. After this, whenever a value is needed, simply call the analogRead() function. The only argument to the function is the input channel desired (zero through five for the Uno). The function returns the digitized value as an integer in the range of 0 to 1023. And when we say the operating voltage ~ this is the voltage available to the Arduino after the power supply circuitry. For example, if you have a typical Arduino Uno board and run it from the USB socket ~sure, there is 5V available to the board from the USB socket on your computer or hub — but the voltage is reduced slightly as the current winds around the circuit to the microcontroller ~ or the USB source just isn’t up to scratch. This can easily be demonstrated by connecting an Arduino Uno to USB and putting a multimeter set to measure voltage across the 5V and GND pins. Some boards will return as low as 4.8 V, some higher but still below 5V. So if you're gunning for accuracy, power your board from an external power supply via the DC socket or Vin pin - such as 9V DC. [Link] Schematic Diagram of connecting analog circuit (voltage source with variable resistor) to Arduino: Fig. 5 shows the schematic diagram of connecting an analog circuit to the arduino and blink an LED using a condition if the ADC output is greater that some threshold value. Figure 5: Schematic Diagram of Connecting Analog Circuit to Arduino and Blink an LED [Link] Source Code of connecting analog circuit (voltage source with variable resistor) to Arduino: int sensorPin = AQ; // select the input pin for the potentiometer int ledPin=13; _// select the pin for the LED int sensorValue = 0; // variable to store the value coming from the sensor void setup() { i{ declare the ledPin as an OUTPUT: pinMode(ledPin, OUTPUT); Serial:begin(9600); } void loop() { // read the value from the sensor: sensorValue = analogRead(sensorPin); //turn the ledPin on If (sensorValue >=500) digitalWrite(ledPin, HIGH); Serial printIn(sensorValue); // stop the program for milliseconds: delay(sensorValue); // turn the ledPin off: } 1.2.2 Configuration of the Arduino Built-in ADC using AREF PIN: When your Arduino takes an analogue reading, it compares the voltage measured at the analogue pin being used against what is known as the reference voltage. In normal analogRead use, the reference voltage is the operating voltage of the board. For the more popular Arduino boards such as the Uno, Mega, Duemilanove and Leonardo/Yn boards, the operating voltage of SV. So if you have a reference voltage of 5V, each unit returned by analogRead() is valued at 00488 V. (This is calculated by dividing 1024 into 5V). What if we want to measure voltages between 0 and 2, or 0 and 4.6? our signal has very low range and we want a resolution of | than 0.00488 V? How would the ADC know what is 100% of our voltage range? And there in lies the reason for the AREF pin. AREF means Analogue REFerence. It allows us to feed the Arduino a reference voltage from an external power supply. For example, if we want to measure voltages with a maximum range of 3.3V, we would feed a nice smooth 3.3V into the AREF pin — perhaps from a voltage regulator IC. Then the each step of the ADC would represent around 3.22 millivolts (divide 1024 into 3.3). Note that the lowest reference voltage you can have is 1.1V. There are two forms of AREF — internal and external, so let’s check them out. [Link] Configuration using External AREF PIN: An external AREF is where you supply an external reference voltage to the Arduino board. This can come from a regulated power supply, or if you need 3.3V you can get it from the Arduino’s 3.3V pin. If you are using an external power supply, be sure to connect the GND to the Arduino’s GND pin. Or if you're using the Arduno’s 3.3V source — just run a jumper from the 3.3V pin to the AREF pin. To activate the external AREF, use the following in void setup(). analogReference(EXTERNAL); // use AREF for reference voltage This sets the reference voltage to whatever you have connected to the AREF pin ~ which of course will have a voltage between 1.1V and the board’s operation voltage. Very important note — when using an external voltage reference, you must set the analogue reference to EXTERNAL before using analogRead(). This will prevent you from shorting the active internal reference voltage and the AREF pin, which can damage the microcontroller on the board. If necessary for your application, you can revert back to the board’s operating voltage for AREF (that is — back to normal) with the following: analogReference(DEFAULT); Fig. 6 shows the schematic diagram for interfacing the low-level analog circuit (0-3.3 Volt) with Arduino. For a signal less than 3.3 Volt and greater/equal to 1.1 volt, we have to connect this AREF pin to an external source and the Arduino ground PIN to that external source. Figure 6: Schematic Diagram of Connecting Analog Circuit to Arduino Using AREF PIN as an External Reference for measure signal (0-33 Volts) The source code for the schematic of Fig. 6 is below: int sensorPin= A0;_ // select the input pin for the potentiometer intledPin= 13; select the pin for the LED int sensorValue = 0; // variable to store the value coming from the sensor void setupd { {declare the ledPin as an OUTPUT pinMode(ledPin, OUTPUT); analogReference(EXTERNAL); [Link](9600); 1 void loop) ( fread the value from the sensor: sensorValue = analogRead(sensorPin); // tar the ledPin on If (sensorValue >-500) digitalWrite(ledPin, HIGH); [Link](sensorValue); | stop the program for milliseconds: delay(sensorValue}; // tur the ledPin off: [Link] Configuration using Internal AREF: The microcontrollers on our Arduino boards can also generate an internal reference voltage of 1.1V and we can use this for AREF work. Simply use the line: analogReference(INTERNAL); and we don’t need to connect the AREF pins to any voltage source. 1.3 Interfacing an Analog Sensor with Arduino: Transducer is a device that converts a primary form of energy into a corresponding signal with a different energy form. Primary Energy Forms: mechanical, thermal, electromagnetic, optical, chemical, etc. It takes form of a sensor or an actuator. In this section of the Lab, we will focus how to interface the IR Sensor for obstacle detection and measuring the distance between obstacle and transmitter. The list of hardware requirements are: Arduino 4 Sensors having analog output with 1 IR LED receiver (photodiode with 2 pins, not the phototransistor with 3 pins) and IR LED emitters 4 100K resistor (brown black yellow) & Jumper wires Breadboard 1.3.1 Schematics of Interfacing an IR Sensor using its Analog Output with Arduino: Fig. 7 shows the schematic diagram of interfacing the IR sensor (Transmitter (White LED Figure 7: Schematic Diagram of Connecting Analog Output IR Sensor with Arduino shown)/Receiver (Black LED)). The emitter is connected with the +5V and Ground pins, and the receiver is connected with analog input pin AQ. 1.4 Interfacing an Digital Sensor (Single Bit Output) with Arduino: The purpose of this exercise is for you to get familiar to interface the digital and physical worlds, by connecting sensors. We will interface the KY033 (IR Sensor) with the Arduino. The list of hardware requirements are: # Arduino 4 Sensor (KY033) having digital output 1.4.1 Schematics of Interfacing an IR Sensor using its Digital Output with Arduino: Fig. 8 shows the schematic diagram of interfacing the Digital IR sensor with the Arduino. Figure 7: Schematic Diagram of Connecting Analog Output IR Sensor with Arduino 1.5 Lab-2 Tasks: % In-Lab Task Interface an analog circuit (potentiometer/variable resistor based voltages) with Ardiuno and provide a table for default, internal and external configuration of ADC. Each table must show a variation of input voltages from (0-5), digital value calculated through mathematical equation, digital value given by Arduino ADC, Error of digital values, converted value into voltage, and error in input and value (which is called quantization error). For each configuration you have to provide schematic, and also code. Input Voltage ADC Dee | ADC Error Value Converted Value Formula © Interface a digital sensor (IR Sensor) with Arduino. © Interface an analog sensor (using potentiometer as a temperature sensor with sensitivity 1*C/0.1 V), For all these tasks you should provide in report: -Task Title -Task Objectives -Schematic Diagram -Flow Chart if possible and you think there is a condition checking, “ode of the Task -Results in presentable way (Tables etc. ) and Discussion * Post-Lab Task ° Interface an analog circuit having an output of 0-10V with Arduino. Change the input in the range of 0-SV which is acceptable by Arudino. Show the calibration process how the high range is converted in acceptable range, and what will the sensitivity factor. Interface one analog and one digital sensor.

You might also like