Monday, February 6, 2017

Hach-a-Toy Assignment

I name my creation: "Forward/Reverse LDR Tank"

Picture Goes Here:)
Video Goes Here Too :))



A Description of Project:

     Okay, originally I wanted my tank to have two H-Bridge components, so that I could also program a LEFT and RIGHT turn protocol.  But, I soldered a wrong transistor on my H-Bridge circuit and that took me a couple of stressful days to figure it out.  The lesson I learned was; Test your components functionality before any assembly!!!  I had to settle for the FORWARD and REVERSE protocol instead, so what a huge bummer :(

Front View
     My first idea was to do something that included a Tamiya gear box, because they are so cool and interesting.  I bought the Double Gear Box Kit, because it gives you four gear ratios: 12.7:1, 38:1, 115:1, or 344:1.  I chose 344:1, because the full set of yellow and glue gears looks supper cool.  The Twin-Motor Kit only allows two gear ratios and is slimmer in width.  I also bought the Universal Frame Kit and the Track and Wheel Kit separately to make a tank-like frame chassis. 
Rubber Track Assembly
Gear Ratio Set-Up

Motor Case Assembly
     The only Draw back to my chose was due to the wider gear box, I had to cut chunks out of my frame out on both sides to allow the mounting bar connect on the frame securing the gear box.  Also, it took me what seemed forever to connect four or five strands of rubber tracks to interlock.  It was like a Chinese puzzle, where you need to think out of the box.
Motor Case Mounting
Okay, I bought a battery holder that holds four AA batteries, which gives me enough juice to power the Arduino, H-Bridge, the two motors, and the LDR sensor.  The battery holder had one of those two button-like 9V male terminals, and I happen to have the female terminal connectors wired to a power jack that fits the Arduino.  I used a super small breadboard for small prototyping, and it has no power busses.  What a bummer :(  Mr. Denny gave me out of the kindness of his heart a working H-Bridge.  I also stole a 100K LDR and a 10K resistor, and a few solderless leads.  I cut off the ends of four leads and soldered them to the two DC motors that came with the Double Gear Kit :)
Side Shot of Battery Holder and DC Motor

Side Shot of Power Jack and Battery Holder

Track and Wheel Assembly
It turns out that you only need to output pins to make the darn thing go forwards and backwards, and an analog input pin as well.  I also used the 5V output to power everything besides the Arduino.  On the H-Bridge circuit we have 8 pins to use three of which are grounds.  From top to bottom these are the pins: Input 1, Input 2, Motor +, Motor -, Vcc, and the three grounds.  They way I have the DC motors configured Motor + is forward and Motor - is reverse.  Determining which input was forward or reverse in the Arduino Developer Environment, because it matters which terminal on the DC motors really does turn CW or CCW in relation to assigning the pin Motor 1 or 2 the correct command of HIGH or LOW.  When typing out your C++ code, figured out a few ways to make the motors actually do what I want (F/R).  It bothers me tremendously, when you assign a pin a specific function, only to figure that it really does the opposite of what you labeled it to do.  I fixed those bugs, even though there are many ways to do the same thing. 
Rear View
H-Bridge and Small Breadboard

     



I had PIN 13 connected to Input 1, PIN 12 to Input 2, Ground(Arduino) to Ground(H-Bridge), 5V output to Vcc, and DC motor terminals to there corresponding inputs Motor +/-.  The analog PIN A0 went to the LDR and resistor and all grounds from the sensor and H-bridge to a common row going all the way back to the Arduino ground next to PIN 13.  I uploaded the program to the Arduino chip, so my little creation can be free of its USB plug.  I will show the code later.  When the battery holder is plugged into the Arduino it powers on and goes into reverse when the LDR senses low light level (Below 850) and goes forward when the LDR senses light(Above 850).  And that is pretty much all it can do and this is what I spent days and days tinkering with.  This is why I have no gf :'(

BUT IT WORKS!!!!! :0 (Forever Alone face                 


    Copy and Paste Code Goes Here!!!!

Hack-a-Toy file

#define forwardAB 13  // Input 1 goes forward (CW)
#define reverseAB 12  // Input 2 goes reverse (CCW)

#define sensorPin A0  // Sensor  LDR
int sensorValue = 0;   //

void setup()
{
  Serial.begin(9600);  // Analog Input monitor

  pinMode(forwardAB,OUTPUT);
  pinMode(reverseAB,OUTPUT);

  pinMode(sensorPin,INPUT);
}

void loop()
{
  sensorValue = analogRead(sensorPin);  //  Sends input value data to serial monitor

    if(sensorValue > 850)
    {
     digitalWrite(forwardAB,HIGH);  // Motor A & B turns CW
     digitalWrite(reverseAB,LOW);    //
    }
    else if(sensorValue < 850)
    {
      digitalWrite(reverseAB,HIGH);  // Motor A & B turns CCW
      digitalWrite(forwardAB,LOW);
    }
   
    Serial.println(sensorValue);  //  Prints the value of the LDR input to serial monitor
    delay(300);
}




     I would have initialized forwardA/reverseA and forwardB/reverseB if I had two H-Bridges to assign each motor its own function to go forward or reverse independently; giving my hack-a-Toy to also turn left and right.
I noticed that the tank doesn't maintain a straight line because I tightened the gear box case differently for the two motors; not on purpose though and giving them roughly the same tolerance still did not fix the problem.  One motor just so happens to be fast than the other.
To fix this I will figure out Duty Cycle for the analogWrite() function for both motors if  I had an extra H-bridge.
I have another battery holder of the same voltage that I dedicate fully to the DC motors and increase the speed a bit, so that the battery hold for the Arduino is not carrying all the load.


This is the Tamiya website to chick out all there products:

http://www.tamiya.com/english/products/list/gearboxes/kit700P01.htm

The Pololu website has some decent prices:

https://www.pololu.com/category/34/tamiya-motors-and-gearboxes

Tuesday, January 31, 2017

Lab 11 - Using the Serial Port

Demonstrate Serial Input Turning the LED ON

Materials:

Summary:

CODE.ORG Homework Asssignment

Code Goes Here:)

In this game you start off as R2-D2 at normal speed on Endor, but be careful there are two Stormtroopers after you.  You must get the Mynock, which then produces a Puffer Pig.  Get the Puffer Pig and you are now on Hoth with a Tauntaun.  The bad guys are still after you.  Get the Tauntaun and you find yourself on a Starship and as C3-PO.  C3-PO is super slow, so use the Obstacles to give him super speed.  Get the Mouse Droid, but two more Stormtroopers follow it.  You must quickly kill the Probot to save the Rebel Pilot, who is also being chased by two more Stormtroopers.  You win the game by saving the Rebel Pilot and lose the game whenever a Stormtrooper kills you at any map level.

Have Fun!!!

setBackground("Endor");
setMap("blobs");
setDroid("R2-D2");
setDroidSpeed("normal");
playSound("R2-D2random");
function whenUp() {
  goUp();
}
function whenDown() {
  goDown();
}
function whenLeft() {
  goLeft();
}
function whenRight() {
  goRight();
}
moveSlow("PufferPig");
moveSlow("Probot");
moveNormal("Mynock");
moveNormal("Tauntaun");
moveNormal("RebelPilot");
moveFast("MouseDroid");
moveFast("Stormtrooper");
addCharacter("Mynock");
addCharacter("Stormtrooper");
addCharacter("Stormtrooper");
function whenTouchObstacle() {
  setDroidSpeed("fast");
}
function whenGetMynock() {
  setDroidSpeed("normal");
  addCharacter("PufferPig");
  playSound("MynockRandom");
  addPoints(1);
}
function whenGetPufferPig() {
  addCharacter("Tauntaun");
  playSound("PufferPigRandom");
  addPoints(5);
  setBackground("Hoth");
  setMap("circle");
  setDroidSpeed("normal");
}
function whenGetTauntaun() {
  addCharacter("MouseDroid");
  playSound("TauntaunRandom");
  addPoints(10);
  setDroidSpeed("normal");
}
function whenGetMouseDroid() {
  setDroid("C-3PO");
  setDroidSpeed("slow");
  setBackground("Starship");
  setMap("grid");
  addCharacter("Stormtrooper");
  addCharacter("Stormtrooper");
  addCharacter("Probot");
  playSound("MouseDroidSoundRandom");
  addPoints(25);
}
function whenGetProbot() {
  addCharacter("RebelPilot");
  addCharacter("Stormtrooper");
  addCharacter("Stormtrooper");
  playSound("ProbotSoundRandom");
  addPoints(50);
  setDroidSpeed("fast");
}
function whenGetStormtrooper() {
  endGame("lose");
  playSound("alert1");
  removePoints(100);
}
function whenGetRebelPilot() {
  endGame("win");
  playSound("R2-D2random");
  addPoints(100);
}
I put a lot of time and thought into this game so it wasn't just a bunch of random aliens forever spawning, and then crash the game cus there are thousands of them.  You actually need to collect the critter with getting killed by stormtroopers and save the rebel pilot.  This game makes sense and has a defined goal and story to it.
Be nice!!! 
I made a super awesome snowflake, you'll just have to take my word for it.

I did the Design one, all my animals had free range.  Zombies and Creepers always attack at night and my Iron Golem beats them up without me having to tell it.

Sunday, January 29, 2017

Lab 7 - Introduction to Microcontrollers

What is a Microcontroller?

A microcontroller is pretty much a computer on a chip.  It looks like a small piece of black plastic with a bunch of metal legs protruding from the sides and goes on a circuit board.  Microcontrollers are a lot than meets the eye as it is low-cost and has many function integrated into it to perform specific operations.  The microcontroller is an integrated circuit (IC) that contains memory, processing units, and input/output circuitry on a small chip that interfaces with a much larger circuit board that may have sensors, switches, and motors.  Every microcontroller that is purchased comes as a "blank", which means you need to plug it into your computer and program it with a specific control program.  When the microcontroller is programed with a specific purpose it can then be built into a product to make it more intelligent and easier to use.  A super, big plus of a microcontroller is that it can replace a number of separate parts and components, or complete an electronic circuit.  Everyday products that use microcontrollers are household appliances, alarm systems, medical equipment, vehicle subsystems, and electronic instrumentation.

Advantages:
  • Increase reliability through a smaller part count
  • Reduce stock levels, as one microcontroller replaces several parts
  • Simplified product assembly and smaller end products
  • Greater product flexibility and adaptability since features are programmed into the microcontroller and not built into the electronic hardware
  • rapid production changes or development by changing the program and not the electronic hardware
Demonstrate Knight Rider LED Flashing Band

Materials:
  • Arduino Board
  • Breadboard
  • Sufficient wire
  • 4 LEDs
  • 4 resistors between 200-500 Ohms (Red, red , brown is 220ᘯ is ideal)
Summary:

To show how simple and easy it is to get started with programming the Arduino we needed to go to the link Arduino.cc to download the Programming Environment for the Arduino (PEA).  It took about 5 minutes to download everything needed for this lab.  The PEA is also easy to navigate with example lessons.  First we need to make sure the settings are correct by clicking "Tools" so that the PEA can communicate and transfer programs to the Arduino via USB cable.  We start off with a program called Blink and run the program to the Arduino to blink its orange light built into the board.  Then we are tasked to change the blinking intervals from 1 second to half of a second.

We first go over three functions that are easy to understand: pinMode(Pin #, Input/Output), digitalWrite(Pin #, LOW/HIGH), and delay(time in milliseconds).  The pinMode() function initializes the digital I/O pin on the Arduino board and defines it as an output signal for switches or input signal for sensors.  The digitalWrite() function tells the pin being used to either be HIGH (5V or 3.3V) or LOW (0V).  HIGH and LOW can be thought of as On and Off.  The delay() function causes the Arduino to halt execution for the specified time between its parenthesis bar in milliseconds.


K.I.T.T. LED Flash (Program as typed into PEA):

void setup()

{
pinMode(10,OUTPUT);  //Initialize Digital Pin 10 as an output
pinMode(9,OUTPUT);  //Initialize Digital Pin 9 as an output
pinMode(8,OUTPUT);  //Initialize Digital Pin 8 as an output
pinMode(7,OUTPUT);  //Initialize Digital Pin 7 as an output
}

void loop()

{
digitalWrite (10,HIGH);  //Set the LED On
delay(500);                      //Wait for 500ms
digitalWrite(10,LOW);   //Set the LED Off
delay(500);                     //Wait for 500ms

digitalWrite (9,HIGH);
delay(500);
digitalWrite(9,LOW);
delay(500);

digitalWrite (8,HIGH);
delay(500);
digitalWrite(8,LOW);
delay(500);

digitalWrite (7,HIGH);
delay(500);
digitalWrite(7,LOW);
delay(500);

digitalWrite (8,HIGH);
delay(500);
digitalWrite(8,LOW);
delay(500);

digitalWrite (9,HIGH);
delay(500);
digitalWrite(9,LOW);
delay(500);
}     


Lab 10 - Microcontollers, Input and Output

Lab 10 is mainly apply C++ code knowledge to take information form sensor to turn ON and OFF output devices, which is pretty fun once you know a few good function and what the variable represent in the physical world.

"HELLO WORLD!"

Demonstrate Flashing LED with Variable Delay

Example Code:
  • "#define"-  Sometimes it can be hard to remember which pins are connected to which devices.  This command can be used at the start of the program to rename the inputs and outputs.
  • A "function"-  Is like the void setup() or void loop() in the program below.  When the label is first defined as a "type".  The type void means that it won't return any data.
  • "delay()" and "delayMicroseconds()"-  The delay() command delays for a time in milliseconds.  delayMicroseconds() command delays for a time in microseconds for shorter intervals.
  • for loops- Repeats a block of statements enclosed in brackets. The for loop is used for any repetitive operation and is used in combination with arrays to operate on a collection of data/pins.
#define LED 6     //Define the symbol LED to be pin 6

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

void loop()
{
    digitalWrite(LED,HIGH);  //Set the LED On
    delayMicroseconds(16000);  //Wait for 116ms
     digitalWrite(LED,LOW);  //Set the LED OFF
    delayMicroseconds(16000);  //Wait for 16ms
}

For loop Example:

for(int = 0 ; x < 100 ; x++)
{
      println(x);  //prints 0 to 99
}

Summary:

Change your loop so that the delay varies from 1000 to 50 in increments to -50.

#define LED 6
void setup()
{
pinMode(LED,OUTPUT);  //Initialize Digital Pin 6 as an OUTPUT

for(int counter = 1000;counter < 50; counter = counter-50)
     {
      digitalWrite(LED,HIGH);  //Set the LED on
      delay(200);  //Wait for 0.2 second
      digitalWrite(LED,LOW);  //Set LED off
      delay(200);  //Wait for 0.2 second
      }
}

void loop()
{
      digitalWrite(LED,HIGH);  //Set the LED on
      delay(1000);  //Wait for 1 second
      digitalWrite(LED,LOW);  //Set LED off
      delay(1000);  //Wait for 1 second
}


Demonstrate Pushbutton LED Using if/else Statement

Example Code:
  • A digital sensor is a simple switch that can only be on or off.
  • "Variable"-  A variable as a bit of program memory that can store information, which we will use to store the status of the button
  • "if()"-  If is used in conjunction with comparison operator, test whether a certain condition has been reached, such as an input being above a certain number.
    • Comparison Operators
      • x == y (x is equal to y)
      • x != y (x is not equal to y)
      • x < y (x us less than y)
      • x > y (x is greater than y)
      • x <= y (x is less than or equal to y)
      • x >= y (x is greater than or equal to y)
  • "if()/else"-  Allows greater control over the flow of code than the basic if statement, by allowing multiple tests to be grouped together.    
#define buttonPin 8  //the number of the pushbutton pim
#defineledPin 6  //the number of the LED pin
int buttonState = 0;  //variable for reading the pushbutton status

void setup()
{
pinMode(ledPin,OUTPUT);  //initialize the LED pin as an output
pinMode(buttonPin, INPUT);  //initialize the pushbutton pin as an input
}

void loop()
{
buttonState = digitalRead(buttonPin);  //read the state of the push button value
//Check if the button is pressed.  If it is, the buttonState is HIGH
if(buttonState == HIGH)
      {
            digitalWrite(ledPin,HIGH);  //turn LED on
      }
if(buttonState == LOW)
      {
          digitalWrite(ledPin, LOW);  //turn LED off
       }
}

Summary:

Modify your code above to replace the two if statements with a single if/else block.

#define buttonPin 8  //the number of the pushbutton pim
#defineledPin 6  //the number of the LED pin
int buttonState = 0;  //variable for reading the pushbutton status

void setup()
{
pinMode(ledPin,OUTPUT);  //initialize the LED pin as an output
pinMode(buttonPin, INPUT);  //initialize the pushbutton pin as an input
}

void loop()
{
buttonState = digitalRead(buttonPin);  //read the state of the push button value
//Check if the button is pressed.  If it is, the buttonState is HIGH
if(buttonState == HIGH)
      {
            digitalWrite(ledPin,HIGH);  //turn LED on
      }
else
      {
          digitalWrite(ledPin, LOW);  //turn LED off
       }
}



Demonstrate LDR Controlling LEDs

Example Code:
  • An analog sensor measures a continues signal such as light, temperature, or position; and provides a varying voltage, which is represented by a number in range 0 to 255.  This means 0 is the equivalent to dark and 255 is the equivalent to super bright.
  • "readAnalog()"- The value of an analog input can be copied into a variable.  The following code switch's the LED on, if the value is greater than 750 and off if it is less than 750.
#define sensorPin A0  //select the input pin for the potentiometer
#defineledPin 6  //the number of the LED pin
int sensorValue = 0;  //variable to store the value coming from the sonsor

void setup()
{
pinMode(ledPin,OUTPUT);  //initialize the LED pin as an output
}

void loop()
{
sensorValue = analogRead(sensorPin);  //read the value of the sensor
if(sensorValue > 750)
      {
            digitalWrite(ledPin,HIGH);  //turn ledPin on
            delay(sensorValue);              //stop the program for <sensorValue> milliseconds
      }
else
      {
          digitalWrite(ledPin, LOW);  //turn ledPin off
          delay(sensorValue);  //stop the program for <sensorValue> milliseconds
       }
}

Summary:

Now attach a second LED to pin 7 of your Arduino using a 220 Ohm series resistor.  Change your program so that it has 4 states:
  • If the room is Bright both LEDs on
  • If the room is Medium lit turn LED 1 on
  • If the room is Dimly lit turn LED2 on
  • If the room is Dark turn LEDs off
#define sensorPin A0
#define ledPin 6
#define ledPIn 7
int sensorValue = 0;

void setup()
{
pinMode(ledPin, OUTPUT);  //LED 1
pinMode(ledPIn,OUTPUT);  //LED 2
}

void loop()
{
sensorValue = analogRead(sensorPin);
if(sensorValue>900)
{
digitalWrite(ledPin,HIGH);
digitalWrite(ledPIn, HIGH);
}

if(sensorValue>850)
{
digitalWrite(ledPin,HIGH);
digitalWrite(ledPIn, LOW);
}

if(sensorValue>800)
{
digitalWrite(ledPin,LOW);
digitalWrite(ledPIn, HIGH);
}

else
{
digitalWrite(ledPin,LOW);
digitalWrite(ledPIn, LOW);
}
}


Demonstrate Thermistor Controlling Motors

Materials:
  • 10K thermistor
  • 10K resistor
  • TIP 120 transistor
  • BDC motor
Summary:
#define sensorPin A0
#define ledPin 6
int sensorValue = 0;

void setup()
{
Serial.begin(9600);
pinMode(ledPin, OUTPUT);  //LED 1
}

void loop()
{
sensorValue = analogRead(sensorPin);
if(sensorValue>490)
{
digitalWrite(ledPin,HIGH);
delay(sensorValue);
}
else
{
digitalWrite(ledPin,LOW);
delay(sensorValue);
}
Serial.println(sensorValue);
}


Use the LDR code from the previous  page to turn on and off the motor.  It should turn on  if it sees room temperature, and turn off if it gets warmer than room temperature.  You may need to adjust the if statement as well as the variable names and comments to get this to work.

Demonstrate Potentiometer Controlling Buzzer

Materials:
  • 100K potentiometer
  • Buzzer
  • 5V power source
Summary:

Similar to the two previous programs, you are to build a control circuit where the potentiometer controls whether a buzzer is on or off.  The circuit should look similar to the one on the previous page except the middle pin of the potentiometer goes to the Arduino, the top pin goes to your 5V power supple, and the bottom pin goes to the ground.  ON the output side , the buzzer requires 24mA as you will need to use a transistor as part of you circuit to get it to work since the Arduino cannot supply this from one single pin.(Without a transistor the Arduino will only be able to output about 19MA.  It will still work without a transistor, it just won't be as loud)
#define sensorPin A0
#define ledPin 6
int sensorValue = 0;

void setup()
{
Serial.begin(9600);
pinMode(ledPin, OUTPUT);  //LED 1
}

void loop()
{
sensorValue = analogRead(sensorPin);
if(sensorValue>500)     // used half way point on potentiometer to trigger the switch at 500K ohms
{
digitalWrite(ledPin,HIGH);
delay(sensorValue);
}
else
{
digitalWrite(ledPin,LOW);
delay(sensorValue);
}
Serial.println(sensorValue);
}

Demonstrate Motion Sensor Controlling Relay

Materials:

Summary:
#define sensorPin A0
#define ledPin 6

int sensorValue = 0;

soid setup()
{
Serial.begin(9600);
pinMode(ledPin,OUTPUT);
}

void loop()
{
sensorValue = analogRead(sensorPin);

if(sensorValue>950)
{
digitalWrite(ledPin, HIGH);
}
else
{
digitalWrite(ledPin,LOW);
}
delay(100);
Serial.println(sensorValue);
}

Lab 9 - Driving Motors and Other Output Devices

In this lab we are to experiment with different output devices to the Arduino microcontroller. 

Standard Interfacing Circuits

The Arduino provides up to 10mA per channel, and the micro ship is limited to about 50mA.  This means you can light about 4 to 5 LEDs from the Arduino.  Anything more will burn out you microprocessor.  To solve this problem we use transistors to boost current for our output devices and as switches for our pins.  For instance, the 2N3904 transistor rated to output 200mA and has a gain of 25.

So the transistor needs 8mA to output 200mA, because Current = 200 mA / 24 gain = 8 mA.

The microcontroller runs at 5 V, so we need a resistor that will provide us with at least 8mA.  There is a 0.7V voltage drop across the transistor, which reduces the overall supply to 4.3V.  We ned a resistor that is less than the maximum output:

Resistance = 4.3 V / 0.008 A = 550 Ohms

Resistors are manufactured in a variety of amounts. The closes resistor we have to 550 Ω is 470 Ω.  It is good practice to connect in parallel to the output device a back emf suppression diode, because devices like relays, solenoids, and motors produce a back emf when power is switched off. 

Darlington Transistors
 
The MPSA42 is a medium, power transistor that can handle up to 300V at 600mA of current, which is three times as much as our last.  Transistor only multiply or amplify the input current from the power source, so we increase the resistance to the base of the transistor.  The MPSA42 transistor needs about 20mA to turn on completely and this is more than what the Arduino can supply through channel.  To solve this problem we first connect a transistor that can handle the input of the microcontroller like the 2N3904 and connect the base of the MPSA42 to the emitter of the 2N3904.  When we connect the transistors collectors together the gain is further multiplied.  This arrangement of transistors is called a Darlington, named after the inventor.  The gain of a 2N3904 is 25 band the gain of a MPSA42 is 30, and the gain in the Darlington configuration os Total Gain = 25 * 30 = 750.  A few Darlington transistors for high current DC motors are: MPSA13 low power NPN 30V 1.2A ($0.1.0), MPSA64 low power PNP 30V 1.2A ($0.08), and TIP 120 medium power NPN 60V 5A ($0.24).  The package of transistors thus far have been TO-92 package, so now we will use the larger package TO- 220.

DC Motors

Brushed DC motors (BDC) used in many applications like toys and other hobbies, because they are easy to use , inexpensive, and abundant.  BDC motors are made of the same components: a stator, rotor, brushes, and a commuter.  The stator generates a stationary magnetic field that surrounds the rotor.  This field is generated by either permanent magnets or electromagnetic windings.  The different kinds of BDC motors are based on there construction of the stator or the way the electromagnetic windings are connected to the power source.  The rotor, also called the armature, is made up of one or more windings.  When these windings are energized they produce a magnetic field. The magnetic poles of this rotor field will be attracted to the opposite poles generated by the stator, causing the rotor to turn.  As the motor turns, the windings are constantly being energized in a different sequence so that the magnetic poles generated by the rotor do not overrun the poles generated in the stator.  This switching of the field is the rotor windings is called commutation.  Unlike other electric motor types, BDC do not require a controller to switch current in the motor windings.  Instead, the commutations of the windings of a BDC is done mechanically.  A segmented copper sleeve, called a commutator, resides on the axles of a BDC motor.  As the motor turns, carbon brushes slide over the commutator, coming in contact with different segments of the commutator.  The segments are attached to the different rotor windings, therefore, a dynamic magnetic field is generated inside the motor when a voltage is applied across the brushes of the motor.  Its is important to note that the brushes and commutator are the parts of a BDC motor that are most prone to wear because they are sliding past each other.  One downside to BDC motors is that the motor introduces a lot of noise on the power rails, which can affect the microcontroller and some cases can completely stop the control of a program functioning.  Electrical noise can be reduced by soldering suppression capacitors across the motor contacts

Basic Principal of PWM

Pulse width modulation is achieved with the help of a square wave whose duty cycle is changed to get a varying voltage output as a result of average value of waveform.     

Demonstrate Microcontroller Controlling signal Lamp

Materials:
  • 470Ω resistor
  • 3.3KΩ resistor
  • 2N3904 transistor
  • Signal lamp
  • 5V power supply
Summary:

WE are to build a circuit that uses the transistor to an output device under a load.  Using pin 6 as our signal and connected to the resistor to protect the transistor from burning out.  The base of the transistor is connected to the resistor, collector to the output device, and emitter to the ground.We are using a signal lamp powered by a 5V powersupply.  It is important to identify the transistor pins or else the desired outcome will not be achieved.  The signal lamp is programed to turn on for one second and turn off for one second.  We measure the voltage drop across the signal lamp, which is 5.2V.  We then replace the 470Ω resistor with a 3.3KΩ resistor, which is much larger.  The result is the signal light is turned on, but very dimly.  The new voltage drop across the signal lamp is 4.9V.  



Demonstrate Darlington Controlling signal Lamp

Materials:
  • 470 resistor
  • 3.3K resistor
  • MPSA13 transistor
  • 2N3904 transistor
  • MPSA42 transistor
  • Signal lamp
  • 5V power supply
Summary:

This lab is very similar to the previous lab, but we use the MPSA13 Darlington transistor, and the 2N3904 and MPSA42 to compare resistor change outs.  The MPSA13 Darlington transistor is the equivalent to the to 2N3904 and MPSA42 combo transistors, because the signal light did not change in brightness.



Demonstrate Microcontroller Controlling Motor

Materials:
  • 2.2K resistor
  • TIP 120 transistor
  • 1N4001 diode
  • BDC motor
  • 1.5V battery and battery holder
Summary:

IN this lab we use a medium power transistor to turn ON and OFF a BDC motor with an emf suppression diode.  Although, we could use a capacitor, but we will not need tot solder it directly to the BDC terminal, because we can just use a diode.

Behold the DC motor turns ON and OFF from Arduino controller program.  YA!!!
Yes, we used a digital square wave signal.

Demonstrate PWM signal driving Motor

Materials:
  • 2.2K resistor
  • TIP 120 transistor
  • 1N4001 diode
  • BDC motor
  • 1.5V battery and battery holder
Summary:

In this lab we will use a PWM signal, which sort of mimics an analog signal.  AS we know digital signals cannot be analog signals, right?  A digital signal sends two or more signal at different constant voltage levels to turn our little motor on and off.  An analog signal would be like a sine waveform that is constantly changing and never rests at one particular voltage level.  Well, PWM is a type of digital signal that copies the overall pattern of a sinewave, does so in tiny intervals of constant voltage levels, so when averaged together looks like an analog signal.  The key to controlling a PWM is setting a D.C., not direct current, but Duty Cycle.  A Duty Cycle is percentile of "pulses", which can look like a lopsided square wave.  But a square wave that looks symmetrical and is actually a 50:50 D.C.  And by adjusting the duty cycle you can sort of set a certain speed, besides the full blast speed of 1.5V or 5V ON mode. 


(Drops microphone) PEACE!!!!

Lab 8 - Bi-directional Motor Control

One transistor can allow us to turn a 1.5V DC motor on or off.  Reversing the direction, however, needs more a complex arrangement.  There are to approaches to control the direction of a DC motor.

One way it to use the Double Pole Double Throw relay switch.  The diagram for this lab contains a DPDT relay switch controlled by a TIP120 transistor to reverse the direction of the motor.  This approach requires a dual 5-Pin relay that control this process.  The first pin starting with the coil is the mechanism that does the physical switching once power is applied to these terminals.  The second pin is called the Normally Close for when the switch poles are not activated.  You can say this is the passive switch position when the is no power to the coil.  The third pin is called the Common and is the pole that moves or pivots when activated, also a power supply is suppose to go here too or a signal.  The fourth pin is called the Normally Open, because in its passive, unpowered state the poles of the switch are not touching it and are therefore an open circuit.  The fifth pin is called Not Connected and its function means just that, the pin is not connected to the switch, so we don't use this one.  It is very important to know the functions of every pin on the relay or else you will be super confused and randomly connect anything and hope something happens.

Another way to reverse directions for a DC motor is to use a circuit called an H-Bridge.  It is called this name because there are four switching elements at the corners of the "H" and the motor makes up the horizontal line of the H.  Usually the top part of the H is the positive pole and the bottom is the negative pole where power is supplied.  There are two other inputs on the left and right side of the H-Bridge.  The left input is connected to the two transistors located on the left side of the H from the top and bottom.  The right input has the same connection, but to the Right top and bottom transistors.  The H-Bridge contains two NPN transistors (MPSA 13), two PNP transistors (MPSA 64), four diodes (1N4001), and four resistors (3.3Kᘯ) to protect the transistors from burning out.  The switches are turned on in pairs from high left to lower right of the H, but never on the same side.  Anything that can carry a current will work such as: four SPST switches, one DPDT switch, relays, transistors, and MOSFETs.  I believe there are other applications besides reversing the direction of a DC motor.  The H-bridge can be configured to use all four switches independently and make a four quadrant device.        


Demonstrate DPDT Relay Controlling Motor

Materials:
  • 1KΩ resistor
  • TIP120 transistor
  • DPDT relay
  • DC motor
  • 1.5V C battery
  • Battery holder
  • Breadboard
  • Wires/Leads
  • 5V power supply
Summary:

We are to build the schematic shown in lab manual.  It consists of the ON/OFF switch lead connected to a 5V power supply to the 1KΩ resistor, which is then connected in series to the TIP120 transistor.  The collector pin is connected to the Common pin of the DPDT relay.  The emitter pin is then connected to a pin on the relay that powers the coil.  the opposite pin connect to the coil goes to the ground.  The 1.5V battery's positive terminal connects to the Common on the relay that is opposite of the collector connection.  The negative terminal on the battery goes to the ground.  The left Normally Closed pin of the relay is connected to the right Normally Open pin. The left Normally Open pin is connected to the right Normally Closed pin.  The DC motor is also connected to the left Normally Open pin and also to the right Normally Closed pin.  As we see here the Normally Open pi is connected to the opposite Normally Closed pin and vis versa to reverse the direction of the motors spinning.  But once the wire that is connected to the 5V power supply is disconnected the relay returns to its passive state and switches the direction of the motor.  The coil is thus activated whenever connected to a 5V power supply thus switching the direction of the motors spin like an On and OFF button.

Demonstrate H-Bridge Circuit Controlling Motor Using 5V Power Supply

Materials:
  • 4 x 3.3KΩ resistors
  • 2 x PNP transistors (MPSA64)
  • 2 x NPN transistors (MPSA13)
  • 4 x 1N4001 diodes
  • DC Motor
  • 1.5V battery and battery holder
  • Breadboard
  • Wires/Leads 
  • 5V power supply
Summary:

We build a very basic H-Bridge schematic with two inputs at the left and right side, and the DC motor is connected between the top and bottom half of the H-Bridge.  The bottom half of the H-Bridge circuit use the bottom portion of the breadboard's ground bus and the top half of the circuit is connected to the top portion of the breadboards ground bus.  Connecting the H-Bridge to bottom ground bus the top 5V power supply bus is very important.  The 1.5V batter continuously runs the DC motor, while connecting the 5V power supply's positive terminal to either the top or bottom half of the bread board reverses the direction of the DC motor.  This is very similar to the previous lab.



Demonstrate H-Bridge Circuit Controlling Motor Using Arduino

Materials:
  • PCB H-Bridge or Breadboard H-Bridge
  • 1.5V DC motor
  • Arduino
Summary:

This lab is very similar to the previous, but for a few minor differences The wire that connects the upper and bottom portion of the breadboard is now replaced by two more wires that are connected to the Arduino's pin 12 and pin 13.  Also the Arduinos ground pin is connected to the breadboard.  Pin 12 will be programed to turn ON for 2 seconds with a 1 second STOP delay and pin 13 will turn ON for 2 seconds with a 1 second STOP delay.

Supper cool!!!! Right!?!?!