When I first began coding and circuit analysis, I wanted to solve the issue of the parallel resistance and series capacitance lengthy formula computations. Thus, in order to develop my coding and analysis skills, I built a few functions and algorithms that compute equivalent resistance and capacitance values from certain inputs. My library additionally consists of various mathematical formulas for easy computation as well as a few functions for sensors, specifically the HC-SR04 ultrasonic sensor.
F1: The StopwatchAbove is a section of my function that acts as a stopwatch. Find an excuse to use this function, and you'll have seconds and minutes counting up in the serial monitor, as if you had a real stopwatch clutched in your hand! This code was particularly fun to write, as I needed a stopwatch and challenged myself to code it in less than fifteen minutes when I began coding (definitely wasn't procrastinating other tasks). A simple google search for "stopwatch" would have been quite sufficient, but where's the fun in that.
F2: Ultrasonic DisplacementThe fragment from the displacement function pictured above is used concurrently with the HC-SR04 Ultrasonic sensor, a popular and reliable displacement sensor for hobbyists and makers. This function takes two integer arguments, namely the GPIO pins used for trigger and echo purposes. The function takes advantage of the sensor's ability to send and receive waves and compute a time that a wave traveled. With this knowledge, the code is optimized to receive time intervals for which waves travel and compute a displacement, using known properties of waves.
F3: Parallel ResistanceIf anyone has any familiarity with the parallel resistance formula, and others such as KVL, KCL, series capacitance, then you know it's a pain to plug into a calculator and move terms around. This functions makes this process easy. Simply plug in comma-separated values of up to seven resistors (if you have fewer, leave zeros for other spaces of the seven function arguments). After plugging in seven arguments, the serial monitor will have printed an equivalent resistance, cool!
F4: Pythagorean TheoremFunction three of my simple-computations library features a classic in the study of geometry: the coveted Pythagorean Theorem. My code is rather elementary given that it takes two float arguments, the perpendicular sides, and computes the third side, the hypotenuse.
F5: Series CapacitanceGiven that equivalent series capacitance follows the same mathematical framework and formula as the parallel resistance, I have recoded almost the exact same function, with minor differences in function names and comments.
F6: Ohm's LawThe function above takes arguments v, i, and r and has a float return value. Although this function requires little to no mathematical rigor, it's still useful if you're missing a calculator or lacking an internet connection. Simply plug in the two known values, leaving the third and unknown value set to zero, and the function will compute and return a float with the value of the unknown value, accurate up to seven decimal places!
Creating One's Own LibraryA library, used for Arduino or other software/hardware applications, is as simple as a line of code. It provides software for others to use. One of the best functions of Arduino is their public library manager, as it has thousands of pre-made libraries that come ready to download and use. Creating your own library starts with writing the code, such as functions, then uploading it for installment. Then the user can download your library either manually or through different library managers.
Discover:Check out my other projects on my dashboard:
- Arduino Uno DIY Drone
- Arduino Smart Traffic Light
- Blindsight: a Wearable Device that Aids the Visually Impaired
- IAADL: an Infrared Activated Automatic Door Lock
Check out all of my projects code at my GitHub repository.
Comments
Please log in or sign up to comment.