Close

Week 6

A project log for Reaction Wheel Self Balancing Cube

This project attempts to prototype a self balancing cube using three reaction wheels

dami-kimDami Kim 03/21/2025 at 08:050 Comments

Feb 16 - 22

const int potentiometerPin = A0;  // Potentiometer connected to analog pin A0
#define PWM_PIN 9      // Yellow - Speed control (PWM)
#define START_PIN 8    // Blue - Start/Stop
#define DIR_PIN 7      // Green - Direction (CW/CCW)
#define BRAKE_PIN 4    // White - Brake (GND = brake, Floating = release)

void setup() {
    pinMode(START_PIN, OUTPUT);
    pinMode(DIR_PIN, OUTPUT);
    pinMode(BRAKE_PIN, OUTPUT);

    // Set default motor state
    digitalWrite(START_PIN, HIGH);  // Start motor
    digitalWrite(DIR_PIN, LOW);     // Default: CW rotation
    digitalWrite(BRAKE_PIN, HIGH);  // Release brake

    Serial.begin(9600);
    pinMode(9, OUTPUT);  // Set pin 9 as output for tone generation
}

void loop() {
  // Read the potentiometer value
  int potValue = analogRead(potentiometerPin);

  // Map the potentiometer value to the desired frequency range
  int frequency = map(potValue, 0, 1023, 1000, 26000);

  // Generate tone on pin 9
  tone(PWM_PIN, frequency);
  Serial.print(frequency);
  Serial.println(" Hz");
}

Discussions