# How to place and rotate a Galvanometer using Circuitikz

I'm new to ciruitikz so my question could be a silly one.

I was trying to draw a circuit using the circuitikz package, but I stumbled upon the problem of inserting a galvanometer and rotating it.

Here is a code example of the circuit using a voltmeter instead of the galvanometer:

\documentclass[12pt]{article}
\usepackage[siunitx]{circuitikz}
\begin{document}
\begin{circuitikz}
\draw (0,-0.1) to[sinusoidal voltage source] (0,2)
to[switch] (2,2);
\draw (3,2) node[transformer] {}
(0,-0.1) -- (2,-0.1);
\draw (4.05,-0.1) -- (6.05,-0.1) to[voltmeter] (6.05,2) -- (4.05,2);
\end{circuitikz}
\end{document}


Which results in this circuit:

How can I rotate the voltmeter by 270° and maintain the pieces of wire that it generates vertical?

How can I replace the voltmeter, which is used just for this example, with a galvanometer?

Unfortunately, I haven't found anything in the circuitikz manual or anywhere else, thank you for your time.

\documentclass[]{standalone}

\usepackage{circuitikz}

\ctikzset{bipoles/galvanometer/height/.initial=.60}
\ctikzset{bipoles/galvanometer/width/.initial=.60}

\ctikzset{bipoles/galvanometer/arrow rotate/.initial=0,% <=new key
rotation/.style={bipoles/galvanometer/arrow rotate=#1},% style for ease introduction in code
}

% code from pgfcircbipoles.sty
\makeatletter
\pgfcircdeclarebipole{}{\ctikzvalof{bipoles/galvanometer/height}}{galvanometer}{\ctikzvalof{bipoles/galvanometer/height}}{\ctikzvalof{bipoles/galvanometer/width}}{
\def\pgf@circ@temp{right}
\ifx\tikz@res@label@pos\pgf@circ@temp
\pgf@circ@res@step=-1.2\pgf@circ@res@up
\else
\def\pgf@circ@temp{below}
\ifx\tikz@res@label@pos\pgf@circ@temp
\pgf@circ@res@step=-1.2\pgf@circ@res@up
\else
\pgf@circ@res@step=1.2\pgf@circ@res@up
\fi
\fi

\pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@zero}}
\pgfpointorigin \pgf@circ@res@other =  \pgf@x  \advance \pgf@circ@res@other by -\pgf@circ@res@up
\pgfpathlineto{\pgfpoint{\pgf@circ@res@other}{\pgf@circ@res@zero}}
\pgfusepath{draw}

\pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\pgfstartlinewidth}

\pgfscope
\pgfpathcircle{\pgfpointorigin}{1.0\pgf@circ@res@up}
\pgfusepath{draw}
\endpgfscope

\pgftransformrotate{\ctikzvalof{bipoles/galvanometer/arrow rotate}}% <= magic line
\pgfsetlinewidth{\pgfstartlinewidth}

\pgfsetarrowsend{latex}
\pgfpathmoveto{\pgfpoint{0.7\pgf@circ@res@up}{\pgf@circ@res@zero}}
\pgfpathlineto{\pgfpoint{0.7\pgf@circ@res@down}{\pgf@circ@res@zero}}
\pgfusepath{draw}
\pgfsetarrowsend{}

%    \pgfpathmoveto{\pgfpoint{-\pgf@circ@res@other}{\pgf@circ@res@zero}}
%    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@zero}}
%    \pgfusepath{draw}

%% G for galvanometer
%\pgfnode{circle}{center}{\textbf{G}}{}{}
}

% As used in pgfcircpath.tex
\def\pgf@circ@galvanometer@path#1{\pgf@circ@bipole@path{galvanometer}{#1}}
\compattikzset{galvanometer/.style = {\circuitikzbasekey, /tikz/to path=\pgf@circ@galvanometer@path}}

\makeatother

\begin{document}

\begin{circuitikz}
\draw (0,-0.1) to[sinusoidal voltage source] (0,2)
to[switch] (2,2);
\draw (3,2) node[transformer] {}
(0,-0.1) -- (2,-0.1);
\draw (4.05,-0.1) -- (6.05,-0.1) to[galvanometer,rotation=90] (6.05,2) -- (4.05,2);
\end{circuitikz}

\end{document}


It incorporates the function \drawmeteringcircle into the galvanometer declaration and adds some magic stuff to rotate the arrow.

• Thank you very much it worked, but how can I insert a galvanometer instead of the voltmeter? – Edoardo Serra Aug 25 '18 at 11:30
• I updated the answer. I don't know if this is the correct symbol for a galvanometer. I removed the sloped arrow. – Jesse op den Brouw Aug 25 '18 at 14:44
• Thanks, I've managed to do the same but the correct symbol should have a thick black arrow pointing to the right ad I can't find out how to do that. – Edoardo Serra Aug 25 '18 at 14:49
• I will look into that shortly. – Jesse op den Brouw Aug 25 '18 at 15:09
• updated the answer (again) – Jesse op den Brouw Aug 25 '18 at 15:34

Unfortunately circuitikz doesn't provide a way to properly rotate an object, and it doesn't provide the galvanometer as an object either. My answer is based on Zarko's code to rotate an object because I think that of the two examples presented in the former answers is the most readable one.

Let's take Zarko's code and substitute vm and Vm with gm an Gm for galvanometer instead of voltmeter. Let's also delete the V inside the node's contents brackets and the following strings:

append after command={\pgfextra{\let\LN\tikzlastnode
\draw[-stealth] (\LN.south -| \LN.west) --  (\LN.north -| \LN.east);}}


Since the content of the node isn't a letter but an arrow it has to be defined a command, to be inserted in the node contents brackets, that draws the arrow itself:

\newcommand{\arrow}{\begin{tikzpicture}
\draw[->, very thick]{(5.9,1.05) -- (6.35,1.05)};
\end{tikzpicture}
}


Here is a MWE of the circuit:

\documentclass[12pt]{article}
\usepackage{circuitikz}
\usetikzlibrary{positioning}
\newcommand{\arrow}{\begin{tikzpicture}
\draw[->, very thick]{(5.9,1.05) -- (6.35,1.05)};
\end{tikzpicture}
}

\begin{document}
\begin{circuitikz}
\tikzset{Gm/.style={circle, draw, thick,
node contents={\arrow},
}}
\node[transformer] (t) {};
\node (gm) [Gm, right=15mm of t];
\draw   (t.A2)  -- + (-2,0) coordinate (aux1)
to [sV]  (aux1 |- t.A1)
to[switch] (t.A1)
(t.B1)  -|  (gm) |- (t.B2);
\end{circuitikz}
\end{document}


Tre result is the following:

This method isn't a good one though, every time a galvanometer has to be drawn it must be defined a new \arrow command with the right positioning and dimensions in the circuitikz environment; answers which provides a more rigorous and elegant way are very appreciated.

unfortunately circuitikznot define instruments bipoles which will enable them rotating or even better oriented it with path direction. in this site exist many suggestion how to overcome this lack of features, however for your particular case you can define volt meter as node:

since it is not clear what you like to obtain i rather delete my answer.

• Thank you very much it worked, but how can I insert a galvanometer instead of the voltmeter? – Edoardo Serra Aug 25 '18 at 11:30
• I've somehow managed to make it work, it's not the most elegant or practical solution though. I'll write an answer. – Edoardo Serra Aug 25 '18 at 15:10
• @EdoardoSerra, please explain what you mean with "galvanometer". instrument without letter "V". in this case delete node contents={V} and in circuit 's code write \node (vm) [Vm, right=15mm of t] {}; – Zarko Aug 25 '18 at 15:29
• I've added an answer where it can be seen what I intend the galvanometer to look like, thank you for your help. – Edoardo Serra Aug 25 '18 at 15:35
• @EdoardoSerra, see addendum to my answer. – Zarko Aug 25 '18 at 15:38