How to create complex op-amp diagrams with Circuitikz

Richard Robinson 07/15/2018. 3 answers, 404 views
tikz-pgf diagrams circuitikz circuits

I am familiar with LaTeX but semi-new to Circuitikz. I am comfortable creating simple diagrams with nodes and bipolar, however combining them with op amps is difficult for me. I am trying to replicate this schematic: what I want

This is what I have thus far:

what I have

(0, 0) node[op amp] (opamp) {}
(opamp.-) to[R,l_=$R_1$,-o] (-2, 0.35) -- (-3, 0.35) to [V=$v_1$] (-3,-0.5) to (-3,-0.5) node[ground]{}
(opamp.-) to[short,*-] ++(0,0.5) coordinate (leftC)
to[R=$R_2$] (leftC -| opamp.out)
to[short,-*] (opamp.out) to [short,-o] (1.5,0) to (1.5,-0.5) node[ground]{}
(opamp.+) -- (-1,-0.35) to (-1,-0.5) node[ground]{}

The main things I am struggling with which I cannot find resources for are the following:

  1. Reducing (a) label size and (b) specific element size such as resistors
  2. Adding floating arrows, labels, voltages, and circled numbers
  3. Customizing the color of the op amp and labels, and thickness of lines and elements

Thanks in advance for all the help! I really appreciate it!

3 Answers

J Leon V. 07/16/2018.

Just for fun an option creating customized components, in the basic way with scope; using circuitikz support shapes to declare some points (N3);(N2);(N6);(N6-OUT), to draw pasive components, then create a line style using markings to draw reference voltages, because the given by circuitikz looks bad (the minus simbol is shorten than the positive, and the label position is not at the center); for the currents I use the option midway to define a node in the middle of the path,and then using the anchor and the inner seperation to control the text position and finally using a label with style to put the number marks.

RESULT:enter image description hereMWE:

\usepackage{amsmath}%To allow \cfrac macro
\usepackage{bm}%Bold math

        %Environment Config
        MyArrow/.style={%Style for the current
            line width=1.5pt,
            shorten >= 5pt,
            shorten <= 1pt
        Vref/.style={%Style for the voltage reference
            postaction={decorate,decoration={markings,mark=at position 0.5 with {\node{\Large #1};}}},
            postaction={decorate,decoration={markings,mark=at position 0.15 with {\node{\Large $\bm{+}$};}}},
            postaction={decorate,decoration={markings,mark=at position 0.85 with {\node{\Large $\bm{-}$};}}}
        Numbered/.style = {% Style for circle marks
                line width=1.5pt,
                inner sep=4pt,
                label distance=15pt
    \def\MyOpamp(#1)#2{%Customized opamp
    %Component Shape
    \draw[fill=cyan!25,line width = 2pt, line join=round] (0,0)++(-1,1.5)
        --++(2.5,-1.5) -- ++(-2.5,-1.5)-- cycle; 
    % Label and component identifier.
    \draw(0,0) node{\sf U-#2}; % IC LABEL
    % Draw the pins
    % Some that you have to learn about label nodes, draw lines, and name coordinates in Tikz
    \draw[line width = 1.5pt] (-1,1) node [anchor=180]{$-$} -- ++(-0.5,0)  coordinate (#2 IN-); % IN - 
    \draw[line width = 1.5pt] (-1,-1) node [anchor=180]{$+$}  -- ++(-0.5,0) coordinate (#2 IN+); % IN +
    \draw[line width = 1.5pt] (1.5,0)  -- ++(0.5,0) coordinate (#2 OUT); % OUT  
    \def\MyGround(#1)#2{%customized ground
    %Component Shape
    \draw[line width = 2pt, line cap=round]
    (0,0) coordinate (#2 GND)++(-0.3,0)--++(0.6,0)

    %Put the customzed opamp in position

    %Put some short nodes
    \draw(-7,1) node[ocirc,scale=2,line width=1.5pt](N3){};
    \draw(-3,1) node[circ,scale=2,line width=1.5pt](N2){};
    \draw(3,0) node[circ,scale=2,line width=1.5pt](N6){};
    \draw(5.5,0) node[ocirc,scale=2,line width=1.5pt](N6-OUT){};
    \MyGround(1 GND -| N2){2}
    \MyGround(1 GND -| N6-OUT){3}

    %Draw the Wires and pasive components
    \draw[line width=1.5pt]
    (N3)%From node N3
        to [R,l=\Large$R_1$] (N2)
        --(1 IN-)
        --++(0,2) coordinate (N5)
        -| (N6)
    (1 OUT) 
        -- (N6-OUT)
    (1 IN+)
        -|(2 GND);
    %Voltage references
        -- (1 GND);

    \draw[Vref=$0$ V,color=cyan]
    (1 IN-)
        ++(-0.5,0) coordinate (temp) 
        -- (1 IN+ -| temp)
            label={[Numbered,black]180:\bf 1}

        -- (3 GND) 
        node [
            label={[Numbered,black,label distance=5pt]180:\bf 6}
        ]{$\bm{v_o} = 0-\cfrac{v_1}{R_1}R_2$};

        node [
            label={[Numbered,black,label distance=5pt]180:\bf 2}
        ](C1){$\bm{v_1} = 0$ \bf (Virtual ground)}
    (C1.168) %get a point from center to node box at 168 degrees
        to [out=80, in=-150] (N2);

    %Draw currents
        -- ++(1.5,0)
        node [
            inner sep=10pt,
            label={[Numbered,black,label distance=0pt]180:\bf 3}
        ]{$\bm{i_1} = \cfrac{v_1}{R_1}$};

        -- ++(1.2,0)
        node [
            inner sep=10pt,
            label={[Numbered,black,label distance=0pt]12:\bf 4}
    (N5)++(0.3,0.3) %node gap
        -- ++(2,0) % Arrow longitude
        node [
            inner sep=10pt,
            label={[Numbered,black,label distance=0pt]180:\bf 5}
        ]{$\bm{i_2} = \bm{i_1} =\cfrac{\bm{v_1}}{R_1}$};
    (C1 -| 3 GND)
        node [
            inner sep=10pt,
        ]{$\bm{v_o} = -\cfrac{R_2}{R_1}v_i$};


PSD: This code is derived from How can i rotate circuitkz figure vertical?, 555 timer schematic, for label styles drawing circles and squares with TikZ

John Kormylo 07/15/2018.

I made a few changes to make it look more like the original, and to commit fully to relative coordinates. Note that to centers the components between the end points, so to offset the component you need move the end points.

To add text you use normal TikZ nodes (circuitikz is a tikzpicture). Since they don't have to be perfectly aligned one has some freedom in placement. I put the first label relative to coordinate (L1).

\draw (0, 0) node[op amp] (opamp) {}
      (opamp.-) to[short,-*] ++(-1, 0) coordinate(A)
      (opamp.+) -| ++(-1,-1) node[ground](B){}
      (opamp.out) to[short,*-o] ++(1, 0) coordinate(C)
      (C |- B) node[ground]{} node[ocirc]{}
      (A) to[R,l_=$R_1$,-o] ++(-2, 0) -- ++(-1, 0) coordinate(D) to [V<=$v_1$] (D |- B) node[ground]{}
      (A) |- ++(1,1) coordinate[yshift=1ex] (L1) to[R=$R_2$] ++(2,0) -| (opamp.out) to[short,-o] ++(1,0)
\draw[blue,->] (L1 -| A) -> (L1);
\node[blue,above left] (L2) at (L1) {$i_1=i_2=\frac{v_1}{R_1}$};
\node[draw,circle,left] at (L2.west) {5};


Zarko 07/15/2018.

as starting point ...

enter image description here

\usetikzlibrary{automata, positioning}

\tikzset{every pin/.append style={pin distance=11mm,
                                  pin edge={<-,shorten <=2pt,semithick,cyan},
                                  align=center, text=cyan}}
\draw   (0,0)   node[below] {$+$}
                to [short,i=\textcolor{cyan}{$i_1{=}\frac{v_I}{R_1}$},o-]    ++ (1,0)
                to [R=$R_1$,-*] ++ (2.0,0)
                coordinate[pin={[xshift=1em]240:{$v_I=0$}\\ (Virtual ground)}] (aux1)
                to [short,i=\textcolor{cyan}{$i_1{=}0$}]    ++ (1,0)
                node [op amp, anchor=-] (amp) {}
        (aux1)  -- ++ (0,2)
                to [short,i=\textcolor{cyan}{$i_2{=}i_1=\frac{v_I}{R_1}$}]    ++ (1,0)
                to [R=$R_2$]    ++ (2,0)
                |- (amp.out)
                to [short,-o]   ++ (2,0)
                node[below] {$+$}
                to [open,l=\textcolor{cyan}{$v_o{=}0-\frac{v_1}{R_1}$}] ++ (0,-2)
                node[ground,label=$-$] (aux2) {}
        (amp.+) -| (aux1 |- aux2)
                node[ground] {}
        (0,0)   to [open,l_=\textcolor{cyan}{$v_I$}] (0,0 |- aux2)
                node[ground,label=$-$] (aux2) {}
\end{document} - Download Hi-Res Songs


Kiss And Make Up flac

BLACKPINK. 2018. Writer: Soke;Kny Factory;Billboard;Chelcee Grimes;Teddy Park;Marc Vincent;Dua Lipa.
2 Martin Garrix

Waiting For Tomorrow flac

Martin Garrix. 2018. Writer: Pierce Fulton;Mike Shinoda;Martijn Garritsen;Brad Delson.
3 Martin Garrix

Access flac

Martin Garrix. 2018. Writer: Martin Garrix.
4 John Legend

Written In The Stars flac

John Legend. 2018. Writer: Kiana Brown;Santoy;Kevin White;Mike Woods;MZMC;The Heavy Group;Rice N' Peas.
5 Martin Garrix

Yottabyte flac

Martin Garrix. 2018. Writer: Martin Garrix.
6 Alan Walker

Diamond Heart flac

Alan Walker. 2018. Writer: Alan Walker;Sophia Somajo;Mood Melodies;James Njie;Thomas Troelsen;Kristoffer Haugan;Edvard Normann;Anders Froen;Gunnar Greve;Yann Bargain;Victor Verpillat;Fredrik Borch Olsen.
7 Cardi B

Taki Taki flac

Cardi B. 2018. Writer: Bava;Juan Vasquez;Vicente Saavedra;Jordan Thorpe;DJ Snake;Ozuna;Cardi B;Selena Gomez.
8 Bradley Cooper

Shallow flac

Bradley Cooper. 2018. Writer: Andrew Wyatt;Anthony Rossomando;Mark Ronson;Lady Gaga.
9 Post Malone

Sunflower flac

Post Malone. 2018. Writer: Louis Bell;Billy Walsh;Carter Lang;Swae Lee;Post Malone.
10 Dyro

Latency flac

Dyro. 2018. Writer: Martin Garrix;Dyro.
11 Zara Larsson

Ruin My Life flac

Zara Larsson. 2018. Writer: Delacey;Michael Pollack;Stefan Johnson;Jordan Johnson;Sermstyle;Jackson Foote.

Fingers flac

ZAYN. 2018. Writer: Zayn Malik;Alex Oriet;David Phelan.
13 Halsey

Without Me flac

Halsey. 2018. Writer: Halsey;Delacey;Louis Bell;Amy Allen;Justin Timberlake;Timbaland;Scott Storch.
14 Lady Gaga

I'll Never Love Again flac

Lady Gaga. 2018. Writer: Benjamin Rice;Lady Gaga.
15 Sia

I'm Still Here flac

Sia. 2018. Writer: Sia.
16 Dewain Whitmore

Burn Out flac

Dewain Whitmore. 2018. Writer: Dewain Whitmore;Ilsey Juber;Emilio Behr;Martijn Garritsen.
17 Little Mix

Woman Like Me flac

Little Mix. 2018. Writer: Nicki Minaj;Steve Mac;Ed Sheeran;Jess Glynne.
18 Mako

Rise flac

Mako. 2018. Writer: Riot Music Team;Mako;Justin Tranter.
19 Blinders

Breach (Walk Alone) flac

Blinders. 2018. Writer: Dewain Whitmore;Ilsey Juber;Blinders;Martin Garrix.
20 Rita Ora

Let You Love Me flac

Rita Ora. 2018. Writer: Rita Ora.

Related questions

Hot questions


Popular Tags