LED – Diode Circuit

\documentclass[border=3pt]{standalone}

% Circuits
\usepackage[european,s traightvoltages, RPvoltages, americanresistor, americaninductors]{circuitikz}
\tikzset{every picture/.style={line width=0.2mm}}

% Notation
\usepackage{amsmath}

% Tikz Library
\usetikzlibrary{calc}

% Bipoles Specifications
\ctikzset{bipoles/thickness=1.2, label distance=1mm, voltage shift = 1}

% Arrows Above Compenents
% Source: https://tex.stackexchange.com/questions/574576/circuitikz-straight-voltage-arrows-with-fixed-length
\newcommand{\fixedvlen}[3][0.4cm]{% [semilength]{node}{label}
    % get the center of the standard arrow
    \coordinate (#2-Vcenter) at ($(#2-Vfrom)!0.5!(#2-Vto)$);
    % draw an arrow of a fixed size around that center and on the same line
    \draw[-{Triangle[round,open]}] ($(#2-Vcenter)!#1!(#2-Vfrom)$) -- ($(#2-Vcenter)!#1!(#2-Vto)$);
    % position the label as it where if standard voltages were used
    \node[ anchor=\ctikzgetanchor{#2}{Vlab}] at (#2-Vlab) {#3};
}
\newcommand{\fixedvlendashed}[3][0.75cm]{% [semilength]{node}{label}
    % get the center of the standard arrow
    \coordinate (#2-Vcenter) at ($(#2-Vfrom)!0.5!(#2-Vto)$);
    % draw an arrow of a fixed size around that center and on the same line
    \draw[dashed,-{Triangle[round,open]}] ($(#2-Vcenter)!#1!(#2-Vfrom)$) -- ($(#2-Vcenter)!#1!(#2-Vto)$);
    % position the label as it where if standard voltages were used
    \node[ anchor=\ctikzgetanchor{#2}{Vlab}] at (#2-Vlab) {#3};
}

\begin{document}
	\begin{circuitikz}
%			%Grid
%			\def\length{8}
%			\draw[thin, dotted] (-\length,-\length) grid (\length,\length);
%			\foreach \i in {1,...,\length}
%			{
%				\node at (\i,-2ex) {\i};
%				\node at (-\i,-2ex) {-\i};	
%			}
%			\foreach \i in {1,...,\length}
%			{
%				\node at (-2ex,\i) {\i};	
%				\node at (-2ex,-\i) {-\i};	
%			}
%			\node at (-2ex,-2ex) {0};
			
			%Circuit
			\def\x{6}
			\def\y{3}
			\draw 
			(0,0) to[sV, v>, name=v_in] (0,\y)
				to[R, l=$R$] (0.5*\x,\y)
				to[led, fill=red, l_=$D_1$, *-*] (0.5*\x,0) -- (0,0)
			(0.5*\x,\y) -- (\x,\y)
			(0.5*\x,0) -- (\x,0)
				to[led, fill=red, l_=$D_2$, *-*] (\x,\y)
			(0,0) to[short,*-] (0,0.1) node[ground] {};
			
			%Voltages
			\fixedvlen[0.4cm]{v_in}{$v_\text{in}$}
	\end{circuitikz}
\end{document}	

Leave a Reply

Your email address will not be published.