Demos – 16-223 Work https://courses.ideate.cmu.edu/16-223/f2017/work Introduction to Physical Computing: Student Work Wed, 21 Feb 2018 02:22:37 +0000 en-US hourly 1 https://wordpress.org/?v=4.8.24 Tech Demo 3: Catapult! https://courses.ideate.cmu.edu/16-223/f2017/work/2017/10/09/tech-demo-3-catapult/ https://courses.ideate.cmu.edu/16-223/f2017/work/2017/10/09/tech-demo-3-catapult/#respond Mon, 09 Oct 2017 04:38:25 +0000 https://courses.ideate.cmu.edu/16-223/f2017/work/?p=1644

 

For our tech demo 3, Stone and I decided to make a catapult that would launch an object when a sensor notified the servo to move.  The sensor detected the distance between itself and a moving object and determined when to shoot.  We laser cut a base, 2 walls to hold a metal rod that would allow the catapult to actively and frictionlessly throw the ball, and  the catapult (thrower) itself.  The spring in the front allows for tension to build as a weight with a string attached keeps the catapult from moving.  When the servo moves, however, it pulls the weight from the catapult and the tension takes over and whips the catapult into action.


// ReadSonar - measure distance using a HC-SR04 or compatible ultrasonic ranger
//
// With the help of Garth Zieglin
================================================================================
// Define constant values.
#include <Servo.h>
// The wiring assignment.
const int TRIG_PIN = 8;
const int ECHO_PIN = 7;
const int SERVO_PIN = 9;
Servo servo;

// The rated distance limit of the sensor, in cm.
const int MAX_DISTANCE = 450;

// A typical speed of sound, specified in cm/sec.
const long SOUND_SPEED = 34000;

const long TIMEOUT = (2 * MAX_DISTANCE * 1000000)/SOUND_SPEED;

void setup()
{
// Initialize the serial UART at 9600 bits per second.
Serial.begin(9600);
servo.attach(SERVO_PIN);
servo.write(0);

// Initialize the trigger pin for output.
pinMode(TRIG_PIN, OUTPUT);
digitalWrite(TRIG_PIN, LOW);

// Initialize the echo pin for input.
pinMode(ECHO_PIN, INPUT);
}
// ================================================================================
// Run one iteration of the main event loop. The Arduino system will call this
// function over and over forever.
void loop()
{

long duration = ping_sonar(); // function is defined below

if (duration > 0) {
float distance = (duration * 1e-6 * SOUND_SPEED) / 2;
if(distance < 10){
servo.write(180);
}

} else {
// if no pulse detected
Serial.println("No ping.");
}

// Allow a little extra time for the sonar to recover.
delay(30);
}

long ping_sonar(void)
{
// Generate a short trigger pulse.
digitalWrite(TRIG_PIN, HIGH);
delayMicroseconds(10);
digitalWrite(TRIG_PIN, LOW);

// Measure the pulse length
return pulseIn(ECHO_PIN, HIGH, TIMEOUT);
}

Source:  Course Website (for parts of the code)

]]>
https://courses.ideate.cmu.edu/16-223/f2017/work/2017/10/09/tech-demo-3-catapult/feed/ 0
Tech Demo_03: Pop-Up Castle https://courses.ideate.cmu.edu/16-223/f2017/work/2017/10/08/tech-demo_03-pop-up-castle/ https://courses.ideate.cmu.edu/16-223/f2017/work/2017/10/08/tech-demo_03-pop-up-castle/#respond Mon, 09 Oct 2017 01:06:36 +0000 https://courses.ideate.cmu.edu/16-223/f2017/work/?p=1614 Created by : Alessandra and Ghalya

Inspired by the Game of Thrones opening with several castles slowly moving up from a flat plane through the spinning of an array of gears, we thought that we try just making one castle move up in a similar fashion.

The most difficult part of the design was making sure the paper castle could move up smoothly. This required several iterations of understanding where internal flaps and holders would be required to keep the structure stable.

For the actuation of moving the castle up vertically, we initially used a servo motor.

Finding that the servo was not strong enough to push through multiple layers of a castle, we turned to using a stepper motor.

The scripting for the stepper motor was relatively simple and similar to a servo with the exception if its ability to rotate 360 degrees (for this project we only needed 6/8 of a full rotation).  In terms of connection the stepper to the Arduino board, we did initially use a bridge and try to connect the motor.  However after a few failed attempts, we eventually just plugged it directly into the Arduino. Since a Nema17 stepper only needs 5V to run, it was able to work…..though probably not the best idea or method of powering a stepper.

</pre>
<div>#include <Stepper.h></div>
<div></div>
<div>const int stepsPerRevolution = 360;  // change this to fit the number of steps per revolution</div>
<div>// for your motor</div>
<div></div>
<div>// initialize the stepper library on pins 8 through 11:</div>
<div>Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);</div>
<div></div>
<div>void setup() {</div>
<div>  // set the speed at 60 rpm:</div>
<div>  myStepper.setSpeed(10);</div>
<div>  // initialize the serial port:</div>
<div>  Serial.begin(9600);</div>
<div>}</div>
<div></div>
<div>void loop() {</div>
<div>  // step one revolution  in one direction:</div>
<div>  Serial.println("clockwise");</div>
<div>  myStepper.step(-<wbr />stepsPerRevolution);</div>
<div></div>
<div></div>
<div>}</div>
<pre>

For a future iteration. We would look to take the movement of the gears to a third dimension and have horizontally facing gears help rotate multiple vertical gears.

]]>
https://courses.ideate.cmu.edu/16-223/f2017/work/2017/10/08/tech-demo_03-pop-up-castle/feed/ 0
Technical Demo 3: Nightmare Music Box https://courses.ideate.cmu.edu/16-223/f2017/work/2017/10/08/technical-demo-3-nightmare-music-box/ https://courses.ideate.cmu.edu/16-223/f2017/work/2017/10/08/technical-demo-3-nightmare-music-box/#respond Mon, 09 Oct 2017 00:54:08 +0000 https://courses.ideate.cmu.edu/16-223/f2017/work/?p=1606 Sorry, but you do not have permission to view this content. ]]> Sorry, but you do not have permission to view this content. ]]> https://courses.ideate.cmu.edu/16-223/f2017/work/2017/10/08/technical-demo-3-nightmare-music-box/feed/ 0 Tech Demo 3: Gumball Dispenser https://courses.ideate.cmu.edu/16-223/f2017/work/2017/10/08/tech-demo-3-gumball-dispenser/ https://courses.ideate.cmu.edu/16-223/f2017/work/2017/10/08/tech-demo-3-gumball-dispenser/#respond Sun, 08 Oct 2017 21:10:44 +0000 https://courses.ideate.cmu.edu/16-223/f2017/work/?p=1585

 

 

For Tech Demo 3, Rachel and I decided to make a simple gumball dispenser. A string attached to a servo operated by a switch uses a simple pulley mechanism to pull up the flap for gumballs to drop out.

To make the box and the spool for the pulley, we simply used the laser cutter. We had some trouble exporting the box to dimensions, so we had to improvise in order to get the box to fit in the laser cutting program. Rachel designed the spool using Autofusion 360.

#include <Servo.h>

Servo wiggling_servo;

const int SERVO_PIN = 9;
const int SWITCH_PIN = 2;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  // Initialize the Servo object to use the given pin for output.
  wiggling_servo.attach(SERVO_PIN);
  pinMode(SWITCH_PIN, INPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  int switchValue = digitalRead(SWITCH_PIN);
  int knockValue = analogRead(KNOCK_PIN);
  if (switchValue == 1) {
    wiggling_servo.write(360);
  }
  else {
    wiggling_servo.write(0);
  }
}

 

]]>
https://courses.ideate.cmu.edu/16-223/f2017/work/2017/10/08/tech-demo-3-gumball-dispenser/feed/ 0
Tech Demo 3: Gripping Arm https://courses.ideate.cmu.edu/16-223/f2017/work/2017/10/08/tech-demo-3-gripping-arm/ https://courses.ideate.cmu.edu/16-223/f2017/work/2017/10/08/tech-demo-3-gripping-arm/#respond Sun, 08 Oct 2017 20:06:09 +0000 https://courses.ideate.cmu.edu/16-223/f2017/work/?p=1562 Brandon Darreff and Evan Hill

For the tech demo 3, we created a gripping arm based on the motion of a finger curling. We aimed to find a simple solution that recreates the complex curling movement.

Mechanical Features:

We laser cut acrylic to make the arm and the base. The base was cut so that it fits together without glue and includes holes to easily mount the servos.  The arm is held together by hollow metal pins. These pins serve as the joints about which the arm moves as well as the structure for the tendons to be threaded through. Because acrylic does not glue well, we opted to drill smaller pins through the hollow pins. While this was more complicated, it led to a much sturdier and cleaner final result. Not using glue also ensured that our joints would rotate more freely as there was no spillover from other parts. To make the arm curl, we attached monofilament tendons which are threaded through the pins in the arm in an opposing fashion. When one tendon is pulled, the arm curls right and pulling the opposite tendon causes it to curl to the left. Each tendon runs from the servo arm to the tip of the arm. Using this setup, we were able to curl three links in both directions simply using two servos.

 

Sensors:

We included two photocells to make the arm more responsive to its environment. The photocells are positioned on opposing sides of the gripping arm. When one photocell senses less light than the other, the servos respond by curling the arm in the direction of the photocell with less light. This enables the arm to sense the presence of an object and move to grip it. As shown in the video, the photocells also react by curling in the opposite direction of a flashlight beam.

 

 

Code:

The code tells the arm to read the two photocells and curl in the direction with less light.

 

//import servo library
#include <Servo.h>;

//assign names to servos
Servo servo1;
Servo servo2;

//set photoresistor input pins as constants
const int sensorPin1 = A0;
const int sensorPin2 = A1;

//define photoresistor input and servo output variables
int photoIn1;
int photoIn2;
int servoOut1;
int servoOut2;

void setup(){

Serial.begin(9600);

//assign servos to digital pins
servo1.attach(9);

servo2.attach(10);

}

void loop(){

//define servo inputs based on photoresistor states
photoIn1 = analogRead(sensorPin1);

photoIn2 = analogRead(sensorPin2);

// if there is more light on sensorPin1 then curl servo2
if (photoIn1 > photoIn2) {
servo1.write(180);
servo2.write(180);
}
// if there is more light on sensorPin2 then curl toward servo1
else if (photoIn2 > photoIn1) {
servo2.write(0);
servo1.write(0);
}
}

 

Prototyping:

We made prototypes out of cardboard as a proof of concept for the curling motion using tendons. Our prototypes also allowed us to determine how far the tendon must be pulled to fully curl the arm.

 

Future Iterations:

If we were to make future iterations, the length of the links as well as the tendon path could be optimized for better movement. The current links are slightly too long and the tendon path is too complex which causes the arm to bind when the servos reach their max torque. One way to solve this is by turning the arm on its side so that the servos do not have to lift the full weight of the mechanism. Using two links instead of three would also lead to less binding and more predictable movements.

]]>
https://courses.ideate.cmu.edu/16-223/f2017/work/2017/10/08/tech-demo-3-gripping-arm/feed/ 0
Tech Demo 3: Hair Brushing Machine https://courses.ideate.cmu.edu/16-223/f2017/work/2017/10/08/tech-demo-3-hair-brushing-machine-2/ https://courses.ideate.cmu.edu/16-223/f2017/work/2017/10/08/tech-demo-3-hair-brushing-machine-2/#respond Sun, 08 Oct 2017 19:13:12 +0000 https://courses.ideate.cmu.edu/16-223/f2017/work/?p=1565

For Tech Demo 3, Warren and I created a hair brushing machine. A hair brush, attached to a rack and pinion drive, moves back and forth over a user’s head. The machine is activated using an ultrasonic sensor, so the brush will only move if someone’s head is in the correct location.

Here is our code. Much of it is adapted from the course website.


// TECH DEMO 3 HAIR BRUSHING MACHINE

//StepperSweep - move a stepper motor at different rates
//
// Copyright (c) 2016, Garth Zeglin. All rights reserved. Licensed under the
// terms of the BSD 3-clause license as included in LICENSE.
//
// This program assumes that:
//
// 1. A A4988 stepper motor driver is connected to pins 2 and 3.
// 2. A control potentiometer can vary the voltage on A0.
// 3. The serial console on the Arduino IDE is set to 9600 baud communications speed.

// ================================================================================
// Define constant values and global variables.

// Define the pin numbers on which the outputs are generated.
#define DIR_PIN 2 // The direction pin controls the direction of stepper motor rotation.
#define STEP_PIN 3 // Each pulse on the STEP pin moves the stepper motor one angular unit.
#define ENABLE_PIN 4 // Optional control of the driver power.

// Alternate definitions for the Protoneer CNC Shield board X axis.
// #define DIR_PIN 5
// #define STEP_PIN 2
// #define ENABLE_PIN 8

// ================================================================================
// Configure the hardware once after booting up. This runs once after pressing
// reset or powering up the board.

const int TRIG_PIN = 8;
const int ECHO_PIN = 7;

// The rated distance limit of the sensor, in cm.
const int MAX_DISTANCE = 600;

// A typical speed of sound, specified in cm/sec.
const long SOUND_SPEED = 34000;

// Determine the maximum time to wait for an echo. The maximum rated distance is
// 4.5 meters; if no echo is received within the duration representing this
// round-trip distance, stop measuring. The timeout is specified in
// microseconds.
const long TIMEOUT = (2 * MAX_DISTANCE * 1000000)/SOUND_SPEED;
void setup(void)
{
 // Initialize the stepper driver control pins to output drive mode.
 pinMode(DIR_PIN, OUTPUT); 
 pinMode(STEP_PIN, OUTPUT);
 pinMode(ENABLE_PIN, OUTPUT);

// Drive the /ENABLE pin low to keep the motor always energized.
 digitalWrite(ENABLE_PIN, LOW);
 
 // Initialize the serial UART at 9600 bits per second.
 Serial.begin(9600);
 
 pinMode(TRIG_PIN, OUTPUT);
 digitalWrite(TRIG_PIN, LOW);
 
 // Initialize the echo pin for input.
 pinMode(ECHO_PIN, INPUT);
} 
/****************************************************************/

void rotate_stepper(int steps, float speed)
{
 // Configure the direction pin on the stepper motor driver based on the sign
 // of the displacement.
 int dir = (steps &amp;gt; 0)? HIGH:LOW;
 digitalWrite(DIR_PIN, dir);

// Find the positive number of steps pulses to emit.
 int pulses = abs(steps);

// Compute a delay time in microseconds controlling the duration of each half
 // of the step cycle.
 // microseconds/half-step = (1000000 microseconds/second) * (1 step/2 half-steps) / (steps/second)
 unsigned long wait_time = 500000/speed;

// The delayMicroseconds() function cannot wait more than 16.383ms, so the
 // total delay is separated into millisecond and microsecond components. This
 // increases the range of speeds this function can handle.
 unsigned int msec = wait_time / 1000;
 unsigned int usec = wait_time - (1000*msec);
 
 // Loop for the given number of step cycles. The driver will change outputs
 // on the rising edge of the step signal so short pulses would work fine, but
 // this produces a square wave for easier visualization on a scope.
 for(int i = 0; i &amp;lt; pulses; i++) {
 digitalWrite(STEP_PIN, HIGH);
 if (msec &amp;gt; 0) delay(msec);
 if (usec &amp;gt; 0) delayMicroseconds(usec);

digitalWrite(STEP_PIN, LOW); 
 if (msec &amp;gt; 0) delay(msec);
 if (usec &amp;gt; 0) delayMicroseconds(usec);
 }
}
// ================================================================================
// Run one iteration of the main event loop. The Arduino system will call this
// function over and over forever.
void loop(void)
{
 // Begin the motion sequence with a few back-and-forth movements at faster and faster speeds.
 long duration = ping_sonar(); 
 
 
 if (duration &amp;lt; MAX_DISTANCE &amp;amp;&amp;amp; duration &amp;gt; 0) {
 
 float distance = (duration * 1e-6 * SOUND_SPEED) / 2;
 
 Serial.print("Ping: ");
 Serial.print(duration);
 Serial.print(" usec Distance: ");
 Serial.print(distance);
 Serial.println(" cm");
 
 // Convert to a distance. Note that the speed of sound is specified in
 // cm/sec, so the duration is scaled from microsecondst o seconds. The
 // factor of 2 accounts for the round-trip doubling the time.
 rotate_stepper( 200, 200);
 rotate_stepper( -200, 200);
 } else {
 // if no pulse detected
 Serial.println(duration);
 }
}
long ping_sonar(void)
{
 // Generate a short trigger pulse.
 digitalWrite(TRIG_PIN, HIGH);
 delayMicroseconds(10);
 digitalWrite(TRIG_PIN, LOW);

// Measure the pulse length
 return pulseIn(ECHO_PIN, HIGH, TIMEOUT);
}

/****************************************************************/

&lt;br data-mce-bogus="1"&gt;

]]>
https://courses.ideate.cmu.edu/16-223/f2017/work/2017/10/08/tech-demo-3-hair-brushing-machine-2/feed/ 0
Tech Demo 3: Whac-A-Mole https://courses.ideate.cmu.edu/16-223/f2017/work/2017/10/08/tech-demo-3-whac-a-mole/ https://courses.ideate.cmu.edu/16-223/f2017/work/2017/10/08/tech-demo-3-whac-a-mole/#respond Sun, 08 Oct 2017 17:40:11 +0000 https://courses.ideate.cmu.edu/16-223/f2017/work/?p=1543

We created a Whac-A-Mole game with solenoid moles and a two-digit score counter.

At random intervals, a random solenoid piston will extend. If the extended piston is hit within the time limit, it will fall and depress the button placed under it. The score then gets incremented.

Here’s the circuit diagram to show how the solenoid extension and feedback works:
(Modified from circuit images found in course webpage)

And here’s a glimpse of the actual circuit:

The scoring mechanism uses a Geneva drive to turn the ten’s digit wheel in discrete steps, one step per full rotation of the one’s digit:

Finally, this is a code that drives the whole game:

//====================================================================================
//Digital Port Definitions
#define HIT_TRIGGER 9
#define MOTOR_DIR 10
#define MOTOR_STEP 11
enum mole_t {MOLE_0, MOLE_1, MOLE_2, MOLE_3, MOLE_4, MOLE_5, MOLE_6, MOLE_7, MOLE_8};

//====================================================================================
//State Definitions
enum state_t {GAME_IDLE, NEW_MOLE, WAIT_HIT, WAS_HIT, NOT_HIT, GAME_OVER} game_state;
int mole;
int score;
int timer;

//====================================================================================
void setup() {
  //set up the moles
  pinMode(MOLE_0, OUTPUT); digitalWrite(MOLE_0, LOW);
  pinMode(MOLE_1, OUTPUT); digitalWrite(MOLE_1, LOW);
  pinMode(MOLE_2, OUTPUT); digitalWrite(MOLE_2, LOW);
  pinMode(MOLE_3, OUTPUT); digitalWrite(MOLE_3, LOW);
  pinMode(MOLE_4, OUTPUT); digitalWrite(MOLE_4, LOW);
  pinMode(MOLE_5, OUTPUT); digitalWrite(MOLE_5, LOW);
  pinMode(MOLE_6, OUTPUT); digitalWrite(MOLE_6, LOW);
  pinMode(MOLE_7, OUTPUT); digitalWrite(MOLE_7, LOW);
  pinMode(MOLE_8, OUTPUT); digitalWrite(MOLE_8, LOW);
  
  //set up hit feedback
  pinMode(HIT_TRIGGER, INPUT);

  //set up score-keeping motor
  pinMode(MOTOR_DIR, OUTPUT); 
  pinMode(MOTOR_STEP, OUTPUT);

  //initialize gamestate
  game_state = GAME_IDLE;
  score = 0;
}

void loop() {
  timer++;
  switch(game_state) {
    case GAME_IDLE:
      game_state = NEW_MOLE;
      break;
      
    case NEW_MOLE:
      new_mole();
      timer = 0;
      game_state = WAIT_HIT;
      break;
      
    case WAIT_HIT:
      if (!digitalRead(HIT_TRIGGER)) {
        digitalWrite(mole, LOW); 
        game_state = WAS_HIT;
      }
      else if (timer >= random(1000,3000)) {
        digitalWrite(mole, LOW);
        timer = 0; 
        game_state = NOT_HIT;
      }
      break;
      
    case WAS_HIT:
      score++;
      game_state = NEW_MOLE;
      digitalWrite(MOTOR_DIR, HIGH);
      for(int i = 0; i < 80; i++) {
        digitalWrite(MOTOR_STEP, HIGH); delay(1);
        digitalWrite(MOTOR_STEP, LOW);  delay(1);
      }
      break;

    case NOT_HIT:
      game_state = NEW_MOLE;
      break;
      
    case GAME_OVER:
      break;
      
  }
  delay(1);
}

void new_mole(){
  delay(random(1000));
  mole = random(9);
  digitalWrite(mole, HIGH); 
  delay(10);
}
]]>
https://courses.ideate.cmu.edu/16-223/f2017/work/2017/10/08/tech-demo-3-whac-a-mole/feed/ 0
Tech Demo 3: Drawing Machine https://courses.ideate.cmu.edu/16-223/f2017/work/2017/10/07/tech-demo-3-drawing-machine/ https://courses.ideate.cmu.edu/16-223/f2017/work/2017/10/07/tech-demo-3-drawing-machine/#respond Sun, 08 Oct 2017 00:29:38 +0000 https://courses.ideate.cmu.edu/16-223/f2017/work/?p=1534 Josh and I made a drawing machine with a planetary gear head. We attached the carrier plate for the smaller gears to a D/C motor and connected the motor to a switch to turn the machine on and off.

]]>
https://courses.ideate.cmu.edu/16-223/f2017/work/2017/10/07/tech-demo-3-drawing-machine/feed/ 0
Phil and Kaushik: Tech demo 3 https://courses.ideate.cmu.edu/16-223/f2017/work/2017/10/07/phil-and-kaushik-tech-demo-3/ https://courses.ideate.cmu.edu/16-223/f2017/work/2017/10/07/phil-and-kaushik-tech-demo-3/#respond Sat, 07 Oct 2017 20:26:22 +0000 https://courses.ideate.cmu.edu/16-223/f2017/work/?p=1514 Sorry, but you do not have permission to view this content. ]]> Sorry, but you do not have permission to view this content. ]]> https://courses.ideate.cmu.edu/16-223/f2017/work/2017/10/07/phil-and-kaushik-tech-demo-3/feed/ 0 Tech Demo 3: Basketball Catapult (John and Stone) https://courses.ideate.cmu.edu/16-223/f2017/work/2017/10/02/tech-demo-3-basketball-catapult-john-and-stone/ https://courses.ideate.cmu.edu/16-223/f2017/work/2017/10/02/tech-demo-3-basketball-catapult-john-and-stone/#respond Mon, 02 Oct 2017 12:20:18 +0000 https://courses.ideate.cmu.edu/16-223/f2017/work/?p=1463 Stone and I decided to make a basketball catapult as our project.  The idea is that a ball is tossed from the catapult into a netting or bucket, as in basketball, when a sensor is triggered.

(Our catapult – made from a base, a lens, a lens holder, and two squares designed with a hole in the center to allow essentially frictionless movement of the catapult)

(Our servo that will be used to stimulate the catapult)

(All together now)

 


#include <Servo.h>
const int SERVO_PIN = 9;
Servo wiggling_servo;
int x = 0;

void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
wiggling_servo.attach(SERVO_PIN);
}

void loop() {
if(x < 1){
wiggling_servo.write(0);
delay(50);
wiggling_servo.write(90);
delay(50);
wiggling_servo.write(180);
delay(100);
wiggling_servo.write(0);
x++;
}
}

]]>
https://courses.ideate.cmu.edu/16-223/f2017/work/2017/10/02/tech-demo-3-basketball-catapult-john-and-stone/feed/ 0