<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Scarlett Chen on Medium]]></title>
        <description><![CDATA[Stories by Scarlett Chen on Medium]]></description>
        <link>https://medium.com/@scarlettchen315?source=rss-0bb870234368------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*59pLB-qV87yDpqtdrncsqQ.jpeg</url>
            <title>Stories by Scarlett Chen on Medium</title>
            <link>https://medium.com/@scarlettchen315?source=rss-0bb870234368------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 19:16:17 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@scarlettchen315/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Audio Denoising and Amplification (Part 1: Prototype)]]></title>
            <link>https://medium.com/@scarlettchen315/audio-denoising-and-amplification-part-1-prototype-ce53ce85aa54?source=rss-0bb870234368------2</link>
            <guid isPermaLink="false">https://medium.com/p/ce53ce85aa54</guid>
            <category><![CDATA[electronics]]></category>
            <category><![CDATA[signal-processing]]></category>
            <dc:creator><![CDATA[Scarlett Chen]]></dc:creator>
            <pubDate>Sun, 25 Oct 2026 04:30:23 GMT</pubDate>
            <atom:updated>2026-10-25T04:30:23.943Z</atom:updated>
            <content:encoded><![CDATA[<p>I’m often told that my voice is too quiet. To get my revenge, I have been working on this electronics project to denoise a microphone input and amplify my voice (with the help of a bluetooth speaker)!</p><p>On a more serious note, I’ve also been wanting to try low-level signal-processing with wavelets, which I have some experience in, and with the FPGAs I learned to use over the summer.</p><h3>Demonstration</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FxHaurgY9SMg%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fshorts%2FxHaurgY9SMg%3Ffeature%3Dshare&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FxHaurgY9SMg%2Fhq2.jpg&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/ed90e729389ccc5c7055a53252f67d06/href">https://medium.com/media/ed90e729389ccc5c7055a53252f67d06/href</a></iframe><h3>Overall Function</h3><p>Sound from the microphone travels via I2S format to a field-programmable gate array (FPGA). Unlike the Arduinos I’ve worked with before, FPGAs use look-up tables to act as a kind of reprogrammable logic circuit or chip. Instead of a programming language, they are programmed with hardware description languages (HDLs), which specify wires, registers, logic gates, etc. that run simultaneously as a real circuit would. FPGAs are often used for functions that require real-time speed, like real-time audio denoising!</p><p>The FPGA outputs a one-bit modulated pulse that represents the signal. This is smoothed via an RC filter and exits through the Bluetooth transmitter. A potentiometer can be used to control the volume as well.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DUt535iSZ6eQoanRGGz99g.png" /><figcaption>How the audio signal flows through the system. For clarity, the Bluetooth transmitter isn’t attached.</figcaption></figure><h4>List of Materials</h4><ul><li>Nandland Go Board FPGA</li><li>INMP441 I2S Microphone Module</li><li>Bluetooth 2-in-1 Transmitter &amp; Receiver, 3.5mm (only the transmitter setting is used)</li><li>Stereo Audio Jack Breakout Board, TRS Connector (for the transmitter)</li><li>Perfboard</li><li>4x 100nF capacitors, 1x 10k Ohm potentiometer, 1x 100 Ohm resistor, wires (some jumper &amp; some solid-core)</li><li>Bluetooth speaker or headphones</li></ul><h3>Wavelet Transform</h3><p>Wavelet transforms use specialized transforms to analyze signals. A signal can be decomposed into wavelets, which are scaled and shifted versions of a base function, called the “mother wavelet”. The Fourier transform, which perfectly translates a signal from the time to the frequency domain, loses <em>when</em> a specific frequency happens. Wavelet transforms allow for an (imperfect) representation of both the time and frequency domains of a signal. That is, it lets you approximate the frequencies a signal is composed of at a certain point in time. You can watch the first few minutes of <a href="https://youtu.be/jnxqHcObNK4?si=B4--4OAxMPOa1dnb">this video</a> for a better explanation!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xOVaEOCI8DqPm5rP0EnkiQ.png" /><figcaption>Time and frequency domains for signals. The wavelet transform decomposes signals with wavelet functions, letting you see a bit of both.</figcaption></figure><p>For digital signal processing, a discrete version of the wavelet transform (discrete wavelet transform, DWT) is used. This uses low-pass and high-pass filters to split the signal into approximation and detail coefficients.</p><h4>DWT for Denoising</h4><p>Because noise can be modeled as a high-frequency signal added to the original signal, we can use the DWT to isolate and remove it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*csUvvGqupiqigtwaYccPnw.png" /><figcaption>Steps for DWT-based denoising. Notes from video: <a href="https://youtu.be/uMav4AyA4lA?si=TKstVsafkmEdlkep">https://youtu.be/uMav4AyA4lA?si=TKstVsafkmEdlkep</a></figcaption></figure><p>First, the DWT is used to separate the signal into detail and approximation coefficients.</p><p>The detail coefficients are then thresholded. With hard thresholding, only detail coefficients with a magnitude within the band (-λ, λ) are zeroed, and the rest are kept. With soft thresholding, coefficients outside the band are lessened. Soft thresholding is used here because its continuity decreases the likelihood that strange jumps or artifacts make their way into the output.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DD1jc_Z_rxReuaQsQsybVA.png" /><figcaption>Hard vs. soft thresholding of wavelet coefficients. X-axis is the input , and y-axis is the output. Notes from video: <a href="https://www.youtube.com/watch?v=uMav4AyA4lA">https://www.youtube.com/watch?v=uMav4AyA4lA</a></figcaption></figure><p>In this project, λ is manually selected with the buttons on the Go Board.</p><p>Finally, the approximation and the thresholded detail coefficients are put through an inverse-DWT (I-DWT), which reconstructs the denoised signal.</p><h4>The Lifting Scheme</h4><p>The lifting method of the wavelet transform (LWT) reduces computational complexity, simplifying the steps and calculating in-place (As you can see from the block diagram below, no auxiliary memory is required). This makes it great for a real-time hardware application like this one!</p><p>I used the Haar wavelet, which is square-shaped and thus simplifies the process. However, it should be noted that it’s not the best type for denoising; I only used it because I was more confident that I could understand what I was doing with it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nBhkUQwCYRafCi9z7KYOIQ.png" /><figcaption>The lifting scheme. Notes from paper: <a href="https://9p.io/who/wim/papers/athome/athome.pdf">https://9p.io/who/wim/papers/athome/athome.pdf</a></figcaption></figure><p>The LWT is split into three steps:</p><ol><li><em>Split</em>: Splits signal into two disjoint sets, even-indexed and odd-indexed.</li><li><em>Predict</em>: Use the even set to predict the odd. Because I’m using a Haar wavelet, predicted odd samples are simply the even samples to their left. The detail coefficients are equal to the odd sample minus the predicted (i.e. even) one, and can be stored in place of the original odd coefficient.</li><li><em>Update</em>: We need to calculate the approximation coefficient. In the case of the Haar wavelet, it is the average of the odd and even samples. Wait a minute, didn’t we rewrite the odd sample with the detail? Fortunately, we can still get it back with some algebra. From the equation below, we can see that the update step for a Haar wavelet simply involves halving the detail coefficient.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jwnmUi0pOmNCZydpqCPg-A.png" /><figcaption>approximation = even + detail / 2 = even + (odd — even)/2 = (even + odd) / 2</figcaption></figure><p>The inverse LWT is literally this process in reverse (i.e. flip all the signs and arrows)!</p><h3>RTL Structure &amp; Other Verilog Modules</h3><p>The LWT is the core purpose of the Verilog code, but it also takes some work to get the inputs and outputs into their desired formats.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PZP8HQfvAVHC4-R78QEbTA.png" /></figure><h4>I2S Input</h4><p>Having tested the denoiser, I was about to connect everything together when I realized that built-in protocols are among the many things that can’t be taken for granted.</p><p>Very briefly, here’s the signal diagram for I2S, which had to be coded in Verilog:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/916/0*Sz9r0t-OVXAiUhUs.png" /><figcaption>Source: <a href="https://www.beyond-circuits.com/wordpress/tutorial/tutorial18/">https://www.beyond-circuits.com/wordpress/tutorial/tutorial18/</a></figcaption></figure><p>I just used the left channel and tied L/R to ground.</p><h4>Sigma-Delta (Digital-to-Analog Converter)</h4><p>Similarly, the 16-bit output of the denoiser can’t be straight-up used as the output signal. I chose to use a sigma-delta DAC instead of PWM to get better audio resolution.</p><p>Here’s the block diagram:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*96lypsdpFChsZSQC.png" /><figcaption>Source: <a href="https://e2e.ti.com/blogs_/archives/b/precisionhub/posts/delta-sigma-adc-basics-understanding-the-delta-sigma-modulator">https://e2e.ti.com/blogs_/archives/b/precisionhub/posts/delta-sigma-adc-basics-understanding-the-delta-sigma-modulator</a></figcaption></figure><h3>Circuit &amp; Bluetooth Output</h3><h4>Circuit Schematic</h4><p>Here’s the schematic:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HbCMjUJv3yaSlqyd9X4JAQ.png" /></figure><p>As a side note, I used to have an power op-amp (TDA2822) in between the potentiometer and the output (with the suggested capacitors etc.), but found that it added a ton of noise when I built it on a breadboard.</p><p>That horrendous function on the BSource (yes, it’s from AI) simulates a 3.3V PWM (not sigma-delta) just to see if the RC filter was working as intended.</p><p>Here’s the simulation results:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vpqJB-KFd6fGoACs9_Yqlg.png" /></figure><p>The RC filter smooths the PWM, the coupling capacitor removes DC offset (i.e. the output/red signal is zeroed) and the potentiometer (which is set at 0.5 in this simulation) affects its amplitude.</p><p>You can see some ripple if you zoom in:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0XEIrxPP941Oon7hxvjyeg.png" /></figure><h4>Putting it all Together</h4><p>And here’s the first working prototype!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hZpPg9yw3lDbtf9dfHay9A.jpeg" /><figcaption>A working breadboard prototype! For clarity, the transmitter isn’t attached.</figcaption></figure><h3>Perfboard</h3><p>I <em>will </em>be getting some soldering helping hands before I do something like this again — you should have seen all of the strange stacks of leftover breadboards I had to make to keep everything flat, and even then it wasn’t great…</p><p>Other than it taking a few hours, I don’t think there’s much to note since the wiring is exactly the same. The only thing that might not be obvious from the image is that there is a ground wire on the back side, on the second row from the bottom, connecting the various grounds together.</p><p>Once it was done and tested, I trimmed off any long legs and haphazardly velcro-ed it to the Go Board case. It’s a prototype, after all.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YuuDqUnWixesFWfQoiB6Sg.jpeg" /><figcaption>Perfboard! Again, the transmitter isn’t attached.</figcaption></figure><h3>Some random things that happened…</h3><p>During the debugging of this circuit, I inadvertently came across some signal processing features:</p><ul><li>On the breadboard, I initially somehow managed to use a 1M resistor for the RC filter instead of 100 (don’t judge). This caused some crazy distortions because the cutoff frequency = 1/(2πRC) was too low.</li><li>While trying to track down the problem, I also temporarily removed the coupling capacitor, which caused a (scary) pop in from the DC offset.</li><li>After soldering the perfboard, the microphone didn’t appear to work until I put my hand on the L/R wire, which was supposed to be grounded. I realized I was acting as the ground and managed to re-solder the connection. I think it’s was a miracle that it was the only problem!</li></ul><p>It’s interesting to read about these problems in a textbook, yet fun to see how they played out on a real circuit!</p><h3>Future Work &amp; Conclusions</h3><p>From listening to the soundbytes all the way at the top, you may be surprised by how little of a difference the wavelet actually makes. In reality, as I unfortunately realized, a single-level Haar transform won’t be able to achieve that great of a denoising effect. Additionally, the Bluetooth transmitter also adds noise (when I disconnect it from the circuit, the speaker still is a bit noisy).</p><p>Now that I’ve got the basic structure down, I’d like to work with a different type of wavelet — perhaps Daubechies? — or incorporate other methods into the Verilog code. I’ll also see what I can do to improve the analog circuit.</p><p>And of course, I’ll work on the form factor! I’m thinking about fixing the gain and threshold and using a smaller FPGA that can stick directly onto a board. Speaking of the board, I may either suffer through another perfboard or make a custom PCB. Either way, everything will be nicely screwed to a compact 3-D print.</p><p>I hope that I will soon be able to bring my voice to the table without having to lose it first!</p><h3>Code Availability</h3><p>Verilog code can be found <a href="https://github.com/Scarlett315/FPGA-Denoising">here</a>.</p><h3>Sources/Further Reading</h3><p>Here are the main sources I used for this project:</p><ul><li><a href="https://youtu.be/jnxqHcObNK4?si=pdWAvKddDTGk_Gin">Wavelets: a mathematical microscope</a></li><li><a href="https://9p.io/who/wim/papers/athome/athome.pdf">Building Your Own Wavelets at Home</a>, by Wim Sweldens and Peter Schroder</li><li><a href="https://www.youtube.com/watch?si=TKstVsafkmEdlkep&amp;v=uMav4AyA4lA&amp;feature=youtu.be">Wavelet Based Denoising of Audio Signals using MATLAB &amp; SIMULINK</a></li><li><a href="https://justanotherelectronicsblog.com/?p=402">Using FPGAs for audio processing</a></li><li><a href="https://www.instructables.com/Using-Perfboard/">Using Perfboard | Soldering Basics</a></li><li><a href="https://github.com/briansune/Delta-Sigma-DAC-Verilog">Delta-Sigma-DAC-Verilog</a> (GitHub Repo)</li><li><a href="https://www.beyond-circuits.com/wordpress/tutorial/tutorial18/">Tutorial 18: I2S Receiver</a></li></ul><p>For transparency, I used AI for the following:</p><ul><li>Coding the interface where you can use the buttons to increase/decrease the threshold λ</li><li>Assisting with coding the I2S input + gain and suggested the use of gain</li><li>Writing testbenches/golden models for implementations of the LWT and denoising process, I2S input, and delta-sigma output</li><li>Checking over my circuit schematic</li><li>When debugging the circuit, used to rapidly code tests to isolate issues (e.g. a pass-through test without any wavelet things, an output-only test with a predefined sound, etc.)</li></ul><p><strong>Note</strong>: While proofreading, I found that the potentiometer in the built circuit isn’t wired the way the schematic shows. It still changed the volume, so I missed it during testing. I’ll fix it in Part 2.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ce53ce85aa54" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Lock-In Box (2: Functional Version)]]></title>
            <link>https://medium.com/@scarlettchen315/lock-in-box-2-functional-version-dc13c8e9974b?source=rss-0bb870234368------2</link>
            <guid isPermaLink="false">https://medium.com/p/dc13c8e9974b</guid>
            <category><![CDATA[electronics]]></category>
            <dc:creator><![CDATA[Scarlett Chen]]></dc:creator>
            <pubDate>Thu, 01 Oct 2026 02:08:05 GMT</pubDate>
            <atom:updated>2026-10-01T02:08:05.844Z</atom:updated>
            <content:encoded><![CDATA[<p>This is the counterpart to the <a href="https://medium.com/@scarlettchen315/lock-in-box-1-prototype-fe6755898552">article</a> I wrote earlier. It was all supposed to be one article, but it was getting quite long…</p><p>Anyways, to recap I had built and submitted a phone box prototype for an Arduino contest. It includes a reed switch circuit for detecting tampering (lid open) and an IMU for detecting vibrations for incoming phone calls.</p><p>The code and mechanics were all functional, but let’s be real — nobody, including myself, is going to use that gigantic thing in real life.</p><p>And so, I decided to make a second version! My goals were:</p><ol><li>Remove the need for a breadboard</li><li>Condense the space as much as possible</li><li>Make it look a little more like a consumer product</li></ol><p>And without further ado, here’s how it looks!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JBYMOD_qSs-RMIQWd0HLGg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ahCI9qfQplBEw0IDdzIyUw.jpeg" /></figure><p>I got an introduction to PCB design on KiCAD through a summer program and thought it would be fun to utilize it on this! I also had to learn how to use basic Onshape to create a better-looking CAD model.</p><h3>Demonstration</h3><p>This box has the same functionalities as the first version. Here’s a demonstration of the tampering and call detection.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*uhv4JhSGDo_RVawr.gif" /><figcaption>Tampering detection. The timer is currently paused, but when the lid is opened the LCD prompts the user to close it before the timer can be started again.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*KlNnayoYw5NY2r2i.gif" /><figcaption>Call detection. When I call the phone inside the box, its vibration is detected by the IMU, the box is unlocked, and the timer is paused.</figcaption></figure><h3>PCB Design</h3><h4>Schematic</h4><p>Since this was my first PCB, I didn’t want to try anything crazy like putting the microcontroller chip directly onto the PCB, so I used a footprint for the Arduino. I did try this for the IMU — and it got quite complicated — but I saw that it would cost around $80 for the MPU6050 chips, and that wasn’t anywhere near worth it for something that might not even work. So, the GY-521 module is also placed directly on.</p><p>Besides that, there’s nothing really worth saying about the schematic; it’s essentially a copy of the wiring done in the first version.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*M_WB_R4gVUrSpKhFHYDR7Q.png" /></figure><p>(Beware that the “Arduino Nano Every” footprint does not in fact mean every Arduino Nano, because the Every is an actual model. I realized this after making the entire thing and it was a pain to undo…)</p><h4>Layout</h4><p>On the PCB, I made only the battery wire inputs screw terminals; the rest are header pins. I also added some mounting holes the size of some screws I already had, and some fun text!</p><p>I did all of the routing by hand, so it might not be the most efficient as evidenced by the strangely-placed vias. I think it’s good to do it manually at least once, though.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/976/1*ThMz_nAeGDhAYECu4yCZ_g.png" /></figure><p>Also, if I could just take a minute to complain: while I was learning to do all this stuff I kept getting ads for AI softwares that claimed to basically do the entire process— way to discourage an aspiring engineer!</p><h4>Assembly</h4><p>Once the PCBs arrived, I could finally put everything together! With the little experience I have, I don’t think the soldering looks too shabby. I honestly was dreading it because it used to be a huge struggle of it’s-not-melting-what-do-I-do, but then I discovered the amazingness of flat tips for the soldering iron. For once, it actually went relatively quickly.</p><p>The only issue is that the IMU is very tilted despite all of my elaborate schemes to keep it level (without one of those “helping hands”), although it doesn’t come across on the image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QaOgdgaGD8c_H0WkmDql8w.jpeg" /></figure><p>Honestly, I was very shocked when all of the old code actually turned out ot work on the PCB! There was a scare where I thought I had mixed up the SDA and SCL pins for the IMU inputs, but thankfully it turned out to be a labeling and not wiring problem.</p><h3>CAD Model &amp; Design Changes</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*si6AYsN4-fO62ecI-GqtZA.png" /><figcaption>Initial sketches. It ended up looking a bit different, but isn’t that how all things go?</figcaption></figure><p>The overall structure remains the same, with a divider separating electronics from the phone storage area. However, I was able to deliberately condense it to a reasonable size by using the measurements of all components, and left room for one phone. Since the phone goes in vertically, I left a little tab open to make it easier to take out.</p><p>I also changed the lid from hinged to sliding, making it smoother to open and close. This allows the servo (in its own holder) to peek up from the bottom to lock the lid, taking up less space.</p><p>For the divider, like the first model I made a groove on the main box and added screw holes so the PCB can go in vertically. However, the grooves for the divider weren’t inset enough, leading to the slight bending that’s in the final product.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1iktvDX506zu_N7VcaKMyA.png" /><figcaption>CAD models for the main box (top left), servo holder (bottom left), sliding lid (top right), and divider (bottom right).</figcaption></figure><p>While Onshape obviously has more of a learning curve, it probably ended up saving me more time — it’s great how all of the actions are built on top of each other, so it’s easy to do things like change the shape of something by editing the underlying sketch.</p><h3>Conclusion</h3><p>Every part of this project — code, CAD files, and PCB files — can be viewed <a href="https://github.com/Scarlett315/sscs_arduino_contest_26">here on Github</a>.</p><p>I guess if I really wanted to go full-on commercial product, the next steps would be to put the Arduino microcontroller (i.e. ATMega328 chip) and IMU chip directly onto the PCB and find proper, non-hobby electronics. But as far has <em>hobby</em> electronics go, it’s definitely the most well-functioning project I’ve done so far! As in, I’ve actually been using it, and it’s been helpful :D</p><p>As always, I learned a ton and hope to continue exploring!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dc13c8e9974b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Lock-In Box! (1: Prototype)]]></title>
            <link>https://medium.com/@scarlettchen315/lock-in-box-1-prototype-fe6755898552?source=rss-0bb870234368------2</link>
            <guid isPermaLink="false">https://medium.com/p/fe6755898552</guid>
            <category><![CDATA[electronics]]></category>
            <dc:creator><![CDATA[Scarlett Chen]]></dc:creator>
            <pubDate>Wed, 30 Sep 2026 02:22:04 GMT</pubDate>
            <atom:updated>2026-09-30T02:22:04.651Z</atom:updated>
            <content:encoded><![CDATA[<p>For the SSCS Arduino Contest’s prompt of “solutions to everyday challenges”, I built a phone lockbox that can take both tampering and emergencies into account.</p><p>Additionally, I’ve made a Part 2 with a much better design, including a custom PCB and proper CAD.</p><h3>Purpose &amp; Summary</h3><p>We’ve all faced the daily challenge of being distracted by our phones. While just keeping devices out of sight usually works fine for me, sometimes it’s helpful to have a physical blockade, i.e. the box.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*TCZiAwtB1W6L4Rqv.gif" /></figure><p>There’s a lot of them out there, and frankly a non-electronic solution will work just fine. For this project I wanted to solve two main problems in particular:</p><h4><strong>1. Tampering</strong></h4><p>Especially when you’re managing a child or sibling’s device, it’s helpful to know if they’re tampering!</p><p>I implemented tamper detection by using a reed switch, which is composed of two thin metal strips that make contact when a magnet is brought near it. If we attach a magnet to the lid and a reed switch to the box, the circuit opens when the lid is open and vice versa. We can thus tell when the box is open.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*gqDTGR9y099Rk7gF.png" /><figcaption><a href="https://www.deeterelectronics.com/reed-switch-how-it-works/">https://www.deeterelectronics.com/reed-switch-how-it-works/</a></figcaption></figure><p>Unfortunately it can’t do much but nag the user via the display, but it’s an interesting area for expansion.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*LDBjAdiC5GJjoTAb.gif" /></figure><h4>2. Lack of Emergency/Call Detection</h4><p>What if someone important is trying to reach you, and you can’t get to your phone because you still have — let me check — 23 minutes left on the clock? That’s a problem I came across a lot when researching the problems people had with personal phone boxes.</p><p>I implemented call detection by using an IMU to detect phone vibrations that are within a certain range, so that vibration detect is accurate while other disturbances (like shaking the box) do not trigger it. When a call is detected, the box simply unlocks.</p><p>Specialized vibration sensors were not on the part list for the contest, so I did not use them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*HHRNr4moscHPL9NW.gif" /></figure><h3>Materials</h3><p>Here’s a list of materials:</p><ul><li>Arduino Uno</li><li>6V battery pack (4x 1.5V)</li><li>SG90 Servo</li><li>I2C-enabled LCD Screen</li><li>Three buttons (START, +15 mins, -15 mins)</li><li>Reed switch and small magnet</li><li>GY-521 IMU/accelerometer (based on MPU6050)</li><li>3-D printed enclosure</li></ul><h3>Design</h3><h4>Electronics</h4><p>The glorious Canva wiring diagram makes a comeback:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PZoAoSWVoUkIbGBeuwT_XQ.png" /></figure><p>I attached the reed switch near the top inside of the box and the magnet to a corresponding spot on the lid. The Arduino can detect an opened lid if that input pin is pulled HIGH by the open switch (uses Arduino’s internal pull-up resistor).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pr6fn_yz-hYEy93mrBiMtw.jpeg" /></figure><p>I mounted the IMU to the box via a 3-D printed mount and glue. It was originally connected via Velcro, but it wasn’t such a great idea for something that’s supposed to detect vibrations.</p><p>All electronics are shoved into a partition within the box. Despite the craziness of the wires and breadboard, it didn’t look as messy as I thought it would!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XQtq4ncf6VytvIOT7XujCw.jpeg" /></figure><h4>CAD</h4><p>So, I don’t really know CAD. I learned Onshape more properly for attempt no. 2, but just bear with this TinkerCAD monstrosity for now:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5_k1hunUj_3_pjqWBkujtA.png" /></figure><h3>Control</h3><p>The lockbox is managed with a finite state machine of four states: IDLE, LOCKED, TAMPER, and PAUSE. Here is the state diagram:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AdpJu7Z14S_j8HlQRYs4WA.png" /></figure><p>The core functionality is that we can set a timer, place our phone into the box, close the lid, and once the center button is pressed, we move to the LOCKED state. Once the timer is complete, we move back to the IDLE state, and the servo goes back to the unlocked position.</p><p>Let’s add the tampering logic. If we are in LOCKED and the lid is opened, we go into the TAMPER state, where the timer stops and the user is told to close the lid. When the lid is closed, we enter the PAUSE state, where the user can choose to resume the timer.</p><p>And finally, the vibration detection. When the phone vibrates, we directly enter the PAUSE state and the servo turns to unlock the box. Again, we can re-enter the LOCKED state by pressing the center button.</p><h4>Vibration Detection</h4><p>I used a root-mean square (“energy”) of the z-axis acceleration measurements from the IMU and compared against an activation range. A call was detected if 8 out of 10 root mean square samples in a sliding window were within the range.</p><p>I would have liked to measure the frequency of the vibrations, but from some initial testing I didn’t think this IMU was up to it in terms of sampling frequency. Oh, well.</p><p>Tuning was definitely an ordeal, though! I really had to push the IMU to be able to detect vibrations in the first place. I was worried because the raw measurements were initially coming out like this, where vibrations were virtually indistinguishable from sensor noise.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bbtWOA1HRf57CVlUMgRtDw.png" /></figure><p>I had to run a lot of trials and make a lot of adjustments (&gt;15 trials of staring at these graphs). Most notably, I changed to the RMS to measure signal “energy” and average out noise, increased the measurement frequency, and (probably most impactful) just mounted the IMU much more rigidly to the box.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xnGx_Cx5K58ZMoKq_MBtCg.png" /></figure><p>This was the final result, where vibrations are apparent and can be distinguished both from noise (left) and from me shaking the box (right).</p><p>However, the sensitivity of the IMU is still something to tune in the future, as I noticed some flukes like a washing machine being able to also open the box.</p><h3>Conclusion</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IRd7s3nLcCfZx8sxswzEUg.png" /></figure><p>This was a fun project to make! I got to exercise some simple electronics and control strategy skills, and I got a little better at dealing with hardware.</p><p>The actual entry (video) can be found <a href="https://youtu.be/Q1daKXmKgNE?si=ohhtvUVE8MyahgoM">here</a>; I’ve repurposed the script and added some more details for this article.</p><p>The code and files for the project (version 2) can be viewed from <a href="https://github.com/Scarlett315/sscs_arduino_contest_26">this link. </a>I also will have another article for version 2 up soon :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fe6755898552" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Making a Spectrometer!]]></title>
            <link>https://medium.com/@scarlettchen315/making-a-spectrometer-f07c99ee8c08?source=rss-0bb870234368------2</link>
            <guid isPermaLink="false">https://medium.com/p/f07c99ee8c08</guid>
            <category><![CDATA[spectroscopy]]></category>
            <category><![CDATA[optics]]></category>
            <category><![CDATA[diy-projects]]></category>
            <category><![CDATA[physics]]></category>
            <dc:creator><![CDATA[Scarlett Chen]]></dc:creator>
            <pubDate>Sun, 05 Jul 2026 23:04:11 GMT</pubDate>
            <atom:updated>2026-07-05T23:04:11.618Z</atom:updated>
            <content:encoded><![CDATA[<p>A while back, my physics class had an independent study project. I made my presentation on wave optics, specifically focusing on diffraction and spectroscopy. As part of the project, I built a spectrometer and learned a few things along the way!</p><h3>The (basic) Physics Behind Spectroscopy</h3><p>Spectroscopy is an incredibly useful tool that is used in a variety of applied contexts, from astronomy to materials science. To understand how spectroscopy works, it is essential to understand the wave nature of light and diffraction. Since it covers a lot, I didn’t include many of the equations and technical details here.</p><p>Unless otherwise cited, all information in this section comes from my physics textbook (Walker, Halliday and Resnick). Citations are at the bottom of this article.</p><h4>Light as an Electromagnetic Wave</h4><p>Electromagnetic (EM) waves consist of sinusoidally oscillating electric and magnetic fields. The various frequencies of EM waves form a spectrum, with wavelengths from short-wavelength gamma rays to long-wavelength radio waves. Visible light makes up a small portion of this spectrum, covering the wavelength range 380nm to 700nm (NASA). As humans, we interpret differences in wavelength as color.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*hNYkCBkLT8NWNvZn.jpg" /><figcaption>The electromagnetic spectrum. <a href="https://www.primalucelab.com/blog/components-of-electromagnetic-spectrum/">https://www.primalucelab.com/blog/components-of-electromagnetic-spectrum/</a></figcaption></figure><p>An essential property of EM waves is self-propagation, or the ability to sustain itself through space without needing a physical medium. A mechanical wave might travel along a rope, and sound waves travel through air, but light from many light-years away can travel through the vacuum of space and hit our telescopes here on Earth! In short, this results from a combination of Faraday’s Law of Induction and Maxwell-Amperè’s Law, which explain how the magnetic and electric fields continuously create each other with induction. (Hence, optics is classified as subject within electricity and magnetism!)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/725/0*I3h0mMqUanb8BwCx.gif" /><figcaption>An electromagnetic wave. mriquestions.com/radiofrequency-waves.html.</figcaption></figure><h4><strong>Interference and Diffraction</strong></h4><p>Waves follow the principle of superposition; thus, when two waves interfere, they superimpose to form a resultant wave (Physics LibreTexts). When the two waves are perfectly in phase, constructive interference occurs and the resultant wave has the amplitude of the sum of the original waves. In destructive interference, the waves are completely out of phase (180 degrees) and the resultant amplitude decreases (Physics LibreTexts). Interference is usually in between completely constructive and completely destructive.</p><p>Diffraction is a special type of interference in which the waves that interfere originate from the same wavefront. If a wave encounters an edge, obstacle, or aperture that has dimensions similar to the wavelength, the part that passes through the opening diffracts, or flares out, from the other side, and these new wavefronts interfere. A pattern of constructive and destructive interference is caused by a path-length difference between two waves that reach the same ending point.</p><p>Both interference and diffraction can be seen in Young’s Double Slit Experiment. The linked page in the caption of the image below explains the experiment and its importance in depth.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/862/1*99DveLDKfYOaTHc05_phOQ.png" /><figcaption>Fig. 3. Young’s Double-Slit Experiment. <a href="https://phys.libretexts.org/@go/page/4499.">https://phys.libretexts.org/@go/page/4499.</a></figcaption></figure><p>You can find interference/diffraction in, for example, the iridescence of bubbles or butterfly wings! Interference is also used in LIGO to detect gravitational waves.</p><h4>Diffraction Gratings</h4><p>Imagine adding way more slits, as in thousands per millimeter. Now, you have a diffraction grating!</p><p>Due to the sheer number of slits, even a slight angular deviation from the maxima causes enough destructive interference to make the area dark; thus, the maxima (lines) become very narrow, and they are separated by relatively wide dark regions . Confusing? This <a href="https://www.khanacademy.org/science/ap-physics-2/x0e2f5a2c:waves-sound-and-physical-optics/x0e2f5a2c:diffraction-and-interference-of-light/v/diffraction-grating">Khan Academy video</a> explains it better than I probably ever could…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/970/1*Jfj-qobqKrmuSEfwpDwdVA.png" /><figcaption>A diffraction grating in action! <a href="https://www.gophotonics.com/community/what-is-an-optical-grating">https://www.gophotonics.com/community/what-is-an-optical-grating</a></figcaption></figure><p>Because light of different wavelengths interferes at different intervals, the angle of diffraction is related to the wavelength of light (i.e. color). Thus, A diffraction grating can be used to separate an incident wave into its component wavelengths. This relationship is governed by the equation:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/183/1*zJweSxCaphIr0UyVKPmzUw.png" /></figure><p>where <em>m </em>is the order number, λ is the wavelength of light, d is the distance between slits, and θ is the angle between the center line and the specified maxima.</p><h4>Spectroscopy</h4><p>Spectroscopy is a scientific method of studying objects and materials based on detailed patterns of wavelengths (NASA). Prisms or diffraction gratings can be used to split the incident light into its wavelengths. Spectroscopy has many uses, from determining material composition, density, celestial objects’ speed (using cosmological redshift), and more (NASA). Certain wavelengths are absorbed, emitted, transmitted, reflected, or refracted to uncover chemical properties (NASA). The most common types of spectra are absorption and emission, but all spectra essentially show how brightness varies with wavelength (NASA).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/954/1*SPiL1Dea_UKaLCREMVQRUA.png" /><figcaption>Fig. 4. An example of an absorption spectrum. science.nasa.gov/mission/webb/science-overview/science-explainers/spectroscopy-101. ‌</figcaption></figure><p>Here’s an example of spectroscopy in action! The Webb telescope used spectroscopy to determine the chemical composition of a galaxy using its NIRSpec technology.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*qYAIcleOqduguFJV" /><figcaption>Webb Telescope spectra. <a href="https://science.nasa.gov/asset/webb/webbs-first-deep-field-nirspec-emission-spectrum/">https://science.nasa.gov/asset/webb/webbs-first-deep-field-nirspec-emission-spectrum/</a></figcaption></figure><h3>My Experiment</h3><p>The spectrometer I built consists of a single slit, a diffraction grating with grooves parallel to the slit, and a webcam. The light to be analyzed passes through the slit and diffracts. As light passes through the grating, it is separated into its component wavelengths before hitting the camera’s sensor. The user is able to view a spectrum through the webcam, which can be turned into a graph of intensity vs. position for each color.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/884/1*2-pKL0CQ4jOROvmFIPsOEg.png" /><figcaption>A simple diffraction spectrometer. <a href="http://www.instructables.com/DIY-Low-Cost-Spectrometer/">www.instructables.com/DIY-Low-Cost-Spectrometer/</a></figcaption></figure><p>Following a tutorial (<a href="https://www.instructables.com/DIY-Low-Cost-Spectrometer/">Technovation</a>), I built a simple spectrometer. I originally murdered a CD for it, but eventually switched to a proper diffraction grating as I found the CD wasn’t good enough to pick up atomic spectra for demonstration. The camera is angled to capture the first and second orders, as the zeroth order is generally just the incident light and its brightness can overwhelm the image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WmFQn4nXw26WkUSWNFCNWA.png" /><figcaption>My spectrometer!</figcaption></figure><p>The <a href="https://github.com/kousheekc/DIY-Spectrometer-Analyser">code that came with the tutorial </a>calculated intensity vs. pixel distance for each primary color, as well as the overall intensity (Fig. 7). I wanted to try and extend this further. After a painful amount of research, going in circles, and attempting to use ChatGPT, I got a (highly questionable) derivation which uses the diffraction equation to calculate the wavelength from measured distances.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/820/1*4674eoSxCk14niadkyeWmw.png" /><figcaption>Attempt at deriving a way to calculate wavelength from available information. The camera had a field of view of 70 degrees, which was used with the FOV equation (PixelBank) to convert pixel distance to actual distance.</figcaption></figure><p>I used the above method to write code that experimentally calculates the wavelength, with a substitution to convert the pixel length and field of view of the camera to a measurable distance (PixelBank). However, all measured wavelengths ended up in the red/infrared range regardless of color, indicating that other factors (ignoring the equation itself, which, again, could very well be wrong), such as the camera lens warp, were affecting the result. Most spectrometers for scientific use are calibrated by using regression on experimental values (Inorganic Ventures), and this, as well as limitations of the slit and the diffraction grating, are open avenues for improving the results.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/966/1*Yis1kFnUEzQ5nKb1vGefVg.png" /></figure><h4>Some Interesting Results</h4><p>I first used the spectrometer on a sunset lamp, which makes all color combinations from a red, green, an blue light in its center (right). When the spectrometer was pointed at white light, it was able to separate it back into its component colors.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/684/1*5_aD9ROcCdYBShxjDRdXIw.png" /></figure><p>The white light from an iPhone flashlight is more complete because it comes from a blue LED covered by a phosphor coating that better mimics the full color range of sunlight. Here, I also used the tutorial’s pixel color analyzer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/516/1*YvBoUU785NQZFSVEYwrnXA.png" /></figure><p>Finally, I was able to use it on my physics teacher’s atomic emission (spectral) lamp! Here’s the photo of nitrogen’s spectra (top), with another spectra on the bottom for reference:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/456/1*AY4Iqg0NsqUBFy_Tjpx6uw.png" /><figcaption>Spectra of nitrogen from my spectrometer (top) and another experimental spectra from HyperPhysics (<a href="http://hyperphysics.phy-astr.gsu.edu/hbase/quantum/atspect.html">http://hyperphysics.phy-astr.gsu.edu/hbase/quantum/atspect.html</a>)</figcaption></figure><h3>Conclusion</h3><p>Isn’t light so interesting? Hopefully, you learned something here! Since this was just a month-long research endeavor for class, I didn’t go too much in depth, but there’s a lot more to learn about spectroscopy and optical physics as a whole.</p><h3>Works Cited</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QqyA8KB-xpWbh9WwavC0mw.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f07c99ee8c08" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[2026 Science Olympiad Electric Vehicle — Process & Documentation]]></title>
            <link>https://medium.com/@scarlettchen315/2026-science-olympiad-electric-vehicle-process-documentation-ccfd4a8ce149?source=rss-0bb870234368------2</link>
            <guid isPermaLink="false">https://medium.com/p/ccfd4a8ce149</guid>
            <category><![CDATA[science-olympiad]]></category>
            <dc:creator><![CDATA[Scarlett Chen]]></dc:creator>
            <pubDate>Sat, 04 Apr 2026 01:58:33 GMT</pubDate>
            <atom:updated>2026-10-19T04:21:14.271Z</atom:updated>
            <content:encoded><![CDATA[<p>I participated in the Electric Vehicle event of Science Olympiad, where I was responsible for finding and putting together the electronic parts and programming the robot, which was done from scratch and on a relatively low level. This is a documentation of what I did and learned along the way, as someone who had no experience in electronics. I hope that if you’re interested in this event or electronics in general, this article helps you get started!</p><p>The major change in this year’s game is that there is now an incentive for the robot to be able to turn or travel in an arc to get between two water bottles that are offset from the line connecting start and finish points:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tAHhmjiMc-g84ZnQddpSoA.png" /><figcaption>Diagram of the track, from the 2026 <a href="https://www.soinc.org/sites/default/files/uploaded_files/Science_Olympiad_Div_C_Rules_2026_for_Web_Secured.pdf">Science Olympiad manual.</a></figcaption></figure><p>Much of what I did relied on this article (<a href="https://medium.com/@vikramaditya.nishant/designing-and-programming-a-high-speed-differentially-driven-vehicle-3017b72f5790">https://medium.com/@vikramaditya.nishant/designing-and-programming-a-high-speed-differentially-driven-vehicle-3017b72f5790</a>), which goes into a lot more depth and incorporates more advanced control. Like the author, we also made a differentially-driven vehicle, which places most of the complexity on the software; however, there are many other ways to get the desired result that involve mechanical adjustments rather than being able to individually control the two wheels.</p><h3>Hardware</h3><h4>Mechanical Parts</h4><p>Since I was not responsible for the mechanical parts, I won’t comment too much on it; in brief, the chassis was modeled in Onshape and 3-D printed, we used the <a href="http://- BaneBots Wheel, 2&quot; x 0.8&quot;, Hub Mount, 30A, Green">BaneBots T81 wheels</a>, and the <a href="https://www.pololu.com/product/955">Polulu ball 3/4in ball caster</a>. The breadboard and battery pack were stuck on with Velcro so that they could be moved easily if needed, but the IMU was screwed on to keep it rigid.</p><h4>Microcontroller</h4><p>I used the Arduino Nano ESP32, which can stick directly into the breadboard. I imagine most other Arduinos would work as well.</p><h4><strong>Motor Selection</strong></h4><p>As a warning — if you are experienced with these things, this is going to sound incredibly stupid, but we learn from our mistakes :)</p><p>When first selecting the motors, I only considered compatibility with the power supply and microcontroller. This led me to pick Polulu’s 75:1 6V Low Power Micro Metal Gearmotors. After they arrived, however, I realized that I had never processed how small they actually are — about the size of my thumb! — and more importantly, the fact that they wouldn’t be able to produce enough torque to move the robot.</p><p>I decided to pick a different model from the same line of motors, and found the <a href="https://www.pololu.com/product/5160">50:1 6V HP Micro Metal Gearmotors</a>, which had a much higher torque. I then had to learn how to do a torque calculation to see if the robot would move at all. Just be aware that I’m not sure if this is the correct way (and I’m not trusting ChatGPT either since it gaslit me into believing the first motors would work).</p><p>Torque, in general, is a force applied a perpendicular distance from an axis of rotation. I thought of it as “If I were to hang a mass off of one of the wheels, how much torque would that mass need to provide to move the robot?”. Torque is measured in Newton-meters, but for these motors they recorded it in kg cm (I think essentially omitting the “g” from Torque = F_g * r = mgr when I did the calculations).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/990/1*OlEwE9WOpWyzhK9skU4j1g.png" /></figure><p>Given that torque should generally remain &lt;50% of stall torque and an approximated 80% of the mass is on the motors (the rest on the ball caster):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/642/1*7BVVvvUfMnSF6_LLA3Bd_w.png" /></figure><p>This was still realistic for the robot. Fortunately, I had the time to return the old motors, get the new ones, and adjust other parts. I also cross-referenced this answer with the fact that Polulu provides a kit for a robot using two of these motors, which with a load of 500g can run 1 m/s or so.</p><p>Each motor also has a quadrature encoder built into it, which records how much it has turned.</p><p>These motors were not good for the vehicle, but were more or less a compromise for my mistake — ideally, either the robot itself would have to be a lot smaller and lighter, or the motors more powerful. Our setup meant that the vehicle, in the majority of cases, would not go fast enough to reach the target time.</p><h4>Motor Control</h4><p>I initially was going to use a motor driver board, which acts a medium between the microcontroller and the motors; however, I realized after some more research that it would involve actually sending the raw electrical signals from the microcontroller to the driver. I did not want to figure out how to do that, and there was also the risk of it being too resource-intensive, so I opted for a <a href="https://www.pololu.com/product/5078">motor controller</a> instead. Motor controllers have their own microcontroller inside of them, which allows them to take care of signal generation, and the libraries that come with them simplify the process of running motors and include safeguards.</p><h4>IMU</h4><p>I used an <a href="https://docs.arduino.cc/hardware/modulino-movement/">Arduino Modulino Movement</a>, which is a gyroscope/accelerometer. I did not realize is that this sensor was part of a kit where everything was compatible so that pins did not have to be soldered, but since I did not have this kit, I had to learn soldering (yay!).</p><h4><strong>Final Wiring</strong></h4><p>Yes, I used Canva to do this. There are better options, but I was got extremely confused trying to use Fritzing, and I decided at some point that it would probably take longer to figure it out than to just use some digital whiteboard. This just involved looking at the pinout for every component and putting them together, and it helped immensely when I had the parts in front of me. This diagram does not include the button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*slMRvUrrwewLfOvprsxEPg.png" /></figure><p>At first, I just used jumper wires to connect everything, however, it became messy quickly and there were also issues with certain wires coming loose. I ended up cutting pieces of wire instead so that it would fit the lengths more exactly.</p><p>And…here’s the final electric vehicle!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RoSPRNkbxtXzTuxYWp1G8g.png" /></figure><h3>Software</h3><h4>Process</h4><p>I am definitely more familiar with coding, even though I hadn’t dealt with Arduino or C++ before, but this combination of hardware and software and their respective problems still often proved a mess to get through.</p><p>For example, I had an issue where the motor controller turned on when the Arduino was connected to my computer, but not when everything was on battery. After some research, I was convinced that it was an issue with the motors drawing too much current on startup, but after failing to fix it with like 10 parallel capacitors, I found that I had a line in my code telling the microcontroller to wait until the Serial (the output that appears on my computer) was connected — which would never happen when my computer wasn’t connected to it! Current draw is still an issue that should have been accounted for, but I think the motors we had were small enough for it not to be a problem in this case.</p><p>In general, I tested each component separately (the motors, IMU, button press, etc.), then slowly put them together (e.g. use the button to engage the motors) until the robot was able to move. This strategy worked well especially since debugging was very difficult in the first place.</p><h4>Localization</h4><p>For localization, there are three sensors available: the two encoders, one on each motor, and the IMU.</p><p><strong>Encoders: </strong>I had first to convert the raw sensor signals into usable data, or “encoder counts”, which is not included here as it is straightforward and directly copied from a <a href="https://www.pololu.com/blog/900/video-from-content-creator-curio-res-how-to-control-a-dc-motor-with-encoder">tutorial</a>. The counts need to then be converted to distance. This involved some dimensional analysis!</p><pre>// encoder counts --&gt; wheel angle --&gt; distance traveled<br>float counts_to_angle(int encoder_counts){ return ((float) encoder_counts / (float) (ENCODER_CPR)) / (float) GEAR_RATIO * 360.0; }<br>float angle_to_dist(float wheel_angle){ return (wheel_angle / 360.0) * (2 * PI * WHEEL_RADIUS) ;}<br><br>// target distance --&gt; target wheel angle --&gt; target encoder counts<br>float angle_to_counts(float angle){ return angle / 360.0 * (float) GEAR_RATIO * (float) (ENCODER_CPR); }<br>float dist_to_angle(float target_dist){ return target_dist / (2 * PI * WHEEL_RADIUS) * 360; }</pre><p>I left it like this since it’s easier to understand, but it can be simplified.</p><p><strong>IMU: </strong>The angular velocity reading of the<strong> </strong>IMU was used to calculate the heading.<strong> </strong>Angular position, or heading, is the integral of angular velocity (technically the <em>change </em>in angular position, or my physics teacher will come after me). We can approximate this integral by multiplying angular velocity by a very small change in time to get a very small change in position, doing this many times in a second, and adding/accumulating all these small changes. (a Riemann sum!)</p><pre>void update_heading(){<br>  movement.update();        // Read new movement data from the sensor<br>  omega = movement.getYaw() + DRIFT_CORRECTION; // angular velocity; this had an experimental error of ~0.06-0.12 for some reason<br>  <br>  unsigned long now = millis();<br>  dT = now - prev_time; // calculate the change in time<br>  prev_time = now;<br><br>  // integrate angular velocity with respect to time to get heading <br>  dTheta = dT/1000 * omega;      // change in heading = change in time (seconds) x angular velocity<br>  heading += dTheta  * ANGLE_CORRECTION;       // calculate new heading<br>  <br>  //make the value wrap around (so that -180 &lt; theta &lt; 180)<br>  heading = normalize_angle(heading);<br>}</pre><p>The DRIFT_CORRECTION and ANGLE_CORRECTION were a few manual corrections I had to do resulting from experimentation.</p><h4>PD</h4><p>In general, a PID controller involves correction based on three types of error: the proportional, integral, and derivative.</p><ul><li><strong>Proportional</strong>: The magnitude of the proportional correction is based on the error between the target and current headings; i.e. if it’s farther away from the target, this component will apply a larger correction.</li><li><strong>Derivative</strong>: The derivative correction is based on how fast the proportional error is changing. As the current heading nears the target, it ensures that the applied correction is accordingly smaller; if there is a sudden error (like if I were to pick up the vehicle and turn it 90 degrees), it will apply a larger correction. This helps to avoid overshooting and oscillations, smoothing out the motion.</li><li><strong>Integral</strong>: The integral correction is based on the accumulation of the proportional error. This helps to eliminate steady errors that are not corrected by the P term due to bias/inaccuracy, or the D term since it is not changing.</li></ul><p>I ended up incorporating a PD controller, omitting the integral because when I tried to, it made the motors spin extremely fast due to some problem in my implementation, and I didn’t want to test further at the risk of anything breaking! The robot did have an issue with constantly drifting to one direction, which is what the I term is meant to fix.</p><pre>// heading error calculation &amp; implementation of PD<br>unsigned long now = millis();<br>float dt = (now - last_time_correction) / 1000.0; // change in time<br>if (dt &lt;= 0) dt = 1e-3; // prevent mistakes/huge corrections<br>last_time_correction = now;<br><br>float heading_error = shortest_angle(target_angle, heading); //proportional<br>float d_error = (heading_error - prev_heading_error) / dt; //derivative<br>prev_heading_error = heading_error;<br><br>float correction = Kp_heading * heading_error + Kd_heading * d_error; // PD correction calculation</pre><p>There are better and more rigorous ways to tune the parameters kP and kD, but I just kept running and adjusting them until the run looked about right.</p><h4>Full Drive</h4><p>The general structure of the run is a series of motion states, or individual steps, where the current state of the robot is determined by a variable holding it. This means that functions like updating the heading don’t have to wait until a step is finished. I think this might not make sense when I put it into words, so you can just take a look at the code:</p><pre><br>// motion states / &quot;steps&quot;<br>enum MotionState {<br>  WAITING,<br>  DRIVE_INITIAL,<br>  DRIVE_OUT,<br>  DRIVE_FORWARD,<br>  DRIVE_BACK,<br>  DONE,<br>  DRIVE_TEST<br>};<br><br>MotionState motion_state = WAITING;<br><br><br>// Setup &amp; Run!<br>void setup() {<br>  setup_hardware();<br>  delay(100);<br>  Serial.println(&quot;Everything has been set up!&quot;);<br>}<br><br>void loop() {<br>  //update frequency = 1 / 50ms = 20Hz<br>  if (millis() - last_heading_update &gt;= 50){<br>    update_heading();<br>    last_heading_update = millis();<br>  }<br>  <br>  // ---- motion state  ----<br>  switch (motion_state) {<br>    case WAITING:<br>      if (await_button()){<br>        motion_state = DRIVE_INITIAL;<br>      }<br>      break;<br><br>    case DRIVE_INITIAL:<br>    if (drive_towards(300, INITIAL_RUN_DIST, 0, true)) {  <br>      motion_state = DRIVE_OUT;<br>    }<br>    break;<br><br>    case DRIVE_OUT:<br>      if (drive_towards(TURN_SPEED, dist_angled, 30, true)) {<br>        motion_state = DRIVE_FORWARD;<br>      }<br>      break;<br><br>    case DRIVE_FORWARD:<br>      if (drive_towards(300, dist_straight, 0, true)) {<br>        motion_state = DRIVE_BACK;<br>      }<br>      break;<br><br>    case DRIVE_BACK:<br>    if (drive_towards(TURN_SPEED, dist_angled + FINAL_OFFSET, -30, true)) {<br>      motion_state = DONE;<br>    }<br>    break;<br><br>    case DONE:<br>      break;<br>  }<br>}</pre><p>Besides WAITING (for the button press) and DONE, these steps create a trapezoidal shape that looks something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lnX-_-2vglnwIBqTa7gfZg.png" /></figure><p>I input the track distance and can distance, and dist_straight and dist_angled are calculated with geometry!</p><pre>//run constants<br>// angle is 30 degrees<br>const float TRACK_DIST = 9.5; // 7m &lt; d &lt; 20m<br>const float TARGET_CAN_DIST = 0.8; // distance from center line to middle of cans (m)<br>const float INITIAL_RUN_DIST = 0.5;  <br><br>const float FINAL_OFFSET = 0.05; // final distance is usually off by a few cm<br>const float TURN_SPEED = 300; <br><br>//run distances<br>float dist_angled = 2 * TARGET_CAN_DIST; // target can distance / sin 30<br>float dist_straight = TRACK_DIST - INITIAL_RUN_DIST - 1.73205 * dist_angled; // last term is 2 * dist_angled * cos 30 </pre><p>As you can also see, I don’t actually have a turn function; I just set the target angle and let PID do the rest! I thought this wouldn’t go well, but it actually worked and saved me a lot of time. Due to the aforementioned speed constraints, there was no point going for the target time, so the motor speed was hard-coded to the fastest it could be without being too inaccurate.</p><h4>Source Code</h4><p>Here’s the GitHub with the final code, as well as code for when I tested individual functions.</p><p><a href="https://github.com/Scarlett315/Electric-Vehicle">GitHub - Scarlett315/Electric-Vehicle</a></p><h3>Video</h3><p>Here’s a video of the robot running:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FE4t3LsiMPt4%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fshorts%2FE4t3LsiMPt4&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FE4t3LsiMPt4%2Fhq2.jpg&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/fba0347bd7dac1933f3910e9b2a5e93d/href">https://medium.com/media/fba0347bd7dac1933f3910e9b2a5e93d/href</a></iframe><h3>Conclusion</h3><p>If you’ve gotten here, I hope you enjoyed reading it all; there’s always more than meets the eye when it comes to these kinds of things, and even I’m surprised by how much I have to say! If the event runs again, I’m looking to make improvements mainly by putting the breadboard connections onto a PCB to make the robot smaller and lighter, getting the I term to work in PID, and figuring out how to properly use prototyping software.</p><p>If it’s not obvious already, I want to make clear that this is not a very good blueprint — the motor selection was bad, my wiring is a little questionable, and so on. I do want to show that it’s never too late to start. I know that sounds silly coming from a high school student, but hear me out! I had been thinking about majoring in electrical engineering for a while, but I had just about zero self-confidence in building anything. After making it through this alive, I’m a little more prepared to take on new projects and more confident that EE is something I would enjoy as a career.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ccfd4a8ce149" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>