Wednesday, February 3, 2016

Day 5 - Intro to c code and hbridge


  • Driving Motors and Other Output Devices
  1. Demonstrate microcontroller controlling signal lamp
    1. Here is the picture of the contraption In addition here is the code that allowed the microcontroller to control the signal lamp.
void setup() {
  pinMode(9, OUTPUT); //Initialize Digital Pin 9 as an output
}

void loop() {
  digitalWrite(9, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(5000);              // wait for a second
  digitalWrite(9, LOW);    // turn the LED off by making the voltage LOW
  delay(3000);              // wait for a second
}
2. Demonstrate Darlington controlling signal lamp
3. Demonstrate microcontroller controlling motor

void setup() {
  pinMode(9, OUTPUT); //Initialize Digital Pin 9 as an output
}

void loop() {
  digitalWrite(9, HIGH);   // turn the motor on (HIGH is the voltage level)
  delay(5000);              // wait for a second
  digitalWrite(9, LOW);    // turn the motor off by making the voltage LOW
  delay(3000);              // wait for a second
}
4. Demonstrate PWM signal driving motor
#define motorPin 9 //Motor connected to dig. pin 9
void setup() {
  // nothing happens in set up

}

void loop() {
analogWrite (motorPin, 90);//set motor to 20%
delay (1000);
analogWrite (motorPin, 50);//set motor to 90%
delay (1000);

}
  • Bi-directional Motor Control
  1. This first video demonstrates DPDT relay controlled the motor in both directions.
  2. In addition, this next picture and video shows a motor being controlled in opposing directions because of the arduino programming.Here is the code for this achievement 
    void setup() {
      pinMode (13, OUTPUT) ; //Initialize Digital Pin 13 as an output
        pinMode (12, OUTPUT) ; //Initialize Digital Pin 12 as an output
    }

    void loop () {
      digitalWrite (13,HIGH) ; //Set the motor On ClockWise
      delay (100);           //Wait for 1000 ms (1 Second)
      digitalWrite(13,LOW);  //Set the LED off
      delay (1000);   //Wait for 1 second
     
      digitalWrite (12,HIGH) ; //Set the motor On CounterClockWise
      delay (100);           //Wait for 1000 ms (1 Second)
      digitalWrite(12,LOW);  //Set the LED off
      delay (1000);   //Wait for 1 second
    }

No comments:

Post a Comment