0% found this document useful (0 votes)
3 views

Unit 1 Lab Report (Section 1, Table 10) (1)

The experiment investigated the current-voltage (IV) relationships of resistors and LEDs using potentiometer and waveform generator methods, demonstrating Ohm's Law for resistors and analyzing forward voltages for LEDs. Results indicated that the experimental resistance values deviated from the theoretical 1,000 Ω due to calibration errors and systematic noise, leading to the rejection of the hypothesis that resistance values would align. Forward voltages for LEDs were consistent with theoretical expectations, confirming the relationship between wavelength and forward voltage across both methods.

Uploaded by

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

Unit 1 Lab Report (Section 1, Table 10) (1)

The experiment investigated the current-voltage (IV) relationships of resistors and LEDs using potentiometer and waveform generator methods, demonstrating Ohm's Law for resistors and analyzing forward voltages for LEDs. Results indicated that the experimental resistance values deviated from the theoretical 1,000 Ω due to calibration errors and systematic noise, leading to the rejection of the hypothesis that resistance values would align. Forward voltages for LEDs were consistent with theoretical expectations, confirming the relationship between wavelength and forward voltage across both methods.

Uploaded by

colinddchu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

Ohm’s Law and IV Curves for Resistance and Forward

Voltage with Potentiometer and Waveform Generator


Physics 4 BL, Winter 2025, Jan 20, 2025
Lab Section 1, Table 10

Colin Chu, Nafiz Faiaz, Nicolas Camacho, Jack Shi

Abstract
This experiment aimed to explore the current-voltage (IV) relationships of resistors and light-emitting
diodes (LEDs) using both potentiometer and waveform generator methods. The objective was to
demonstrate Ohm’s Law for a resistor and analyze the forward voltage of LEDs with varying wavelengths.
Calibration of ESP32 measurements ensured accurate voltage readings, enabling precise data analysis.

The setup involved constructing a circuit on a breadboard with a 1,000 Ω resistor or an LED as the test
element. The potentiometer was used to manually vary resistance, while the waveform generator allowed
for automated voltage modulation, facilitating smoother data collection. Voltage data was converted to
current using Ohm's Law and plotted to generate IV curves.

Results showed an experimental resistance of 1,119.39 Ω for the potentiometer method, with an error of
2.60 Ω. For the waveform generator method, the experimental resistance was 1,163.38 Ω, with an error of
9.52 Ω. Given the theoretical resistance of 1,000 Ω, the hypothesis that the resistor would exhibit a linear
IV relationship and a resistance close to the expected value is rejectedThe expected value of 1,000 Ω lies
outside two standard deviations for both methods, indicating that systematic noise and calibration errors
influenced the measurements.

Forward voltages for LEDs using the potentiometer method were 2.66 V (blue), 2.25 V (green), 1.88 V
(yellow), and 1.77 V (red), while the waveform generator method yielded 2.57 V (blue), 2.20 V (green),
1.94 V (yellow), and 1.78 V (red). Discrepancies were attributed to noise and calibration limitations.

Introduction/Theory
Ohm’s Law describes the proportionality between voltage, current, and resistance in a linear relationship:

V = I R (1)

where V is voltage, I is current, and R is resistance. This fundamental principle governs the behavior of
resistors, which exhibit a linear IV curve. LEDs, however, deviate from this linearity due to their
semiconductor properties. Below a specific threshold, known as the forward voltage, the current through
an LED remains negligible. Once the forward voltage is reached, the current increases exponentially.
2

Because there is a following 1000 Ω resistor that still obeys Ohm’s Law, the current through the LED can
still be found, as the resistor and LED are in series and thus share equivalent current.

Error analysis was crucial for evaluating reliability. The resistance uncertainty (ΔR) was calculated using
error propagation as:​
ΔR = Δm / (m × m),​
where m is the IV curve slope and Δm its standard deviation from the curve fit.

Voltage calibration uncertainty (ΔV_real) was computed as:​


ΔV_real = sqrt((V_esp × Δm)² + (Δb)²),​
using the slope (m), intercept (b), and their standard deviations (Δm, Δb).

Python’s np.polyfit with cov=True provided a covariance matrix, whose diagonal elements yielded the
variances of m and b, enabling error propagation. The hypothesis was tested within two standard
deviations of experimental values, rejecting it if the theoretical 1,000 Ω fell outside this range.

Calibration was crucial to ensure accurate voltage measurements, as the ESP32 records only analog bit
values rather than true voltage. These analog values were converted into real voltages using the
calibration equation:

V_real = m × V_esp + b (2)

where m is the slope and b is the intercept. These would be found using the two point method and using a
multimeter.

m = (V_real2 - V_real1)/(V_esp2 - V_esp1) (3)

Where V_real2 and V_real1 are the voltages collected from the multimeter, and V_esp2 and V_esp1 are
the voltages collected from the ESP32. The intercept b was determined by rearranging the equation

b = V_real - (m × V_esp) (4).

These calibration parameters were then used to convert raw analog outputs from the ESP32 into real
voltage values. A voltmeter ensured precision during this step.

The ESP-32 microcontroller, programmed using Arduino, automated data collection. Our group utilized
Google Sheets to record and save analog outputs as CSV files, which were later analyzed using Python
to calculate current using Ohm’s Law and plot IV curves. Python further facilitated curve fitting and error
analysis.

The circuit construction involved careful placement of wires and components to ensure functionality and
accuracy. A breadboard allowed for efficient connections between the ESP32, resistors, and LEDs.
Jumper wires facilitated these connections. The potentiometer, functioning as a variable resistor, enabled
manual adjustment of resistance, while the waveform generator provided automated voltage variations.
Before performing the experiment, the oscilloscope was employed to verify the waveform generator’s
output, ensuring the correct amplitude and frequency of the signal.
3

This combination of components allowed for the collection of IV data for both resistors and LEDs. The
experiment provided insights into the behavior of linear and non-linear circuit elements, with forward
voltage and IV relationships explored for different LED colors.

Method/ Experimental Setup

Equipment

●​ ESP32 microcontroller
●​ 1 kΩ resistor (3)
●​ LEDs (blue, green, yellow, red)
●​ Multimeter
●​ Oscilloscope
●​ Potentiometer
●​ Waveform generator
●​ Breadboard and jumper wires (8)
●​ Transistor
●​ Double sided BNC cable
●​ Alligator Clip BNC cable
●​ Python code, Google Sheets, and Arduino Code software

The procedure began by constructing a circuit on a breadboard. This included a 1 kΩ resistor as the test
element, connected in series with a 1 kΩ “follower” resistor to measure current indirectly, and was fed in a
maximum of 3.3 volts, which is what it could handle. (Figure 1). The ESP32 microcontroller was used to
record voltage measurements. A potentiometer manually varied resistance, while a waveform generator
automated current modulation for different trials. The waveform generator fed in 5V, and the breadboard
included a transistor and another resistor connected to it, as well as additional jumpers to connect to the
generator. (Figure 3)In the two LED setup, the test element was replaced by an LED instead of the
resistor. While the resistor follows Ohm’s Law strictly (Eq. 1), the LED introduces non-linear behavior due
to its semiconductor properties. The current through the LED was determined using the same follower
resistor, as LEDs do not directly follow Ohm’s Law but rely on a threshold voltage for significant current to
flow. (Figures 2 and 4).

Assumptions made include consistent and reliable ESP32 analog readings, accurate calibration
converting bit values to true voltages, and ideal behavior of the 1 kΩ resistor per Ohm’s Law. LEDs are
assumed to have negligible current below forward voltage and exponential current increase above it. The
waveform generator is expected to produce precise triangle waves without distortion, verified by the
oscilloscope. Breadboard and jumper wire connections are assumed to not cause significant resistance or
noise.

Calibration of the ESP32 required two distinct voltage readings, taken with a multimeter, at corresponding
bit values output by the ESP32. Using these measurements, the calibration slope m and intercept b were
calculated (Eqs. 3 and 4). This calibration equation was applied to convert the ESP32’s analog outputs
into true voltage readings (Eq. 2). A voltmeter ensured accuracy throughout this process. The m and b
4

are assumed to be constant, even though they vary by ESP, because it is close enough that there is a
negligible effect.

The transistor in the circuit acted as a switch or amplifier controlled by the input from the waveform
generator. The transistor's base was connected to the waveform generator, while the collector and emitter
connected to the power source and the circuit, respectively. This allowed the transistor to regulate current
flow based on the waveform generator's input, automating the IV curve data collection for both resistors
and LEDs.The potentiometer was adjusted manually, allowing voltage across the test element and the
follower resistor to be recorded simultaneously by the ESP32. This step was repeated four times to
ensure a complete range of data per trial. The waveform generator automated the modulation process. A
triangle wave with parameters (0.1 Hz frequency, 5 Vpp amplitude, and 2.5 V DC offset) was generated
and verified using an oscilloscope. This wave was input into the circuit to modulate current linearly. Data
was collected as before, but the waveform generator had auto variation in voltage, thus resulting in a time
interval based data collection instead of four rotations.. The BNC cables and alligator clip adapters were
used to securely connect the waveform generator output to the circuit.

The Arduino code uploaded to the ESP32 managed data acquisition. Using the analogRead() function, it
recorded two voltage values: one across both resistors and one across the follower resistor. These
outputs were saved in the form (V1 + V2, V2) to the serial monitor. The Arduino also included commands
to type “start” and “stop” to initiate and pause data collection. Data was copied from the serial monitor
after data collection into Google sheets, where it was saved as a CSV and loaded into the Jupyter
notebooks for Python analysis. The code first calculates and stores the m and b values (Eq. 3 and 4). It
then would extract data from the CSV files and convert them to voltages using Equation 2. Using
Equation 1 and a resistance of 1000 ohms, the current would be found, and be plotted against the
extracted and calibrated voltage using Python libraries. For both resistor set ups, there was additional
code to use the polyfit function in Python to find the slope and inverse it for the resistance. For the LEDs,
they were plotted with the same axes with each other. Visually observing the forward voltage and finding
the wavelengths of the colors of the light on the internet, another plot was generated of max wavelength
against forward voltage, which was inputted manually. These three plots were repeated for the waveform
generator data for analysis.

Figure 1: Setup, Resistor, Potentiometer Figure 2: Setup, LED, Potentiometer


5

Figure 3: Setup, Resistor, Waveform Generator Figure 4: Setup, LED, Waveform generator

Analysis and Results

Figure 5: Resistor IV Curve (Potentiometer Method)

The IV curve obtained for the resistor using the potentiometer method exhibited a linear shape, as
expected for an ideal resistor following Ohm’s Law. The experimental resistance calculated from the slope
of the line was 1,119.39 Ω, with an error of 2.60 Ω. This value is within approximately 12 percent of the
theoretical resistance of 1,000 Ω. While this deviation may be attributed to minor variations in resistor
manufacturing and the calibration process, the hypothesis that the resistor exhibits linear behavior and a
resistance close to 1,000 Ω is rejected, as the theoretical value lies outside the two-standard-deviation
range of the experimental value. The bounds for voltage, with a maximum of 3.3 volts, were determined
by the ESP32’s voltage handling capacity.

The calibration parameters used were a slope of 0.000790 volts per bit and an intercept of 0.134960
volts, which remained constant throughout the analysis. These calibration constants, along with error
propagation methods, enabled robust evaluation of systematic and random uncertainties in the
experiment.
6

Figure 6: Resistor IV Curve (Waveform Generator Method)

Using the waveform generator, the resistor IV curve remained linear but displayed an experimental
resistance of 1,163.38 Ω, with an error of 9.52 Ω. This represents a deviation of approximately 16% from
the theoretical resistance of 1,000 Ω. The hypothesis regarding linearity is accepted; however, the
resistance result does not fully support the hypothesis, as the theoretical resistance falls outside the
two-standard-deviation range of the experimental value.

The graph shows a clustering of points near the maximum voltage of 3.3 volts, which is due to the
ESP32's sampling behavior. During the triangle wave's ramp-up, the ESP32 records values more
frequently at the higher voltage levels, leading to an uneven data distribution. This differs from the
potentiometer method, where manual adjustments result in a more gradual and uniform distribution of
points. Filtering the data to exclude points with currents exceeding 0.0016 amperes addresses some of
the outliers but may slightly skew the slope calculation, resulting in an artificially increased resistance.

While filtering can improve consistency, the unfiltered data points are critical to include in resistance
calculations. These points represent valid measurements and capture the complete behavior of the
system, especially at high voltage and current levels. Excluding them may underestimate or misrepresent
the systematic errors introduced by the waveform generator's signal irregularities or circuit noise.
Therefore, calculations for resistance must incorporate both filtered and unfiltered data to ensure a robust
analysis and accurate representation of the experimental setup.
7

Figure 7: LED IV Curves (Potentiometer Method)

The IV curves for LEDs showed non-linear exponential growth beyond the forward voltage, consistent
with their semiconductor behavior. The order of forward voltages was blue (2.66 V), green (2.25 V), yellow
(1.88 V), and red (1.77 V), matching theoretical expectations for energy band gaps. The smoothness of
the curves indicates reliable data collection, and the hypothesis is accepted.

Figure 8: LED IV Curves (Waveform Generator Method)

For the waveform generator method, LED IV curves followed the same order of forward voltages but were
slightly less smooth due to increased noise from the automated voltage modulation. This noise did not
significantly affect forward voltage determination, with blue (2.57 V), green (2.20 V), yellow (1.94 V), and
red (1.78 V) aligning well with expected values. The clustering of points near the maximum voltage is
again observed, caused by the ESP32 sampling behavior during the triangle wave input. Results are also
similar to the manual variation. Thus, the hypothesis regarding forward voltage order is accepted.
8

Figure 9: Wavelength vs. Forward Voltage

Figure 10: Wavelength Comparison Across Methods

The LED IV curves obtained from both the potentiometer and waveform generator methods exhibited the
expected exponential growth beyond the forward voltage. Forward voltages for the potentiometer method
were recorded as blue (2.66 V), green (2.25 V), yellow (1.88 V), and red (1.77 V), while the waveform
generator method yielded slightly lower values: blue (2.57 V), green (2.20 V), yellow (1.94 V), and red
(1.78 V). These results confirm the expected order of forward voltages based on energy band gaps, with
shorter wavelengths (blue) requiring higher forward voltages than longer wavelengths (red). The
comparison of wavelength and forward voltage trends across the potentiometer and waveform generator
methods showed close agreement. Minor deviations in forward voltage values were noted, primarily due
to increased noise in the waveform generator data. However, the consistency of the inverse trend across
methods validates the hypothesis and supports the experiment’s accuracy.

Conclusion
This experiment effectively characterized the IV relationships of resistors and LEDs, demonstrating
fundamental electrical principles. The resistor IV curves were linear, confirming Ohm’s Law. The
9

potentiometer method yielded a resistance of 1119.39 with an error of 2.90Ω, and the waveform
generator method resulted in 1163.38 with an error of 9.52 Ω. Both values deviated from the expected
1000 Ω due to calibration errors and noise, with the waveform generator introducing more systematic
noise. The experimental value is not within 2 standard deviations of either calculated resistance, so the
hypothesis that the resistance values were to be the same is rejected.

The LED IV curves demonstrated the expected exponential growth, with forward voltages aligning with
theoretical expectations. The forward voltages for the potentiometer method ranged from 2.66 V (blue) to
1.77 V (red), while the waveform generator method showed values from 2.57 V (blue) to 1.78 V (red). The
observed trends confirmed that shorter wavelengths (blue) correspond to higher forward voltages,
consistent with energy band gap theory.

The wavelength versus forward voltage analysis reinforced the inverse relationship, with both methods
showing agreement despite slight deviations caused by noise in the waveform generator data. These
results support the hypothesis and validate the experimental setup.

Sources of error included calibration inaccuracies, noise in automated data collection, and manufacturing
tolerances in components. Improvements could include more precise calibration procedures, using
higher-resolution equipment, and optimizing the ESP32 sampling rate. Additionally, expanding the
experiment to include other semiconductor devices or investigating temperature effects on LED behavior
could provide further insights.

Overall, the experiment was successful in demonstrating the principles of Ohm’s Law and semiconductor
behavior while highlighting the differences between manual and automated data collection methods.

References
BYJU’s. "Wavelength of Light." https://byjus.com/physics/wavelength-of-light/ Accessed January 8, 2025.

Code Appendix
import numpy as np
import matplotlib.pyplot as plt

import numpy as np
import matplotlib.pyplot as plt

# Load the CSV data (adjust filename and delimiter as needed)


data = np.loadtxt("Data Lab1.csv", delimiter=',')

bv_1 = 1097 # Bit value


bv_2 = 2676
mm_1 = 1.002 # Multimeter value
mm_2 = 2.250

m = (mm_2 - mm_1)/(bv_2 - bv_1) # slope


b = mm_2 - (m * bv_2) # intercept
10

# Extract analog values and current values from the correct columns
analog_values = data[:, 0] # Column for v1 and v2 readings
current_values_raw = data[:, 1] # Column for just v2 values

V1 = m * analog_values + b # Convert V1 from ADC to voltage


V2 = m * current_values_raw + b # Convert V2 from ADC to voltage

V_R1= V1 - V2

# Calculate current through R1 using Ohm's law


R2 = 1000 # Resistance of R1 in ohms
current_R2 = V2 / R2

coeffs, cov_matrix = np.polyfit(V_R1, current_R2, 1, cov=True)

slope = coeffs[0]
intercept = coeffs[1]
variance_slope = cov_matrix[0, 0] # Variance of the slope
std_slope = np.sqrt(variance_slope) # Standard deviation of the slope

# Calculate resistance and its error


resistance = 1 / slope
error_resistance = std_slope / (slope**2)

# Print results
print(f"Slope (m): {slope:.6f} ")
print(f"Intercept (b): {intercept:.6f}")
print(f"Experimental resistance: {resistance:.2f} ohms")
print(f"Error in resistance (δR): {error_resistance:.2f} ohms")

# Plot IV curve
plt.plot(V_R1, current_R2, 'o', label='IV Data')
plt.plot(V_R1, slope * V_R1 + intercept, label=f'Fit')
plt.xlabel('Voltage Across R1 (V)')
plt.ylabel('Current Through R1 (A)')
plt.title('IV Curve for R1')
plt.legend()
plt.show()

import numpy as np
import matplotlib.pyplot as plt

# Load the CSV data (adjust filename and delimiter as needed)


data_b = np.loadtxt("Data Blue LED.csv", delimiter=',')

bv_1 = 1097 # Bit value


11

bv_2 = 2676
mm_1 = 1.002 # Multimeter value
mm_2 = 2.250

m = (mm_2 - mm_1)/(bv_2 - bv_1) # slope


b = mm_2 - (m * bv_2) # intercept

# Extract analog values and current values from the correct columns
analog_values_b = data_b[:, 0] # Column for v1 and v2 readings
current_values_raw_b = data_b[:, 1] # Column for just v2 values

V1b = m * analog_values_b + b # Convert V1 from ADC to voltage


V2b = m * current_values_raw_b + b # Convert V2 from ADC to voltage

V_R1b = V1b - V2b

# Calculate current through R1 using Ohm's law


R2 = 1000 # Resistance of R1 in ohms
current_R2b = V2b / R2

# load in other color data


data_g = np.loadtxt("Data Green LED.csv", delimiter=',')
data_y = np.loadtxt("Data Yellow LED.csv", delimiter=',')
data_r = np.loadtxt("Data Red LED.csv", delimiter=',')

# Extract values from green


analog_values_g = data_g[:, 0] # Column for v1 and v2 readings
current_values_raw_g = data_g[:, 1] # Column for just v2 values

V1g = m * analog_values_g + b # Convert V1 from ADC to voltage


V2g = m * current_values_raw_g + b # Convert V2 from ADC to voltage

V_R1g = V1g - V2g

# Calculate current through R1 using Ohm's law


current_R2g = V2g / R2

# Extract values from yellow


analog_values_y = data_y[:, 0] # Column for v1 and v2 readings
current_values_raw_y = data_y[:, 1] # Column for just v2 values

V1y = m * analog_values_y + b # Convert V1 from ADC to voltage


V2y = m * current_values_raw_y + b # Convert V2 from ADC to voltage

V_R1y = V1y - V2y

# Calculate current through R1 using Ohm's law


12

current_R2y = V2y / R2

# Extract values from red


analog_values_r = data_r[:, 0] # Column for v1 and v2 readings
current_values_raw_r = data_r[:, 1] # Column for just v2 values

V1r = m * analog_values_r + b # Convert V1 from ADC to voltage


V2r = m * current_values_raw_r + b # Convert V2 from ADC to voltage

V_R1r = V1r - V2r

# Calculate current through R1 using Ohm's law


current_R2r = V2r / R2

# Plot IV curve using V_R1 and current through R1


plt.plot(V1b, current_R2b, 'o', label='IV Data for Blue', color = 'blue')
plt.plot(V1g, current_R2g, 'o', label='IV Data for Green', color = 'green')
plt.plot(V1y, current_R2y, 'o', label='IV Data for Yellow', color = 'yellow')
plt.plot(V1r, current_R2r, 'o', label='IV Data for Red', color = 'red')
plt.xlabel('Voltage Across R1 (V)')
plt.ylabel('Current Through R1 (A)')
plt.title('IV Curve for Different LEDs')
plt.legend()
plt.show()

print(f"Calibration slope (m): {m:.6f} V/bit")


print(f"Calibration intercept (b): {b:.6f} V")

# maximum wavelength in range


rw = 750
gw = 570
bw = 495
yw = 590

# foward voltages
rfv = 1.77
yfv = 1.88
gfv = 2.25
bfv = 2.66

# Plot wavelength against foward voltage


plt.plot(bw, bfv, 'o', label='Blue', color = 'blue')
plt.plot(yw, yfv, 'o', label='Yellow', color = 'yellow')
plt.plot(gw, gfv, 'o', label='Green', color = 'green')
plt.plot(rw, rfv, 'o', label='Red', color = 'red')

plt.xlabel('wavelength (nm)')
plt.ylabel('Foward Voltage (V)')
13

plt.title('Wavelength vs Foward Voltage')


plt.legend()
plt.show()

import numpy as np
import matplotlib.pyplot as plt

# Load the CSV data (adjust filename and delimiter as needed)


data = np.loadtxt("1B Ohm.csv", delimiter=',')

bv_1 = 1097 # Bit value


bv_2 = 2676
mm_1 = 1.002 # Multimeter value
mm_2 = 2.250

m = (mm_2 - mm_1)/(bv_2 - bv_1) # slope


b = mm_2 - (m * bv_2) # intercept

# Extract analog values and current values from the correct columns
analog_values = data[:, 0] # Column for v1 and v2 readings
current_values_raw = data[:, 1] # Column for just v2 values

V1 = m * analog_values + b # Convert V1 from ADC to voltage


V2 = m * current_values_raw + b # Convert V2 from ADC to voltage

V_R1= V1 - V2

# Calculate current through R1 using Ohm's law


R2 = 1000 # Resistance of R1 in ohms
current_R2 = V2 / R2

# Filter data for points with current <= 0.0016 A


# Filter data for points with current <= 0.0016 A
filtered_indices = current_R2 <= 0.0016
filtered_V1 = V1[filtered_indices]
filtered_current_R2 = current_R2[filtered_indices]

# Perform linear regression on the data


coeffs, cov_matrix = np.polyfit(V1, current_R2, 1, cov=True)
slope = coeffs[0] # Slope of the line
intercept = coeffs[1] # Intercept of the line
coeffs1, cov_matrix1 = np.polyfit(filtered_V1, filtered_current_R2, 1, cov=True)
filtered_slope = coeffs1[0] # Slope of the line
filtered_intercept = coeffs1[1] # Intercept of the line

# Calculate resistance and error using the covariance matrix


resistance = 1 / slope
14

variance_slope = cov_matrix[0, 0] # Variance of the slope


std_slope = np.sqrt(variance_slope) # Standard deviation of the slope
error_resistance = std_slope / (slope**2) # Error in resistance

# Plot IV curve for both filtered and unfiltered data


plt.plot(V1, current_R2, 'o', label='IV Data for R1')
plt.plot(filtered_V1, filtered_current_R2, 'o', label='Filtered IV Data for R1')
plt.plot(V1, slope * V1 + intercept, label=f'Fit: I = {slope:.4f}V + {intercept:.4f}')
plt.plot(V1, filtered_slope * V1 + filtered_intercept, label=f'Fit: I = {filtered_slope:.4f}V +
{filtered_intercept:.4f}')
plt.xlabel('Voltage Across R1 (V)')
plt.ylabel('Current Through R1 (A)')
plt.title('Filtered and Regular IV Curve for R1, Waveform Generator')
plt.legend()
plt.show()

# Print results
print(f"Calibration slope (m): {m:.6f} ")
print(f"Calibration intercept (b): {b:.6f} ")
print(f"Experimental resistance: {resistance:.2f} ohms")
print(f"Error in resistance (δR): {error_resistance:.2f} ohms")

import numpy as np
import matplotlib.pyplot as plt

# Load the CSV data (adjust filename and delimiter as needed)


data_b = np.loadtxt("blue.csv", delimiter=',')

bv_1 = 1097 # Bit value


bv_2 = 2676
mm_1 = 1.002 # Multimeter value
mm_2 = 2.250

m = (mm_2 - mm_1)/(bv_2 - bv_1) # slope


b = mm_2 - (m * bv_2) # intercept

# Extract analog values and current values from the correct columns
analog_values_b = data_b[:, 0] # Column for v1 and v2 readings
current_values_raw_b = data_b[:, 1] # Column for just v2 values

V1b = m * analog_values_b + b # Convert V1 from ADC to voltage


V2b = m * current_values_raw_b + b # Convert V2 from ADC to voltage

V_R1b = V1b - V2b

# Calculate current through R1 using Ohm's law


15

R2 = 1000 # Resistance of R1 in ohms


current_R2b = V2b / R2

# load in other color data


data_g = np.loadtxt("green.csv", delimiter=',')
data_y = np.loadtxt("yellow.csv", delimiter=',')
data_r = np.loadtxt("red.csv", delimiter=',')

# Extract values from green


analog_values_g = data_g[:, 0] # Column for v1 and v2 readings
current_values_raw_g = data_g[:, 1] # Column for just v2 values

V1g = m * analog_values_g + b # Convert V1 from ADC to voltage


V2g = m * current_values_raw_g + b # Convert V2 from ADC to voltage

V_R1g = V1g - V2g

# Calculate current through R1 using Ohm's law


current_R2g = V2g / R2

# Extract values from yellow


analog_values_y = data_y[:, 0] # Column for v1 and v2 readings
current_values_raw_y = data_y[:, 1] # Column for just v2 values

V1y = m * analog_values_y + b # Convert V1 from ADC to voltage


V2y = m * current_values_raw_y + b # Convert V2 from ADC to voltage

V_R1y = V1y - V2y

# Calculate current through R1 using Ohm's law


current_R2y = V2y / R2

# Extract values from red


analog_values_r = data_r[:, 0] # Column for v1 and v2 readings
current_values_raw_r = data_r[:, 1] # Column for just v2 values

V1r = m * analog_values_r + b # Convert V1 from ADC to voltage


V2r = m * current_values_raw_r + b # Convert V2 from ADC to voltage

V_R1r = V1r - V2r

# Calculate current through R1 using Ohm's law


current_R2r = V2r / R2

# Plot IV curve using V_R1 and current through R1


plt.plot(V1b, current_R2b, 'o', label='IV Data for Blue', color = 'blue')
plt.plot(V1g, current_R2g, 'o', label='IV Data for Green', color = 'green')
plt.plot(V1y, current_R2y, 'o', label='IV Data for Yellow', color = 'yellow')
16

plt.plot(V1r, current_R2r, 'o', label='IV Data for Red', color = 'red')


plt.xlabel('Voltage Across R1 (V)')
plt.ylabel('Current Through R1 (A)')
plt.title('IV Curve for Different LEDs with Waveform Generator')
plt.legend()
plt.show()

print(f"Calibration slope (m): {m:.6f} V/bit")


print(f"Calibration intercept (b): {b:.6f} V")

# maximum wavelength in range


rw = 750
gw = 570
bw = 495
yw = 590

# foward voltages
rfv = 1.78
yfv = 1.94
gfv = 2.20
bfv = 2.57

# Plot wavelength against foward voltage


plt.plot(bw, bfv, 'o', label='Blue', color = 'blue')
plt.plot(yw, yfv, 'o', label='Yellow', color = 'yellow')
plt.plot(gw, gfv, 'o', label='Green', color = 'green')
plt.plot(rw, rfv, 'o', label='Red', color = 'red')

plt.xlabel('wavelength (nm)')
plt.ylabel('Foward Voltage (V)')
plt.title('Wavelength vs Foward Voltage using Waveform Generator')
plt.legend()
plt.show()

You might also like