Project showcase

Balloon cart with Proportional Deceleration © GPL3+

A cart with a balloon is pulled toward a wall of spikes and must come to a stop within 2 centimeters without the balloon popping.

  • 633 views
  • 0 comments
  • 0 respects

Components and supplies

About this project

Project for my System Controls class at Cal Poly Pomona. The cart and balloon are pulled up the incline via a motor. The motor speed is controlled with pulse width modulation and decreases proportionally with its distance from the wall of nails through use of an ultrasonic sensor. Once the cart is within 2 centimeters of the spikes it reverses back down the ramp. The wall of nails is able to be manually moved anywhere along the Velcro rails without changing the system performance.

Code

Code to control motor shield proportionally with an ultrasonic range finder Arduino
Apologies for this code not being as simple consolidated as I could've made it but printing to the serial monitor helps with debugging the system when tuning.
#include <AFMotor.h>    //Adds Motor shield library

#define trigPin 7
#define echoPin 6  

float v;
int duration;
long distance;
long distance1;
long distance2;

AF_DCMotor motor(1);

void setup() {
  Serial.begin(9600);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);

  motor.setSpeed(200);
  motor.run(RELEASE);
}

void loop() {
  do{
  distance = (duration/2) /29.1; 
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(1000);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = (duration/2) /29.1;
  Serial.print("distance ");
  Serial.print(distance);
  Serial.println("cm");
  }while(distance <= 4 || distance > 40);

 do{
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(1000);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance1 = (duration/2) /29.1;
  Serial.print("distance1 loop ");
  Serial.print(distance1);
  Serial.println("cm");
  delay(100);
  v = ((float)distance1/(distance+1))*255;
  Serial.print("speed ");
  Serial.println(v);
  motor.run(FORWARD); 
  motor.setSpeed(v);
  Serial.println("Forward");
 }while(distance1 > 5);

motor.run(RELEASE);
motor.setSpeed(0);
delay(3000);

do{
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(1000);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance2 = (duration/2) /29.1;
  Serial.print("distance2 loop 2 ");
  Serial.print(distance2);
  Serial.println("cm");
  Serial.println("Backward");
  motor.run(BACKWARD);
  motor.setSpeed(150);
}while(distance2 <= 19);
motor.run(RELEASE);
delay(3000);
}

Comments

Similar projects you might like

Arduino Bluetooth Basic Tutorial

by Mayoogh Girish

  • 455,062 views
  • 42 comments
  • 239 respects

Home Automation Using Raspberry Pi 2 And Windows 10 IoT

Project tutorial by Anurag S. Vasanwala

  • 289,739 views
  • 96 comments
  • 677 respects

Security Access Using RFID Reader

by Aritro Mukherjee

  • 229,753 views
  • 38 comments
  • 239 respects

OpenCat

Project in progress by Team Petoi

  • 196,321 views
  • 154 comments
  • 1,364 respects
Add projectSign up / Login