Sunday, February 18, 2018

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 with predetermined dimensions using only the code we created.  Not only did we need to navigate the maze successfully but we also needed to locate a light source.  The light source we used was a cluster of infrared LED's attached to a breadboard and power source.  Since we were required to put out the flame of a candle, we placed a piece of paper on top of the infrared LED's to simulate the candle flame and a successful extinguishing of the "flame" would be turning on our VEX robot fans and knocking the piece of paper off the breadboard.


We first started by writing our code for the VEX.  Since we had used functions in previous labs, the first step was to create our functions in the code.  This would allow us to write specific code for movements in a simpler manner than having to write out the entire section.  Here is the first parts of our code and you can see the functions we used.




You can see that the functions we created were functions to move straight, turn right, turn left and move back.  They were all listed before the main task so we could refer to them when writing our commands for the VEX.



For the first part of the main task of the code, we had the VEX travel down the left hand hallway towards room #2.  For each room we had two parts: the VEX would turn and "look" into the room, then either enter the room after finding the light source or move on to the next room.  If there was no light source, the VEX would turn and continue searching.  Once the VEX picked up on the light source in a room, the code for extinguishing the flame took over.







You can see that for each room the VEX comes across, it either sees the light source and enters the room or moves on to the next room.  Since our light source was a cluster of infrared LED's, the light was able to bounce off the walls and be seen by the flame sensor on the VEX.  The VEX didn't even need to enter the room to find the light source, just facing the opening was good enough to register an increase in the flame sensor value.


Once our code had been tested, adjusted and retested many times, it was time to perform the challenge.  We only wrote one code for all 3 challenges since that one code would search the entire maze and find the light source no matter which room the light source was in.  Here is our VEX robot in action finding and extinguishing the light sources like a boss!



The VEX robot was able to successfully navigate the maze and complete all 3 challenges with the highest average time.  This was due in large part to the extra time we spent as a group refining the code and testing the path of the VEX!


Lab 17 finished!


Sunday, February 11, 2018

Lab 16: Ultrasonic Rangefinder and other Sensors

In this lab, we worked with the ultrasonic rangefinder and continued to program the VEX robot in preparation for our final lab.  A lot of this lab consisted of reading the provided information and learning how the ultrasonic rangefinder can help us complete our final lab challenge.  At the end of the lab, there were two mini challenges to complete.  The first mini challenge required us to write a program that causes the robot to turn away from obstacles in front of it.



You can see that when the robot is right next to an object in front of it, the ultrasonic rangefinder recognizes this and the robot turns.



The second challenge required us to write a program for the VEX robot which made the robot turn in circles until it located an object in front of it.  We used a pink lunch bag as the object.  The VEX then spun in circles until the ultrasonic rangefinder located the lunch bag.  Once the lunch bag was located, the VEX then moved forward until right next to the bag, then the robot stopped.  This was practice for stopping in front of the burning candle and preparing to blow out the flame for our final lab challenge.



The VEX instantly located the lunch bag and quickly moved towards it, then stopped just short.  This movement was a direct result of our programming.  Parameters can always be adjusted by modifying the code to the VEX.



Lab 16 finished!

Lab 15: Building Square bot and doing the Electrical Tape Maze with and without Encoders

In this lab, we constructed the VEX robot.  The manual is available online at:
http://www.bit.ly/vexmanual .  We constructed the VEX robot according to the instructions except that we also added encoders for the left and right side of the robot.  The only thing we had to change out from the instructions were the 3" front square axels.  Those were switched with 4.5" square axels which were slightly longer to accommodate the encoder.



Here you can see we are assembling the VEX robot.



Once the VEX robot was assembled, we downloaded a program to the robot which would allow us to control it using a remote control.



Here you can see that I am controlling the VEX robot by using the remote control.  This exercise was only for practice and future movements by the VEX will be controlled using programming.



The next step was to write code that made the robot go where we wanted it to go.   There was a small course setup in the hallway with electrical tape that we navigated.  After a few trials of understanding the distances and numbers relating to the encoders, we were able to successfully navigate the course.



This video is one of our trial attempts that we used to determine travel distances and their relation to the encoders.  We only needed to make a few adjustments before we successfully completed the course without touching the course boundaries.


Lab 15 finished!

Lab 13: Building Sensors For Your Robot

In this lab, we focused on making sensors for our VEX robots.  We first constructed a flame sensor circuit and tested the phototransistor with a candle.  Once the circuit was completed, we used the flame of the candle to get sensor readings.



You can see that as she brings the candle closer to the phototransistor, the sensor readings on the serial monitor are changing.  The phototransistor is working properly and this quick exercise confirmed it.



We then constructed our own flame sensor by soldering the phototransistor to a resistor and lead wires.  Once the soldering was completed, we inserted heat shrink tubing over the connections and shrunk them to protect the connections from shorting out.  This flame sensor will be attached to our VEX robot and used to detect the candle flame in the maze which we hope to extinguish by then turning on fans that will blow out the candle.



Lab 13 finished!

Lab 12: Distance Sensing With Ultrasonic Sensor and Arduino

In this lab we used the ultrasonic sensor in combination with the Arduino to obtain sensor readings from the ultrasonic sensor.  Once connected per the lab instructions, we then opened the serial monitor to observe what the sensor readings were.


You can see the values changing as her hand moves closer and farther away from the ultrasonic sensor.  The sensor is detecting her hand and the distance it is from the sensor, then displaying those sensor readings in the serial monitor.


We then added a motor to the circuit and adjusted the program so that if there was something in front of the ultrasonic sensor less than a predetermined distance, the motor would then be turned on.



You can see that when her hand is placed close to the ultrasonic sensor, the sensor reading then becomes within the predetermined distance and the motor is turned on by the Arduino.  These sensor values can be adjusted to whatever distance you like.


Lab 12 finished!

Lab 11: Microcrontrollers, Input and Output

In this lab, we looked at microcontrollers and how they work.  Microcontrollers are like small computers that can take input such as sound, light, movement or a switch and convert it to operating a motor, turning on a light or emitting a sound from a speaker.  They can also be programmed to react however the user wishes by simply adjusting the code.


We entered a code that would flash and LED 8 times, then stop.  This was done with a "for" statement that said as long as the LED hasn't flashed 8 times, flash with a 200ms delay.  Once the LED had flashed 8 times, the loop ended and the flashing stopped.



We also programmed the arduino to turn or off a pin connected to an LED based on when a switch was pushed.  This made it so we could turn the light on and off with the switch, just like a typical light switch, except this one was programmed with a microcontroller.



You can see the LED light up as the switch is pushed.


Another part of the lab concerned if statements and comparison operators (==, !=, <, >).  We can tell the arduino that "if" some condition is met, then perform a certain operation.  If/else can also be useful in that the program can check to see if the "if" statement is true, and when the statement isn't true, the "else" part of the program will be performed.


LDR (Light Dependent Resistors) are resistors that change their resistance based on the amount of light hitting the sensor.  We put the LDR into the circuit we still had from the previous exercise.  We then entered the code into the program that would switch between turning 2 LED's on based on the amount of light hitting the LDR.


Here you can see we are using the light from a phone to increase or decrease the amount of light hitting the LDR, which then will turn on or off the LED's based on the sensor value of the LDR.



Next we used a thermistor to control a motor.  We used the same circuit from the previous experiment and just switched the LDR with the thermistor.  We also added a TIP120 transistor to the circuit to control the motor.



As the thermistor is covered by her hands, the temperature goes up and shuts off the motor.  Then as she releases the thermistor, it cools off and the motor turns back on.  The control of the motor is done by the preset sensor range in the program.



The last part of the lab we connected a motion detector to the Arduino as an analog input.  We also connected a relay to the circuit so that when the motion sensor detected movement, the relay would switch.



You can hear the clicking of the relay as my hand is placed in front of the motion sensor, which is the black spherical looking component on the breadboard.



Lab 11 finished!

Tuesday, February 6, 2018

CODE.ORG Homework Assignment

This work was done online on the site CODE.ORG.  As practice for our future lab where we have to code the VEX robots, we did some practice coding on the code.org website.  There were three different parts to the coding exercises: Star Wars, Minecraft and Elsa from Frozen.



In this video, you can see that I entered code with those colored blocks.  The coding lesson was simplified by making each command a drag and drop block.  Actual coding is more complicated but for our learning purposes, simpler is better.  I chose the characters, music, points added or subtracted.




In this video, you can see that the scene froze and would not play after clicking the "Run" button.  I added exploding barrels through code but when they exploded, it froze the program.  You can see the barrels frozen in mid explosion.  However, the video is still good to look at because you can see the code blocks I added to make the scene.  I added things like how far to walk, when to turn, what to do if there's lava ahead.



Here you can see I had a chance to practice with Elsa.  The code I added on the right made her create the snowflake shape on the ice.  You can see that I directed her by telling her how far to skate, when to turn, how far to turn, and how many times to repeat the same movements.



Here you can see that I chose my own blocks of code to add to the coding and this was the shape she skated out.  I didn't know ahead of time exactly what the shape would be but it turned out pretty cool in my opinion.



Overall, I'm glad we had this practice of coding because we will soon be putting this knowledge to the test when we program our own VEX robots in a similar manner.



CODE.ORG Homework Assignment finished!

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!

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 ...