| 
View
 

dc motor pushbutton

Page history last edited by Kristin Lucas 17 years, 10 months ago
Program a DC motor or a Solenoid to be operated by a Pushbutton
 
Parts: 
1 DC motor (such as a fan motor) or Solenoid
1 relay (we'll use a Rayex LU-5 ordered from Jameco Electronics)
1 pushbutton
1 Arduino Diecimila
jumper wire
 
 
Download diagram  dc motor pushbutton.pdf
 
 
// In this circuit we use a momentary pushbutton to turn on a dc motor.
 
// We have replaced the variable name ledPin from our original pushbutton code with the variable name dcMotor.
 
// Try this circuit with a dc motor like a cooling fan or a toy motor. 
 
 
int dcMotor=11; // dcMotor is connected to the output of digital port 11
 
int inputPin = 2;               // choose the input pin (for a pushbutton)
 
int val = 0;                    // variable for reading the pin status
 
void setup() {
 
  pinMode(dcMotor, OUTPUT);      // declare LED as output
 
  pinMode(inputPin, INPUT);     // declare pushbutton as input
}
 
void loop(){
 
  val = digitalRead(inputPin);  // read input value
 
  if (val == HIGH) {            // check if the input is HIGH
 
    digitalWrite(dcMotor, LOW);  // turn LED OFF
  } else {
 
    digitalWrite(dcMotor, HIGH); // turn LED ON
  }

 


 

Comments (0)

You don't have permission to comment on this page.