0% found this document useful (0 votes)
29 views15 pages

Arduino Controlled Photogate

Uploaded by

briaaamaaam
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)
29 views15 pages

Arduino Controlled Photogate

Uploaded by

briaaamaaam
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/ 15

(c) 2024 Rom. Rep. Phys.

(for accepted papers only)

AN IMPROVED ARDUINO-CONTROLLED PHOTOGATE

CĂLIN GALERIU1,a , ION GRUIA1,2


1
Military Technical Academy “Ferdinand I”, Bvd. George Coşbuc 39-49, Bucharest 050141, Romania
2
University of Bucharest, Faculty of Physics, Str. Atomiştilor 405, Măgurele 077125, Romania
a
Corresponding author: [email protected]
Compiled July 4, 2024

Since the development of our Arduino-controlled photogate in 2012, we and


other physics educators have used it with excellent results in both high school and
college settings. At the same time, the feedback received during the manufacturing
process, during the teaching of how the photogate works, and during the actual data
collection and analysis, has brought us some very valuable pedagogical insights and
has allowed us to improve upon our original photogate housing design and Arduino
code. The goal of this follow-up article is to disseminate these observations.
Key words: Arduino Uno, physics education, a measurement of acceleration.

1. INTRODUCTION

In the last decade the Arduino Uno microcontroller board has emerged as an
important player in the field of physics education. Among the very first publications
describing Arduino-based physics experiments we mention a study of photovoltaic
cells [1], where the Arduino controls a digitally programmable potentiometer, and
our measurement of the gravitational acceleration [2], where the Arduino checks
the status of a home-made photogate. Today, there is an extensive list of physics
activities that engage our students in the learning process in a more active manner by
revealing the hardware and software details of a variety of mobile electronic devices
and sensors [3,4]. For example, the gravitational acceleration can also be determined
by measuring the time of free fall with the Acoustic Stopwatch phyphox app [5], or
by measuring the period of a Kater’s pendulum with a TSOP sensor module [6].
Our experimental determination of the gravitational acceleration [2] is done
by dropping an object with alternating transparent and opaque stripes through the
arms of a photogate. This object is often called a “picket fence”or a “Lego® ladder”.
While we have monitored the IR light transmitted through the object, one could also
determine the position of the object from the reflected light [7]. Since the position of
an object in free fall as a function of time is given by the equation x(t) = x0 + v0 t +
a t2 /2, the experimental data points are fitted with a quadratic function of the form
y(x) = A + B x + C x2 . After finding the best-fit parameters A, B, and C, we extract
the constant acceleration as twice the coefficient of the quadratic term, a = 2 C.
Rom. Rep. Phys. Romanian Academy Publishing House ISSN: 1221-1451
2 Călin Galeriu, Ion Gruia (c) 2024 RRP

2. IMPROVEMENTS IN THE PRESENTATION OF THE LESSON

One conceptual question that we must ask our students is: What exactly are
we measuring and graphing? The position of what? The coordinate x describes the
position of one point in space, while our Lego ladder is an extended object, and not a
material point. The students must understand that we are measuring and graphing the
position as a function of time of one point A that sits on the first rung, at the front of
the Lego ladder, as seen in Fig. 1. By our choice, the origin O of the x reference axis
is exactly where the beam of infrared (IR) light is. This is why, when the Lego ladder
blocks the IR beam for the first time, at time t1 , the position coordinate x1 of point
A is exactly zero. When the Lego ladder blocks the IR beam for the second time, at
time t2 , the position coordinate x2 of point A is obtained by measuring the distance
between two neighboring rungs. The same reasoning applies for all the other position
measurements.

Fig. 1 – With the help of a ruler we can easily determine the position coordinates of point A (that sits
on the leading edge of the Lego ladder) at the time moments when the IR beam is blocked.

Another important question that we must ask our students is: What are the
sources of experimental errors? The Arduino-controlled photogate measures time
with an error of 12 µs, this is exceedingly accurate. With a ruler, the distances are
measured with an error of 1 mm. By using a caliper, this error can be decreased to 0.1
mm or less. Another quite significant source of experimental errors is the fact that
http://www.infim.ro/rrp submitted to Romanian Reports in Physics ISSN: 1221-1451
(c) 2024 RRP An Improved Arduino-Controlled Photogate 3

the Lego ladder may not fall in a perfectly vertical position, but instead it could make
a small angle θ with the vertical. Sometimes, due to this tilt, the Arduino will report
fewer time measurements than expected. As seen from Fig. 2, the traveled distance is
underestimated by a factor of cos(θ), which means that the gravitational acceleration
is also underestimated by the same factor. The better measurements, when angle θ
is smaller, result in larger calculated values of the gravitational acceleration. The
students must understand that here we are not dealing with the familiar Gaussian
distribution of errors, where the measured values are evenly scattered to the left and
to the right of the true value. Instead, the true gravitational acceleration is at the upper
end of the set of experimentally determined values. A similar situation happens when
using the HC-SR04 ultrasonic position sensor, for which the true echo time is at the
lower end of the set of reported values [8].

Fig. 2 – During the time interval measured by the photogate, when the Lego ladder is falling in a tilted
position, point A travels a distance AB that is longer than the distance AC used for data analysis.

http://www.infim.ro/rrp submitted to Romanian Reports in Physics ISSN: 1221-1451


4 Călin Galeriu, Ion Gruia (c) 2024 RRP

3. IMPROVED LEGO LADDER AND PHOTOGATE HOUSING

When it comes to blocking an IR beam of light, not all Lego bricks are equally
good absorbers. This discovery was made by accident when, due to a fateful en-
counter with red Lego plates at a sale price, we realized that these red Lego pieces
are essentially transparent to IR light. An experimental investigation was soon de-
veloped in order to serve as a practical demonstration of the fact that Lego bricks
of different colors absorb IR light in different proportions. During this hands-on ac-
tivity the students insert different Lego plates between a remote control (LEGO®
Power Functions IR Remote Control 8885) and a receiver (LEGO® Power Func-
tions IR Receiver 8884), and then they measure the maximum distance at which
reliable communication between the two is still possible. With an Ocean Optics
HR4000 High-Resolution Spectrometer we have also measured the UV/VIS trans-
mission spectra of Lego plates of different colors. As a result of these investigations,
we now recommend that only black 6 × 4 Lego plates be used for the Lego ladder.
In order to build the Lego ladder, the following black Lego pieces are needed:
• 6 × 4 plates, 6 pieces
• 6 × 1 plates, 8 pieces
• 4 × 1 plates, 42 pieces
We do not recommend saving on the number of Lego pieces by replacing some
4 × 1 plates with longer 12 × 1 plates, since this will give the Lego ladder a slight
curvature.
Another observation is that the original photogate housing [2] was made with
PVC water pipe parts, which required the drilling of a 5 mm diameter hole in the
center of the PVC plugs. We have eliminated the need for drilling by also assembling
the photogate housing from black Lego bricks.
In order to build the photogate housing, the following black Lego pieces are
needed:
• 4 × 4 plates, 4 pieces
• 4 × 2 plates, 8 pieces
• 10 × 2 bricks, 5 pieces
• 2 × 1 bricks, 2 pieces
• 2 × 1 Technic bricks, 2 pieces
• 1 × 1 bricks, 2 pieces
All these individual Lego pieces can be easily ordered online from
https://brickdepot.ro/piese-lego in Romania, or from
https://www.lego.com/en-us/pick-and-build/pick-a-brick elsewhere.
When the photogate is taking measurements at the edge of a table, as seen in
Fig. 3, a heavier object should be placed on top of it in order to hold it steady.

http://www.infim.ro/rrp submitted to Romanian Reports in Physics ISSN: 1221-1451


(c) 2024 RRP An Improved Arduino-Controlled Photogate 5

Fig. 3 – The photogate housing is made entirely from black Lego pieces. The 4 × 4 Lego plate that
sits on top of the phototransistor has been removed, in order to reveal the construction details.

4. AN ARDUINO UNO PROTO SHIELD FOR THE ELECTRONIC CIRCUIT

The electronic circuit of the photogate, whose diagram is given in Fig. 4, con-
sists of one IR LED (5 mm diameter, 940 nm peak wavelength), one matching NPN
phototransistor (PT), one 100 Ω resistor R1 in series with the LED, and one 4.7 kΩ
resistor R2 in series with the PT. First the leads of the LED and the PT are soldered
on four pieces of tinned copper hook-up wire (22 AWG single core), and then some
2.5 mm diameter heat shrinkable tubing is wrapped around the soldered joints. The
cathode (shorter leg) of the LED and the emitter (longer leg) of the PT are connected
to GND pins of the Arduino, while the resistors are connected to the 3.3 V pin of
the Arduino. The voltage drop on the PT is measured on digital pin 2 (D2) of the
Arduino. When no object is inside the photogate, the IR light falls on the PT and the
electric current through the PT is large. As a result the voltage drop on R2 is large,
and the voltage measured on pin D2 is small, with logic value LOW . When an object
is inside the photogate, the IR beam is blocked and the electric current through the
PT is small. As a result the voltage drop on R2 is small, and the voltage measured on
pin D2 is large, with logic value HIGH.
The original electronic circuit [2] was soldered on a small 1.5 × 1.75 in2 printed
circuit board (PCB), with the exposed ends of three solid copper wires being plugged
into the appropriate Arduino female pin headers. This method of connecting the pho-
togate to the Arduino Uno board has allowed for occasional errors, with wires going
http://www.infim.ro/rrp submitted to Romanian Reports in Physics ISSN: 1221-1451
6 Călin Galeriu, Ion Gruia (c) 2024 RRP

Fig. 4 – The diagram of the electronic circuit of the photogate, with the Arduino Uno pins on the right
side. The schematic drawing was made with DigiKey’s free online tool Scheme-it [9].

into the wrong places. As a result, we now recommend soldering the electronic
circuit on an Arduino Uno Proto Shield PCB, as seen in Fig. 5. For increased me-
chanical resistance, the wires going to the LED or PT are glued together, with a little
drop of Kragle, to the surface of the PCB. Although the reader cannot discover this
just by looking at Fig. 5, because the super glue is transparent, the small parallel
segments of the four colored wires are indeed frozen in place.

Fig. 5 – The photogate’s electronic circuit is soldered on an Arduino Uno Proto Shield PCB. The red
wire is connected to the LED’s anode, the black wire to the LED’s cathode, the blue wire to the PT’s
emitter, and the yellow wire to the PT’s collector.

http://www.infim.ro/rrp submitted to Romanian Reports in Physics ISSN: 1221-1451


(c) 2024 RRP An Improved Arduino-Controlled Photogate 7

5. A COLLECTION OF IMPROVED ARDUINO SKETCHES

5.1. AN ARDUINO CODE WITH FRIENDLY VARIABLES

The updated photogate1.ino Arduino code, listed in Appendix I, uses four


friendly variables, photogateNow, photogatePrev, timeNow, and timePrev, that
are directly related to the relevant measured physical quantities. This makes the
operation of the C program a lot easier to understand. During the execution of the
loop() function, at a time moment recorded in the timeNow variable, the photogate
is checked and the photogateNow status variable is assigned a value of 1 if there is
an object inside the photogate, or 0 otherwise. The photogatePrev and timePrev
variables are used for saving the photogate status and the related time moment when
the photogate was checked during the previous execution of the loop() function.

Fig. 6 – The voltage on digital pin 2 changes when an object enters (at time tE ) or leaves (at time tL )
the photogate. Each data point (open circle) corresponds to one execution of the loop() function.

Looking at Fig. 6, it now becomes clear how to determine the time moment
when the object has entered or left the photogate. When the photogate status changes
from photogatePrev = 0 to photogateNow = 1, we know that the object has just
entered the photogate. When the photogate status changes from photogatePrev = 1
to photogateNow = 0, we know that the object has just left the photogate. The best
estimate of the exact time moment when these two events of interest have happened
is the arithmetic mean (timePrev + timeNow) / 2. Please notice that there is no need
to divide by 2.0 in order to avoid the rounding of the result to an integer value, as it
is customarily done in the C programming language. This is due to the fact that, on
a 16 MHz Arduino board like the Arduino Uno, the micros() function returns only
multiples of 4 microseconds. We can get an estimate of the measurement error that
http://www.infim.ro/rrp submitted to Romanian Reports in Physics ISSN: 1221-1451
8 Călin Galeriu, Ion Gruia (c) 2024 RRP

is affecting the time value if, instead of the two lines


if(photogateNow && !photogatePrev)
Serial.println((timePrev + timeNow)/2);
we write the five lines
if(photogateNow && !photogatePrev)
{
Serial.println(timePrev);
Serial.println(timeNow);
}
and in this way we discover that the differences between timeNow and timePrev are
either 8 µs or 12 µs. This shows that, on the average, it takes about 10 µs for the
Arduino Uno to execute the loop() function once.
The photogate1.ino Arduino code, like its predecessor photogate.ino from
Ref. [2], is designed to capture the time moments tE when the IR beam is blocked
by a sequence of equally spaced objects entering the photogate. There are two ad-
vantages in designing the data collection procedure like this. First, the x1 , x2 , ... ,
x6 position values become the terms of an arithmetic series, and the measurement
error affecting them is minimized. On the other hand, due to some very small gaps
in between the Lego pieces, the open spaces in the Lego ladder are a tiny bit wider
than the opaque Lego plates. Second, since from an electronic point of view all the
measurements look the same, if the photogate system has a reaction time, then this
constant systematic error is canceled during the calculation of the acceleration.
We could also measure the gravitational acceleration by capturing the time mo-
ments tL when the IR beam is unblocked by a sequence of equally spaced objects
leaving the photogate. This is achieved by replacing the above mentioned two lines
with
if(photogatePrev && !photogateNow)
Serial.println((timePrev + timeNow)/2);
We could also record both the time moment tE when the object enters the
photogate and the time moment tL when the object leaves the photogate. This is
achieved by writing all four lines
if(photogateNow && !photogatePrev)
Serial.println((timePrev + timeNow)/2);
if(photogatePrev && !photogateNow)
Serial.println((timePrev + timeNow)/2);
and in this way, when we know the length of the IR light blocking object, we can
accurately determine its speed [10].
http://www.infim.ro/rrp submitted to Romanian Reports in Physics ISSN: 1221-1451
(c) 2024 RRP An Improved Arduino-Controlled Photogate 9

5.2. AN ARDUINO CODE THAT USES INTERRUPTS

The updated photogate2.ino Arduino code, listed in Appendix II, uses Ar-
duino hardware interrupts. Software and hardware interrupts will temporarily stop
the normal flow of a computer program, call an Interrupt Service Routine (ISR) to
take care of an emergency situation, and then restore the normal flow of operations.
The Arduino Uno allows us to use digital pin 2, like in our photogate2.ino pro-
gram, or digital pin 3, in order to set up a hardware interrupt. The ISR will be called
whenever the voltage, or the change in voltage, on that dedicated digital pin matches
the condition selected by the programmer.
It is a good idea to introduce our advanced computer science students to the
concept of interrupts. Why should the Arduino be wasting time by doing nothing
but repeatedly checking the status of the photogate, measuring the voltage on pin
D2, like it does in the photogate1.ino program? All that really matters is the time
moment when the object enters the photogate, and the voltage on pin D2 goes up,
and the time moment when the object leaves the photogate, and the voltage on pin
D2 goes down. When using interrupts, a lot of time is freed and can be used by the
computer for other things. For example, with our improved photogate2.ino code,
the Arduino is now able to take a one millisecond break during every execution of
the loop() function.
The photogate2.ino Arduino code is designed to capture the time moments
tE when the IR beam is blocked, and the voltage on pin D2 is rising. The line that
selects this condition is
attachInterrupt(n, isr, RISING);
We could modify the Arduino code, in order to make it capture the time mo-
ments tL when the IR beam is unblocked, and the voltage on pin D2 is falling. In
this case the line that selects the condition becomes
attachInterrupt(n, isr, FALLING);
We could also modify the Arduino code in another way, in order to make it
capture both time moments tE and tL when the voltage on pin D2 is changing. In
this case the line that selects the condition becomes
attachInterrupt(n, isr, CHANGE);
Although both computer programs presented here, the photogate1.ino code
that does not use interrupts and the photogate2.ino code that uses interrupts, cap-
ture the time moments tE and tL with sufficient accuracy, and thus they both measure
the same value of the gravitational acceleration, there are other physics experiments,
like for example those using a Geiger counter [11], when the voltage change on the
Arduino digital pin is very fast, and as a consequence we have no other option but to
use interrupts in order to avoid missing some of the Geiger pulses.
http://www.infim.ro/rrp submitted to Romanian Reports in Physics ISSN: 1221-1451
10 Călin Galeriu, Ion Gruia (c) 2024 RRP

Whenever using Arduino interrupts, please keep in mind that: a) The variables
modified by an ISR must be declared volatile. This is to let the compiler know that
no copy of them should be made in the cache memory, for optimization purposes.
At compile time we cannot predict when these variables will change their value.
b) Whenever the above mentioned variables are manipulated in other parts of the
program, not in an ISR, that critical section of code must be sandwiched between
noInterrupts(); and interrupts(); instructions. This is to prevent an interrupt
from changing these variables in the middle of their reading or writing process. Just
imagine a 4 byte integer that could get 2 bytes from its value before the interrupt and
the other 2 bytes from its value after! c) Inside an ISR we cannot print to the Serial
Monitor, because that operation is completed using USART interrupts. d) Inside an
ISR we cannot use delay(), and the value returned by millis() will not increase,
because these functions rely on Timer interrupts. The ATmega328P microprocessor
of the Arduino Uno disables interrupts while an ISR is being executed, and takes care
of any raised interrupt flags only after [12, 13].

5.3. AN ARDUINO CODE FOR A MOBILE PHOTOGATE

The updated photogate3.ino Arduino code, listed in Appendix III, allows for
the photogate system to be completely disconnected from the computer (desktop or
laptop) once the compiled program has been uploaded. This is an added advantage of
using an Arduino Uno Proto Shield for the photogate’s electronic circuit, because an
Arduino LCD Keypad Shield can now be snapped on top of the photogate shield, as
seen in Fig. 7. Instead of printing the six measured time values on the Serial Monitor
window, the Arduino Uno microcontroller will now perform, all by itself, the fitting
of the experimental data points with a quadratic function, and then write on the LCD
shield only the values of the instantaneous velocity (when the IR beam is blocked for
the first time) and constant acceleration of the Lego ladder. A 9 V alkaline battery
provides the needed electric power to this mobile photogate system.
The best fit polynomial function is found using the method of least squares,
by linking the Arduino code with the polyfit.c and polyfit.h source files. The
polyfit() function was written in C by Henry Forson, with design goals that include
“simplicity and ease of porting” [14]. Before calling the polyfit() function we
make sure that the times are given in seconds and the positions are given in meters.
Also, it is necessary to make sure that the origin of the time axis is the moment when
the leading edge of the Lego ladder enters the photogate. Otherwise, the numerical
errors are way too large. The gravitational acceleration calculated with polyfit()
matches the acceleration calculated with Microsoft Excel in the first 4 digits. This
small numerical error could be due to the fact that, on the 8-bit Arduino Uno machine,
a variable of type double occupies only 4 bytes, just like a variable of type float.
http://www.infim.ro/rrp submitted to Romanian Reports in Physics ISSN: 1221-1451
(c) 2024 RRP An Improved Arduino-Controlled Photogate 11

Fig. 7 – The mobile system has an Arduino Uno board on the bottom, the photogate’s electronic
circuit on an Arduino Proto Shield in the middle, and an Arduino LCD Keypad Shield on top.

6. CONCLUSIONS

Our Arduino-controlled photogate has proved to be a powerful workhorse, a


real piece of resistance in the physics laboratory. In addition to measuring the con-
stant gravitational acceleration, we have also used it in order to verify Newton’s
second law, to verify the conservation of mechanical energy, to measure the period
of a mass-spring system, and to measure the variable acceleration of a Lego car with
a pull-back motor. The operation of the improved photogate is now easier to un-
derstand, and its manufacturing process has been simplified. Last but not least, we
hope that our Arduino-controlled photogate will continue to inspire many students,
increasing their interest in STEM related topics.

APPENDIX I. AN ARDUINO CODE WITH FRIENDLY VARIABLES

// photogate1.ino

const int photogatePin = 2;


int photogateNow, photogatePrev;
unsigned long timeNow, timePrev;

void setup()
{
http://www.infim.ro/rrp submitted to Romanian Reports in Physics ISSN: 1221-1451
12 Călin Galeriu, Ion Gruia (c) 2024 RRP

Serial.begin(115200);
pinMode(photogatePin, INPUT);
photogatePrev = digitalRead(photogatePin);
timePrev = micros();
}

void loop()
{
photogateNow = digitalRead(photogatePin);
timeNow = micros();
if(photogateNow && !photogatePrev)
Serial.println((timePrev + timeNow)/2);
photogatePrev = photogateNow;
timePrev = timeNow;
}

APPENDIX II. AN ARDUINO CODE THAT USES INTERRUPTS

// photogate2.ino

const int photogatePin = 2;


volatile bool event = false;
volatile unsigned long eventTime;

void setup()
{
Serial.begin(115200);
pinMode(photogatePin, INPUT);
int n = digitalPinToInterrupt(photogatePin);
attachInterrupt(n, isr, RISING);
}

void loop()
{
delay(1); // the Arduino can work on other tasks
if(event)
{
noInterrupts();
Serial.println(eventTime);

http://www.infim.ro/rrp submitted to Romanian Reports in Physics ISSN: 1221-1451


(c) 2024 RRP An Improved Arduino-Controlled Photogate 13

event = false;
interrupts();
}
}

void isr()
{
eventTime = micros();
event = true;
}

APPENDIX III. AN ARDUINO CODE FOR A MOBILE PHOTOGATE

// photogate3.ino

#include <LiquidCrystal.h> // DFRobot LCD shield


LiquidCrystal lcd(8, 9, 4, 5, 6, 7); // also D10 and A0

#include "polyfit.c"

const int photogatePin = 2;


int photogateNow, photogatePrev;
unsigned long timeNow, timePrev;

const int N = 6; // the number of experimental data points


double t[N]; // array for the time values
double x[N]; // array for the position values
double c[3]; // the coefficients of the best fit parabola

void setup()
{
lcd.begin(16, 2);
lcd.setCursor(0, 0);
lcd.print("v = ");
lcd.setCursor(0, 1);
lcd.print("a = ");
pinMode(photogatePin, INPUT);
photogatePrev = digitalRead(photogatePin);
timePrev = micros();

http://www.infim.ro/rrp submitted to Romanian Reports in Physics ISSN: 1221-1451


14 Călin Galeriu, Ion Gruia (c) 2024 RRP

x[0] = 0.0;
x[1] = 0.064;
x[2] = 0.128;
x[3] = 0.192;
x[4] = 0.256;
x[5] = 0.320;
}

void loop()
{
int i = 0;
while(i<N)
{
photogateNow = digitalRead(photogatePin);
timeNow = micros();
if(photogateNow && !photogatePrev)
{
t[i] = (timePrev + timeNow)/2000000.0;
i = i + 1;
}
photogatePrev = photogateNow;
timePrev = timeNow;
}
double t0 = t[0];
for(int j=0; j<N; j++) t[j] = t[j] - t0;
int errorCode = polyfit(N, t, x, 3, c);
if (errorCode == 0)
{
lcd.setCursor(4,0);
lcd.print(" m/s ");
lcd.setCursor(4,0);
lcd.print(c[1],5);
lcd.setCursor(4,1);
lcd.print(" m/s2");
lcd.setCursor(4,1);
lcd.print(2*c[0],5);
}
}

http://www.infim.ro/rrp submitted to Romanian Reports in Physics ISSN: 1221-1451


(c) 2024 RRP An Improved Arduino-Controlled Photogate 15

REFERENCES

1. K. Zachariadou, K. Yiasemides and N. Trougkakos, Eur. J. Phys. 33, 1599-1610 (2012).


2. Calin Galeriu, Phys. Teach. 51 (3), 156-158 (2013).
3. Giovanni Organtini, Physics Experiments with Arduino and Smartphones, (Springer, Cham, 2021).
4. Martı́n Monteiro and Arturo C. Martı́, Am. J. Phys. 90 (5), 328-343 (2022).
5. Marilena Colţ, Corina Radu, Ovidiu Toma, Cristina Miron, Vlad-Andrei Antohe, Rom. Rep. Phys
72 (4), 905 (2020).
6. B. Chiriacescu, Fabiola Sanda Chiriacescu, Cristina Miron, C. Berlic, V. Barna, Rom. Rep. Phys 72
(1), 901 (2020).
7. Sohaib AbdElazem and Watheq Al-Basheer, Eur. J. Phys. 36 (4), 045017 (2015).
8. Calin Galeriu, Phys. Teach. 60 (4), 284-288 (2022).
9. https://www.digikey.com/en/schemeit/home
10. John Wolbeck, Phys. Teach. 48 (4), 262-263 (2010).
11. Călin Galeriu, Rom. Rep. Phys. 75 (2), 906 (2023).
12. Atmel® , posted at: https://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-7810-A
utomotive-Microcontrollers-ATmega328P Datasheet.pdf
13. Nick Gammon, posted at: https://gammon.com.au/interrupts
14. https://github.com/henryfo/polyfit

http://www.infim.ro/rrp submitted to Romanian Reports in Physics ISSN: 1221-1451

You might also like