Half size line follower

Step 4 PWM Outputs
LEDs & Motors
Step 4

So far we have been outputting signals to Pins as 0 or 1: ON that is OFF
This step shows how to output a variable signal between 0 and 1.
A signal that can dim an LED gradually, or drive a motor at different speeds.

 
  The output is actually always 0 or 1.

  It is automatically switched between the two with a ratio
  which Pico program controls with the duty() method of the PWM output.

This is the python code you need to set up a Pulse Width Modulation output.
do this at the start of your program
Having set up the outputs you also have to set up the speed at which the pulses go on and off
You may have heard the motors on the UKMARSBOT whistling.
This is because of the PWM frequency is within the audible range

Finally the program needs to set the proportion of time the PWM signal is on or off
this is called the duty ratio, and is controlled by the PWM's duty_u16() method.
Step 4a

This step shows how to drive the motors at different speeds.
Also, how to drive them backwards.

The diagram below shows how the transistors are used to steer the electrical
current to flow forwards, or backwards through the motor,(at the centre).
 
  The motor is fed via four transistors.

  These are labelled fwd and rev in the diagram.
  If both fwd ones are on then the motor goes forwards.

  If both rev ones are on then the motor goes backwards.

You need to have set up the 2 PWM pins for each motor as above.

Also set the freq() for each to be 1000

Then you need to set the duty ratio, of the fwd and rev PWM outputs
according to the speed (forwards or backwards) you want for the motor.

Full speed ahead

Half speed backwards

© Copyright St Albans Robots