How do servo motors work?

Learn It

  • A servomechanism (servo) can refer to quite a few different machines that have been around longer than most may realize. Essentially, a servo is any motor-driven system with a feedback element built in. Servos are found everywhere from heavy machinery, to power steering in vehicles, to robotics and a wide variety of electronics.
  • There are 2 types of servo motors:
    • A standard hobby or “closed-loop" servo will have a movement range of 90 or 180 degrees. Some will be slightly greater or lesser than the specified range, so check the specifications of the motor you wish to use before implementing it in your project. Standard servos provide feedback for the controller to monitor its position on the movement arc over the control signal wire. This allows you to move the servo to precise locations with the right pulse length from your controller.
    • Continuous rotation or “open-loop" servos do not work like the standard servo. The control signal only controls direction and speed, not position. These enable you to easily control how fast the drive shaft is moving and which direction it's going, but there's no feedback for position control, so they are not recommended for applications that require moving between specific points on the rotation arc.
  • For this project, we will be using the standard hobby servo.

Learn It

  • The microcontroller uses Pulse-Width Modulation (PWM) to drive the servo into the correct position. You have learned about PWM in the 555 fan project.
  • When connecting a servo, you need to ensure the pin is capable of PWM.
  • All 3 output of the Genie 08 can be used for PWM, although it is best to avoid G0 as it is also status and will pulse when connected to the computer, causing errors.

Try It

  • Let's build a simple circuit to try and get a GENIE chip to drive a servo motor
  • Use CircuitWizard to build the circuit shown below
  • When opening circuit wizard, you need to choose the 'Circuit with GENIE Flowchart' option.
  • You will find the Servo is under 'electromechanical' in the drop down menu (towards the bottom).
  • You will find the Genie 08 under 'microcontrollers' in the drop down menu.

analogueCirc1.png

  • We will now need to write a code to get the servo motor to turn.
  • Add the motor block to your flowchart.

  • Now you need to add the setting to the motor block.
  • Double click on the block and then select 'servo'

  • You will now need to select the position you want the motor to turn to.
  • Note, the range is from 75 to 225 (0 is not a position - this can be confusing as the usual analogue range is 0-255)
    • 75 = 0 degrees
    • 225 = 180 degrees
  • You will start with position 75. 
  • You will also need to select the output you have connected the servo to, in this case it is G2 (remember, G0 is to be avoided as it is also status)

  • After this is setup, you then need to add a wait and then repeat this code to move it to position 225 (180 degrees).
  • NOTE: you can also set the speed at which the motor takes to move the the set position when you are in the motor block settings.

  • You can now go back to the circuit diagram and run the program.

  • Micro-controllers can't detect resistances, they only read voltages. Let's have a look at the voltage drop between the input pin and ground for out circuit.
  • Recreate this circuit in Circuit Wizard and have a look at the voltage differences that are generated when the temperature levels reaching the thermistor are altered.
  • You will be able to view the analogue value changing when you change the light level by clicking on the 'View several monitor panes at once', this is on the right, highlighted in blue.
  • The voltmeter (V) can be found under 'Test Instruments' right at the bottom of the gallery.

 

 

  • As you can see, altering the temperature levels at the thermistor has a minimal to no effect on the voltage at the pin. While we could use a setup like this, we'd have a very insensitive detector.

Learn It

  • There's a way to provide a larger voltage differential at the pin, by adding a single resistor to the circuit.
  • We're going to create something called a potential divider.
  • The visualisation below shows a standard set up for a potential divider. You can use the slider to alter the resistance of the thermistor, and type in values for the resistor beneath it. Look at what happens to the voltage readings for Vout_.
 

Badge It - Silver

  • Now you know how to set up an analogue sensor on the GENIE chip, use Circuit Wizard to create a temperature monitoring circuit.
  • We'll also need a switch connected to a digital input. You've done this before when you made the digital die. Have a look at this resource if you need reminding about digital inputs.
  • Once you've completed the inputs for the circuit, take a screenshot.

2 Setting up visual outputs

Try It

  • We're going to need a couple of LEDs (one red and one green) attached to the digital outputs of the GENIE chip.
  • Don't forget that LEDs are sensitive to large currents can can 'pop' if the current is too high. A couple of 330 Ω resistors should be sufficient to protect them

Badge It - Gold

  • Create a flowchart program that causes the LEDs to alternately flash on and off when the temperature levels reaching the thermistor are high.

Badge It - Platinum

  • Create a flowchart program that saves the current temperature level reaching the thermistor in a variable, when the button is pushed.
  • The program should wait for a few seconds and then the LEDs should flash on and off if the temperature level goes above the recorded level.