Du bist hier: Aktor > Servo

Arduino Servo ansteuern

Ein Servo Motor ist ein Aktuator, der mit seinen präzise programmierbaren Bewegungen Leben in deine Projekte bringt, denn das Ansteuern mit dem Arduino ist ganz einfach.

Diese Anleitung basiert auf dem vereinfachten Controller von PGLU, kann aber mit jedem Arduino UNO oder NANO umgesetzt werden.

Hier geht's zur Übersetzung der Pin-Belegung ↗

1. Vorbereiten

1.1. Servo an Arduino anschliessen

Normale Servos können Bewegungen von ca. 180° abdecken und das mit einem erstaunlichen Drehmoment von bis zu mehreren kg/cm. Das Servo wird über drei farbige Litzen mit dem Mikrocontroller verbunden. Die Farben dieser drei Anschlüsse sind je nach Produkt unterschiedlich und haben diese Funktion:

  • Rot          →  +5V
  • Braun     →  -5V
  • Orange   →  -L2 (minus)

 

Anschluss an Arduino UNO/NANO:

  • Rot          →  +5V
  • Braun     →  GND
  • Orange   →  D10

  • Hinweis: Die Abbildungen zeigen unsere Breakout-Boards  Komfort ↗ oder  Pixel ↗
  • Hinweis: Alle Projekte können auch mit dem Arduino Uno, Nano oder weiteren umgesetzt werden
  • Hinweis: Mit dieser Methode "ohne Library" können beliebig viele Servos angeschlossen- und programmiert werden
  • Hinweis: Wenn sich das Servo unerwartet verhält einen Elko mit 470-1000μF einsetzen (Bild). Polung beachten. Für weitere Infos hier klicken ↗.
Servo an Mikrocontroller KOMFORT anschliessen

1.2. PWM Steuersignal verstehen

  • Hinweis: du kannst auch mit dem Servo arbeiten, wenn du dieses Kapitel überspringst! Programmiere einfach das untenstehende Sketch 1 oder 2 und experimentiere mit dem Servo. Den Originalen Arduino Code findest du dann in der Code-Ansicht des Editors.

Die genaue Position des Servos wird mit einem PWM Signal (Pulsweiten Modulation Signal) gesteuert:

  • Das Servo erwartet alle 20ms einen kurzen Impuls von 5V → t = Zeitabstand Impulse
  • Die Dauer dieses Impulses bestimmt über den Winkel des Servohebels → i = Impulsdauer
  • i soll (in der Theorie) zwischen 1000 μs und 2000 μs betragen.
  • i = 1000 μs entspricht der Anfangsposition
  • i = 1500 μs entspricht der Mittelposition
  • i = 2000 μs entspricht der Endposition
Steuersignal eines Arduino Servos verstehen

2. Servo mit Arduino programmieren

Alle Programmierungen werden mit dem grafischen PGLU-Editor ↗ gemacht. Den originalen Arduino Code findest du dann in der Code-Ansicht des Editors.

2.1. Konstruiere deine eigene "Arduino Servo Funktion"

  • Tipp: Verstehe die Grundlagen einer Funktion hier
  • Tipp: Klicke auf den schwarzen Punkt, um die Funktionsvariablen Position und Servo Pin einzugeben.
  • Tipp: Schaue genau, ob du eine Pause in ms oder in μs verwendest!
  • Tipp: Experimentiere mit dem Wert wiederhole 10 mal. Er gibt die Anzahl Steuerimpulse an, die an das Servo gesendet werden. Je nach Situation kannst du hier zwischen 2 und 30 Impulsen variieren. Weniger Impulse machen die Bewegung smoother (z.B. bei der direkten Steuerung mit einem Poti), mehr Impulse machen sie sicherer.
Sketch 1: Arduino Servo steuern ohne Library (Klick für Zoom)

Kopiere diesen XML-Code mit Klick/Berührung und füge ihn in den PGLU-Editor ↗ ein:

<xml xmlns="https://developers.google.com/blockly/xml"><variables><variable id="_DQjdhaJfR6,f$7cgOQ7">Position in °</variable><variable id="Vw5IBG9C#Pa@r0U!+Bbh">Servo Pin</variable><variable id="K:G4UACKdRDr(dE9O39G">Pause</variable></variables><block type="basic_comment" id="H~UW;?gR9HL56l!+P|SL" x="-108" y="-514"><field name="COMMENT">Setze diesen Block dort ein, wo du ein Servo auf 90° stellen möchtest</field></block><block type="procedures_callnoreturn" id="h,f[+#.Bb}Xe`}luH7k@" x="-106" y="-464"><mutation name="stelle Servo"><arg name="Position in °"></arg><arg name="Servo Pin"></arg></mutation><value name="ARG0"><block type="math_number" id="_MO;sfr4*5jcgxQb^oIs"><field name="NUM">90</field></block></value><value name="ARG1"><block type="led_pin" id=".q/9|Grs%E++O#5z!HW("><field name="LED">LED2</field></block></value></block><block type="basic_comment" id="|.$x+yKiz`j-,~[?eRLs" x="-108" y="-340"><field name="COMMENT">Nicht löschen, dies ist die Servofunktion</field></block><block type="procedures_defnoreturn" id="DYYovfp[/{/^ryWHZBvf" x="-104" y="-281"><mutation><arg name="Position in °" varid="_DQjdhaJfR6,f$7cgOQ7"></arg><arg name="Servo Pin" varid="Vw5IBG9C#Pa@r0U!+Bbh"></arg></mutation><field name="NAME">stelle Servo</field><statement name="STACK"><block type="variables_set" id="b*l`jfDpwv@_`yEQ:sQU"><field name="VAR" id="_DQjdhaJfR6,f$7cgOQ7">Position in °</field><value name="VALUE"><block type="math_map" id="wY2I~E@9)6mqH{`4}Min"><value name="VALUE"><block type="variables_get" id="sM%OH#-),/XvNLAfoDgM"><field name="VAR" id="_DQjdhaJfR6,f$7cgOQ7">Position in °</field></block></value><value name="FROMLOW"><block type="math_number" id="5*[TWQi3eTy;dTNqRejO"><field name="NUM">0</field></block></value><value name="FROMHIGH"><block type="math_number" id="3FohKj*x~t~gZ.sYtS2("><field name="NUM">180</field></block></value><value name="TOLOW"><block type="math_number" id="y+3B7BV,l3#e!tC#zP45"><field name="NUM">400</field></block></value><value name="TOHIGH"><block type="math_number" id="n[XOgoHB+-0i.,Gpwf%1"><field name="NUM">2600</field></block></value></block></value><next><block type="variables_set" id=".xsEB~Y8Qx!^%8P%)mh;"><field name="VAR" id="K:G4UACKdRDr(dE9O39G">Pause</field><value name="VALUE"><block type="math_arithmetic" id="{F9Honx#=x}}p5s6~3pd"><field name="OP">MINUS</field><value name="A"><block type="math_number" id="nN}B3!9SLvv*1{Zlf(%h"><field name="NUM">20000</field></block></value><value name="B"><block type="variables_get" id="mZbi[2Xx35m9qZ2Wz|b_"><field name="VAR" id="_DQjdhaJfR6,f$7cgOQ7">Position in °</field></block></value></block></value><next><block type="flow_repeat" id="gN=t~3M0%R7Pe)/i-V4G"><value name="REPEATS"><block type="math_number" id="+qOr!,*|C9.5wJ[w,ENN"><field name="NUM">10</field></block></value><statement name="DO"><block type="led_write_state" id="6!l6z?iL+={{9KAi,H|9"><value name="LED"><block type="variables_get" id="0L`R`5_!X{Az,9F)`Qac"><field name="VAR" id="Vw5IBG9C#Pa@r0U!+Bbh">Servo Pin</field></block></value><value name="VALUE"><block type="code_pin" id="+7pwX/P2*!~K,CbqH7gH"><field name="CODE_PIN">HIGH</field></block></value><next><block type="flow_delay_micro" id="Y3736,h2Aea/$FEM%mGd"><value name="DELAY_MICRO"><block type="variables_get" id=")Lg-8viw{x?GWSZtdPfK"><field name="VAR" id="_DQjdhaJfR6,f$7cgOQ7">Position in °</field></block></value><next><block type="led_write_state" id="=R-dB9$gUgUf[f1#amX?"><value name="LED"><block type="variables_get" id="L{aTSjwfCBro[60WW.0E"><field name="VAR" id="Vw5IBG9C#Pa@r0U!+Bbh">Servo Pin</field></block></value><value name="VALUE"><block type="code_pin" id="ZI?r50,S}Q!N4EWcI9rk"><field name="CODE_PIN">LOW</field></block></value><next><block type="flow_delay_micro" id="7il;NbzoR^Es7say`(zt"><value name="DELAY_MICRO"><block type="variables_get" id="|@!H=EXua/xr-NRDCr5g"><field name="VAR" id="K:G4UACKdRDr(dE9O39G">Pause</field></block></value></block></next></block></next></block></next></block></statement></block></next></block></next></block></statement></block><block type="basic_main_loop" id="9~210UV)!{|GniQxFn|[" deletable="false" x="-102" y="136"><value name="BLINK"><block type="basic_blinkcode" id="u@6%knhMhK2g(1JYw[10"><field name="SHORT">1</field><field name="LONG">1</field></block></value></block></xml>

2.2. Sketch: Arduino Servo schnell stellen

Sketch 2: Arduino Servo ohne Library schnell stellen (Klick für Zoom)

Kopiere diesen XML-Code mit Klick/Berührung und füge ihn in den PGLU-Editor ↗ ein:

<xml xmlns="https://developers.google.com/blockly/xml"><variables><variable id="_DQjdhaJfR6,f$7cgOQ7">Position in °</variable><variable id="Vw5IBG9C#Pa@r0U!+Bbh">Servo Pin</variable><variable id="K:G4UACKdRDr(dE9O39G">Pause</variable></variables><block type="basic_comment" id="H~UW;?gR9HL56l!+P|SL" x="-99" y="37"><field name="COMMENT">Servo schnell stellen</field></block><block type="basic_comment" id="|.$x+yKiz`j-,~[?eRLs" x="-583" y="121"><field name="COMMENT">Nicht löschen, dies ist die Servofunktion</field></block><block type="basic_main_loop" id="9~210UV)!{|GniQxFn|[" deletable="false" x="-99" y="117"><value name="BLINK"><block type="basic_blinkcode" id="u@6%knhMhK2g(1JYw[10"><field name="SHORT">1</field><field name="LONG">1</field></block></value><statement name="CODE"><block type="procedures_callnoreturn" id="h,f[+#.Bb}Xe`}luH7k@"><mutation name="stelle Servo"><arg name="Position in °"></arg><arg name="Servo Pin"></arg></mutation><value name="ARG0"><block type="math_number" id="_MO;sfr4*5jcgxQb^oIs"><field name="NUM">0</field></block></value><value name="ARG1"><block type="led_pin" id=".q/9|Grs%E++O#5z!HW("><field name="LED">LED2</field></block></value><next><block type="flow_delay" id="[69ur6?b$5+ATh[A~v.L"><value name="DELAY"><block type="math_number" id="dvki%hg:;in)eO3lr)]a"><field name="NUM">1000</field></block></value><next><block type="procedures_callnoreturn" id="`Mm@E[|eV;hFyZNE]q)S"><mutation name="stelle Servo"><arg name="Position in °"></arg><arg name="Servo Pin"></arg></mutation><value name="ARG0"><block type="math_number" id="f%WsGCMsWrfu)Y]4`kB4"><field name="NUM">90</field></block></value><value name="ARG1"><block type="led_pin" id="KKbnA[o-+SQNFyb%*|;O"><field name="LED">LED2</field></block></value><next><block type="flow_delay" id="vOnnDQ|h=u5xrscEU1DN"><value name="DELAY"><block type="math_number" id="#py.sj^x*DZ)^FW`;kH]"><field name="NUM">1000</field></block></value><next><block type="procedures_callnoreturn" id="~Wm*g:1#m!P#3Hytl/o4"><mutation name="stelle Servo"><arg name="Position in °"></arg><arg name="Servo Pin"></arg></mutation><value name="ARG0"><block type="math_number" id="M*[h3p,g?6x5~hz26{xI"><field name="NUM">180</field></block></value><value name="ARG1"><block type="led_pin" id="qR(`bq!),1~:T^;5;:hx"><field name="LED">LED2</field></block></value><next><block type="flow_delay" id="]#6[;nj6!VBo)i]$5qI{"><value name="DELAY"><block type="math_number" id="4dCkkeM9GMBPyN(V`:ST"><field name="NUM">1000</field></block></value></block></next></block></next></block></next></block></next></block></next></block></statement></block><block type="procedures_defnoreturn" id="DYYovfp[/{/^ryWHZBvf" collapsed="true" x="-581" y="165"><mutation><arg name="Position in °" varid="_DQjdhaJfR6,f$7cgOQ7"></arg><arg name="Servo Pin" varid="Vw5IBG9C#Pa@r0U!+Bbh"></arg></mutation><field name="NAME">stelle Servo</field><statement name="STACK"><block type="variables_set" id="b*l`jfDpwv@_`yEQ:sQU"><field name="VAR" id="_DQjdhaJfR6,f$7cgOQ7">Position in °</field><value name="VALUE"><block type="math_map" id="wY2I~E@9)6mqH{`4}Min"><value name="VALUE"><block type="variables_get" id="sM%OH#-),/XvNLAfoDgM"><field name="VAR" id="_DQjdhaJfR6,f$7cgOQ7">Position in °</field></block></value><value name="FROMLOW"><block type="math_number" id="5*[TWQi3eTy;dTNqRejO"><field name="NUM">0</field></block></value><value name="FROMHIGH"><block type="math_number" id="3FohKj*x~t~gZ.sYtS2("><field name="NUM">180</field></block></value><value name="TOLOW"><block type="math_number" id="y+3B7BV,l3#e!tC#zP45"><field name="NUM">400</field></block></value><value name="TOHIGH"><block type="math_number" id="n[XOgoHB+-0i.,Gpwf%1"><field name="NUM">2600</field></block></value></block></value><next><block type="variables_set" id=".xsEB~Y8Qx!^%8P%)mh;"><field name="VAR" id="K:G4UACKdRDr(dE9O39G">Pause</field><value name="VALUE"><block type="math_arithmetic" id="{F9Honx#=x}}p5s6~3pd"><field name="OP">MINUS</field><value name="A"><block type="math_number" id="nN}B3!9SLvv*1{Zlf(%h"><field name="NUM">20000</field></block></value><value name="B"><block type="variables_get" id="mZbi[2Xx35m9qZ2Wz|b_"><field name="VAR" id="_DQjdhaJfR6,f$7cgOQ7">Position in °</field></block></value></block></value><next><block type="flow_repeat" id="gN=t~3M0%R7Pe)/i-V4G"><value name="REPEATS"><block type="math_number" id="+qOr!,*|C9.5wJ[w,ENN"><field name="NUM">10</field></block></value><statement name="DO"><block type="led_write_state" id="6!l6z?iL+={{9KAi,H|9"><value name="LED"><block type="variables_get" id="0L`R`5_!X{Az,9F)`Qac"><field name="VAR" id="Vw5IBG9C#Pa@r0U!+Bbh">Servo Pin</field></block></value><value name="VALUE"><block type="code_pin" id="+7pwX/P2*!~K,CbqH7gH"><field name="CODE_PIN">HIGH</field></block></value><next><block type="flow_delay_micro" id="Y3736,h2Aea/$FEM%mGd"><value name="DELAY_MICRO"><block type="variables_get" id=")Lg-8viw{x?GWSZtdPfK"><field name="VAR" id="_DQjdhaJfR6,f$7cgOQ7">Position in °</field></block></value><next><block type="led_write_state" id="=R-dB9$gUgUf[f1#amX?"><value name="LED"><block type="variables_get" id="L{aTSjwfCBro[60WW.0E"><field name="VAR" id="Vw5IBG9C#Pa@r0U!+Bbh">Servo Pin</field></block></value><value name="VALUE"><block type="code_pin" id="ZI?r50,S}Q!N4EWcI9rk"><field name="CODE_PIN">LOW</field></block></value><next><block type="flow_delay_micro" id="7il;NbzoR^Es7say`(zt"><value name="DELAY_MICRO"><block type="variables_get" id="|@!H=EXua/xr-NRDCr5g"><field name="VAR" id="K:G4UACKdRDr(dE9O39G">Pause</field></block></value></block></next></block></next></block></next></block></statement></block></next></block></next></block></statement></block></xml>

2.3. Sketch: Arduino Servo langsam stellen

Sketch 3: Arduino Servo ohne Library langsam stellen (Klick für Zoom)

Kopiere diesen XML-Code mit Klick/Berührung und füge ihn in den PGLU-Editor ↗ ein:

<xml xmlns="https://developers.google.com/blockly/xml"><variables><variable id="_DQjdhaJfR6,f$7cgOQ7">Position in °</variable><variable id="Vw5IBG9C#Pa@r0U!+Bbh">Servo Pin</variable><variable id="DoyC0N[TR?Wtuv+]QNjk">von Pos in °</variable><variable id="8M|lsZfG.{JMk^B,=:P[">bis Pos in °</variable><variable id="|H,0pDre=%.#lJkTh33Q">Tempo in %</variable><variable id="K:G4UACKdRDr(dE9O39G">Pos 1</variable></variables><block type="basic_comment" id="H~UW;?gR9HL56l!+P|SL" x="-132" y="-25"><field name="COMMENT">Servo langsam stellen</field></block><block type="basic_comment" id="|.$x+yKiz`j-,~[?eRLs" x="-700" y="32"><field name="COMMENT">Nicht löschen, dies ist die Servofunktion</field></block><block type="basic_main_loop" id="9~210UV)!{|GniQxFn|[" deletable="false" x="-130" y="38"><value name="BLINK"><block type="basic_blinkcode" id="u@6%knhMhK2g(1JYw[10"><field name="SHORT">1</field><field name="LONG">1</field></block></value><statement name="CODE"><block type="procedures_callnoreturn" id="Vfhx+nVHlq|yNn.Om{0h"><mutation name="stelle Servo langsam"><arg name="von Pos in °"></arg><arg name="bis Pos in °"></arg><arg name="Tempo in %"></arg><arg name="Servo Pin"></arg></mutation><value name="ARG0"><block type="math_number" id="av[R3`#Q=lhK$:_o5q3J"><field name="NUM">0</field></block></value><value name="ARG1"><block type="math_number" id=".5KEY{}9vzTLe)yMV7q/"><field name="NUM">180</field></block></value><value name="ARG2"><block type="math_number" id="bDUQIs!(,A-+2ZNZf[[2"><field name="NUM">10</field></block></value><value name="ARG3"><block type="led_pin" id=".q/9|Grs%E++O#5z!HW("><field name="LED">LED2</field></block></value><next><block type="procedures_callnoreturn" id="ZI4Ovc]#Plp5X.+wYX-2"><mutation name="stelle Servo langsam"><arg name="von Pos in °"></arg><arg name="bis Pos in °"></arg><arg name="Tempo in %"></arg><arg name="Servo Pin"></arg></mutation><value name="ARG0"><block type="math_number" id="i!dE{_3Mh(4j$e?9J^N4"><field name="NUM">180</field></block></value><value name="ARG1"><block type="math_number" id="?u7L(/g=6)Wd+%DK:*5n"><field name="NUM">0</field></block></value><value name="ARG2"><block type="math_number" id="xDC}9*N9YLe-}Oyn(ltL"><field name="NUM">10</field></block></value><value name="ARG3"><block type="led_pin" id="G_Ek@X/xB;^Z,p{[ehZ3"><field name="LED">LED2</field></block></value></block></next></block></statement></block><block type="procedures_defnoreturn" id="DYYovfp[/{/^ryWHZBvf" collapsed="true" x="-700" y="91"><mutation><arg name="Position in °" varid="_DQjdhaJfR6,f$7cgOQ7"></arg><arg name="Servo Pin" varid="Vw5IBG9C#Pa@r0U!+Bbh"></arg></mutation><field name="NAME">stelle Servo</field><statement name="STACK"><block type="variables_set" id="b*l`jfDpwv@_`yEQ:sQU"><field name="VAR" id="_DQjdhaJfR6,f$7cgOQ7">Position in °</field><value name="VALUE"><block type="math_map" id="wY2I~E@9)6mqH{`4}Min"><value name="VALUE"><block type="variables_get" id="sM%OH#-),/XvNLAfoDgM"><field name="VAR" id="_DQjdhaJfR6,f$7cgOQ7">Position in °</field></block></value><value name="FROMLOW"><block type="math_number" id="5*[TWQi3eTy;dTNqRejO"><field name="NUM">0</field></block></value><value name="FROMHIGH"><block type="math_number" id="3FohKj*x~t~gZ.sYtS2("><field name="NUM">180</field></block></value><value name="TOLOW"><block type="math_number" id="y+3B7BV,l3#e!tC#zP45"><field name="NUM">450</field></block></value><value name="TOHIGH"><block type="math_number" id="n[XOgoHB+-0i.,Gpwf%1"><field name="NUM">2550</field></block></value></block></value><next><block type="variables_set" id=".xsEB~Y8Qx!^%8P%)mh;"><field name="VAR" id="K:G4UACKdRDr(dE9O39G">Pos 1</field><value name="VALUE"><block type="math_arithmetic" id="{F9Honx#=x}}p5s6~3pd"><field name="OP">MINUS</field><value name="A"><block type="math_number" id="nN}B3!9SLvv*1{Zlf(%h"><field name="NUM">20000</field></block></value><value name="B"><block type="variables_get" id="mZbi[2Xx35m9qZ2Wz|b_"><field name="VAR" id="_DQjdhaJfR6,f$7cgOQ7">Position in °</field></block></value></block></value><next><block type="flow_repeat" id="gN=t~3M0%R7Pe)/i-V4G"><value name="REPEATS"><block type="math_number" id="+qOr!,*|C9.5wJ[w,ENN"><field name="NUM">4</field></block></value><statement name="DO"><block type="led_write_state" id="6!l6z?iL+={{9KAi,H|9"><value name="LED"><block type="variables_get" id="0L`R`5_!X{Az,9F)`Qac"><field name="VAR" id="Vw5IBG9C#Pa@r0U!+Bbh">Servo Pin</field></block></value><value name="VALUE"><block type="code_pin" id="+7pwX/P2*!~K,CbqH7gH"><field name="CODE_PIN">HIGH</field></block></value><next><block type="flow_delay_micro" id="Y3736,h2Aea/$FEM%mGd"><value name="DELAY_MICRO"><block type="variables_get" id=")Lg-8viw{x?GWSZtdPfK"><field name="VAR" id="_DQjdhaJfR6,f$7cgOQ7">Position in °</field></block></value><next><block type="led_write_state" id="=R-dB9$gUgUf[f1#amX?"><value name="LED"><block type="variables_get" id="L{aTSjwfCBro[60WW.0E"><field name="VAR" id="Vw5IBG9C#Pa@r0U!+Bbh">Servo Pin</field></block></value><value name="VALUE"><block type="code_pin" id="ZI?r50,S}Q!N4EWcI9rk"><field name="CODE_PIN">LOW</field></block></value><next><block type="flow_delay_micro" id="7il;NbzoR^Es7say`(zt"><value name="DELAY_MICRO"><block type="variables_get" id="|@!H=EXua/xr-NRDCr5g"><field name="VAR" id="K:G4UACKdRDr(dE9O39G">Pos 1</field></block></value></block></next></block></next></block></next></block></statement></block></next></block></next></block></statement></block><block type="procedures_defnoreturn" id="c^Q=?l{x:FJ?Cm3Ncch(" collapsed="true" x="-700" y="149"><mutation><arg name="von Pos in °" varid="DoyC0N[TR?Wtuv+]QNjk"></arg><arg name="bis Pos in °" varid="8M|lsZfG.{JMk^B,=:P["></arg><arg name="Tempo in %" varid="|H,0pDre=%.#lJkTh33Q"></arg><arg name="Servo Pin" varid="Vw5IBG9C#Pa@r0U!+Bbh"></arg></mutation><field name="NAME">stelle Servo langsam</field><statement name="STACK"><block type="flow_for" id="MoL^$qp,s]q|#V}PCNel"><field name="VAR" id="_DQjdhaJfR6,f$7cgOQ7">Position in °</field><value name="FROM"><block type="variables_get" id="wU4r,RDpQh@jfxg;EcxR"><field name="VAR" id="DoyC0N[TR?Wtuv+]QNjk">von Pos in °</field></block></value><value name="TO"><block type="variables_get" id="8P)Er_m+.;4yannpX11Q"><field name="VAR" id="8M|lsZfG.{JMk^B,=:P[">bis Pos in °</field></block></value><value name="BY"><block type="math_map" id="XD^P~Qk|P($W8{5DOc}p"><value name="VALUE"><block type="variables_get" id="E?Zd6*s)DOd5/Y_5,2lM"><field name="VAR" id="|H,0pDre=%.#lJkTh33Q">Tempo in %</field></block></value><value name="FROMLOW"><block type="math_number" id="%GC=-JD8|y;:B[[f[n#U"><field name="NUM">0</field></block></value><value name="FROMHIGH"><block type="math_number" id=".ZWBxd~-|{*~cc2o9|q7"><field name="NUM">100</field></block></value><value name="TOLOW"><block type="math_number" id="f%@Q!+NEovExdlCD_d#n"><field name="NUM">0.01</field></block></value><value name="TOHIGH"><block type="math_number" id="relQ-8H6-k~[,FEIc#HH"><field name="NUM">5</field></block></value></block></value><statement name="DO"><block type="procedures_callnoreturn" id="h,f[+#.Bb}Xe`}luH7k@"><mutation name="stelle Servo"><arg name="Position in °"></arg><arg name="Servo Pin"></arg></mutation><value name="ARG0"><block type="variables_get" id="r@^JSALbD:Ryki$nBg.;"><field name="VAR" id="_DQjdhaJfR6,f$7cgOQ7">Position in °</field></block></value><value name="ARG1"><block type="variables_get" id="$cU5xUL=@X?`I5bGb%`r"><field name="VAR" id="Vw5IBG9C#Pa@r0U!+Bbh">Servo Pin</field></block></value></block></statement></block></statement></block></xml>

2.4. Sketch: Arduino Servo sanft stellen

Dies ist eine besonders interessante Methode ein Servo zu steuern, denn es führt die Bewegung nicht bloss langsam aus, sondern auch in einer sanften Wellenbewegung, gleich wie ein Pendel. Probiere es aus!

Servo sanft stellen

Kopiere diesen XML-Code mit Klick/Berührung und füge ihn in den PGLU-Editor ↗ ein:

<xml xmlns="https://developers.google.com/blockly/xml"><variables><variable id="_DQjdhaJfR6,f$7cgOQ7">Position in °</variable><variable id="Vw5IBG9C#Pa@r0U!+Bbh">Servo Pin</variable><variable id="DoyC0N[TR?Wtuv+]QNjk">von Pos in °</variable><variable id="8M|lsZfG.{JMk^B,=:P[">bis Pos in °</variable><variable id="|H,0pDre=%.#lJkTh33Q">Tempo in %</variable><variable id="K:G4UACKdRDr(dE9O39G">Pos 1</variable></variables><block type="basic_comment" id="H~UW;?gR9HL56l!+P|SL" x="-132" y="-25"><field name="COMMENT">Servo sanft stellen mit Zufallsgenerator</field></block><block type="basic_comment" id="|.$x+yKiz`j-,~[?eRLs" x="-700" y="32"><field name="COMMENT">Nicht löschen, dies ist die Servofunktion</field></block><block type="basic_main_loop" id="9~210UV)!{|GniQxFn|[" deletable="false" x="-131" y="37"><value name="BLINK"><block type="basic_blinkcode" id="u@6%knhMhK2g(1JYw[10"><field name="SHORT">1</field><field name="LONG">1</field></block></value><statement name="CODE"><block type="procedures_callnoreturn" id="Vfhx+nVHlq|yNn.Om{0h"><mutation name="stelle Servo sanft"><arg name="von Pos in °"></arg><arg name="bis Pos in °"></arg><arg name="Tempo in %"></arg><arg name="Servo Pin"></arg></mutation><value name="ARG0"><block type="math_number" id="e9#`X:ZNUM3%@]-Qg4xT"><field name="NUM">0</field></block></value><value name="ARG1"><block type="math_number" id="Na8s,c)uNNTr~.b+.Y|U"><field name="NUM">180</field></block></value><value name="ARG2"><block type="math_number" id="bDUQIs!(,A-+2ZNZf[[2"><field name="NUM">10</field></block></value><value name="ARG3"><block type="led_pin" id=".q/9|Grs%E++O#5z!HW("><field name="LED">LED2</field></block></value><next><block type="procedures_callnoreturn" id="^r,zfkd`(Z@^0P68)8GG"><mutation name="stelle Servo sanft"><arg name="von Pos in °"></arg><arg name="bis Pos in °"></arg><arg name="Tempo in %"></arg><arg name="Servo Pin"></arg></mutation><value name="ARG0"><block type="math_number" id="o^(y.cE!qbBHZEM0|[(L"><field name="NUM">180</field></block></value><value name="ARG1"><block type="math_number" id="+#~rbBHYS~_+G]$]%)MB"><field name="NUM">0</field></block></value><value name="ARG2"><block type="math_number" id="WBu]6!NK7Iuf4tc8K[C%"><field name="NUM">10</field></block></value><value name="ARG3"><block type="led_pin" id="w-v*:ho!s]wp.,s%}$O^"><field name="LED">LED2</field></block></value></block></next></block></statement></block><block type="procedures_defnoreturn" id="DYYovfp[/{/^ryWHZBvf" collapsed="true" x="-700" y="91"><mutation><arg name="Position in °" varid="_DQjdhaJfR6,f$7cgOQ7"></arg><arg name="Servo Pin" varid="Vw5IBG9C#Pa@r0U!+Bbh"></arg></mutation><field name="NAME">stelle Servo</field><statement name="STACK"><block type="variables_set" id="b*l`jfDpwv@_`yEQ:sQU"><field name="VAR" id="_DQjdhaJfR6,f$7cgOQ7">Position in °</field><value name="VALUE"><block type="math_map" id="wY2I~E@9)6mqH{`4}Min"><value name="VALUE"><block type="variables_get" id="sM%OH#-),/XvNLAfoDgM"><field name="VAR" id="_DQjdhaJfR6,f$7cgOQ7">Position in °</field></block></value><value name="FROMLOW"><block type="math_number" id="5*[TWQi3eTy;dTNqRejO"><field name="NUM">0</field></block></value><value name="FROMHIGH"><block type="math_number" id="3FohKj*x~t~gZ.sYtS2("><field name="NUM">180</field></block></value><value name="TOLOW"><block type="math_number" id="y+3B7BV,l3#e!tC#zP45"><field name="NUM">450</field></block></value><value name="TOHIGH"><block type="math_number" id="n[XOgoHB+-0i.,Gpwf%1"><field name="NUM">2550</field></block></value></block></value><next><block type="variables_set" id=".xsEB~Y8Qx!^%8P%)mh;"><field name="VAR" id="K:G4UACKdRDr(dE9O39G">Pos 1</field><value name="VALUE"><block type="math_arithmetic" id="{F9Honx#=x}}p5s6~3pd"><field name="OP">MINUS</field><value name="A"><block type="math_number" id="nN}B3!9SLvv*1{Zlf(%h"><field name="NUM">20000</field></block></value><value name="B"><block type="variables_get" id="mZbi[2Xx35m9qZ2Wz|b_"><field name="VAR" id="_DQjdhaJfR6,f$7cgOQ7">Position in °</field></block></value></block></value><next><block type="flow_repeat" id="gN=t~3M0%R7Pe)/i-V4G"><value name="REPEATS"><block type="math_number" id="+qOr!,*|C9.5wJ[w,ENN"><field name="NUM">4</field></block></value><statement name="DO"><block type="led_write_state" id="6!l6z?iL+={{9KAi,H|9"><value name="LED"><block type="variables_get" id="0L`R`5_!X{Az,9F)`Qac"><field name="VAR" id="Vw5IBG9C#Pa@r0U!+Bbh">Servo Pin</field></block></value><value name="VALUE"><block type="code_pin" id="+7pwX/P2*!~K,CbqH7gH"><field name="CODE_PIN">HIGH</field></block></value><next><block type="flow_delay_micro" id="Y3736,h2Aea/$FEM%mGd"><value name="DELAY_MICRO"><block type="variables_get" id=")Lg-8viw{x?GWSZtdPfK"><field name="VAR" id="_DQjdhaJfR6,f$7cgOQ7">Position in °</field></block></value><next><block type="led_write_state" id="=R-dB9$gUgUf[f1#amX?"><value name="LED"><block type="variables_get" id="L{aTSjwfCBro[60WW.0E"><field name="VAR" id="Vw5IBG9C#Pa@r0U!+Bbh">Servo Pin</field></block></value><value name="VALUE"><block type="code_pin" id="ZI?r50,S}Q!N4EWcI9rk"><field name="CODE_PIN">LOW</field></block></value><next><block type="flow_delay_micro" id="7il;NbzoR^Es7say`(zt"><value name="DELAY_MICRO"><block type="variables_get" id="|@!H=EXua/xr-NRDCr5g"><field name="VAR" id="K:G4UACKdRDr(dE9O39G">Pos 1</field></block></value></block></next></block></next></block></next></block></statement></block></next></block></next></block></statement></block><block type="procedures_defnoreturn" id="c^Q=?l{x:FJ?Cm3Ncch(" collapsed="true" x="-701" y="146"><mutation><arg name="von Pos in °" varid="DoyC0N[TR?Wtuv+]QNjk"></arg><arg name="bis Pos in °" varid="8M|lsZfG.{JMk^B,=:P["></arg><arg name="Tempo in %" varid="|H,0pDre=%.#lJkTh33Q"></arg><arg name="Servo Pin" varid="Vw5IBG9C#Pa@r0U!+Bbh"></arg></mutation><field name="NAME">stelle Servo sanft</field><statement name="STACK"><block type="flow_for" id="MoL^$qp,s]q|#V}PCNel"><field name="VAR" id="_DQjdhaJfR6,f$7cgOQ7">Position in °</field><value name="FROM"><block type="math_number" id="V;Ieuii8?o:Tnb.0[a[N"><field name="NUM">0</field></block></value><value name="TO"><block type="math_number" id="^-^,ZT.?5jVw*o/}OAU@"><field name="NUM">3.141</field></block></value><value name="BY"><block type="math_map" id="XD^P~Qk|P($W8{5DOc}p"><value name="VALUE"><block type="variables_get" id="E?Zd6*s)DOd5/Y_5,2lM"><field name="VAR" id="|H,0pDre=%.#lJkTh33Q">Tempo in %</field></block></value><value name="FROMLOW"><block type="math_number" id="%GC=-JD8|y;:B[[f[n#U"><field name="NUM">0</field></block></value><value name="FROMHIGH"><block type="math_number" id=".ZWBxd~-|{*~cc2o9|q7"><field name="NUM">100</field></block></value><value name="TOLOW"><block type="math_number" id="f%@Q!+NEovExdlCD_d#n"><field name="NUM">0.001</field></block></value><value name="TOHIGH"><block type="math_number" id="relQ-8H6-k~[,FEIc#HH"><field name="NUM">0.1</field></block></value></block></value><statement name="DO"><block type="procedures_callnoreturn" id="h,f[+#.Bb}Xe`}luH7k@"><mutation name="stelle Servo"><arg name="Position in °"></arg><arg name="Servo Pin"></arg></mutation><value name="ARG0"><block type="math_map" id="mwXTpN_o):;]m;don~^w"><value name="VALUE"><block type="math_trig" id="*CoOOO~/KSP!ivteXph]"><field name="OP">COS</field><value name="NUM"><block type="variables_get" id="r@^JSALbD:Ryki$nBg.;"><field name="VAR" id="_DQjdhaJfR6,f$7cgOQ7">Position in °</field></block></value></block></value><value name="FROMLOW"><block type="math_number" id="{w-,lfw.uDu:8c/o=obQ"><field name="NUM">1</field></block></value><value name="FROMHIGH"><block type="math_number" id="Xa^2u$_Kn+/@4V/)o(-j"><field name="NUM">-1</field></block></value><value name="TOLOW"><block type="variables_get" id="wU4r,RDpQh@jfxg;EcxR"><field name="VAR" id="DoyC0N[TR?Wtuv+]QNjk">von Pos in °</field></block></value><value name="TOHIGH"><block type="variables_get" id="8P)Er_m+.;4yannpX11Q"><field name="VAR" id="8M|lsZfG.{JMk^B,=:P[">bis Pos in °</field></block></value></block></value><value name="ARG1"><block type="variables_get" id="$cU5xUL=@X?`I5bGb%`r"><field name="VAR" id="Vw5IBG9C#Pa@r0U!+Bbh">Servo Pin</field></block></value></block></statement></block></statement></block></xml>

3. Challenge: Arduino Servo Projekte im Technischen Gestalten

3.1. Figur mit Servo und Mikrofon nach Musik steuern

Kopiere diesen XML-Code mit Klick/Berührung und füge ihn in den PGLU-Editor ↗ ein:

<xml xmlns="https://developers.google.com/blockly/xml"><variables><variable id="_DQjdhaJfR6,f$7cgOQ7">Position in °</variable><variable id="Vw5IBG9C#Pa@r0U!+Bbh">Servo Pin</variable><variable id="K:G4UACKdRDr(dE9O39G">Pause</variable></variables><block type="basic_comment" id="H~UW;?gR9HL56l!+P|SL" x="-99" y="37"><field name="COMMENT">Servo musikgesteuert für Spielfigur</field></block><block type="basic_comment" id="|.$x+yKiz`j-,~[?eRLs" x="-583" y="121"><field name="COMMENT">Nicht löschen, dies ist die Servofunktion</field></block><block type="basic_main_loop" id="9~210UV)!{|GniQxFn|[" deletable="false" x="-99" y="117"><value name="BLINK"><block type="basic_blinkcode" id="u@6%knhMhK2g(1JYw[10"><field name="SHORT">1</field><field name="LONG">1</field></block></value><statement name="CODE"><block type="logic_if" id="JAlKzh~SRm]hEK1YRmz4"><value name="IF0"><block type="logic_compare" id="i+2,yH0fhu1HpCV3cRyx"><field name="OP">GT</field><value name="A"><block type="sensor_read_percentage" id="^Y-Mi@=UVAzrZb/v0:Yf"><value name="SENSOR"><block type="sensor_pin" id="{]i(hc+pMRvqdZ+yiltp"><field name="SENSOR">SENSOR3</field></block></value></block></value><value name="B"><block type="math_number" id="TaY=h]:-|RmTv7xSqBy5"><field name="NUM">60</field></block></value></block></value><statement name="DO0"><block type="procedures_callnoreturn" id="h,f[+#.Bb}Xe`}luH7k@"><mutation name="stelle Servo"><arg name="Position in °"></arg><arg name="Servo Pin"></arg></mutation><value name="ARG0"><block type="math_random_int" id="a%ltJl@t(:`H/mN8a}`o"><value name="FROM"><block type="math_number" id="WO3mh5S68i@kGnsq#i7T"><field name="NUM">0</field></block></value><value name="TO"><block type="math_number" id="?!B*NfP9$a:%245`VqA,"><field name="NUM">180</field></block></value></block></value><value name="ARG1"><block type="led_pin" id=".q/9|Grs%E++O#5z!HW("><field name="LED">LED2</field></block></value><next><block type="flow_delay" id="6N*Cs1y$8`$2]{M=gh2["><value name="DELAY"><block type="math_number" id="_owfS^Z:VFf7RN*SpTG4"><field name="NUM">200</field></block></value></block></next></block></statement></block></statement></block><block type="procedures_defnoreturn" id="DYYovfp[/{/^ryWHZBvf" collapsed="true" x="-581" y="165"><mutation><arg name="Position in °" varid="_DQjdhaJfR6,f$7cgOQ7"></arg><arg name="Servo Pin" varid="Vw5IBG9C#Pa@r0U!+Bbh"></arg></mutation><field name="NAME">stelle Servo</field><statement name="STACK"><block type="variables_set" id="b*l`jfDpwv@_`yEQ:sQU"><field name="VAR" id="_DQjdhaJfR6,f$7cgOQ7">Position in °</field><value name="VALUE"><block type="math_map" id="wY2I~E@9)6mqH{`4}Min"><value name="VALUE"><block type="variables_get" id="sM%OH#-),/XvNLAfoDgM"><field name="VAR" id="_DQjdhaJfR6,f$7cgOQ7">Position in °</field></block></value><value name="FROMLOW"><block type="math_number" id="5*[TWQi3eTy;dTNqRejO"><field name="NUM">0</field></block></value><value name="FROMHIGH"><block type="math_number" id="3FohKj*x~t~gZ.sYtS2("><field name="NUM">180</field></block></value><value name="TOLOW"><block type="math_number" id="y+3B7BV,l3#e!tC#zP45"><field name="NUM">400</field></block></value><value name="TOHIGH"><block type="math_number" id="n[XOgoHB+-0i.,Gpwf%1"><field name="NUM">2600</field></block></value></block></value><next><block type="variables_set" id=".xsEB~Y8Qx!^%8P%)mh;"><field name="VAR" id="K:G4UACKdRDr(dE9O39G">Pause</field><value name="VALUE"><block type="math_arithmetic" id="{F9Honx#=x}}p5s6~3pd"><field name="OP">MINUS</field><value name="A"><block type="math_number" id="nN}B3!9SLvv*1{Zlf(%h"><field name="NUM">20000</field></block></value><value name="B"><block type="variables_get" id="mZbi[2Xx35m9qZ2Wz|b_"><field name="VAR" id="_DQjdhaJfR6,f$7cgOQ7">Position in °</field></block></value></block></value><next><block type="flow_repeat" id="gN=t~3M0%R7Pe)/i-V4G"><value name="REPEATS"><block type="math_number" id="+qOr!,*|C9.5wJ[w,ENN"><field name="NUM">10</field></block></value><statement name="DO"><block type="led_write_state" id="6!l6z?iL+={{9KAi,H|9"><value name="LED"><block type="variables_get" id="0L`R`5_!X{Az,9F)`Qac"><field name="VAR" id="Vw5IBG9C#Pa@r0U!+Bbh">Servo Pin</field></block></value><value name="VALUE"><block type="code_pin" id="+7pwX/P2*!~K,CbqH7gH"><field name="CODE_PIN">HIGH</field></block></value><next><block type="flow_delay_micro" id="Y3736,h2Aea/$FEM%mGd"><value name="DELAY_MICRO"><block type="variables_get" id=")Lg-8viw{x?GWSZtdPfK"><field name="VAR" id="_DQjdhaJfR6,f$7cgOQ7">Position in °</field></block></value><next><block type="led_write_state" id="=R-dB9$gUgUf[f1#amX?"><value name="LED"><block type="variables_get" id="L{aTSjwfCBro[60WW.0E"><field name="VAR" id="Vw5IBG9C#Pa@r0U!+Bbh">Servo Pin</field></block></value><value name="VALUE"><block type="code_pin" id="ZI?r50,S}Q!N4EWcI9rk"><field name="CODE_PIN">LOW</field></block></value><next><block type="flow_delay_micro" id="7il;NbzoR^Es7say`(zt"><value name="DELAY_MICRO"><block type="variables_get" id="|@!H=EXua/xr-NRDCr5g"><field name="VAR" id="K:G4UACKdRDr(dE9O39G">Pause</field></block></value></block></next></block></next></block></next></block></statement></block></next></block></next></block></statement></block><block type="basic_comment" id="=jdt/;MG.`}zUK2z?3k[" x="415" y="157"><field name="COMMENT">Mikrofon an S3</field></block></xml>

3.2. Arduino Push Rollbot

Tipp: Lasse einen Fotowiderstand ↗ erkennen, ob sich das Servo in der Nähe des Bodens befindet, weil es dann dunkler wird.

3.3. Arduino Soap Bubble Machine

3.4. Arduino Servo Draw Bot

3.5. Arduino Bug

3.6. Animalische Roboter (Boston Dynamics)

3.7. Robot Contest