Tuesday, February 12, 2013

Day 11 Autonomous driving using sensors and ultra sonic sensor

01/30/2013

          Today's challenge was use all the sensors and sonars installed on the robot to do an autonomous driving test, in which the robot would turn right after it sensed the wall, then drive straight and stop upon reaching a blackline. After, it would detect a lit candle, and finally driving straight toward the candle until it reached the marked circle surrounding the candle.

The team's robot has a ultra sonic sonar at the front to detect the wall; a line sensor at the back of the sonar to detect the black line, and the flame sensor is on the toppest compartment in the middle, protected from crashing into the wall.
 
The team's strategy was to use the flame sensor's value to determine the robot's distance from the flame. If the value was over a certain limit, the robot will stop as it knew that it was close to the fire.
 
The team's strategy functions as anticipated. The robot reach it final destination at the outter rim of the candle.

Day 10 Project 1 due; Ultra sonic sonar

01/29/2013

          An ultra sonic sonar is a device that a robot uses to measure the distance between it and an object.

The ultra sonic sonar has two speaker-like cyclinders. One of them produces an ultra sonic sound wave; another one recvieves the returning wave. The sonar measure the distance by measuring how long does it take for the wave to bounce back.
 
The sonar is usually installed at the front of the viechle.
 
The red-looking devices at the back of the viechles are call encoders. They are used to keep tracks how many rotations the wheels have turn. The encode can be used to meansure the amount of rotation needed for the viechle to move for a certain distance.
 
 
 

Day 9 Starting "Fire Fighting Robot" Project; Finishing "Toy Hacking" Project

02/24/2013

         "Fire Fighting Robot", Our new project as well as the final project. The goal for this project is to build an autonomous viechle using 2 VEX robot kits that search for a candle in a predetermined maze and using a fire-extinguishing mechanism to put out the candle without disrupting the base which the candle is placed on.

           The goal for today is to build a functional line sensor and flame sensor and install both sensors onto the VEX rebot that have been built week ago.

 
The flame sensor is composes of a phototransistor and a 10k ohm resistor. The phototransistor is connected to the power and the signal calble while the resistor is connected to the signal cable and ground.
 
The line sensor is composes of a detector (phototransistor) as well as an Infrared emitter. The infrared emitter is connected with a 220 ohm resistor in series and connected between power and gound. The dectector is at the same set up at the flame sensor.
 
Black tapes are used to wrap around the frontend of the emitter so that the IR light will not go stright into the detector. The emitter and the detector is then leveled and taped together with another layer of electric tape. 
 
After installing the hardware and properly programmed, the robot is ready for line and flame detection test.

The robot should be able to stop as soon at it reach the black tap and rotate to search for the flame.
If it find the flame it should stop with the flame sensor pointing at it.

The flame sensor should be at the same level as the flame for best reading.
 
--------------------------------------------------------------------------------
 
Completeing the Toy
 
Some minor modification on the circuit and the programming code has been made.
Since the breadboard and the launchPad was too big to be fitted inside the toy, they are left outside for convenience.

The toy is now ready for final testing.

The final tests are successful, and the toy is ready for presentation on next Tuesday.
 

Day 8 Music; Continue on "Toy Hacking" Project

02/23/2013

                       As we have already discussed, there are many output devices that can be controlled by the microprocessor. The microcontroller has pins for digital output that can control frequency for sound output from a speaker. The program's coding that required to control speaker is simply. The only variables needed are pin_numbers, frequency, and play_time.

here is a sample for the code:

void loop( )
{
     noTone(8);                             // turn off the tone function for pin #8
     tone(8, 440, 200);                  // play sound at 440hz for 200ms on pin#8
     delay(200);                            // silent for 200ms
}

Unfortunately, the videos related to music and sound output was lost, so there will not be any videos for examples.

              ------------------------------------------------------------------------------------------

Since there is no time to work on the project during class time, the project has to be done at home.

The circuit for the project is finally completed and the basic programming is finish.
 
A successful test run after hour of debugging the code.
 The music playing through the toy's speaker is controlled by the launchPad
 
The code for the music is exactly the same style as shown above on the top of the page. However, if you find entering every tone is annoying, you can use an array to store all the tones and let the microcontroller plays them according to their position in the array.

Day 7: Controlling motors with microcontroller; Continue with "Toy Hacking" Project

01/22/2013


                           Last week, we have successfully using microcontroller with input devices such as LDR sensor and button to switch on and off LED lights. This time, we will be using other output devices such as a motor.

                Before we start, we have to know that the maximum current output from the launchPad is very small. Therefore we cannot connect the motor directly at the launchPad, we have to use transistors.

                Some transistors that can handle greater current are TIP120, and MPSA13. One can also use Darlington transistors to handle greater current.

Because motors are quite expansive and of limited supply in the class, it is always safer to test out the circuit with a cheaper output device.
 
In this case, a christmas light tree!  
On the side, the circuit using a MPSA13 transistor is shown.
 
 
Voltage across the light when the base pin is connected to a ~2.2k ohm resistor.

 Voltage across the light when the base pin is connected to a ~330 ohm resistor.
 
As you can notice, the smaller the current going to the base pin will decrease the voltage across the output device. Therefore, we can control the output device by changing the current going to the base pin.
 
 
In case you do not have any TIP120 or MPSA13, you can always use a 2N3904 and a MPSA42 transistor to build the darlington transistors.
 
 
After confirming that the circuit is correctly built, hook the extended wires from the toy's motor to the circuit as the output device. As expected, the motor is activated as expected.
 
Aftering completing all the activities involve driving motors, there is no more time to work on the project. The only project-related complishment for today is to get the motors to work under control.

Day 6 More Microcontroller And Begining the "Hack a toy" Project

01/17/2013

          Other than using the button as the input device, other input devices can also be connected to the microcontrollers as long as the microcontroller is programed to recieve the input data.

 
Using LDR sensor (connecting to digital pin) to signal the launchPad (microprocessor) to turn on or off the LED light.

The LDR will gives a different reading of brightness to the launchPad while the launchPad evaluate the LDR reading to turn on or off one of the two LED light, or both.
 
 
Other than switching light on and off, a microprocessor can also output signal to different output devices. Demostration with other output devices will be left to next week.
 
-----------------------------------------------------------------------------
 
Beginning the "Toy Hacking" project. . .
 
They toy has to be skinned and the hardware are taken out for remodification.
 
All the mechanical parts, and other output devices (motors, speakers) are disconnected from the toy's original circuit board. The wires are then lengthened by soldering to extension wires.
 
The purpose for soldering extension wire was to make connection to the breadboard (if used) or microcontroller easier since they may not be able to fit into the toy.
 
 
 

Tuesday, January 29, 2013

Project 1: Hack a Toy!

          The toy is an "ear flapping toy" which would make a sound, flap its ear and swing it's body when the button at its feet is pushed.

          The idea for the hacked toy is to let people understand how much time they will need to spend on taking care puppies (You can pet the toy by covering the LDR at the back of the toy). So that they will think twice before having a puppy.
 
The toy has 3 output devices: 2 motors, 1 speaker,
and 1 input device: button.
 
One of the motor is for controlling the ears to flap, while another motor is respnsible for swinging the body left and right.
 
-------------------------------------------------------------------------------------------------------------
 
During the  Trails...
 
          The first plan is to use a LDR as an input device to the microporcessor. The toy will keeping swinging its body and flap its ears twice every 5 seconds as long as the LDR is not covered by anything. It will repeat the action for three times.

           Before starting the third time, if the LDR is not blocked from a light source, the toy will enter a "happy mode" in which it will flap its ear 4 times. Afterward, it will wait for another 5 second to repeat the whole process again.

          If not, it will then flash the LED light to indicate it enter the "sad mode". Afterward, it will ignore you for 10 second before it repeat the whole process again.

           Here is a example vedio for the action:

 
The circuit includes a Tip 120 transistor to control the current flow to the ear motor. A MPSA13 transistor controls the current flow to the body's motor. They relay controls the direction of the ears.Fially, there are few resistors of different values and a LED light.
 
 

--------------------------------------------------------------------------------------------------------------------------

                                                                 The Final Product
          The final product was modified with few more outputs and refined motions. Instead of giving only 2 chance to interact with the toy to make it happy, it now has 3 chances. Which mean the attention gathering moving is increased to 4 times instead of the original 3. After entering the "happy mode", it will also play a music. As for the "sad mode", it will play another music (a section from the song "さよならの夏” (The Summer we said goodbye) to show its loneliness.

             A potentiometer and a speaker is  added to the circuit for the sound effect.

Here is a sample for the "happy mode":
 (the music may not be heard clearly)
 

Here is a sample for the "sad mode":
(the music may not be heard clearly)
 
The Source-code for the project:
#define sensorPin A0
#define earPin 8
#define directPin 9
#define ledPin 3
#define bodyPin 7
#include "pitches.h"
int sensorValue;
void setup()
{
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(7, OUTPUT);
}
void loop()
{
  int sensorValue;
  sensorValue = analogRead(sensorPin);
  if (sensorValue >= 100)
  {
    int counter;
    counter = 1;
    digitalWrite(ledPin, LOW);
    digitalWrite(earPin, LOW);
    digitalWrite(bodyPin, HIGH);
    while (sensorValue >= 400 && counter < 4) // Automatically activate under day light.
    {
      digitalWrite(earPin, HIGH);
      digitalWrite(directPin, HIGH);
      delay(200);
      digitalWrite(directPin, LOW);
      delay(200);
      digitalWrite(directPin, HIGH);
      delay(200);
      digitalWrite(directPin, LOW);
      delay(200);
      digitalWrite(earPin, LOW);      // Flap the ears twice to attraction attention & wait for interaction.
      counter = counter + 1;
      delay(5000);
      sensorValue = analogRead(sensorPin);
    }
    if (counter < 4 && sensorValue < 400)    // Cover the toy's rear LDR sensor at the back before 3     attempted attractions by the toy to enter friendly
      {                                      // & happy mode.
      digitalWrite(bodyPin, LOW);
      digitalWrite(earPin, HIGH);
      digitalWrite(directPin, HIGH);
      delay(200);
      digitalWrite(directPin, LOW);
      delay(200);
      digitalWrite(directPin, HIGH);
      delay(200);
      digitalWrite(directPin, LOW);
      delay(200);
      digitalWrite(directPin, HIGH);
      delay(200);
      digitalWrite(directPin, LOW);
      delay(200);
      digitalWrite(directPin, HIGH);
      delay(200);
      digitalWrite(directPin, LOW);
      delay(200);
      digitalWrite(earPin, LOW);
      tone(5, NOTE_A3, 200);
      delay(500);
      tone(5, NOTE_A3, 200);
      delay(500);
      tone(5, NOTE_A3, 200);
      delay(200);
      tone(5, NOTE_B2, 200);
      delay(200);
      tone(5, NOTE_E5, 600);
      delay(200);   
      counter = 0;
      delay(5000);
    }
    if (counter >= 4)                      // Leave the toy alone to let it enter the lonely mode &
    {                                      // play the song "The Summer We Said Goodbye".
      digitalWrite(earPin, LOW);
      digitalWrite(bodyPin, LOW);
      digitalWrite(ledPin, HIGH);
      delay(1000);
      digitalWrite(ledPin, LOW);
      delay(500);
      digitalWrite(ledPin, HIGH);
      delay(1000);
      digitalWrite(ledPin, LOW);
     
      // Flash the LED, then play the music.
      // Refer music to sayonara_No_Natsu.ino
     
      tone(5, NOTE_B2, 800);
      delay(400);
     
      tone(5, NOTE_G3, 2000);
      delay(800);
      tone(5, NOTE_B3, 800);
      delay(400);
     
      tone(5, NOTE_F3, 2000);
      delay(800);
      tone(5, NOTE_B3, 800);
      delay(400);
     
      tone(5, NOTE_E3, 2000);
      delay(800);
      tone(5, NOTE_D3, 400);
      delay(400);
      tone(5, NOTE_C3, 400);
      delay(400);
     
      tone(5, NOTE_D3, 2000);
      delay(900);
      tone(5, NOTE_G2, 800);
      delay(400);
     
      tone(5, NOTE_C3, 800);
      delay(400);
      tone(5, NOTE_D3, 800);
      delay(400);
      tone(5, NOTE_E3, 800);
      delay(400);
     
      tone(5, NOTE_B2, 800);
      delay(400);
      tone(5, NOTE_E3, 800);
      delay(400);
      tone(5, NOTE_G3, 800);
      delay(400);
     
      tone(5, NOTE_F3, 200);
      delay(100);
      tone(5, NOTE_G3, 200);
      delay(100);
      tone(5, NOTE_F3, 2000);
      delay(800);
      tone(5, NOTE_CS3, 800);
      delay(400);
     
      tone(5, NOTE_DS3, 2000);
      delay(800);
      tone(5, NOTE_E3, 400);
      delay(400);
     
      tone(5, NOTE_E3, 6000);
      delay(10000);
    }
  }