FRIENDz

FAILURE IS THE SIGN OF SUCCESS!!

Driving a Unipolar Stepper Motor

     If your stepper requires a higher current than the L293 can provide (600 mA for the L293D), you can use the SN754410 chip that handles up to 1 amp. For current up to 2 amps, you can use the L298 chip.A simple way to connect an L298 to Arduino is to use the SparkFun Ardumoto shield (DEV-09213). This plugs on top of an Arduino board and only requires external connection to the motor windings; the motor power comes from the Arduino Vin pin. In1/2 is controlled by pin 12, and ENA is pin 10. In3/4 is connected to pin 13, and ENB is on pin 11. Make the following changes to the code to use the preceding sketch with Ardumoto:

Controlling the Direction of a Brushed Motor with an H-Bridge

            An H-Bridge can control two brushed motors. Figure 8-10 shows the connections for the L293D H-Bridge IC, you can also use the SN754410 which has the same pin layout.In the sketch in this recipe’s Solution, a single motor is controlled using the IN1 and IN2 pins; the EN pin is permanently HIGH because it is connected to +5V.

Controlling Solenoids and Relays

         The choice of transistor is dependent on the amount of current required to activate the solenoid or relay. The data sheet may specify this in milliamperes (mA) or as the resistance of the coil. To find the current needed by your solenoid or relay, divide the voltage of the coil by its resistance in ohms. For example, a 12V relay with a coil of 185 ohms draws 65 mA: 12 (volts) / 185 (ohms) = 0.065 amps, which is 65 mA. Small transistors such as the 2N2222 are sufficient for solenoids requiring up to a few hundred milliamps. Larger solenoids will require a higher power transistor, like the TIP102/TIP120 or similar. There are many suitable transistor alternatives.The purpose of the diode is to prevent reverse EMF from the coil from damaging the transistor (reverse EMF is a voltage produced when current through a coil is switched off). The polarity of the diode is important; there is a colored band indicating the cathode—this should be connected to the

Controlling Servos from the Serial Port

 Each servo line wire gets connected to a digital pin. All servo grounds are connected to Arduino ground. The servo power lines are connected together, and you may need an external 5V or 6V power source if your servos require more current than the Arduino power supply can provide. An array named myservo is used to hold references for the four servos. A for loop in setup attaches each servo in the array to consecutive pins defined in the servoPins array. If the character received from serial is a digit (the character will be greater than or equal to zero and less than or equal to 9), its value is accumulated in the variable pos. If the character is the letter a, the position is written to the first servo in the array (the servo connected to pin 7). The letters b, c, and d control the subsequent servos. 

Controlling the Speed of Rotation Servos

You can use similar code for continuous rotation and normal servos, but be aware that continuous rotation servos may not stop rotating when writing exactly 90 degrees. Some servos have a small potentiometer you can trim to adjust for this, or you can add or subtract a few degrees to stop the servo. For example, if the left servo stops rotating at 92 degrees, you can change the lines that write to the servos as follows:
myservoLeft.write(angle+TRIM); // declare int TRIM=2; at beginning of sketch.


Continuous rotation servos are a form of gear reduced motor with forward and backward speed adjustment. Control of continuous rotation servos is similar to normal servos. The servo rotates in one direction as the angle is increased from 90 degrees; it rotates in the other direction when the angle is decreased from 90

7-Segment LED Displays: Multiplexing

A matrix is created by passing pin numbers for the data, load, and clock pins. loop uses the write method to turn pixels on; the clar method turns the pixels off. write has three parameters: the first two identify the column and row (x and y) of an LED and the third  parameter (HIGH or LOW) turns the LED on or off.This Solution uses the popular MAX7221 LED driver chip to control four-digit commoncathode displays The MAX7221 provides a simpler solution  because it handles multiplexing and digit decoding in hardware.

Driving a 7-Segment LED Display

The segments to be lit for each numeral are held in the array called numeral. There isone byte per numeral where each bit in the byte represents one of seven segments .The array called segmentPins holds the pins associated with each segment. TheshowDigit function checks that the number ranges from zero to 9, and if valid, looks ateach segment bit and turns on the segment if the bit is set. Apin is set HIGH when turning on a segment on a commoncathode display, and it’s set LOW when turning on a segment on a common anode
display. The code here is for a common anode display, so it inverts the value as follows:

Controlling a Matrix of LEDs: Charlieplexing

The term Charlieplexing comes from Charlie Allen (of Microchip Technology, Inc.), who published the method. The technique is based on the fact that LEDs only turn on when connected the “right way” around (with the anode more positive than the cathode). Here is the table showing the LED number that is lit for the valid combinations of the three pins. L is LOW, H is HIGH, and i is INPUT mode. Setting a pin in INPUT mode effectively disconnects it from the circuit:

Controlling an LED Matrix Using Multiplexing

      The resistor’s value must be chosen to ensure that the maximum current through a pin does not exceed 40 mA. Because the current for up to eight LEDs can flow through each column pin, the maximum current for each LED must be one-eighth of 40 mA, or 5 mA. Each LED in a typical small red matrix has a forward voltage of around 1.8 volts. Calculating the resistor that results in 5 mA with a forward voltage of 1.8 volts
gives a value of 680 ohms. Check your data sheet to find the forward voltage of the matrix you want to use. Each column of the matrix is connected through the series resistor to a digital pin. When the column pin goes low and a row pin goes high, the corresponding LED will light. For all LEDs where the column pin is high or its row pin is low, no current will flow through the LED and it will not light. The for loop scans through each row and column and turns on sequential LEDs until all LEDs are lit. The loop starts with the first column and row and increments the row counter until all LEDs in that row are lit; it then moves to the next column, and so on, lighting another LED with each pass through the loop until all the LEDs are lit. You can control the