Making Things Interactive

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

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

Blog at

%d bloggers like this: