Skip to content

12. Output devices

2020 Documentation

Introduction

For the output devices week, I need to control motors with an Arduino UNO board and an Arduino Motor Shield Rev3. To achieve that goal, I will start experimenting with motors and the motor shield.

Experience

1

DC Motors

DC motor is the most common type of motor that can be used for many applications. We can see it in remote control cars, robots, and etc. This motor has a simple structure. It will start rolling by applying proper voltage to its ends and change its direction by switching voltage polarity. DC motors speed is directly controlled by the applied voltage. When The voltage level is less than the maximum tolerable voltage, the speed would decrease.

Servo Motors

Servo motor is a simple DC motor with a position control service. By using a servo you will be able to control the amount of shafts rotation and move it to a specific position. They usually have a small dimension and are the best choice for robotic arms. But we can’t connect these motors to microcontrollers or controller boards such as Arduino directly in order to control them since they possibly need more current than a microcontroller can drive so we need drivers. The driver is an interface circuit between the motor and the controlling unit to facilitate driving. Drives come in many different types.

Stepper Motors

In some projects such as 3D printers, scanners, and CNC machines we need to know motor spin steps accurately. In these cases, we use Stepper motors. Stepper motor is an electric motor that divides a full rotation into a number of equal steps. The amount of rotation per step is determined by the motor structure. These motors have very high accuracy.

The Arduino Motor Shield Rev3 is built around the L298 dual full-bridge driver, made by STMicroelectronics. With the shield, you can drive DC motors, a stepper motor, relays, and solenoids. It comes with two separate channels, called A and B, that you can use to drive 2 DC motors or 1 stepper motor when combined.

1

As mentioned above, stepper motors are very accurate and divide rotation into small steps. Stepper motors are DC motors that move in discrete steps. They have multiple coils organized in groups called “phases”. By energizing each phase in sequence, the motor will rotate one step at a time. With computer-controlled stepping, you can achieve very precise positioning and/or speed control.

Controlling a Stepper Motor

First of all, I need to connect the stepper motor to the board using channels A and B, with each channel connected to one coil. If the stepper has 6 pins instead of 4, we can ignore the middle wires of each coil and it will work just fine. There are many libraries for controlling steppers, but it is possible to control them without using any library by simply turning on each coil separately in the right sequence.

To make it simpler, each channel is connected to one coil, and I’m turning on each coil separately to make the motor rotate. However, I found a stepper with 4 pins and used that instead.

1

    int delaylegnth = 30;

void setup() {

  //establish motor direction toggle pins
  pinMode(12, OUTPUT); //CH A -- HIGH = forwards and LOW = backwards???
  pinMode(13, OUTPUT); //CH B -- HIGH = forwards and LOW = backwards???

  //establish motor brake pins
  pinMode(9, OUTPUT); //brake (disable) CH A
  pinMode(8, OUTPUT); //brake (disable) CH B




}

void loop(){

  digitalWrite(9, LOW);  //ENABLE CH A
  digitalWrite(8, HIGH); //DISABLE CH B

  digitalWrite(12, HIGH);   //Sets direction of CH A
  analogWrite(3, 255);   //Moves CH A

  delay(delaylegnth);

  digitalWrite(9, HIGH);  //DISABLE CH A
  digitalWrite(8, LOW); //ENABLE CH B

  digitalWrite(13, LOW);   //Sets direction of CH B
  analogWrite(11, 255);   //Moves CH B

  delay(delaylegnth);

  digitalWrite(9, LOW);  //ENABLE CH A
  digitalWrite(8, HIGH); //DISABLE CH B

  digitalWrite(12, LOW);   //Sets direction of CH A
  analogWrite(3, 255);   //Moves CH A

  delay(delaylegnth);

  digitalWrite(9, HIGH);  //DISABLE CH A
  digitalWrite(8, LOW); //ENABLE CH B

  digitalWrite(13, HIGH);   //Sets direction of CH B
  analogWrite(11, 255);   //Moves CH B

  delay(delaylegnth);

}

Controlling DC motors

DC motors are the most common type of electric motor and the easiest to use. To control a DC motor, I connected it to channel A using jumpers. Then, with a simple code and delays, I made it rotate.

The next challenge was to make it rotate in 2 directions clockwise and counterclockwise. For that I need a H-bridge. An H-bridge is an electronic circuit that switches the polarity of a voltage applied to a load. These circuits are often used in robotics and other applications to allow DC motors to run forwards or backwards. Most DC-to-AC converters (power inverters), most AC/AC converters, the DC-to-DC push–pull converter, most motor controllers, and many other kinds of power electronics use H bridge.

1

In fact I don’t need to make the H-bridge because the shield hes it built-in.

void setup() {

  //Setup Channel A
  pinMode(12, OUTPUT); //Initiates Motor Channel A pin
  pinMode(9, OUTPUT); //Initiates Brake Channel A pin

}

void loop(){

  //forward @ full speed
  digitalWrite(12, HIGH);
  digitalWrite(9, LOW);
  analogWrite(3, 255);
  delay(1000);
   digitalWrite(12, LOW);
  digitalWrite(9, LOW);
  delay(1000);
   digitalWrite(12,LOW);
  digitalWrite(9, HIGH);
 delay(1000);


}

Dc motor cw and ccw

2024 Documentation

Introduction

For this week, I used the same board that was designed during electronics design. The general plan is to test it by turning on the onboard LED, then using it to control a pump. Also, please check the previous week where I made an ohmmeter using a screen.

Experience

To control the pump, I used a transistor. Specifically, I used an IRFZ44N MOSFET, which has 3 pins: Source and Drain (in N-Mosfets, the source is connected to the ground and the drain to the negative pole of the load) and the gate opening pin. The pump would be controlled (turned on and off) through that gate.

During work and testing, the general plan changed a bit. I decided to turn the pump on and off by pressing a switch on the board. This switch will turn on the pump and the LED simultaneously. Our instructor, Maxime, guided me to make things work.

The first thing I did was write code in the Arduino IDE. Initially, the code was supposed to print “Privet” when I pressed the switch. From there, I made further modifications to the code.

1

Here is the further modified code that is supposed to do all the stuff described above,

int button_pin = 10;
int pump_pin = 2;
int led_pin =8;
bool button_check = false;
bool led_check = false;

void setup() {
  // put your setup code here, to run once:
  pinMode(pump_pin, OUTPUT);
  pinMode(button_pin, INPUT);
  Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  int value = digitalRead(button_pin);

  if (value == 1) {
    if (button_check == false) {
      button_check = true;

      Serial.println("privet");
      if (led_check == false) {
        digitalWrite(pump_pin, 1);
        digitalWrite(led_pin, 1);
        led_check = true;
      } else {
        digitalWrite(pump_pin, 0);
        digitalWrite(led_pin, 0);
        led_check = false;
      }
    }



  } else {
    button_check = false;
  }
}

but something went wrong. While the pump was supposed to turn on and work until I pressed the switch again, it was behaving incorrectly. The pump was just pumping while the switch was pressed, and once I removed my finger from it, it stopped. We checked the code, thinking that the problem was in the code, but quickly realized that we had a hardware problem.

To solve the problem, I asked for help from Maxime and Mkhitar. Maxime checked the MOSFET with an oscilloscope, but it didn’t show the main problem. After a quick discussion, we decided to change the voltage regulator from 3.3V to 5V as we thought it was struggling with a voltage drop since the LED was shining brighter when the switch was pressed. We found out that the gate was closing when the switch was not pressed due to a 0.1V drop.

Troubleshooting the board.

1

Video of turning on and of the led.

Here is the video where everything eventually worked.

Group assignment

Group assignment page

This week we had to measure the power consumption of the output device.

The Power supply we have is: Instek GPD-3303D it has 2 controlled channels 0-30V and one fixed with tis options 2.5V/3.3V/5V/3A. We mainly use the controlled channels. At the back of the device we have the input voltage options. We measured power consumtion of several DC motors and a led strip. We need to connect DC motor to power supply the polarity doesn’t matter since the only difference is the direction of rotation.

Conclusion

This week’s assignment was completed in a short time thanks to the previous weeks’ experience, which helped me a lot. Now in the lab, when the conversation topic is electronics, it seems interesting to me, and I’m trying to be involved, listen, and gain new knowledge. I understand that what I’m doing in electronics is beginner-level simple things, but I hope that the foundation constructed during these and the following weeks will be strong enough for future projects.

Files

KIkad files

VOLKSWAGEN_BEETLE_engravings

VOLKSWAGEN_BEETLE_outline