Build a Wheel of Fortune with a 360-degree servo

FunduinoPublished on

Ein Zufallsgenerator mit 360-Grad-Servomotor und Taster

Ein Tastendruck, das Rad dreht sich für eine zufällige Zeit in eine zufällige Richtung und bleibt auf einem der farbigen Felder stehen: Mit einem 360°-Servomotor und einem Kurzhubtaster baust du ein kleines Glücksrad.

Dabei lernst du den Unterschied zwischen einem gewöhnlichen Servomotor und einem 360°-Servo kennen und arbeitest mit dem Zufallsgenerator des Arduino.

360-degree servo motor FS90R
The FS90R rotates continuously

You need this

FS90R Micro Servo 360° - Continuous Rotation, 4.8-6 V, 60 RPM FS90R Micro Servo 360° - Continuous Rotation, 4.8-6 V, 60 RPM 8,55 € *Item no. F23108874About the product — FS90R Micro Servo 360° - Continuous Rotation, 4.8-6 V, 60 RPM
12x12x6 mm pushbutton - 2 pins, 2.54 mm pitch, normally open 12x12x6 mm pushbutton - 2 pins, 2.54 mm pitch, normally open 0,49 € *Item no. F23106761About the product — 12x12x6 mm pushbutton - 2 pins, 2.54 mm pitch, normally open

All 2 parts together 9,04 € *Ready to ship immediately · Delivery time: 1-3 business days

* All prices include statutory VAT, plus shipping costs.

The 360-degree servo motor

A standard servo motor moves to a specific position. A 360° servo motor, on the other hand, can keep rotating continuously: instead of specifying a position, you specify a direction of rotation and a speed.

  • 0 – maximum speed clockwise
  • 90 – stop motor
  • 180 – maximum speed counterclockwise

The values in between determine the direction of rotation and speed. The closer a value is to 90, the more slowly the motor rotates.

The servo does not need to be connected to a PWM pin: the Servo library generates the signal using a timer and works on any digital pin.

360-degree servo motor FS90R
The FS90R rotates continuously

Connect the pushbutton and motor

For the prize wheel, you only need two components in addition to your microcontroller: a 360° servo motor and a momentary pushbutton.

Connect the motor to pin 9 and the button to pin 7. You don’t need to wire the button separately—the sketch enables the microcontroller’s internal pull-up resistor. This keeps the input HIGH, and pressing the button pulls it LOW.

If the servo draws a lot of current when starting up, it’s better to power it with a separate 5 V power supply and connect only GND and the signal wire to the microcontroller.

Wiring a servo motor and push button to an Arduino
The circuit diagram

The program

First, include the Servo library and declare the variables. Minimum and maximum determine how long the wheel rotates at least and at most.

In the setup section, connect the motor to pin 9, stop it with Motor.write(90), and start the random number generator. randomSeed(analogRead(0)) reads noise from an unconnected analog input so that the random values are different after each restart.

In the loop section, check the button. When it is pressed, random(0, 2) determines the direction of rotation, the motor rotates for a random number of milliseconds, and then stops.

The sketch does not debounce the button or wait for it to be released: if you hold the button down, the wheel keeps spinning. Also, the values Motor.write(80) and Motor.write(100) are close to the dead zone around 90, so the wheel spins very slowly. For a prize wheel, values closer to 0 and 180 work better.

Include the library and define variables
// eingebaute Bibliothek einbinden
# include "Servo.h"
// Name des Motors
Servo Motor;
// Minimum und Maximum der "Laufzeit" des Motors
int Minimum = 300;
int Maximum = 1500;
// Pin des Tasters
int Taster = 7;
// Variable für die Drehrichtung
int Drehrichtung;
The setup part
void setup()
{
  // Motor an Pin 9
  Motor.attach(9);
  // Motor anhalten
  Motor.write(90);
  // Zufallsgenerator starten
  randomSeed(analogRead(0));
  // INPUT_PULLUP: Taster als Eingang definieren, Eingang auf HIGH setzen
  pinMode(Taster, INPUT_PULLUP);
}
The loop section
void loop()
{
  // Check the button status
  int TasterLesen = digitalRead(Taster);
  // Button was pressed
  if (TasterLesen == LOW)
  {
    // Determine the direction of rotation randomly
    Drehrichtung = random(0, 2);
    // Rotate the motor clockwise
    if (Drehrichtung == 0) Motor.write(80);
    // Rotate the motor counterclockwise
    else Motor.write(100);
    // Rotate for a random number of milliseconds
    delay(random(Minimum, Maximum));
    // Stop the motor
    Motor.write(90);
  }
}

The template for the wheel of fortune

Attach a disc with colored sections to the servo motor's pointer. When the button is pressed, the motor turns for a random amount of time, and the pointer stops on one of the sections.

You can use the following template as a starting point: a circle with colored segments and an arrow for the pointer.

Template with a color-divided circle and pointer
Template for wheel and pointer
Rate the instructions

Comments

Ask a question or share an experience

Contact us if something doesn’t work. Please include your board and the error message.

We review every comment before publication. Your email address remains with us.