Arduino coding assigment
Project Three:
Learning Arduino Components
ME250: Introduction to Engineering Design Fall 2018
Overview: In this assignment, you will write a simple code for an Arduino for three types of motors. These motors include: Servo, Direct Current (DC) and Stepper. Each motor requires a different set of instructions and components in order for it to work. To find the hardware required for each exercise, reference the parts list located in the cap of your Super Starter Kit. You will be taken through the process of writing the code and building the circuit diagram. While the functions and a majority of your code will be similar, your code should not be the exact same as the sample provided. There should be variances in timing/naming to prove you understand the exercise. For full credit your code must be uploaded to Blackboard, as well as, an image of each of your circuit diagrams. Due Date: Monday, October 22
nd
Servo Motor
For this exercise, you will learn how to control a small Servo motor. Specifically, you will rotate a lever from an initial angle to a final angle (in degrees) continuously with time delays (in milliseconds). Component Details Cable Length: 25 cm Operating Speed: 0.12s / 60 degrees Temperature: Approximately 30 – 60 °C Working Voltage: 3.5 – 6.0V Dimension: 3.2 cm x 3.0 cm x 1.2 cm Angles of Rotation: 0 – 180 degrees Hardware:
1. Computer/Laptop with Arduino software 2. Uno R3 Controller Board 3. USB Cable 4. Servo Motor SG90 5. One Lever (These can be one of the three levers contained in the same bag as the servo
motor.) 6. 3 Jumper Wires (male to male)
Instructions: 1. Read through the following code, in Figure 1, paying special attention to the comments. Create and
write your own code with similar format.
Figure 1. Code used for servo motor.
2. Connect one of the white levers to the servo motor: The bigger hole on the lever will snap directly on to the white shaft coming out of the top of the Servo.
3. The brown wire on the servo is the ground. Make a connection between the ground of your servo to ground (GND) on the power source of the Controller Board.
4. The red wire on the servo is the power, or 5V. Make a connection between the power of your servo to the 5V on the power source of the Controller Board.
5. The orange wire on the servo sends/receives digital signals (inputs/outputs). Make a connection between the digital signal of your servo to one of the digital pins on the Controller Board. (Hint: These digital pins are located on the opposite side of the power source. They are labeled 0 – 13. The pin used in this exercise is 9.) Refer to Figure 2 to ensure you have made the correct connections.
Figure 2. Circuit diagram for servo exercise
6. Upload your code to the Controller Board by plugging in your USB cable from the computer to the Controller Board. Leave the Uno R3 plugged into the computer. Your lever should now be rotating. Remember the lever will continue to rotate as long as the USB cable is connected to the Controller Board.
7. Take a picture of your circuit diagram and don’t forget to save your code with the following format: NetID_Servo.
DC Motors
In this exercise, you will learn how to control a small DC motor. Specifically, you will rotate a small fan
attachment to a DC motor and set a time delay (in milliseconds) between electrical impulses. (This
activity varies slightly than the Elegoo book version.)
Component Details:
Cable Length: 13.5 cm Operating Speed: 2500 to 5000 RPM Torque: 45.3 g cm Working Voltage: 3.0 – 6.0V Dimension: 2.0 cm x 1.7 cm x 3.8 cm Angles of Rotation: Continuous 360 degrees Hardware:
1. Computer/Laptop with Arduino software 2. Uno R3 Controller Board 3. USB Cable 4. Breadboard 5. Battery Snap-On Connector Clip
6. Power Supply Module (In the reading this was called the breadboard power supply.)
This is used because the DC motor is likely to use more power than the Uno R3
controller can withstand directly. REMINDER: If this is not used there is a good chance of
damaging your Controller Board.
7. 5 Jumper Wires (male to male)
8. 3-6V (DC) Motor
9. Fan attachment for DC motor (yellow nose with translucent blades)
10. 9V Battery
11. L293D (chip)
Allows two motors to be controlled independently. This exercise only uses half of the
chip or motor driver. Pin specifications for the chip are shown in Figure 3. Out 1 and Out
2 will be used in this exercise.
Figure 3. Schematic of L293D chip.
Instructions:
1. Read through the following code, in Figure 4, paying special attention to the comments. Create and write your own code with similar format.
Figure 4. Code used for DC motor.
2. Follow the schematic in Figure 5 to make the same connections using your hardware. Be very careful with the wires on the DC motor. The wires can break off! MAKE SURE THESE CONNECTIONS ARE CORRECT BEFORE CONNECTING THE BATTERY! To connect the battery, the ends on the Battery Snap-On Connector Clip have different sized leads. These leads snap directly onto the 9V battery.
Things to note:
Digital signals 3, 4, and 5 are used from the Controller Board.
Not all prongs emit the same signal on the L293D motor driver. Referencing Figure 3, we can see only out 1 and out 2 are used. Out 1 is connected in series with the 5V/ power source (red wire) to the DC motor. Out 2 is connected in series with the ground (black wire) to the DC motor. (For those that are unsure of this connection, the red and black wires should be inserted in the holes directly below the out 1 and out 2 on the L293D, respectively. Out 1 is the third prong from the end on the left side. Out 2 is the third prong from the end of the right side.)
The yellow circled pieces on the Power Supply Module contain 4 output pins that allow three types of voltage settings: OFF, 3.3 and 5V. There is a white jumper cap covering two of them. You want to ensure the jumper cap is set to 5V. If it is not set to 5V or you are unsure, remove the jumper cap. Notice the cap fits around 2 prongs. Therefore, the cap should fit over the 5V prong and VCC prong.
Figure 5. Circuit diagram for DC motor exercise.
3. Attach the fan to the shaft extending from the DC motor. 4. Upload your code to the Controller Board by plugging in your USB cable from the computer to the
Controller Board. Leave the Uno R3 plugged into the computer. Press the switch on your Power Supply Module to allow power to flow from the battery. (This is the green circled part in Figure 5.) If it is turned on, a green light will light up on your Power Supply Module. It typically takes the DC motor about a minute before it starts rotating. Be patient! In order for it to continue to have enough power, the Controller Board should be plugged into the computer. Unplug your battery and USB cable when you are finished. Be careful when you unplug the L293D chip! The prongs do bend easily!
5. Take a picture of your circuit diagram and don’t forget to save your code with the following format: NetID_DC.
Stepper Motor In this exercise, you will learn how to drive a Stepper motor and change the direction in which it rotates Component Details: Cable Length: 23 cm A, B, C, D four-phase LED indicates the status of the Stepper motor work Voltage: 5V Frequency: 100 Hz Insulation Resistance: > 10 MΩ DC Resistance: approximately 200 Ω Hardware:
1. Computer/Laptop with Arduino software 2. Uno R3 Controller Board 3. USB Cable 4. Breadboard 5. Power Supply Module 6. ULN2003 Stepper Motor Driver Board 7. 9V Battery 8. 6 Female to Male Wires 9. 1 Jumper Wire (male to male)
Instructions 1. Read through the following code in Figure 6, paying special attention to the comments. Create and
write your own code with similar format.
Figure 6. Code used for Stepper motor.
2. Follow the schematic in Figure 7 to build the circuit needed for the Stepper motor exercise. MAKE SURE THESE CONNECTIONS ARE CORRECT BEFORE CONNECTING THE BATTERY! To connect the battery, the ends on the Battery Snap-On Connector Clip have different sized leads. These leads snap directly onto the 9V battery.
Things to Note:
Digital signals 8 through 11 are used from the Controller Board. Follow the colorered wires from the Motor Driver Board to the correct pin on the Controller Board!
Both jumper caps on the Power Supply Module should be set to 5V. Looking back on Figure 5, these are the yellow circled components.
Figure 7. Circuit diagram for Stepper Motor exercise.
3. Upload your code to the Controller Board by plugging in you USB Cable from the computer to the Controller Board. Leave the Uno R3
plugged into the computer. Press the switch on your Power Supply Module to allow power to flow from the battery. (This is the green circled part in Figure 5.) The green light on the Power Supply Module should light up. Your fan should now begin rotating. In order for it to continue to have enough power, the Controller Board should be plugged in by using the USB cable.
4. Take a picture of your circuit diagram and don’t forget to save your code with the following format: NetID_Stepper.