week6

Controlling big switches



Jeff's in-class example with a relay and a transister and a DC motor and a solenoid and electroluminescent (EL) lighting wires.

 

Reading and understanding diagrams of curcuit is hard for me. I was not good at physics and especailly at the part of electricity in my high school days. While working the assingnment, I got confused to read the diagram and asked to Jeff how to connect a momentary switch in series and how to make separate curcuit on the breadboard. Jeff taught the basic 5V closed circuit. Below pictures were the eample of the study. There are two ways to connect the momentary switch in series. One is connecting switch after motor and before ground (upper picture) and another is connecting it before motor after ground. Then, I could understand clearly the concept how to share the ground. Thanks, Jeff! These are the examples of simple basic curcuits and diagrams.

 

After then, I tried to solve the step #1 question. I needed to connect the DC motor to the 5V circuit and make the motor run (see the pictures above ). Then I started to use 9V DC motor. At first, I made it turn with 9V power without BX code. Although the 9V motor run, now I think, it was not good and even harmful to connect it to the breadboard which is hooked up with 5V power and 7805 voltage regulator like this. Now seeing these picture, I can remember that I could smell burning from my 7805. Making the motor run with 9V power and without transister or relay would be the reason why it became hot.

And then I tried to make the 9V DC motor turn with BX code. Because only 5V power should get into the BX 24, I had to use trasistor, which was TIP120.

 

Then I tested servomotor, because I had an project idea using servo motor. I'd like to know how it works. To make it run, I changed the code in the Tom Igoe's site for the servo motor on the web a little bit. I connected it with potentiometer. Here is the code which I used.

 

' Servo testing example
' in this example, a servo attached to pin 12
' should travel slowly from one side to the other,
' then quickly back to the beginning.
' The program starts pulsing the servo at its
' minimum pulsewidth, then increments the pulsewidth
' a small amount with each new pulse until it reaches
' the maximum pulsewidth. Then it sets the
' pulsewidth back to minimum.

dim minPulse as single ' the minimum pulseWidth
dim maxPulse as single ' the maximum pulseWidth
dim pulseWidth as single ' the servo's pulsewidth
dim refreshPeriod as single ' the time between pulses
' dim potVar as integer
dim sensorValue as integer


Sub main()
call delay(0.5) ' start program with a half-second delay

minPulse = 0.0008
maxPulse = 0.0022
pulseWidth = minPulse
refreshPeriod = 0.02


' set initial values for variables:
dim pulseRange as single ' the range of possible pulses
pulseRange = maxPulse - minPulse

' you may need to change the minimum and maximum
' pulseWidths for your servo to get the full
' range of motion. The ideal servo
' has a minimum of 1 milliseconds (0.001) and
' a maximum of 2 milliseconds (0.002). In practice,
' however, this varies. Connect your servo and try
' different values for the max and min below:

' the main do loop:
do
' read a variable resistor sensor on pin 13:
sensorValue = getADC(13)
debug.print "sensorValue = " ; cstr(sensorValue)

' pulse the servo:
call pulseOut(12, pulseWidth, 1)

if pulseWidth <= maxPulse then
pulseWidth = minPulse + ((pulseRange * cSng(sensorValue)) / 1023.0)

else
pulseWidth = minPulse
end if


' increase the pulsewidth for the next pulse:

' --if pulseWidth <= maxPulse then
' pulseWidth = pulseWidth + 0.00001
' else
' pulseWidth = minPulse
' end if

' wait 20 milliseconds before pulsing again
call sleep(refreshPeriod)
loop
End Sub

 

Here are other servo motor code examples which I reffered to.

 

 

Journal Index