Mackay BurkePeyton SenffnerMalek HajahmadEvan Huber
Published © GPL3+

Throttle Control

This is a way to control the speed of a ride-on toy. this uses a potentiometer and a servo motor to vary the speed.

BeginnerShowcase (no instructions)4 hours114
Throttle Control

Things used in this project

Hardware components

Rotary potentiometer (generic)
Rotary potentiometer (generic)
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×1
Argon
Particle Argon
×1

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE

Story

Read more

Schematics

fritzing circuit diagram

how battery is connected with potentiometer

Code

Main

C/C++
this controls the reading of the voltage, current, and throttle amount. It allows the servo to be turned to 3 different positions based on a button input.
#include <Particle.h>
#include <Servo.h>

// Set up ADC pins for current and voltage readings
int currentPin = A0;
int voltagePin = A1;

// Set up ADC pin for throttle input
int throttlePin = A2;

// Set up button pin and servo
int buttonPin = D0;
Servo servo;

// Set servo positions
int position1 = 0; // Initial position
int position2 = 45; // Middle position
int position3 = 90; // End position

// Set up webhook to publish data to Adafruit IO
void publishData(double voltage, double current, double throttle) {
  String data = "{";
  data += "\"voltage\": " + String(voltage, 2) + ",";
  data += "\"current\": " + String(current, 2) + ",";
  data += "\"throttle\": " + String(throttle, 2) + "}";
  Particle.publish("car-data", data, PRIVATE);
}

void setup() {
  // Initialize serial communication
  Serial.begin(9600);

  // Set up ADC pins
  pinMode(currentPin, INPUT);
  pinMode(voltagePin, INPUT);
  pinMode(throttlePin, INPUT);

  // Set up button pin and attach interrupt
  pinMode(buttonPin, INPUT_PULLUP);
  attachInterrupt(buttonPin, buttonISR, FALLING);

  // Set up servo
  servo.attach(D1);
  servo.write(position1);
}

void loop() {
  // Read voltage and current
  double voltage = analogRead(voltagePin) * 0.00488;
  double current = analogRead(currentPin) * 0.000805;

  // Read throttle input
  double throttle = analogRead(throttlePin) * 0.00488;

  // Publish data to Adafruit IO dashboard
  publishData(voltage, current, throttle);

  // Wait for a few seconds before reading values again
  delay(5000);
}

void buttonISR() {
  // Determine current position of servo
  int currentPosition = servo.read();

  // Move servo to next position
  if (currentPosition == position1) {
    servo.write(position2);
  } else if (currentPosition == position2) {
    servo.write(position3);
  } else if (currentPosition == position3) {
    servo.write(position1);
  }
}

Credits

Mackay Burke
3 projects • 3 followers
I strive to be the next MAC
Contact
Peyton Senffner
2 projects • 0 followers
Contact
Malek Hajahmad
1 project • 0 followers
Contact
Evan Huber
1 project • 0 followers
Contact

Comments

Please log in or sign up to comment.