Making Things Interactive

March 2, 2008

assignment 6: servo and brightness

Filed under: 6: More Motion,Assignments,Gee Kim — gskim @ 12:40 am

Pic of the circuit setup

The angle of the servo changes as I turn the potentiometer. And when the value of the servo is at its highest, or when the angle of the servo is turned to its highest value of 93, the LED will gradually get bright.

pic of when servo val=93, and led gets brighter

And when the value of the servo is at its lowest, or when the angle of the servo is turned to its lowest value of 0, the LED will gradually get dim.

pic of when servo val=0, and led dims

here’s the circuit diagram: circuit diagram

here’s the code:

int servoPin = 3;     // connect servo to pin 3
int sensorPin = 2;    // connect potentiometer to pin 2
int brightness = 0;
int ledPin = 5;       // connect led to pin 5

void setup ()
  beginSerial (9600);            //
  pinMode (servoPin, OUTPUT);    // set servo as analog output
  pinMode (sensorPin, INPUT);    // set potentiometer as analog input
  pinMode (ledPin, OUTPUT);      // set led as analog output


void loop ()
   int val = analogRead(sensorPin) / 11;    // set "val" equal to the analog read of the sensor divided by 11
   Serial.println(val);                     // print the value of "val" on the serial monitor
   analogWrite(servoPin, val);              // as the value of the sensor changes, the servo should spin according to "val"

   if (analogRead(servoPin == 0))           // if the analogRead of the servoPin is 0
   {    for (brightness = 0; brightness > 255; brightness ++) // make LED get bright
        analogWrite (ledPin, brightness);
        delay (500);                       // delay for 0.5 seconds
   if (analogRead(servoPin == 93))
   {    for (brightness = 255; brightness > 0; brightness --) // make LED dim
        analogWrite (ledPin, brightness);
        delay (500);                       // delay for 0.5 seconds

February 26, 2008

Finally got the H-Bridge Working!

Filed under: 6: More Motion,Brian Kish — bkish @ 10:56 am

I have been messing around with a H-bridge to control my linear actuator. The H-bridge switches the negative and positive flows of electricity to be able to change the direction of the actuator. For example, the H-bridge allows me to spin a DC motor in forward and reverse or make the actuator move in or out. Cool stuff.

My initial problem was one of 2 things: 1) There was not a common ground between the arduino and external power source 2) I did not have the correct size capacitor. After I did both of these it worked! Unfortunately, after much excitement, I fried my H-bridge. I accidently let go of the ‘switch wire’ I was using to control it and it contacted the H-Bridge and a lot of smoking and nasty smell ensued. I need to get a new H-bridge ASAP. (the joys of working with 24V DC power!)

I used the ITP tutorial to get this to work:

(The schematic and code that I used can be found on in this tutorial)

I also used an old architectural Roboctic handout from Mark:

H-Bride Controller H-Bridge Schematic

Solenoid working! Yay!

Filed under: 6: More Motion,Assignments,Lingshui Wang — lingshui @ 12:34 am

Finally got a solenoid working, used a TIP 3055 transistor. linked it up with a 3V buzzer to be both activated by a rangefinder on a 2 second loop script. Here’s a schematic, a script, and a video:

int buzzer = 13;                    //buzzer set to digital 13
int rangeFinder = 0;                //rangefinder set to analog 0
int solenoid = 8;                   //solenoid set to digital 8
int val;

void setup ()
  Serial.begin (9600);              //serial library set up for troubleshooting
  pinMode (buzzer, OUTPUT);         //buzzer set to output
  pinMode (rangeFinder, INPUT);     //rangefinder set to input
  pinMode (solenoid, OUTPUT);       //solenoid set to output

void loop ()
  val = analogRead (rangeFinder);   //set definition for "val"
  Serial.print("switch input: ");
    if (val  50)                    //if object is far...
	digitalWrite(buzzer, LOW);   //do nothing
    	digitalWrite(solenoid, LOW);

February 24, 2008

Assignment 6: Making more motion (actuation)

Filed under: 6: More Motion,Siddartha Butalia — sbutalia @ 2:28 pm

So i tried to build on my DC motors from last week. I simplified the sensors to a switch to focus on building other components. I aimed to slow down the DC motor by using a rubber band setup. This was not as seccesfull, but i learned how hard it was to prototype details with foam core. the code is a simple algorithm which takes a switch input, and drives a motor

 here are some photos & the code:

Free Image Hosting at Free Image Hosting at

int ledPin = 13;    // defines the check pin
int inputPin = 2;   // defines input for sensor A
int motorPin = 9;   // defines output for motor A

void setup() {

  pinMode(ledPin, OUTPUT);      // declare check LED Pin
  pinMode(motorPin,OUTPUT);     // declare Motor PinA
  pinMode(inputPin, INPUT);     // declare SensorA input Pin


void loop(){

  while (digitalRead(inputPin) == HIGH) {        // check if the input is on
    digitalWrite(ledPin, HIGH);   // turn check LED On
    digitalWrite(motorPin,HIGH);  // turn Motor A On

    digitalWrite(ledPin, LOW);  // turn check LED Off
    digitalWrite(motorPin,LOW); // turn Motor A Off




February 20, 2008

Assignment 5, 6: Solar Power

Filed under: 5: Making Motion,6: More Motion,Assignments,Thomas Hendrickson — tphendrickson @ 7:52 pm

So after a ton of trying, troubleshooting, finding help from friends, I finally got a transistor connection to work and got two DC motors running together off of a code. One motor spins a sun and after it powers up the plants (a 6 second delay from a incremented counter), the flowers spin on the other motor.

here is the code:

int sunPin = 7;        //sun motor pin
int flowerPin = 5;     //flower motor pin
int ledPin = 13;       //led runs as a check
int counter = 0;       //counts how long program has been running</code>

void setup()
pinMode(ledPin, OUTPUT);
pinMode(sunPin, OUTPUT);
pinMode(flowerPin, OUTPUT);


void loop()

digitalWrite(sunPin, HIGH);    //turns on sun immediately

if (counter == 6)              //checks counter value
digitalWrite(flowerPin, HIGH);  //if counter high enough, turns on led and flower
digitalWrite(ledPin, HIGH);

counter++;      //if not long enough, counter is incremented
delay(1000);    //1 second delay


February 19, 2008

Spinning Color Wheel and Servo Motor

Filed under: 6: More Motion,Tiffany Yang — tyang1 @ 3:19 pm

Originally I wanted to create a drive belt that had numbers on them with a DC motor and rubber band. This would be a game where a solenoid controlled by a button would hit the numbers as they moved by.  The higher the numbers the more points you get.  However, the DC motor with 9V could not take any load.  When I put the rubber band on the motor, it stalled the motor.  Plus I could not get the solenoid to work.  So I moved to a new plan.  I couldn’t think of anything except sticking a color wheel on the DC motor.  The DC motor is controlled by a potentiometer so the faster you turn the potentiometer, the more merging of colors you get.  Since we had to control two things, I decided to control a servo motor.  I could not think of anything cool to do with the servo motor so all I ended up with is a spinning color wheel and servo motor.  The servo motor on its own works well but with the DC motor, the servo motor’s movement is a bit jerky.  I am guessing it is from the noise of the DC motor.         

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 servoPin = 3; // sets servo control pin to PWM 3
int angle;
int pulseWidth; // amount to pulse the servo

void servoPulse(int servoPin, int angle) { // creating a subroutine
pulseWidth = (angle * 9) + 300; //
digitalWrite(servoPin, HIGH); // turn servo on
delayMicroseconds(pulseWidth); // length of pulse sets the motor position
digitalWrite(servoPin, LOW); // turn servo off

void setup() {
pinMode(motPin, OUTPUT); // sets motor transistor pin as output
pinMode(potPin, INPUT); // sets potentiometer pin as input
pinMode(servoPin, OUTPUT); // sets servo transistor pin as output

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

for (angle = 0; angle <=180; angle++) { // for eaching angle from 0 to 180... servoPulse(servoPin, angle); // call subroutine } delay(1000); }[/sourcecode]    

Rotational Forms

Filed under: 6: More Motion,Assignments,Nadeem Haidary — nhaidary @ 2:09 pm

I’m using the potentiometer to control a DC motor. I made this as a tool to experiment with rotational forms. You can put a profile on the disc and the motor will spin it to give the illusion of a 3-dimensional form. I was looking at how fast the disc needs to be spinning to create the illusion. I was trying to see how fast the disc needs to be moving for an LED to look stable even though it is actually only seen once per revolution (through the hole).

I am having problems with the power to the motor dying periodically if I crank it up high. I reverted to thick paper after experimenting with foamcore-but the motor is not powerful enough to spin it quickly.

by Nadeem Haidary

with help from ITP Physical Computing tutorials

int transistorPin = 9;              // connected to the base of the transistor
int transistorValue = 180;          // initial value for motor speed (through transistor)

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


void setup() {
pinMode(transistorPin, OUTPUT);   // Set transistor pin as an output pin


void loop() {

//-----DC MOTOR-----
potentiometerValue = analogRead(potentiometerPin);     // read the analog input
motorSpeed = potentiometerValue/4;                     // converts the potentiometer value (0-1023)
// to a range between 0 - 255 for the motor
transistorValue = motorSpeed;                           // Transfer windspeed to motor
analogWrite(9, transistorValue);                       // Turn the DC motor on


Solenoid/Servo Target Shooter

Filed under: 6: More Motion,Assignments,Christopher Bridgman — cbridgma @ 2:00 am

So, for this assignment, i wanted to create a target shooting device out of the solenoid so it would hit a target on the servo motor. i guess this was my interpretation of making the components do something. So here it finally is. This was done by using a simple tilt switch to fire the solenoid to try and hit the servo motor which operated off a simple time delay. However, after hooking all of this stuff up together, the sensor responded very slowly and im not sure why. It made it hard to actually hit the target. But anyways, here is the video.

int statusPin = 13;                // LED connected to digital pin 13
int switchPin = 6;                 // Gravity switch connected to pin 6
int servoPin = 11;                 //servo connected to pin 11
int solenoid = 2;                 //solenoid connected to pin 2
int val;

void setup()                    // run once, when the sketch starts
  pinMode(statusPin, OUTPUT);      // sets the digital pin as output
  pinMode(servoPin, OUTPUT);       //sets the analog pin as output
  pinMode(solenoid, OUTPUT);       //sets the digital pin as output
  pinMode(switchPin, INPUT);       //sets the digital pin as input

void loop()                     // run over and over again
  val = digitalRead(switchPin);

  Serial.print("Value: ");

  if (val == 1)
  if (val == 0)
    digitalWrite(statusPin, LOW);

February 18, 2008

Work with solenoids

Filed under: 6: More Motion,Assignments,Lingshui Wang — lingshui @ 11:57 pm

So, 2 other classmates and I (with the help of an ece friend) took a look at the solenoids to try to get them to work. 3 hours and one blown transistor later, we discovered that the circuit was somehow trying to send current back through the base of the transistor into the arduino instead of through the collector to ground (using a PNP transistor) and the arduino wasn’t letting current back through the pin, thus not enough power was going through the circuit to power a solenoid, but enough was going through to power a LED. We discovered this by isolating the arduino and taking it out of the circuit, hence the blown transistor (the solenoid DID run for a rotation, but then blew the transistor). Anyways, if anyone has had any luck with the solenoid, please tell us!Here’s a few schematic diagrams:

These were tested using a simple time delay program seen here:

void setup ()
{pinMode (8, OUTPUT);    //solenoid connected to digital 8

void loop ()
{digitalWrite (8, HIGH);    //turn on
delay (1000);               //wait 1 sec
digitalWrite (8, LOW);      //turn off
delay(1000);                //wait 1 sec

So this is what I attempted to do earlier in the night, combining a rangefinder I had with a solenoid, using the schematic provided to me for the solenoid and using the rangefinder in a separate circuit (the rangefinder was giving accurate readings):

int rangeFinder = 0;    //rangefinder connected to analog 0
int sole = 3;           //solenoid connected to digital 3
int val;
int val2;
int buttonState;
int soleMode = 0;

void setup()
    pinMode(rangeFinder, INPUT);            //rangefinder input
    pinMode(sole, OUTPUT);                  //solenoid output
    buttonState = analogRead(rangeFinder);

void loop(){
  val = analogRead(rangeFinder);
  val2 = analogRead(rangeFinder);
  Serial.print("Read switch input: ");
  if (val == val2) {                        //is the rangefinder getting an accurate reading?
  if (val < 50) {                           //if rangefinder senses somethign close
    digitalWrite(sole, HIGH);               //run solenoid
    digitalWrite(sole, LOW);
  else if ((val == 50) && (val > 50))       //if nothing's close
    digitalWrite(sole, LOW);                //solenoid remains off

February 14, 2008

Assignment 6: (more motion)

Filed under: 6: More Motion,Assignments — mdgross @ 6:56 pm

Due Tuesday, February 19, 2008.

Complete (if necessary) and extend the previous (making motion) assignment. Make the motors, solenoids actually DO something. Make the motion more sophisticated, or make it more responsive to sensor inputs. Take the project further than a breadboard electronics exercise. See “cabaret mechanical theatre” or “flying pig” for some fun automata ideas (cams, levers, geneva wheels) that you can use to make a motor do something more than spin.

Create a free website or blog at