Making Things Interactive

February 12, 2008

reminder on posting source code – update

Please remember that wordpress is very picky when it comes to the tag. It seems that Windows is being “helpful” by giving you left and right single quotes like this: `’ using the grave accent and the apostrophe. This will break the sourcecode tag, and your code will not be formatted properly.

What you need to do is make sure that both quote marks are the apostrophe character: ‘ . The easiest way to do this is find the single quote before “cpp”, delete it, and manually type in the apostrophe character.

It’s the difference between these two lines:
language=`cpp’
language=’cpp’

Edit: It would seem that my browser is also being “helpful”. When I view this page, a single apostrophe — ‘ — is rendered differently than how two apostrophes around text — ‘foo’ — are rendered. The lesson being, don’t cut-n-paste the tag, type it in directly.

Edit: Also, remember that spaces aren’t allowed around the “=” sign.

Controlling a DC motor and Solenoid

Filed under: 5: Making Motion, Tiffany Yang — tyang1 @ 9:17 pm

My project uses a potentiometer to change the speed of the motor.  On a different pin, a solenoid is just opening and closing.       

int MotPin = 9;                                  // sets base of motor transistor to PWM 9
int potPin = 0;                                  // sets potentiometer to analog 0
int potValue = 0;                                // value returned from the potentiometer

int SolPin = 1;                                  // sets base of solenoid transistor to digital 1
int switchPin = 3;                              // sets switch pin to digital 3
int switchStatus;                                // status of the switch

void setup() {
  pinMode(MotPin, OUTPUT);                       // sets motor transistor pin as output
  pinMode(potPin, INPUT);                        // sets potentiometer pin as input
  pinMode(SolPin, OUTPUT);                       // sets solenoid transistor pin as output
  pinMode(switchPin, INPUT);                     // sets switch pin as input
  Serial.begin(9600);
}

void loop() {
  potValue = analogRead(potPin) / 4;             // read potentiometer, convert to 0 - 255
  analogWrite(9, potValue);                      // use potentiometer to control transistor

  switchStatus = digitalRead (switchPin);        // reads status of switch
  if (switchStatus == HIGH) {                    // If switch is pressed...
    digitalWrite(SolPin, HIGH);                  // turn solenoid on
    Serial.println("button pressed");
    delay(100);
  }
    else {                                       //  otherwise ...
    digitalWrite(SolPin, LOW);                   // turn solenoid off
    Serial.println("button not pressed");
    delay(100);
  }
}

      

Making Motion

Filed under: 5: Making Motion, Assignments, Paul Castellana — paulcastellana @ 2:54 pm

For this assignment, I used a potentiometer to control a DC motor and a servo simultaneously. The speed of the DC changes as you turn the potentiometer, as does the position of the servomotor. At this point my only goal was to produce some sort of variation in the movement of both motors, but it would be useful to further investigate the exact relationship between the turn of the potentiometer and the change in the motors. As it is now, with both motors powered at the same time, the servo is very jumpy and somewhat unpredictable, where as if I turn off the power to the DC motor, the servo runs more smoothly. I’m not sure what the cause of this is… possibly I have the diode in the wrong place?


int potPin = 0;           // Analog in 0 connected to the potentiometer
int potValueT = 0;         // value returned from the potentiometer used to control transistor
int potValueS = 0;        // value returned from the potentiometer used to control Servomotor
int transistorPin = 9;    // connected to the base of the transistor

int servoPin = 2;         // Control pin for the servomotor
int minPulse = 500;       // Minimum servo position
int maxPulse = 2500;      // Maximum servo position
int pulse = 0;            // Amount to pulse the servo

long lastPulse = 0;       // the time in milliseconds of the last pulse
int refreshTime = 20;     // the time needed in between pulses

void setup() {

  pinMode(transistorPin, OUTPUT);  // set the transistor pin as output:
  pinMode(servoPin, OUTPUT);  // Set servo pin as an output pin
  pulse = minPulse;           // Set the motor position value to the minimum
  Serial.begin(9600);
}

void loop() {

  potValueT = analogRead(potPin) / 4;  // read the potentiometer, convert it to 0 - 255:
  analogWrite(9, potValueT);  // use that to control the transistor:

  potValueS = analogRead(potPin);      // read the potentiometer input
  pulse = (potValueS * 19) / 10 + minPulse;    // convert the analog value
                                            // to a range between minPulse
                                            // and maxPulse. 

  // pulse the servo again if rhe refresh time (20 ms) have passed:
  if (millis() - lastPulse >= refreshTime) {
    digitalWrite(servoPin, HIGH);   // Turn the motor on
    delayMicroseconds(pulse);       // Length of the pulse sets the motor position
    digitalWrite(servoPin, LOW);    // Turn the motor off
    lastPulse = millis();           // save the time of the last pulse

  }
}

Linear Actuator & Computer Fan

Filed under: 5: Making Motion, Brian Kish — bkish @ 2:50 pm

http://www.youtube.com/watch?v=fft-9HAuGLw

This is a very simple project that controls a computer fan and a linear actuator. It is able to turn each device on and off. The linear actuator is supposed to use 24V DC and I do have a 24v Lambda power supply to power it. However, I still am not to good at this and the 24v kind of scares me :) I nearly welded the ground and positive wire together and fried an LED and I think possible one of the servos I borrowed :( Therefore, I am now powering it off of a 9V battery.

The next step I would like to take is to understand how to use an H-Chip or the DC Motor Controller that I borrowed so that I could use it to make the linear actuator go in and out (it only goes in right now). I also attempted to use a servo, but every time I connected, the Arduino just shut off.

/*  This is a simple system that is used to control a computer fan and a linear actuator. It currently is only able to make the actuator retract.
*/
int fanPin = 10;                      //  powers fan
int actuatorPin = 12;                 //  powers actuator
int statusPin = 13;                   //  flashing LED tells when the system is running
int highSpeed = 255;                  //  set the speed to 'maximum'
int lowSpeed = 0;                     //  set speed to 'off'
void setup()
{
pinMode(fanPin, OUTPUT);              //  sets the fanPin as an output
pinMode(statusPin, OUTPUT);           //  sets the status pin to output
pinMode(actuatorPin, OUTPUT);         //  sets the actuatorPin to output
}
void loop()
{
analogWrite(fanPin, highSpeed);      //  tells fan to spin at 'maximum' when on high
analogWrite(actuatorPin, highSpeed); //  telss actuator to move at 'maximum' when turned to high
digitalWrite(statusPin, HIGH);       //  turns status LED on
digitalWrite(actuatorPin, HIGH);     //  turns actuator on
digitalWrite(fanPin, HIGH);          //  turns fanPin on
delay(5000);                         //  waits 0.5 seconds
digitalWrite(statusPin, LOW);        //  turns status LED off
digitalWrite(actuatorPin, LOW);      //  turns actuator off
digitalWrite(fanPin, LOW);           //  turns Fan off
analogWrite(actuatorPin, lowSpeed);  //  tells fan to spin at 'off' when on Low
analogWrite(fanPin,lowSpeed);        //  tells actuator to move at 'off' when turned to low
delay(5000);
}

Fan, knife

Filed under: 5: Making Motion, Lea — tovelet @ 2:17 pm

For this exercise, I got to box of motors too late to borrow one, and decided that I would instead use whatever spare motors I could find in my house. I had a few stepper motors and a DC fan which drives air into four tubes. We worked with the steppers in a class I took last semester. One of them already had a convenient laser cut mount, and I still had the integrated circuit that we used, so I just wanted to make the same setup work again (and hopefully actually understand it this time).

Although I could not find any specifications online for the motors I had, Tom Igoe’s page about stepper motor control was very helpful, and I figured that I had a unipolar stepper, and that the two matching leads were probably the center connections to the coils. I adapted his code, which uses the Arduino Stepper library.

The DC fan was simply the circuit and code presented in class last Thursday (see page 2 of the notes). I found the diagrams here and here to be useful in translating the circuit diagram into a breadboard layout. I didn’t have any diodes of the non-light-emitting variety, so I just used what I had, and they served as nice indicators as well.

A 9V battery seems to be sufficient to power the stepper motor; the fan was more powerful with the 12V wall adapter.

The plan, once I had the stepper and fan working, was to create a device that inflated a plastic bag and, on button press, attacked it with a knife. After taping a blade to the swinging arm of the stepper, I found that the bag was fairly resilient to slicing attacks. Since the device was approximately as comically futile with and without the knife, I removed the blade to minimize robot-related injuries in the near future.

/*
 Stress device

 This program swings a knife on a stepper motor to strike a bag being filled by a DC fan,
 based on stepper motor code by Tom Igoe (http://www.tigoe.net/pcomp/code/category/code/arduinowiring/51)
 and DC motor code and wiring diagram from ITP (http://itp.nyu.edu/physcomp/Tutorials/HighCurrentLoads) 

 It uses the built-in Stepper library.

 */

#include <Stepper.h>

#define motorSteps 200     // I don't actually know how many steps my motor has,
                           // but this seems to give good results.
#define motorPin1 8
#define motorPin2 9
#define motorPin3 10
#define motorPin4 11
#define ledPin 13

int fanPin=4;
int switchPin=12;
int buttonPress=1;

// initialize the Stepper library:
Stepper myStepper(motorSteps, motorPin1,motorPin2,motorPin3,motorPin4); 

void setup() {
  // set the motor speed at 60 RPMS:
  myStepper.setSpeed(60);

  // set up the pins:
  pinMode(ledPin, OUTPUT);
  pinMode(fanPin, OUTPUT);
  pinMode(switchPin, INPUT);
}

void loop() {
  digitalWrite(fanPin, HIGH);
  if (digitalRead(switchPin) == HIGH)
  {
    myStepper.step(25);
    digitalWrite(fanPin, LOW);
    delay(500);

    myStepper.step(-25);
    delay(500);
  }
}

Arduino Theremin

Filed under: 5: Making Motion — Dae @ 1:24 pm

I am trying to make a theremin with my Arduio. I used a ultrasonic distance sensor to detect the distance from the sensor to hand gesture. To make a complete theremin, I need two sensors; one for pitch and the other for volume. I couln’t figure out how to control the volume of the pulse with the other sensor, yet.

/* Make basic version of Theremin with Arduino and Ultrasound Sensor
* for Making Things Interactive Class
* by Dae Hong Kim
*/

int ultraSoundSignal = 7;
int toSpeaker = 10;
int val;

void setup()
{
beginSerial(9600);  //Sets the baud rate to 9600
pinMode(toSpeaker, OUTPUT);  //set speaker pin to output
}

int getPing()  //send a 10us pulse to wake up the sonar
{
pinMode(ultraSoundSignal, OUTPUT);
digitalWrite(ultraSoundSignal, HIGH);
delayMicroseconds(10);
digitalWrite(ultraSoundSignal, LOW);

pinMode(ultraSoundSignal, INPUT);
return pulseIn(ultraSoundSignal, HIGH);  //return this value
}

void loop()
{
val = getPing();
digitalWrite(toSpeaker, HIGH);
delayMicroseconds(val);
digitalWrite(toSpeaker, LOW);
delayMicroseconds(val);
}

Arduino + Servo + DC Motor

Filed under: 5: Making Motion, Jesse Chorng — Jesse @ 12:47 pm

Nothing crazy going on here. Just a pulsing status LED along with a DC motor speeding all the way up and all the way down. It is powered by the 9V batter clip the starter kit came with. The servo, powered by 5V from the board, is only moving between two positions.  You don’t see much in the video but you can hear the motors changing along with the LED. 

/*
 *  Arduino Motor Control
 */

int count = 5;                      
int statusPin = 11;                  
int servoPin = 10;               
int motorPin = 9;                  

void setup()                      
{
  pinMode(statusPin, OUTPUT);        
  pinMode(servoPin, OUTPUT);      
  pinMode(motorPin, OUTPUT);       
}

void loop()                       
{
  for (count = 5 ; count <= 255 ; count += 5)   // Count by 5 to gradually increase steps
  {
        analogWrite(statusPin, count);             
        analogWrite(servoPin, 180);           
        analogWrite(motorPin, count);             
        delay(50);                             
  }
  for (count = 255 ; count >= 5 ; count -= 5)   // Count down by 5 to gradually decrease steps
  {   
        analogWrite(statusPin, count);            
        analogWrite(servoPin, 60);           
        analogWrite(motorPin, count);             
        delay(50); 
  }
}

Don Quixote

Filed under: 5: Making Motion, Assignments, Nadeem Haidary — nhaidary @ 4:01 am

For my MakingMotion project I decided to recreate the scene of Don Quixote charging into the windmill. The motor runs a windmill and our hero, Don Quixote, charges on a servo controlled by a potentiometer. I tried to modify the rotational speed of the windmill with a sin wave to give a more natural wind, but the numbers don’t seem to be accurately controlling the motor.


/*
 DON QUIXOTE
 by Nadeem Haidary

 with code from
 "Servo control from an analog input"
 by Tom Igoe
 additions by Carlyn Maw
 */

int transistorPin = 9;              // connected to the base of the transistor
int transistorValue = 180;          // initial value for motor speed (through transistor)
float angle = 0.0;                    // angle for sin-value that modifies windmill speed

int servoPin = 2;                   // Control pin for servo motor
int minPulse = 500;                 // Minimum servo position
int maxPulse = 2500;                // Maximum servo position
int pulse = 0;                      // Amount to pulse the servo

long lastPulse = 0;                 // the time in milliseconds of the last pulse
int refreshTime = 25;               // the time needed in between pulses

int potentiometerValue = 0;         // the value returned from the potentiometer
int potentiometerPin = 0;           // the analog pin reading the potentiometer

//-------------------------------------------------------------------

void setup() {
  pinMode(transistorPin, OUTPUT);   // Set transistor pin as an output pin
  pinMode(servoPin, OUTPUT);        // Set servo pin as an output pin
  pulse = minPulse;                 // Set the motor position value to the minimum
  Serial.begin(9600);
}

//-------------------------------------------------------------------

void loop() {

  //-----DC MOTOR-----
  angle += 0.001;                                        // Modify how quickly the windspeed changes
  float sinval = sin(angle);                             // Use sin to vary windspeed
  int windSpeed = (int)(255 + (sinval * 255))/2;         // Convert sin to motor speed (0-255)
  transistorValue = windSpeed;                           // Transfer windspeed to motor
  Serial.println(transistorValue);
  analogWrite(9, transistorValue);                       // Turn the DC motor on

  //-----SERVO-----
  potentiometerValue = analogRead(potentiometerPin);     // read the analog input
  pulse = (potentiometerValue * 19) / 10 + minPulse;     // convert the potentiometer value (0-1023)
                                                         // to a range between minPulse and maxPulse. 

  // pulse the servo again if rhe refresh time has passed:
  if (millis() - lastPulse >= refreshTime) {
    digitalWrite(servoPin, HIGH);                        // Turn the Servo on
    delayMicroseconds(pulse);                            // Length of the pulse sets the motor position
    digitalWrite(servoPin, LOW);                         // Turn the Servo off
    lastPulse = millis();                                // save the time of the last pulse
  }
}

Assignment 5

Filed under: 5: Making Motion, Assignments, Lingshui Wang — lingshui @ 2:27 am

So after talking to Jet, I decided to use a rangefinder offline, here I’m experimenting with the rangefinder (variable analog switch) and a servo motor, whenever the rangefinder detects motion, it sets the servo through a script, there is sometimes a slight delay because of the time delays in the servo script. Here’s the code and a video:


int servoPin = 10;                          //set servo to digital PWM pin 10
int rangeFinder = 0;                        //set rangefinder to analog 0
int val;
int val2;
int servoMode = 0;                          //set variable modes for servo

void setup ()
{
  Serial.begin(9600);                        //set up serial library
  pinMode (servoPin, OUTPUT);                //servo output
  pinMode (rangeFinder, INPUT);              //rangefinder input
}

void loop(){
  Serial.print("Value: ");
  Serial.println(val);                       //print value to monitor switch values
  val = analogRead(rangeFinder);
  delay(10);
  val2 = analogRead(rangeFinder);            //check values match before taking action
  if (val == val2) {
      if (val < 30) {                        //if resistance is less than 30...
          servoMode = 1;                     //run servomode 1
  if (servoMode == 1) {                      //servomode 1
          analogWrite (servoPin, 10);
          delay (1000);
          analogWrite (servoPin, 200);
          delay(1000);
  }
  if (servoMode == 0) {                      //servomode 0 (default)
    digitalWrite (servoPin, LOW);
  }
}}}

Assignment 5: Making Motion

Filed under: 5: Making Motion, Siddartha Butalia — sbutalia @ 1:43 am

For this assignment I wanted to understand the basics of motor control and how to switch using a transistor. On the other side, i wanted to experiement with photo sensors as I may end up using them in my end of year project. The program I wrote basically takes two analog inputs from two seperate photo sensors which are connected as switches, these in turn control individual motors. I experimented a lot with the analog inputs creating a calibration phase and implementing a sensitivity factor into the sensors. I found it to work quite well, and the calibration section was definetley (successfull under dark and light conditions). The one thing i noticed while fine tuning the sensors is that they are very tricks to use when there is one source of light and not much ambient light. If i had more time i would have wanted to incorporate more photosensors to actually try and analyze the environment, understanding whehter or not the light is ambient, or harsh directional through differences in calibration voltages.

Free Image Hosting at www.ImageShack.us

 heres the code:


int ledPin = 13; // defines the check pin
int CalPin = 12; // defines the Calibration LED Pin
int inputPin = 2; // defines input for sensor A
int inputPin1 = 3; // defines input for sensor B
int ValA = 0; // Initializes Sensor A reading
int ValB = 0; // Initializes Sensor B reading
int motorPin = 8; // defines output for motor A
int motorPin1 = 9; // defines output for motor B
int CalA = 0; // Initializes Sensor A calibration reading
int CalB = 0; // Initializes Sensor B calibration reading
float Sens = .85; // Defines the sensitivity of the photocells (0 - 1.0 "always on")

void setup() {

pinMode(ledPin, OUTPUT); // declare check LED Pin
pinMode(motorPin,OUTPUT); // declare Motor PinA
pinMode(motorPin1, OUTPUT); // declare Motor PinB
pinMode(12,OUTPUT); // declare Calibration Complete Pin
pinMode(inputPin, INPUT); // declare SensorA input Pin
pinMode(inputPin1, INPUT); // declare SensorB input Pin

Serial.begin(9600);
digitalWrite(CalPin, HIGH);
delay(500);
digitalWrite(CalPin, LOW);
delay(500);
CalA = analogRead(1); // Retrieve Ambient Light value for A
CalB = analogRead(0); // Retrieve Ambient Light value for B
digitalWrite(CalPin, HIGH); // Confirms Calibration Complete
delay(500);
digitalWrite(CalPin,LOW);
}

void loop(){

ValA = analogRead(1); // Retrieve Light value Sensor A
ValB = analogRead(0); // Retrieve Light value Sensor B

if (ValA > CalA*Sens) { // check if the input is larger than the threshold (taken from calibration & sensitivity factor)
digitalWrite(ledPin, LOW); // turn check LED OFF
digitalWrite(motorPin,LOW); // turn Motor A OFF
}
else {
digitalWrite(ledPin, HIGH); // turn check LED ON
digitalWrite(motorPin,HIGH); // turn Motor A ON
}

if (ValB > CalB*Sens) { // check if the input is larger than the threshold (taken from calibration & sensitivity factor)
digitalWrite(ledPin, LOW); // turn check LED OFF
digitalWrite(motorPin1,LOW); // turn Motor B OFF
}
else {
digitalWrite(ledPin, HIGH); // turn check LED ON
digitalWrite(motorPin1,HIGH); // turn Motor B ON
}
}

Blog at WordPress.com.