Learning tools

Tools

Quick calculators to help you practice electronics concepts.

Electronics calculator

Ohm's law calculator

Choose two values you know. The calculator finds voltage, current, resistance, and power.

V = I × R

V is voltage in volts, I is current in amperes, R is resistance in ohms, and P is power in watts.

Results

Voltage12 V
Current2 A
Resistance6 Ω
Power24 W

12 V = 2 A × 6 Ω

Electronics calculator

Resistor color code calculator

Select the colors printed on a resistor to find its resistance and tolerance. Six-band resistors also show a temperature coefficient.

Read the bands from left to right, with the tolerance band near the right end.

Results

Resistance1 kΩ
Tolerance±5%
Possible range950 Ω – 1.05 kΩ

Electronics calculator

LED series resistor calculator

Find a current-limiting resistor for one LED or several LEDs connected in series.

R = (Vs − N × Vf) / I

Use the LED forward voltage and current from its datasheet. The suggested wattage includes a 2× margin over the calculated resistor power.

Results

Series resistance500 Ω
Resistor voltage drop10 V
Resistor power0.2 W
Minimum suggested rating0.5 W
Electronics calculator

Voltage divider calculator

Calculate the output voltage between two series resistors.

Vout = Vin × R2 / (R1 + R2)

This is an unloaded divider. Connecting a load to the output can lower the actual voltage.

Results

Output voltage6 V
Divider current6 mA
R1 power0.036 W
R2 power0.036 W
Energy calculator

Power consumption calculator

Estimate the energy used by a device over a number of days and its electricity cost.

Energy = Power × Time

Enter the device's power in watts, its daily running time, and your electricity rate per kWh. Results are estimates.

Results

Daily energy0.8 kWh
Total energy24 kWh
Estimated cost₹192
Running time240 hours
Electronics calculator

SMD resistor code calculator

Decode the marking printed on a surface-mount resistor.

Three- and four-digit codes use the final digit as a power-of-ten multiplier. The letter R marks a decimal point. EIA-96 uses a two-digit value code and a multiplier letter.

The marking identifies nominal resistance; check the component datasheet for tolerance and power rating.

Example: 103 means 10 × 10³ = 10 kΩ.

Results

Resistance10 kΩ
Marking103

10 × 10³ Ω = 10 kΩ

Embedded systems calculator

STM32F103C8T6 timer calculator

Enter ARR and PSC register values, then fill in either timer frequency or delay. Leave the value you want to calculate blank.

Delay = (ARR + 1) × (PSC + 1) / ftimer

STM32 calls the prescaler register PSC. Enter the raw register values; the calculator adds 1 to ARR and PSC.

Use the timer input clock, which may differ from the CPU or APB bus clock. This calculates the update period for an up-counting timer with no repetition counter.

Results

Timer delay1 s
Timer input frequency72 MHz
Update rate1 Hz
Total timer counts72,000,000

(9999 + 1) × (7199 + 1) / 72 MHz = 1 s

Embedded systems calculator

STM32F103C8 UART baud rate calculator

For the STM32F103C8 IC only. Enter the USART peripheral clock and target baud rate to calculate its USART BRR register value.

USARTDIV = fCK / (16 × baud)

For STM32F103 with 16× oversampling. Use the USART peripheral clock: USART1 uses APB2; USART2 and USART3 use APB1.

Results

USART BRR register0x1A0B
Mantissa416
Fraction11
Actual baud rate9,599.52 baud

64,000,000 / (16 × 9,600) = 416.6667; fraction = round(16 × 0.6667) = 11; BRR = (416 << 4) | 11 = 0x1A0B.

USART1->BRR = 0x1A0B;

Embedded systems calculator

STM32F103C8 I²C clock calculator

Calculate I²C_CCR, CR2.FREQ, and TRISE from the APB1 clock, target SCL frequency, and timing mode.

This is for the STM32F103C8 legacy I²C peripheral. SCL timings are ideal estimates; verify the bus rise time and the register settings against your MCU reference manual.

Register calculations

Standard mode: CCR = 32,000,000 / (2 × 100,000) = 160; I2C_CCR = 0x00A0.

CR2.FREQ = PCLK1 in MHz = 32 (0x20).

Standard mode: TRISE = (1000 ns / 31.25 ns) + 1 = 33.

I2C1->CR2 = (I2C1->CR2 & ~0x3FU) | 32U;
I2C1->CCR = 0x00A0;
I2C1->TRISE = 33U;

I²C CCR calculation: formula and steps

One complete SCL clock has a high time and a low time.

TSCL = THIGH + TLOW
fSCL = 1 / TSCL

1. Find the PCLK1 period

For a 32 MHz APB1 peripheral clock:

fPCLK1 = 32 MHz
TPCLK1 = 1 / fPCLK1
TPCLK1 = 1 / 32 MHz
TPCLK1 = 31.25 ns

2. Calculate CCR in standard mode

In standard mode, HIGH and LOW each last one CCR count:

THIGH = CCR × TPCLK1
TLOW = CCR × TPCLK1
TSCL = 2 × CCR × TPCLK1
fSCL = fPCLK1 / (2 × CCR)
CCR = fPCLK1 / (2 × fSCL)

3. Substitute 32 MHz and 100 kHz

CCR = 32 MHz / (2 × 100 kHz)
CCR = 32,000,000 / 200,000
CCR = 160

4. Verify the SCL timing

THIGH = 160 × 31.25 ns = 5 µs
TLOW = 160 × 31.25 ns = 5 µs
TSCL = 5 µs + 5 µs = 10 µs
fSCL = 1 / 10 µs = 100 kHz
I2C1->CCR = 160;  // 0x00A0, standard mode

5. Fast mode, DUTY = 0

THIGH = CCR × TPCLK1
TLOW = 2 × CCR × TPCLK1
TSCL = 3 × CCR × TPCLK1
CCR = fPCLK1 / (3 × fSCL)

6. Fast mode, DUTY = 1

THIGH = 9 × CCR × TPCLK1
TLOW = 16 × CCR × TPCLK1
TSCL = 25 × CCR × TPCLK1
CCR = fPCLK1 / (25 × fSCL)

Quick reference

ModeHIGH timeLOW timeCCR formula
StandardCCR × TPCLK1CCR × TPCLK1fPCLK1 / (2 × fSCL)
Fast, DUTY = 0CCR × TPCLK12 × CCR × TPCLK1fPCLK1 / (3 × fSCL)
Fast, DUTY = 19 × CCR × TPCLK116 × CCR × TPCLK1fPCLK1 / (25 × fSCL)

Easy way to remember: standard mode has 1 high + 1 low = 2; fast mode with DUTY = 0 has 1 high + 2 low = 3; fast mode with DUTY = 1 has 9 high + 16 low = 25.

CR2.FREQ and TRISE

CR2.FREQ is the PCLK1 frequency expressed as a whole number of MHz. For 32 MHz, set FREQ to 32 (0x20).

TPCLK1 = 1000 / 32 = 31.25 ns
Standard mode maximum rise time = 1000 ns; TRISE = (1000 / 31.25) + 1 = 33
Fast mode maximum rise time = 300 ns; TRISE = floor((32 × 300) / 1000) + 1 = 10

Both fast-mode duty settings use the same 300 ns rise-time limit. Newer STM32 I²C peripherals may use I2C_TIMINGR instead of CR2, CCR, and TRISE.

Embedded systems calculator

ADC calculator

Convert an ADC reading into a voltage using the ADC resolution and reference voltage.

Voltage = ADC value / (2bits − 1) × Vref

Uses the full-scale endpoint convention. Confirm the transfer function in your MCU datasheet when precision matters.

Results

Input voltage1.6504 V
Maximum ADC value4,095
Voltage per count0.00080586 V
Programming converter

Binary / decimal / hex converter

Convert an unsigned 32-bit value and inspect its bits in groups of four.

Prefixes such as 0b and 0x are accepted for binary and hexadecimal input.

Results

Decimal172
Hexadecimal0xAC
Binary1010 1100
Programming calculator

Bitwise calculator

Apply 32-bit AND, OR, XOR, NOT, left shift, or logical right shift.

Inputs and results are unsigned 32-bit integers. NOT applies to A; shifts use B as the shift count (0–31).

Results

Decimal12
Hexadecimal0x0000000C
Binary (32 bits)0000 0000 0000 0000 0000 0000 0000 1100
Engineering converter

Unit converter for engineers

Convert voltage, current, resistance, capacitance, frequency, length, temperature, power, and pressure.

Result

Converted value3,300 mV
Electronics calculator

Frequency ↔ time period calculator

Convert between a repeating signal's frequency and its period.

Period = 1 / frequency

Fill in either frequency or period. Leave the value you want to calculate blank.

Results

Frequency1 kHz
Period1 ms

C Programming

1. Data types: type, bytes, and range

These sizes and ranges are typical for systems with 8-bit bytes and 32-bit int. C allows implementations to use different sizes. Check your compiler with sizeof, <limits.h>, and <float.h>.

TypeTypical bytesTypical range / precision
signed char1−128 to 127
unsigned char10 to 255
short2−32,768 to 32,767
int4−2,147,483,648 to 2,147,483,647
unsigned int40 to 4,294,967,295
long4 or 8Depends on compiler and platform
long long8About −9.22 × 1018 to 9.22 × 1018
float4About ±3.4 × 1038; 6–7 significant digits
double8About ±1.7 × 10308; 15–16 significant digits

Plain char may be signed or unsigned. Use <stdint.h> types such as uint8_t and int32_t when an exact integer width is needed and supported.

#include <stdio.h>
#include <limits.h>

printf("int: %zu bytes, range %d to %d\n",
       sizeof(int), INT_MIN, INT_MAX);

2. Format specifiers

The format must match the argument type. printf prints values; scanf usually needs the variable's address.

Type / purposeprintfscanf
int%d%d
unsigned int%u%u
long%ld%ld
long long%lld%lld
float%f (promoted to double)%f
double%f%lf
char%c%c
String (char[])%s%s with a width limit
size_t%zu%zu
Hexadecimal integer%x / %X%x
int count = 10;
double voltage = 3.3;
printf("Count: %d, voltage: %.2f V\n", count, voltage);
scanf("%d", &count);

For a character array, limit scanf input width. For example, char name[20]; scanf("%19s", name); leaves room for the terminating null character.

3. Operators

CategoryOperatorsExample
Arithmetic+ - * / %7 / 2 gives 3 for integers
Comparison== != < > <= >=a > b
Logical&& || !ready && enabled
Assignment= += -= *= /= %=count += 1
Bitwise& | ^ ~ << >>flags & 0x04
Increment / decrement++ --index++
Conditional?:max = a > b ? a : b

&& and || are logical operators; & and | operate on bits. Use parentheses when combining operations so the intended order is clear.

GCC & Make installation

  1. Install MSYS2

    Download and run the official MSYS2 installer. The default installation folder is C:\msys64.

  2. Open the MSYS2 UCRT64 terminal

    From the Windows Start menu, launch MSYS2 UCRT64. Use this environment for the commands below. UCRT64 combines the /ucrt64 toolchain with MSYS tools in /usr/bin.

  3. Update all packages

    pacman -Suy

    If MSYS2 asks you to close the terminal, reopen MSYS2 UCRT64 and run the command again until the update completes.

  4. Check and install Make

    make --version

    If Make is not found, install it and verify again:

    pacman -S make
    make --version

    The MSYS Make package provides /usr/bin/make.exe, which works with Makefiles that invoke /bin/sh.

  5. Install ARM GCC for STM32

    The STM32 Makefile needs arm-none-eabi-gcc, not only a desktop GCC compiler. Install the UCRT64 package and confirm the prompt with Y:

    pacman -S mingw-w64-ucrt-x86_64-arm-none-eabi-gcc

    Verify the compiler inside MSYS2 UCRT64:

    arm-none-eabi-gcc --version
    which arm-none-eabi-gcc

    The path should start with /ucrt64/bin/. With the default installation folder, the Windows executable is C:\msys64\ucrt64\bin\arm-none-eabi-gcc.exe.

  6. Use the tools from VS Code PowerShell (optional)

    If you build from a Windows PowerShell terminal instead of MSYS2 UCRT64, add these folders to your Windows Path, in this order:

    C:\msys64\ucrt64\bin
    C:\msys64\usr\bin

    In Windows, search for Environment Variables, open Edit the system environment variables, choose Environment Variables…, then edit Path. Add each folder, save, and restart all VS Code windows.

  7. Verify in a new VS Code PowerShell terminal

    where.exe make
    where.exe arm-none-eabi-gcc
    make --version
    arm-none-eabi-gcc --version

    The first paths reported should be C:\msys64\usr\bin\make.exe and C:\msys64\ucrt64\bin\arm-none-eabi-gcc.exe. If Cygwin or another ARM toolchain appears first, adjust your Path order or build in MSYS2 UCRT64.

Package references: GNU Make and ARM GCC for UCRT64.