Presentation is loading. Please wait.

Presentation is loading. Please wait.

Khaled A. Al-Utaibi  Digital Vs Analog Signals  Converting an Analog Signal to a Digital One  Reading Analog Sensors with the.

Similar presentations


Presentation on theme: "Khaled A. Al-Utaibi  Digital Vs Analog Signals  Converting an Analog Signal to a Digital One  Reading Analog Sensors with the."— Presentation transcript:

1 Khaled A. Al-Utaibi alutaibi@uoh.edu.sa

2  Digital Vs Analog Signals  Converting an Analog Signal to a Digital One  Reading Analog Sensors with the Arduino  The TMP36 Temperature Sensor  Interfacing The TMP36 Sensor  Reading The TMP36 Sensor  Temperature Sensor Example

3  Digital electrical signals have just two discrete levels: HIGH (5V) and LOW (0V)  In Arduino, we used the following functions to deal with digital signals: − digitalWrite(pin, HIGH) to set a pin HIGH, − digitalWrite(pin, LOW) to set a pin LOW, and − digitalRead(pin) to determine whether a digital pin had a voltage applied to it (HIGH) or not (LOW). Figure 1: Analog Vs digital signals

4  Analog electrical signals have continuous range of values  These signals can vary with an indefinite number of steps between HIGH and LOW values.  In Arduino, HIGH is closer to 5V and LOW is closer to 0V.  In Arduino, we can use the function analogRead(pin) to read analog signals  This function will return a number between 0 and 1023 in proportion to the voltage applied to the analog pin. Figure 1: Analog Vs digital signals

5  It is common to convert analog signals into digital signals in order to allow for efficient transmission and processing of these signals.  To convert an Analog signal into a digital one, some loss of accuracy is inevitable since digital systems can only represent a finite discrete set of values.  The process of conversion is known as Digitization or Quantization.  Analog-to-Digital Converters (ADC) are used to produce a digitized signals.  Digital-to-analog Converters (DAC) are used to regenerate analog signals from their digitized signals.

6  We can use the Arduino ADC pins to convert analog voltage values into number representations that we can work with.  The accuracy of an ADC is determined by the resolution.  In the case of the Arduino Uno, there is a 10-bit ADC for doing your analog conversions.  “10-bit” means that the ADC can subdivide (or quantize) an analog signal into 2 10 =1024 different values.  Hence, the Arduino can assign a value from 0 to 1023 for any analog value that you give it.

7  The default reference voltage of the Arduino ADC is 5V.  The reference voltage determines the maximum voltage that you are expecting, and, therefore, the value that will be mapped to 1023.  So, with a 5V reference voltage, putting − 0V on an ADC pin returns a value of 0, − 2.5V returns a value of 512 (half of 1023), and − 5V returns a value of 1023.

8  To better understand what’s happening here, consider what a 3-bit ADC would do, as shown in Figure 2. − A 3-bit ADC has 3 bits of resolution. − Because 2 3 =8, there are 8 total logic levels, from 0 to 7. − Therefore, any analog value that is passed to a 3-bit ADC will have to be assigned a value from 0 to 7. − Looking at Figure 2, you can see that voltage levels are converted to discrete digital values that can be used by the microcontroller. − The higher the resolution, the more steps that are available for representing each value. − In the case of the Arduino Uno, there are 1024 steps rather than the 8 shown here.

9 Figure 2: 3-bit analog quantization

10  Different Arduinos have different numbers of analog input pins, but you read them all the same way, using the analogRead() command.  The analogRead() function reads the value from the specified analog pin. − Syntax:  analogRead(pin) − Parameters:  pin: the number of the analog pin you want to read (int). − Return:  int (0 to 1023) − Note:  If the analog input pin is not connected to anything, the value returned by analogRead() will fluctuate based on a number of factors (e.g. the values of the other analog inputs, how close your hand is to the board, etc.).

11  The TMP36 temperature sensor (Figure 3) has the following characteristics: − Provides a voltage range from -40 o C to +125 o C. − Provide typical accuracies of ±2°C. − Provides a voltage output that is linearly proportional to the Celsius (centigrade) temperature. − Provides a 750mV output at 25°C. − Provides a 500mV output at 0 o C. − Has an output scale factor of 10mV/°C (every 10mV corresponds to 1 o C). Figure 3: TMP36

12  The TMP36 temperature sensor can be easily interfaced to the Arduino bard as shown in the following Figure 4. Figure 4: Interfacing the TMP36 to the Arduino board.

13  The Arduino uses ADC to read the output of the TMP36 sensor as shown Figure 5.  We can determine the temperature as follows: − (1) Convert the integer value generated by the ADC to voltage (in mV) to determine the input voltage Vin:  V IN = DAC OUT x (V REF x 1000)/1024  V REF = 5V = 5x1000 mV = 5000 mV  Every division of the 1024 DAC output represents 5000/1024=4.88mV − (2) Convert input voltage V IN to the corresponding temperature (in o C):  T IN = (V IN – 500)/10  We subtract 500 from V IN because the TMP36 provides 50mV output at 0 o C.  We divide by 10 because every 10mV corresponds to 1 o C.

14 Figure 5: Reading the TMP36 sensor.

15  Interface the TMP36 sensor to the Arduino board as in Figure 4.  Then, write a program to read the input voltage from the TMP36 and displays the corresponding temperature on on the Arduino environment’s built-in serial monitor.

16 int DACout;// DAC output int A0 = 0;// Analog input A0 double Vref = 5.0;// reference voltage of the DAC double Vin;// input voltage from the TMP36 double Tin;// corresponding input temperature public void setup(){ // initialize and start the serial port Serial.begin(9600); } public void loop(){ // read the DAC output corresponding to analog input A0 DACout = analogRead(A0); // compute the input voltage received from TMP36 Vin = DACout * (Vref * 1000.0)/1024.0; // compute the corresponding input temperature Tin = (Vin - 500.0) / 10.0; // display the temperature on the serial port Serial.println(Tin); }


Download ppt "Khaled A. Al-Utaibi  Digital Vs Analog Signals  Converting an Analog Signal to a Digital One  Reading Analog Sensors with the."

Similar presentations


Ads by Google