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);
    }
  }
   
 

Tuesday, January 22, 2013

Day 5 Drive-testing Square Bot, Transistor, Microcontrollers

01/16.2013

          Test driving with the square bot was successful, and the robot survive the crash testing with no damage to its structure.

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

          A transistor is a switch which control the flow of electric current just like a relay. Yet, it is more sensitive and versatile than a relay. Transistors use "positive" or "negative" voltages to control the switch on or off. There are two type of transister, NPN and PNP. NPN uses a positive potiential to activate the switch, and PNP uses a negative potential.
A schematic with a NPN transistor controlling the brightness of the LED. Always connect a resistor to the transistor because the transistor takes only a small current.
When the button is pushed allowing a positive potential to reach the base (middle pin) of the transistor, the light lit up as more current is allowed through the emitter to the LED.
 
Using the finger tip to activate the transistor. Since the resistance of human skin was so great that the transistor did not fully activated thus allowing only a small current enough for the LED to grow with a dim light.
 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
 
 
 
A microcontroller is a circuit board installed with all the hardware and firmwares ready for uploading programs from computer to control different electronic output devices. The pins on the side of the microcontroller are for revicing inputs and delivering output through small current.
 
 
Using the microcontroller to control the blinking sequence of the LED.
 
K.I.T.T car's pattern from the Knight Rider TV series using a microncontroller and 4 LEDs.
 
Controlling a LED to make it blinks faster and faster after.
 
Using a button
 

Saturday, January 19, 2013

Day 4: Relays and Square Bot

01/15/2013

          A Relay is similar to a switch. Instead of using physcial interactions to activate the switches, a relay rely on the magnetic field set up by a conducting coil to activate (or energizes) itself. In other words, a relay is an electrical self activated switch. Meanwhile, a relay are more applicable with high current.
   
A type of relay used in my circuit.
 
Some schematics with relays connected. The relays here perform as oscillator, when the coil is energized, it will open a contact to disturb power to the coil and relax the relay. The contact will then close again after it is relaxed. This process keep repeating until there is no power supplied to the relay.
 
The relay oscillator turns off and on both LEDs as well as making a buzz sound as the oscillation goes on.
 
By adding a capacitor parallel to the coil, it will slow down the oscillation as some power are used to charge the capacitor. The clicking sound replaces the buzz sound as the oscillation slows.
 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
Constructing a Vex square bot is easy by simply following the instruction manual. However, some parts of the square bot are missing so that finding replacements proves to be the most difficult task in building the robot.
A completed square bot with the processor and battery installed.
 
The square bot will be ready for driving test, and crashing test in the next class.

 

Day 3 Schematics, Ohm's Law, Potentiometers, and Switches.

         01/10/2012

                       Reading a schematics is the most important knowledge when it comes to building a circuit. a schematics is like a circuit sketched on a piece of paper instead of being built physically.
An example of schematics.
 
A schematic can give an overall view of the circuit, and it can also allow an engineer to analyze a circuit without having it built.
 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
The Ohm's law states that when the voltage is the same, a higher resistance will lower the current in a circuit.
 
The Ohm's law is written as such: V = I * R   (where V stands for voltage, I for current, and R for resistance.)
 
Both LEDs are connected in parallel. The light from the top LED is less intense as the bottom because a greater resister is connected to the top LED.
 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
Potentiometer is a device that changes the the voltage supplied to the circuit by changing its resistance.
 
A potentiometer has 3 pins. The iddle one is call the "wiper".
 
If you measure the resistance between the wiper and an outer pin, it will give you a difference reading as if you measure the resistance between the wiper and another outer pin. The sum of these two resistance value will be the maximum resistance of the potential meter.
You can adjust the brightness of a LED by turning the nob on the potentiometer by changing its resistance.
 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
A switch is a device that can connect, or disconnect, by interacting with it.
 
Multiple switches can be connected in a single circuit to allow the user to turn on/off electrical devices at different places with a switch.
A circuit with multiple switches.
 
Each time a switch is flipped, it will either turn on or off the LED depending on the state of the LED before the switch is interacted.
 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
Since I have run out of time today, Relay will be saved for the next day.

Thursday, January 10, 2013

Day 2: 5V power supply (cont.), using breadboards and multimeter

01/09/2013
                          Today's Topic: 5V Power Supply, and Intro. to Breadboard and Multimeter.

       Continuing with the assignment left from last night, I had finally completed repairing the wire loop, and constructing the 5V power supply.
This was the completed loop constructed by connecting 6 black and brown wires with heat shrinks covering the joints.
Here was the completed 5V power supply converted from a recycled cell phone charger.
The following is the procedure of making the power supply:
  1. Cut off the plug end (not the AC adaptor end!!) of the wire.
  2. Seperate the joint wires by slicing between the wires. Strip off the end of both wires (don't need to be too long, one wire shall be striped a little more than the other wire).
  3. Indentify the polarity of the wires and paint come color to identify them. Solder them to a double head joint pins. (1 wire per pin).
  4. Insulate the wires using 2 layers of heat shrink. (apply 1 heat shrink to prvent contact between wires, and the other prevent contact from outside. 
  5. This is the a completed view of the pin end of the 5V power supply. Notice that the copper wire is fully covered by the heat shrink.
     
    Now, let test the power supply!
    How did we test it?  Connect it to a breadboard! If a functional LED lit up in a correctly completed circuit, congratulation! You now have a functional 5V power supply.
Knowing how the plug holes on the breadboard were connected, 3 parallel circuits were built using 100 ohm, 1k ohm, and 10k ohm resisters while each was connected to a LED light. The LED light (yellow) connected to a 100 ohm resister gave off the most intense light because it conducted the strongest current. The LED light (red)connected to a 10k ohm resister gave off the least intense light since it conducted the weakest current.
 
The Last task for the day was measuring resistance, and voltage of different electronic components with the multimeter.
Using the multimeter to measure the resistance of different resistors and to compare with their reported values according to the color codes.
 
Using the multimeter to measure the voltage supplied by a given power source.
Using the multimeter to measure the voltage of different batteries in connection with a 64ohm resistor and determine their service hours base on the reading.
Finally, we overloaded a 100ohm resistor circuit with around 17 volt of power supply.The result was...
Fume comming out of the resistor, smell of burning electronic, and...
a mostly burnt resistor!
 
The lession learned from tonight, power off (or unplug) the circuit immidiately upon smelling burning electronic or seeing fume (or smoke) comming out of the circuit.

Wednesday, January 9, 2013

Day 1: Into. to soldering and making my 5V power supply

01/08/2013

                   Today's Topic:   Introduction to Soldering and making my own 5V Power Supply.



          Tonight, we learned about how to solder electronic components to a solder board and to solder two wires together.

          At first, the class was to solder around 20 components to the solder board. However, I ran out of time and I was only able to solder 7 component to the solder board.
      
The component should be either parallel to the board or perpendicular to the board, but never tilted at an angle!!
 
According to the course material, the solder should be melted and cooled to a shiny conical shape. At the same time, the solder should cover the copper on the solder boarder. As a hint from the experts, ALWAYS put flux to clearn the surface for soldering.
Not the best conical geometry, but still conical and shiny! Caution: Do not forget to trim the lead after soldering.
Covering the specific copper surface with solder.

  The second project of the day was to solder a loop of wire. First, the wire was cut into 3 sections and 6 parts. The wires are connect in series. At the end of each sections, the rubber insulator were to be striped. Then the copper wire of two sections were to be put side to side parallel to each other. At last, they can be soldered together.
Unfortunately, my loop was broken because I had cut too deep and damaged the copper wire inside when I was stripping the wire.
The soldered connection survived the test but not the partially damaged copper wire.
After soldering two wire together, wrap a heat shrink around the joint and apply heat to it to let the shrink and hold onto the wire. the heat shrink will insulate the copper wire from outside.
 
I was unable to complete the 5V power supply on time nor finish repairing the wire loop. But they will be done the next day.