DC Motor
DC Motor
DC Motor
•DC motors make things like appliances
and power tools work by converting
electrical energy to mechanical energy
•Inductive device
Transistor
• Components that
allows you to control
high voltage power
sources to low current
output
• Gate – digital switch Gate
• Drain – connects Drain
output device
Source
• Source - GND
Diode
• Components that control
back voltage
• Allow electricity to flow from
one direction
Back voltage – voltage that
may harm circuits
Activity 1 – Motorized Pinwheel
Activity 1 – Motorized Pinwheel
1. Tactile switch
A – 5V
B – resistor & dig. pin # 2
2. Transitor/Mosfet
Gate (leftmost) – dig. pin 9
Drain (center) – negative (motor) + diode to positive PB
Source – GND
3. Motor
Negative – diode
Positive – 5V
4. Battery - connect +PB to positive (+) and –PB to negative(-)
5. Arduino – connect positive PB to 5V
6. Add a common ground to both Arduino and battery
Activity 1 – Motorized Pinwheel
const int switchPin=2;
const int motorPin=9;
int switchState=0;
void setup() {
pinMode(switchPin,INPUT);
pinMode(motorPin,OUTPUT);
}
Activity 1 – Motorized Pinwheel
void loop() {
switchState=digitalRead(switchPin);
if(switchState==HIGH){
digitalWrite(motorPin,HIGH);
}
Activity 1 – Motorized Pinwheel
else{
digitalWrite(motorPin,LOW);
}
}
Activity 1 – Motorized Pinwheel
const int onPin=13;
const int offPin=12;
const int motorPin=10;
const int ledPin=9;
int switchState=0;
void setup() {
pinMode(onPin,INPUT);
pinMode(offPin,INPUT);
pinMode(ledPin,OUTPUT);
pinMode(motorPin,OUTPUT);
Activity 1 – Motorized Pinwheel
void loop() {
switchState=digitalRead(onPin);
if(switchState==HIGH){
digitalWrite(motorPin,HIGH);
digitalWrite(ledPin,HIGH);
}
Activity 1 – Motorized Pinwheel
switchState=digitalRead(offPin);
if(switchState==HIGH){
digitalWrite(motorPin,LOW);
digitalWrite(ledPin,LOW);
}
}
3rdQtrAct1-Zoetrope
3rdQtrAct1-Zoetrope
Materials needed:
1. Arduino Uno 10. H-bridge or L293NE
2. Breadboard
3. 2 Tactile switches
4. 2 10K Resistors 11. Potentiometer – 3pin
5. 6-12V motor
6. 9V battery
7. Battery snap
8. Jumperwires
9. Laptop with Arduino IDE
H-bridge
•An integrated circuit (IC) that has built-in
components of resistors, transistors and
diodes
•16 pins
Potentiometer
A potentiometer is a simple knob that provides a
variable resistance, which we can read into the
Arduino board as an analog value.
Pin Assignments:
1st – 5V
2nd – pin assignment
3rd - GND
Program
const int controlPin1 = 2;// the control pins will carry
the logic - direction to turn and applied to the H-Bridge
const int controlPin2 = 3;
const int enablePin = 9; // attached to the pin EN
const int directionSWPin = 4;// 4 and 5 carry the values
of button switches
const int onOffSwitchStateSWPin = 5;
const int potPin = A0; // analog signal, because it is a
potentiometer delivering continuous values
Program
int onOffSWState = 0;
int previousOnOffSWState = 0;
int directionSWState = 0;
int previousDirectionSWState = 0;
int motorEnabled = 0;
int motorSpeed = 0;
int motorDirection = 1;
void setup() {
pinMode(directionSWPin,INPUT);
pinMode(onOffSwitchStateSWPin,INPUT);
pinMode(controlPin1,OUTPUT);
pinMode(controlPin2,OUTPUT);
pinMode(enablePin,OUTPUT);