CPE400 Lab8 ARCONADO DEVELLES 2 PDF

Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

Activity No.

8
Controlling DC Motor
Actuators
Course Code: CPE400 Program: BSCPE
Course Title: Embedded Systems Date Performed: OCTOBER 30, 2021
Section: CPE41S1 Date Submitted: OCTOBER 31, 2021
Members: ARCONADO, DEVELLES Instructor: Engr. Mon Arjay Malbog

1. Objective(s):
This activity aims to introduce the concept of DC Motor Control using a microcontroller.
2. Intended Learning Outcomes (ILOs):
After performing the laboratory activity, the students should be able to:
2.1 Implement the circuit and write the program for light and temperature sensors
2.2 Graph/Plot the data being read from the sensors
3. Discussion:
Actuators convert electric signals to another form of energy.

Some of the different types of actuators you would encounter or already have encountered:
• Light Actuators
• Sound Actuators
• Force, Displacement, and Motion Actuators
• Heat Actuators

Motors are also the driving force behind lots of useful products such as water pumps, linear actuators,
and robotics systems. DC Motors are extensively used in precision position-control systems and other
electronic systems, particularly in low-power
applications. This activity will focus on DC motor control using Transistors and an Integrated Motor
Driver Circuit.
4. Materials and Equipment:

Arduino UNO Board with USB Cable


Desktop Computer with Arduino IDE 2 10kΩ Resistors
IRF520 (N-Channel MOSFET) 2 Tactile Switches
L293D (Motor Driver IC) 1N4001 Diode
Brushed DC Motor 9V Battery
Breadboard 9V Battery Clip
Connecting Wires Multimeter

5. Procedure:
Using the LDR and Plotting Light Data
1. Implement the circuit as shown in the Breadboard below:
2. Open the Arduino IDE, and copy the code as shown below:

3. Upload the code to your Arduino Board. Observe the output.


4. Measure the VDS and VGS of the MOSFET while the tactile switch is not pressed and measure
again while the tactile switch is pressed.
Condition VDS (V or mV) VGS (V or mV)
Before pressing the switch 0.23mV 3.8V
While pressing the switch 3.2V 0.46mV

Using the L293D IC


1. Wire the circuit shown (Note: Look at the pin connections carefully before you connect and
power the circuit)

On the Arduino IDE, type and upload the program below


Upload the code to your Arduino Board. Observe the output. Explain the process of the code used
to control the L293D.
In this code, it makes use of the various pins of the L293D DRIVER IC MOTOR. The
various pins of the L293D can control the state of the servo motor, for example, in the first
pin, you can control the speed as well as the motor's on and off switch. Other pins are used
to determine the direction of the motor's rotation. This code successfully uses all of the IC's
features to control the servo motor programmatically.

6. Supplementary Activity:
Tasks
1. Using the MOSFET transistor only, implement the circuit and code that would control the speed
of the Motor.

CIRCUIT:

SOURCE CODE:

// C++ code
//
const int onoffswitchstatepin = 7;
const int enablepin = 6;
const int control = A0;

int onoffswitchstate = 0;
int previousonoffswitchstate = 0;

int motorenabled = 0;
int motorspeed = 0;

void setup()
{
pinMode(enablepin,OUTPUT);
pinMode(onoffswitchstatepin, INPUT);
}

void loop()
{
onoffswitchstate = digitalRead(onoffswitchstatepin);
delay(1);
motorspeed = analogRead(control)/4;
onoffswitchstate = digitalRead(onoffswitchstatepin);

if (onoffswitchstate != previousonoffswitchstate)
{
if(onoffswitchstate == HIGH)
{
motorenabled = !motorenabled;
}
}
if (motorenabled == 1)
{
analogWrite(enablepin, motorspeed);
}
else
{
analogWrite(enablepin, 0);
}
previousonoffswitchstate = onoffswitchstate;

}
2. Using the L293D, modify the given code and circuit (remove the potentiometer) so that the
motor would be able to support two modes of modulated speed using one button only.

CIRCUIT:
SOURCE CODE:

const int controlPin1=2;


const int controlPin2=3;
const int enablePin=9;
const int directionSwitchPin=4;
const int onOffSwitchStateSwitchPin=5;
const int potPin=A0;
int onOffSwitchState=0;
int previousOnOffSWitchState=0;
int directionSwitchState=0;
int previousDirectionSwitchState=0;
int motorEnabled=0;
int motorSpeed=0;
int motorDirection=1;

void setup()
{
pinMode(directionSwitchPin, INPUT);
pinMode(onOffSwitchStateSwitchPin, INPUT);
pinMode(controlPin1, OUTPUT);
pinMode(controlPin2, OUTPUT);
pinMode(enablePin, OUTPUT);
digitalWrite(enablePin, LOW);
}

void loop()
{
onOffSwitchState=digitalRead(onOffSwitchStateSwitchPin);
delay(1);
directionSwitchState=digitalRead(directionSwitchPin);
motorSpeed=1;

if(onOffSwitchState != previousOnOffSWitchState)
{
if(onOffSwitchState==HIGH)
{
motorEnabled = !motorEnabled;
}
}

if(directionSwitchState != previousDirectionSwitchState)
{
if(directionSwitchState == HIGH)
{
motorDirection = !motorDirection;
}
}
if(motorDirection==1)
{
digitalWrite(controlPin1, HIGH);
digitalWrite(controlPin2, LOW);
}
else
{
digitalWrite(controlPin1, LOW);
digitalWrite(controlPin2, HIGH);
}

if(motorEnabled == 1)
{
digitalWrite(enablePin, motorSpeed);

}
else
{
digitalWrite(enablePin, 0);
}

previousDirectionSwitchState=directionSwitchState;
previousOnOffSWitchState=onOffSwitchState;
}

7. Conclusion

I therefore conclude that in this activity, there is an another type of module that an Arduino
can programmatically control is servo motors. Servo motors have a wide range of applications.
For example, you can build an RC car out of four servo motors, but you'll need at least an
NMOSFET or an L293D driver IC to fully utilize the servo motor. You can programmatically
control the state of the servo motor, the speed of rotation, and even the direction of rotation
using these servo motor drivers.

You might also like