ME 588 Lab 4

docx

School

Purdue University *

*We aren’t endorsed by this school

Course

588

Subject

Mechanical Engineering

Date

Feb 20, 2024

Type

docx

Pages

14

Uploaded by mailrahultanwar

Report
ME 588 – Section 4 Lab 4: Analog I/O & Sensor Integration Wednesday Lab – 09/21/22
Lab Summary: The purposes of this lab were to analyze and change analog input and output signals and to calibrate sensors in a circuit. In order to analyze and change analog input and output signals, we first used a function generator to create an input signal. We then read this signal through an Arduino and saw how the PWM output compared to the input signal in a circuit. Then, we used hardware and software filters to filter out noise in the signals of sensors. In order to calibrate sensors in a circuit, we integrated analog and digital IR sensors and saw how their output changed for different stimuli in the surroundings. In our case, we used the distance of an object from the sensor. The first thing that we learned was how reading and outputting analog signals with hardware and software can change the signal. One must be careful not to push the system past its limits in order to retain the entire signal. The second thing that this lab shed light on was the differences between hardware and software filtering. We learned that each type of filtering has its own advantages and disadvantages, and how to effectively use each for different purposes. A third core thing that was learned was integrating sensors into a circuit. This is extremely valuable as this lets a system make decisions based on its surroundings by connecting real life stimuli to digital and analog signals. Lab Analysis Section A: Analog I/O Q1 . Assemble the circuit shown in Circuit 1, in appendix A, and select values of R and Q that give the filter a cutoff frequency of roughly 100 hz. A1. R = 150 Ω, C = 10 µF were used, giving f c = 1 2 πRC = 106 hz Q3. What do the numbers shown on the serial monitor show A.3. The numbers vary between zero and 255. They are the duty cycles of the output PWM signal. Q.4. Calculate the quantization interval of the Arduino ADC. Why is this value important? A.4. i = V ¿ n bits = 5 V 1024 bits = .00488 v . This is the smallest change in voltage that the ADC can pick up. Its also the threshold above which noise will be detected. Q.5 Observe the oscilloscope output. How do they compare? Does the serial monitor being turned on affect this? A.5 . See the figure below. As can be seen, the filtered output from the PWM output matches closely with the analog input waveform. This is not affected by the serial monitor.
Q.6. Adjust the frequency of the input. Can you find the critical frequency where they no longer match? A.6. At roughly 25 Hz input, the phase difference between the two signals hits 90 degrees. At 40 Hz, the shape begins to break down due to gain rolloff and phase difference. At 100 Hz, the signal is lost entirely. This occurs because the filter imposes a -20 db/decade gain rolloff and -90 degree phase drop above the cutoff frequency, but because the bode plot isn’t perfectly linear, some of that occurs before the cutoff. The behavior of the signal being lost entirely above 100 Hz is as expected. Section B: Analog Sensor Reading Q2. Using the oscilloscope, observe the noise on the analog IR sensor output Vo (Do not block the sensor lens). What is the noise range in volts? Include an oscilloscope screenshot in your report A2. The observed noise range is 1.27 to 1.34 Volts, or .07V. The maximum and minimum values in this range are hard to see in the figure below which is zoomed out for a better view, but this range was evident when zoomed in.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Q5. Using the calculated quantization interval, how many digital codes will be spanned by the measured broadband noise voltage range? Can you verify it in the Serial Monitor of Arduino? If so, plot the data from the Serial Monitor. If not, explain the reason. A5. Since the quantization interval is 1024codes/5V, there will be about 14.3 digital codes spanned by the measured broadband noise (see equation below). This can be seen in the figure below as the peak value of the broadband noise is about 280 codes and the trough is about 266 (a range of about 14 codes). dig codes [ codes ] = Q [ codes V ] noise [ V ] = 1024 5 .07 = 14.336 codes
Q6. The analog IR sensor output includes a periodic spike of noise. Identify the frequency and maxi- mum amplitude of the noise spike. Include an oscilloscope screenshot in your report. A6. The maximum amplitude of the spike is about 0.49V (1.75V-1.26V). This can be seen in the figure below as the max and min of the spike. The frequency of this spike is about 1000 Hz. This can be seen in the figure below by 1/period, where the period was 1ms. Q7. Using the calculated quantization interval, how many digital codes will be spanned by the measured noise spike amplitude? Can you verify it in the Serial Monitor of Arduino? If so, plot the data from the Serial Monitor. If not, explain the reason. A7. Since the quantization interval is 1024codes/5V, there will be about 100 digital codes spanned by the measured noise spike (see equation below). This can be seen in the figure below as the peak value of the noise spike is about 360 codes and the trough is about 260 (a range of 100 codes). dig codes [ codes ] = Q [ codes V ] noise [ V ] = 1024 5 .49 = 100.352 codes
Q8. Build an RC filter at the IR sensor output Vo to filter out noise spikes. Use the oscilloscope to compare the unfiltered and filtered signals. Does the filter work? What is the break frequency of the filter? In your report, include a screenshot of the comparison of unfiltered and filtered signals. A8. The filter worked very well as shown in the figure below. The green line is the unfiltered signal and the yellow is the unfiltered signal. We have offset these signals to make them more easily viewable. As you can see, the yellow signal had its noise greatly reduced/cut off. The break/cutoff frequency of the filter was 106Hz as shown in the equation below. This ensured that the higher frequency noise spikes would be removed. f c = 1 2 πRC = 1 2 π ( 150 Ω ) ( 10 μF ) = 106.10 Hz
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Q10. Collect the raw IR sensor reading data and the associated filtered data online concurrently in the Serial Monitor. Plot both data in one figure and see their difference. Include the comparison figure in the report. (Not offline data filtering.) A10. As you can see in the figure below of the serial plotter, the filtered (blue) signal has significantly less noise spikes than the unfiltered (red) signal using an averaging filter. The code for this can be seen in Appendix 2.
Q11. Instead of an averaging filter, use the one-dimensional median filter with a window size of three developed in the Prelab assignment. How well does this filter work? Collect the raw IR sensor reading data and the associated filtered data online concurrently in the Serial Monitor. Plot both data in one figure and see their difference. Include the comparison figure in the report. (Not the offline data filtering.) A11. :( Q12. Identify two advantages and disadvantages for the hardware (RC filter) implementation. A12. One advantage of the hardware RC filter is that the cutoff frequency is easily chosen since it follows a simple equation. Another advantage of the RC filter is that you retain the whole signal before the cutoff frequency, whereas in software filters you might lose some data points. On the other hand, one disadvantage of the RC filter is that it is not easily changed postproduction. With software, a cloud update could be done but changing hardware would require reconstruction. Another disadvantage is that noise before the cutoff frequency is still retained. This can be seen in Figure ____ since the broadband noise is still present in the yellow signal. (I think we cannot say this as the input signal also has noise.) However, we can mention that the output signal from hardware RC filter will always be less than the input signal due to Capacitive reactance, as it acts like a potential divider. This is evident from the data captured in Q8 where input and output are overplotted. To retain a similar level of input, RC filter output needs to be amplified .... Rahul Q13. Identify two advantages and disadvantages for software implementations. A13. One advantage of software implementations of filtering data is that it is easily manipulated to fit different needs. You can easily reuse code by copying and pasting, whereas in hardware you must physically rebuild circuits for testing. Another advantage of software implementations is that signals can be averaged over a certain period. This is different from an RC filter that will cut off all data above a certain frequency. Sometimes seeing noise or outliers in data can be a good thing. On the other hand, one disadvantage of software limitations is that it can take longer to develop during testing. An RC filter can take less than a minute to implement, whereas a software script can take a few minutes to a few hours to write. Another disadvantage of software implementations is that it can cost more initially. Filtering a signal with hardware can cost less than a dollar whereas a software system can cost north of one hundred dollars to set up. Section C: Digital IR Sensor Calibration Q1. Does your code work as expected? Answer: Yes, the code works fine. Q2. According to the specification sheet, at what range of distances will the digital sensor output a LOW signal? Answer : From 20mm to 100mm, sensor output is LOW signal.
Q3. Using a yard stick (or tape measure), record the range of distances for which your digital sensor actually outputs a LOW signal. Answer : Observed range of low signal is 10mm to 100mm. Q4. Does your measured range match the specification sheet value? Answer : Yes, the obtained range of 10mm to 100mm for LOW signal output is close to the specification of 20mm to 100mm. Section D: Analog IR Sensor Calibration Q1. Does your code work as expected? Answer: Yes, the code works fine. Q2. Using a yard stick (or tape measure) to measure distance, and a multimeter to measure voltage, create a graph of the relationship between output voltage and object distance. Answer :
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Q3. What is the maximum output voltage from your analog IR sensor, and at what distance does it occur? Answer : The maximum output voltage from sensor is 3.1V and it occurs at 30mm from sensor. Q4. Does your data match with the values given in the graph on the specification sheet? If not, why do you think this is so? Answer : The peak value of sensor output matches with the specification value i.e., 3.1V. However, the peak output was observed at 30mm distance compared to specification of 5mm. As per specification, for farther distances the output stagnates at around 0.55V compared to observed value of 1V to 1.3V. As per the specification sheet (attached below), the output voltages at farther distance are for a specific reflective white paper made by Kodak Co. This might be the source of error for us as the reflectivity of the paper used might be different than the control. Conclusion The main finding of analog I/O was that analog signals sometimes suffer due to being read in and out of systems. The process of converting the analog signal to a PWM signal, then filtering it back to an analog one resulted in phase lag and gain loss occurring. One main finding in analog filtering is that key differences exist between software and hardware implementations with each having its own benefits and drawbacks as discussed earlier. Another key finding in sensor calibration is that input signals can be noisy and not exact, but with proper circuit design sensors are an effective way of
changing real-world information to signals. Overall, this lab was very effective in teaching us how to read, output, and change digital and analog signals. Appendix 1: Circuit Figures Circuit 1 – PWM Filtering Setup Circuit 2 – Digital IR sensor powering circuit with external LED
Circuit 3 – Analog IR sensor powering circuit with external LED Appendix 2: Code Used in Lab Part B averaging filter
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Part median filter code Digital IR sensor code: Analog IR sensor code: