CircuitTool 1.0.4

There is a newer version of this package available.
See the version list below for details.
dotnet add package CircuitTool --version 1.0.4
                    
NuGet\Install-Package CircuitTool -Version 1.0.4
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="CircuitTool" Version="1.0.4" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CircuitTool" Version="1.0.4" />
                    
Directory.Packages.props
<PackageReference Include="CircuitTool" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add CircuitTool --version 1.0.4
                    
#r "nuget: CircuitTool, 1.0.4"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package CircuitTool@1.0.4
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=CircuitTool&version=1.0.4
                    
Install as a Cake Addin
#tool nuget:?package=CircuitTool&version=1.0.4
                    
Install as a Cake Tool

CircuitTool

A comprehensive C# library for electrical engineering and electronics calculations. CircuitTool simplifies circuit analysis, power calculations, and unit conversions for electrical engineers, electronics enthusiasts, and makers working with Arduino, ESP32, and other microcontrollers.

Features

Core Electrical Calculations

  • Ohm's Law Calculations: Calculate voltage, current, and resistance
  • Resistor Network Analysis: Series and parallel resistor calculations
  • Voltage Analysis: Voltage drop and voltage divider calculations
  • Power Calculations: Various methods to calculate electrical power
  • Energy Calculations: Convert between energy units, calculate energy costs
  • Unit Conversions: Comprehensive electrical unit conversion utilities
  • Specialized Calculators: Power factor, electricity bill, and energy consumption calculators

LED and Lighting Calculations

  • LED Resistor Calculator: Calculate required resistor values for LED circuits
  • LED Power Consumption: Calculate power usage for LED projects
  • LED Brightness Control: PWM duty cycle to brightness ratio calculations
  • Series LED Calculations: Multi-LED circuit calculations

Microcontroller Tools

  • Arduino Tools: ADC conversions, servo control, current consumption calculations
  • ESP32 Tools: ADC conversions, WiFi power management, battery life estimation
  • Touch Sensor Calculations: ESP32 touch threshold calculations

Beginner-Friendly Calculators

  • Battery Life Calculator: Estimate battery runtime for projects
  • Wire Gauge Calculator: Determine appropriate wire gauge for current loads
  • RC Circuit Tools: Time constants, oscillator frequencies
  • Inductor Design: Basic inductor turn calculations
  • Decibel Conversions: Power and voltage ratio to dB conversions
  • Transformer Calculations: Turns ratio calculations

Getting Started

Prerequisites

  • .NET 8.0 SDK or later

Installation via NuGet

To install CircuitTool via NuGet, use the following command:

dotnet add package CircuitTool

Or using the Package Manager Console:

Install-Package CircuitTool

Development Installation

Clone the repository:

git clone https://github.com/jomardyan/CircuitTool.git
cd CircuitTool

Build the library:

dotnet build

Run the tests:

dotnet test

Usage Examples

Ohm's Law Calculations

using CircuitTool;

// Calculate voltage using Ohm's Law (V = I × R)
double voltage = OhmsLawCalculator.Voltage(2.0, 5.0);  // 2A through 5Ω = 10V

// Calculate current using Ohm's Law (I = V / R)
double current = OhmsLawCalculator.Current(10.0, 5.0);  // 10V across 5Ω = 2A

// Calculate resistance using Ohm's Law (R = V / I)
double resistance = OhmsLawCalculator.Resistance(10.0, 2.0);  // 10V, 2A = 5Ω

LED Circuit Calculations

using CircuitTool;

// Calculate resistor value for LED
double resistorValue = LEDCalculator.CalculateResistorValue(9.0, 2.0, 0.02);  // 9V supply, 2V LED, 20mA = 350Ω

// Calculate LED power consumption
double ledPower = LEDCalculator.CalculateLEDPower(5.0, 0.02);  // 5V, 20mA = 0.1W

// Calculate brightness from PWM duty cycle
double brightness = LEDCalculator.CalculateBrightness(75);  // 75% duty cycle = 0.75 brightness

// Calculate resistor for series LEDs
double seriesResistor = LEDCalculator.CalculateSeriesResistor(12.0, 3.3, 3, 0.02);  // 12V, 3x 3.3V LEDs, 20mA

Arduino Tools

using CircuitTool;

// Convert Arduino analog reading to voltage
double voltage = ArduinoTools.AnalogToVoltage(512);  // 512 reading = 2.5V (on 5V Arduino)

// Convert voltage to analog reading
int analogReading = ArduinoTools.VoltageToAnalog(3.3);  // 3.3V = 675 reading

// Calculate servo pulse width for specific angle
double pulseWidth = ArduinoTools.ServoAngleToPulseWidth(90);  // 90° = 1500μs pulse

// Calculate current consumption
double current = ArduinoTools.CalculateCurrentConsumption(20, 5, 2, 50);  // CPU + pins + external = total mA

ESP32 Tools

using CircuitTool;

// Convert ESP32 analog reading to voltage
double voltage = ESP32Tools.AnalogToVoltage(2048);  // 2048 reading = 1.65V (on 3.3V ESP32)

// Calculate WiFi power consumption
double wifiPower = ESP32Tools.CalculateWiFiPowerConsumption(WiFiMode.Active);  // 80mA

// Calculate total ESP32 current consumption
double totalCurrent = ESP32Tools.CalculateTotalCurrentConsumption(240, WiFiMode.Active, true, 20);

// Calculate battery life
double batteryLife = ESP32Tools.CalculateBatteryLife(2000, 50);  // 2000mAh battery, 50mA load = 32 hours

// Calculate touch sensor threshold
int touchThreshold = ESP32Tools.CalculateTouchThreshold(1000, 0.3);  // 1000 baseline, 30% sensitivity

Advanced Circuit Analysis

using CircuitTool;

// Calculate total resistance in series
double seriesResistance = CircuitCalculations.CalculateTotalResistance(new double[] { 10, 20, 30 }, true);

// Calculate total resistance in parallel
double parallelResistance = CircuitCalculations.CalculateTotalResistance(new double[] { 10, 20, 30 }, false);

// Calculate power
double power = CircuitCalculations.CalculatePower(230, 5); // 230V × 5A = 1150W

// Calculate energy
double energy = CircuitCalculations.CalculateEnergy(1150, 2); // 1150W × 2h = 2300Wh

Beginner Calculator Examples

using CircuitTool;

// Calculate battery life
double hours = BeginnerCalculators.BatteryLifeCalculator(1000, 50);  // 1000mAh, 50mA = 20 hours

// Determine wire gauge
int awgGauge = BeginnerCalculators.WireGaugeCalculator(3.0);  // 3A = AWG 20

// Calculate RC time constant capacitor value
double capacitor = BeginnerCalculators.RCTimeConstantCapacitor(1000, 0.001);  // 1kΩ, 1ms = 1μF

// Calculate RC oscillator frequency
double frequency = BeginnerCalculators.RCOscillatorFrequency(1000, 0.000001);  // 1kΩ, 1μF = ~455Hz

// Convert power ratio to decibels
double db = BeginnerCalculators.PowerRatioToDecibels(10);  // 10x power = 10dB

// Convert voltage ratio to decibels
double dbVoltage = BeginnerCalculators.VoltageRatioToDecibels(2);  // 2x voltage = 6.02dB

// Calculate transformer turns ratio
double turnsRatio = BeginnerCalculators.TransformerTurnsRatio(120, 12);  // 120V to 12V = 0.1 ratio

Power and Energy Calculations

using CircuitTool;

// Power factor calculations
double apparentPower = PowerFactorCalculator.ApparentPower(1000, 0.8);  // 1000W real, 0.8 PF = 1250VA
double reactivePower = PowerFactorCalculator.ReactivePower(1000, 0.8);  // 1000W real, 0.8 PF = 750VAR

// Energy consumption calculations
double monthlyCost = EnergyConsumptionCalculator.MonthlyCost(5000, 0.12);  // 5kWh, $0.12/kWh = $600/month
double carbonFootprint = EnergyConsumptionCalculator.CarbonFootprint(1000, 0.5);  // 1kWh, 0.5kg/kWh = 0.5kg CO2

Unit Conversions

using CircuitTool;

// Convert between electrical units
double milliamps = UnitConverter.AmperesToMilliamps(0.5);  // 0.5A = 500mA
double kilovolts = UnitConverter.VoltsToKilovolts(5000);  // 5000V = 5kV
double megaohms = UnitConverter.OhmsToMegaohms(2000000);  // 2MΩ = 2000000Ω

Contributing

We welcome contributions! Please feel free to submit pull requests or open issues for bugs and feature requests.

Development Guidelines

  1. Follow C# coding standards and conventions
  2. Add XML documentation for all public methods
  3. Include unit tests for new functionality
  4. Update the README.md with usage examples

License

This project is licensed under the MIT License - see the LICENSE file for details.

Changelog

Version 1.0.4

  • Added LED circuit calculators
  • Added Arduino and ESP32 tools
  • Added beginner-friendly calculators
  • Improved NuGet package metadata
  • Added comprehensive unit tests
  • Enhanced documentation

Version 1.0.3

  • Improved source linking and symbols
  • Better NuGet package structure

Version 1.0.2

  • Added advanced circuit analysis methods
  • Improved README documentation

Version 1.0.1

  • Initial NuGet package release
  • Core electrical calculations

Support

For questions, issues, or feature requests, please visit the GitHub repository or open an issue.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.2.1 97 6/27/2025
2.2.0 86 6/27/2025
2.1.0 122 6/27/2025
2.0.0 131 6/26/2025
1.0.13 131 6/26/2025
1.0.11 134 6/26/2025
1.0.7 132 6/26/2025
1.0.5 130 6/26/2025
1.0.4 130 6/26/2025
1.0.3 130 6/26/2025
1.0.2 130 6/26/2025
1.0.1 137 6/26/2025
1.0.0 136 6/26/2025