Sunday, January 28, 2018

Lab 10: Using the Serial Port

In this lab we practiced using the serial port and serial debug.  The serial command will allow you to see values from analog sensors.  These values can help you decide how to code the Arduino based on specific values you might be looking for.



We first built the LDR circuit that we previously built with a 10K resistor and connecting to analog pin 0 of the Arduino.  We then coded the Arduino to allow us to use the serial debug.




You can see here that when we cover up the LDR, the resistance changes and this change is registered on the serial debug screen.



We can also code the Arduino such that it will read whatever we want it to read in the serial debug screen.  We changed the code to read "The Sensor reading is" and "ADC counts" by adding it to the code with the Serial.print command.



You can see that the values are still registering on the serial debug screen but now the added words are included based on how the code was changed.



We then practiced using keyboard inputs to trigger the Arduino.  We initialized the serial port again and coded "inChar" into the Arduino which stands for a character or small integer.  After opening the serial monitor and typing numbers and letters, the serial monitor responded with the appropriate response.  The entered characters will get a response based on either dec, hex or binary as specified by the code.



You can see the responses we got in the serial monitor after typing in different characters, numbers and letters.



Next we coded the Arduino to turn a pin on or off based on characters typed into the keyboard.  We used the command: "char inChar = (char)Serial.read();



You can see the prompt in the serial monitor asking for either a 1 or 0.  When the 1 or 0 is pressed you can then see the LED switch on or off based on the code we uploaded.



Lab 10 finished!

Lab 9: Driving Motors and Other Output Devices

In this lab we learned how to use transistors to construct standard interfacing circuits.  These interfacing circuits can be used to create more load as the Arduino is only capable of 50mA max.  The transistor we used in constructing the circuits is the common 2N3904.  We know that the transistor is rated to 200mA and has a gain of 25 so to determine the current, we divide the current by gain to get 8mA (.008A).



We obtained a signal lamp and built a standard interfacing circuit with the 470 ohm resistor and transistor.  Then we used the same "blink" program for the Arduino and got the signal lamp to blink.




Here you can see the signal lamp blinking with the transistor integrated into the breadboard.





We also measured the voltage across the signal lamp with the multimeter while using the 470 ohm resistor in the circuit.  The voltage was an average of 4.81V.




Then we changed the resistor from 470 ohms to 3.3K ohms.  This is a bigger resistance and inserting it into the circuit would expect to produce a drop in voltage.  Measuring the voltage across the signal lamp a second time with the larger resistor gave a voltage of 4.60V.



Next we learned about Darlington transistors and their applications.  For example, the MPSA42 transistor is larger than the 2N3904 and can handle a bigger load.  So you can use the 2N3904 to "turn on" the bigger MPSA42.  This arrangement of transistors turning on bigger transistors is called a "Darlington".  If the gain of a 2N3904 is 25 and the gain of a MPSA42 is 30, the the gain of the two in a Darlingtion configuration is:     Total Gain = 25*30 = 750 gain



We built a Darlington circuit with the 2N3904, MPS, 3.3K ohm resistor, diode for back EMF suppression. 



You can see both the 2N3904 and MPS transistors on the breadboard which make a Darlington.  The signal lamp is being lit but it's not very bright.





We then replaced the MPSA13 transistor with a bigger TIP120 transistor which would increase the current to the signal lamp.  Notice the larger TIP120 on the breadboard and much brighter signal lamp.



Next we built a circuit using the same TIP120 power transistor to switch a small electric motor on and off.  We used a 2.2K ohm resistor and a diode for back EMF suppression along with a battery power supply.



You can see the motor spinning as the power supply (battery) is connected to the circuit, and also notice the TIP120 power transistor on the breadboard as well.



We then connected the circuit and motor to the Arduino and wrote code to adjust the speed of the motor using "analogWrite" to the pin with the motor connected.  The code adjusted the speed of the motor from 20% to 90% and back in a continuous loop with a delay of 1 second in between each switch.



You can see the speed of the motor speeding up and slowing down based on the code we wrote to the Arduino.  With the help of the power transistor TIP120, the Darlington circuit is functioning properly.



Lab 9 finished!

Saturday, January 27, 2018

Lab 8: Bi-directional Motor Control

In this lab we experimented with changing the direction of a spinning motor.  If the positive and negative of the current are switched to the motor, the motor will spin the opposite direction.  This can be achieved with a DPDT relay.  When power is turned on and off to the coil of the relay, the relay switched between normally open and normally closed on both sides of the relay.  This gives the result of the motor changing the spinning direction.  We constructed a simple circuit with the relay and controlled the direction of the spinning motor through the wires that fed power to the relay coil.



You can hear the relay clicking as power is applied and removed and also see the direction of the motor changing as power is applied and removed.



Next we used an H-bridge to control the direction of the motor.  We chose option 2 in the lab which meant we would solder together our own H-bridge to use in the lab.  We obtained the correct circuit board, transistors, resistors, diodes, and soldered everything to the board using the diagram on the circuit board.  Here is the H-bridge:








After building the H-bridge, we connected it to our breadboard and also connected the motor across the M+ and M- pins.  We used the 5V power supply across the VCC and GND pins.  By simply changing the positive and negative to the H-bridge by switching the wires, the motor changed it's direction of spin.





This is like a manual relay where you change the positive and negative by hand and unplug the wires.



Then we connected IN1 and IN2 to pins 12 and 13 of the Arduino and referred to the code used in the previous lab to turn the motor on for 50ms, stop for 1 second, reverse direction for 50ms, stop for 1 second.  This was set up in the loop so that it would continue endlessly.



Lab 8 finished!



Lab 7: Introduction To Microcontrollers

In this lab we learned how to use a microcontroller and what they are designed to do.  The microcontroller that we are using is the Arduino Uno which is a small microcontroller that has both analog and digital inputs, ground, voltage and is programmable.  The code that is programmed into the Arduino turns the pins on or off (High or Low) which then controls whatever is connected to the Arduino.



First we opened the Arduino software and plugged in the Arduino.  After checking the settings, we uploaded a pre-made code for blinking.  We noticed the orange light was blinking after uploading the code and the rate at which the blinking occurred changed as we changed the delay on the code.



Then we build a simple circuit with an LED, 220 ohm resistor and connected the positive end of the LED to pin 10 in the Arduino. After writing a simple code to have the LED turn on and off with a 1 second delay and uploading the code, the LED flashed as expected.



You can see we only had four lines of code in the loop which turned the LED on and off, and a one second delay in between each.


We then used the same technique to connect 4 LED's to the Arduino and control them.  The process was almost identical as the single LED, we just had to write code for each LED changing only the pin numbers based on which pin they were connected to.  We also had to define the pins.  Once the code was uploaded to the Arduino and we adjusted the delay, we had the lights flashing in a pattern similar to the KITT car on Knight Rider.



The delay was adjusted to 25ms which made the cycle much faster and gave the illusion of motion from the pattern of flashing lights.


Lab 7 finished!

Monday, January 22, 2018

Lab 6: Transistor Switching

In this lab we worked with transistors and built circuits using them.  Transistors are like a switch but instead of just a simple on/off, they can switch the flow of electricity.  In this first circuit we built, the transistor is "turned on" by a push button which allows the flow of electricity to the base.  This flow of electricity to the base is what switches the transistor to allow current to flow through it.


Here, I'm pushing the button which is turning on the transistor, which then allows the current to pass through and turn on the LED.



In this next part, we removed the push button switch and resistor #2 and replaced it with our fingers.  Since our bodies have high resistance, they act similar to the small resistor components.


Here, I'm bridging the connection between the wires with my fingers and current is flowing through my body.


Next we set up a circuit with a 100k potentiometer and resistors and used our 5V power supply.  An Ammeter was used to measure the current passing through different points in the circuit, before or after resistors and the transistor.



Here, the ammeter is registering the change in current as I am adjusting the potentiometer.  The Beta (Gain) of our transistor was determined to be 220.  The current was also determined to saturate at 13mA.


Lab 6 finished!

Sunday, January 14, 2018

Lab 5: Switches And Relays

In this lab we learned about and experimented with switches and relays.  Switches can have multiple poles and multiple throw positions.  They are a good way to turn power on and off to the circuit without having to disconnect any components.  Relays use a low voltage or small current to flip between positions.  They are also categorized like switches in that they can be SPST, SPDT, DPST, DPDT, etc.  There is an iron core in the relay with a coil of wire wrapped around it.  When there is current flowing, a magnetic field forms around the iron core and pushes or pulls a lever (springy strip of metal).


After understanding how switches and relays work within circuits, we went ahead and build a circuit that included a push button switch, a DPDT relay, 2 LED's, connecting wires and a 5V power supply all connected using the solderless breadboard.  We ran the power through the relay so that the relay was switching on and off by itself when the pushbutton switch was pushed.  It looked like only one of the LED's was lit because the other one was flashing to fast to see it from the relay switching itself on and off.

You can see that the LED that lights up is controlled by the pushbutton switch.  The switch controls the current to the relay and when current is turned on or off, the relay powers one or the other LED's.



Capacitors act like batteries in a circuit in that they can be charged up and store energy.  Alignment is important when placing capacitors in a circuit.  The long wire needs to be connected to the positive side of the circuit otherwise the capacitor won't work.


A capacitor was introduced to the circuit by attaching the short lead of the capacitor to the negative side of the circuit.  We placed the leads of the capacitor on either side of the relay coil (bottom left and right pins) in the breadboard.  The capacitor charges when the current flows and when the contacts of the relay open, the capacitor acts like a battery and then sends power to the relay.  This cycle repeats over and over which causes the LED's to flash!

Lab 5 finished!

Lab 4: Schematics, Ohm's Law And Potentiometers

In this lab, we learned about schematics, using Ohm's Law (voltage, current, resistance), and potentiometers.  Schematics are a good way to show how a circuit works.  It's essentially a road map of the current path and the stops along the way are any number of electrical components (capacitors, resistors, LED's, relays, potentiometers, etc).



First I got 3 LED's and 3 different resistors (100ohm, 1.0Kohm, 10Kohm).  Then I constructed 3 different circuits, each using one LED and one of the resistors.  As expected, the resistor with the lowest rated resistance produced the brightest light from the LED.



The 100ohm resistor is at the top, then the 1.0Kohm resistor, and the 10K resistor is on the bottom.  You can see that less resistance means higher current based on Ohm's Law.  Since V=IR, if the resistance goes down then the current (I) must go up to satisfy the equation.



To test this even further, I hooked up an LED circuit with no resistance (a wire) to the power supply in the breadboard.  Based on Ohm's Law, since there is no resistance, the current will be very high and possibly damage the LED.




When the power supply was plugged in, the LED didn't explode but instead emitted a dull steady flash.  This was determined to be a safety feature in the power supply that was keeping the full current from running through the circuit and destroying components.



Next we learned more about Ohm's Law and KVL and studied examples.  By noticing the relationship between voltage, current and resistance, we calculated the resistor that would produce the brightest LED without damaging it and staying within the LED's tolerances.  Since the LED uses 1.85V and we're working with a 5V power supply, the resistor needs to take 3.15V.  Using Ohm's Law, the resistance for the circuit should be 105ohms.  I got the resistor that was closest to this number (100ohm resistor) and connected the circuit to the breadboard.




You can see that the LED is very bright when connected to the 100ohm resistor.



Potentiometers are adjustable resistors.  There are many different potentiometers, each with a different rating.  If a potentiometer is connected to a circuit with a resistor also in the circuit, the resistance of the resistor is always added to whatever resistance is dialed into the potentiometer.








Here you can see that when I use the tool to manually adjust the potentiometer, the resistance is also being adjusted.  With adjusted resistance comes adjusted current which leads to varying degrees of brightness.




Finally we connected a LDR (Light Detecting Resistor) in a circuit with the LED and 5V power supply.  The LDR changes it's resistance based on the amount of light that reaches it.  Once the circuit was assembled, the LED was bright.  We covered the LDR and noticed the change in brightness of the LED caused by the change in resistance.



Here you can see that when the LDR is covered up, the resistance goes up and the current goes down to keep the Ohm's Law equation balanced which dims the LED.


Lab 4 finished!




Lab 3: Using A Multimeter

In this lab, we learned how to use a multimeter to test continuity, resistance and voltage.  The multimeter has many more functions but these are the functions we experimented with in the lab.


Continuity is tested by turning the multimeter switch to the icon that looks like a soundwave.  I used the probes to test continuity between paths on the circuit board I worked on in Lab 1.  The multimeter sends a small voltage through the probes and if the voltage comes through the circuit and back to the multimeter, the multimeter beeps and there is continuity.  The paths that were connected had continuity.


Next I tested the voltage of a 1.5V AA battery by adjusting the multimeter to 2V in the DC range.  The 1.5V battery read 1.449V which was only slightly less than the rating.


The 9V battery was then measured by the same process of connecting the probes of the multimeter to the positive and negative ends of the battery.  The 9V battery read 8.152V which was less than the 9V rating meaning it had been used a bit and lost some of it's charge since it was new.


It was also important to keep in mind that the multimeter has AC and DC modes when measuring voltage and you have to switch between the two when testing each one.  If not, your voltage reading will be 0.


We then tested the resistance of 5 resistors.  The value of the resistors was determined from the colored bands around the resistors.  The last color in the first 3 or 4 is a multiplier which tells you how many zeros to add.  The final color give you the tolerance of the component.  The 5 resistors I chose had a value of .68Kohms, 2.70Kohms, 470ohms, 100ohms, 1.00Kohms.  All the resistors had their resistance measured by the multimeter and touching the probes in any order on the ends of the resistor.  All five were very close to their rated resistance.


A potentiometer was tested next.  Potentiometers are resistors that can be adjusted.  I connected the multimeter across two adjacent pins and lowered the potentiometer as far as it would go and the reading was 0.8ohms.  Then I raised the potentiometer as far as I could and the multimeter read 9.76Kohms.  We were also able to tell if the potentiometer was linear by adjusting it to roughly half way and checking to see if the resistance was also roughly halfway between 0 and 10K.  The multimeter read 4.83Kohms which confirmed that the potentiometer was in fact linear.


The LDR (Light Dependent Resistor) was also tested.  By covering up the resistor, the resistance changes due to the change in light.  The max resistance I was able to achieve by covering the LDR was 0.515Mohms.


A similar procedure was followed when measuring a pressure dependent resistor.  After connecting to the multimeter, applying pressure to the resistor registered a change in the resistance.  The resting resistance without applying pressure was 350ohms.


The temperature dependent resistors were also tested in a similar fashion.  Once connected to the multimeter to measure resistance, I held the thermistor in my hand and noticed the increase in resistance.  My classmate also held the thermistor and since her hands were colder than mine, we were able to notice the difference in the two resistances based on the different temperature applied.

Lab 3 finished!

Saturday, January 13, 2018

Lab 2: Introduction To Using A Breadboard

In this lab we practiced building a circuit on a solderless breadboard.  The solderless breadboard is an easy way to experiment with different circuit configurations because you can instantly attach and disconnect components at will without using any solder or connectors.  The breadboard has metal strips that connect columns and rows of holes together.  The metal strips are springy so when a solid-core (not stranded) wire is inserted, the metal strip grabs hold of the wire.



We used an LED and a 1.0K ohm resistor, along with our 5V power supply to practice constructing a circuit on a breadboard.  Here is the assembled circuit with LED lit up.



The LED is lit up and not exploding because the resistor is in the circuit.  The positive and negative leads of the power supply are going into the positive and negative rails of the breadboard.

Lab 2 finished!

Lab 1: Introduction To Soldering And Making Your 5V Power Supply

In this first lab, we completed two main tasks.  We first learned the proper way to solder electronics by instructor explanation and watching videos.  Then we practiced soldering random components on a small circuit board.  I used the techniques we had just learned and soldered five components onto the circuit board.  Having soldered before when changing out electric guitar pickups, the soldering of electronic components to a circuit board was fairly easy.



You can see I placed the components in random positions on the circuit board.



This picture of the back shows that the solder is completely covering the copper contact and the wires have been clipped.



The second task we needed to complete in the lab was to make our own 5V power supply.  To practice for this, I soldered 2 wires together.




These were two small scrap pieces of wire but the technique would be the same when making the power supply so it was good practice.  After being sure to heat both wires with the soldering iron, the solder was sucked into both wires and created a strong connection.



Now, we used this technique in making our power supply.  I exposed the wires and stripped them, determined the polarity and soldered the red lead to the positive and black lead to the negative.  Finally I applied heat shrink tubing to the connections for protection from shorting out the power supply.



The heat shrink tubing is completely covering the soldered connections.

Lab 1 finished!

Lab 17: Using IR Sensors for flame and line detection for the VEX

In this lab, we used everything we learned in the previous labs to complete this final lab challenge.  The challenge was to navigate a maze ...