THE MOST COMPLETE STARTER KIT TUTORIAL FOR MEGA2560 V1.0.17.7.
Preface Our Company Established in 2011, Elegoo Inc. is a thriving technology company dedicated to opensource hardware research & development, production and marketing. Located in Shenzhen, the Silicon Valley of China, we have grown to over 150+ employees with a 10,763+ square ft. factory. Our product lines rang from DuPont wires, 2560 R3 boards to complete starter kits designed for customers of any level to learn Arduino knowledge. In addition, we also sell products of Raspberry Pi accessories like 2.
offer you excellent products and quality service as to meet your expectation and you can reach out to us by simply drop a line at service@elegoo.com or EUservice@elegoo.com. We look forward to hearing from you and any of your critical comment or suggestion would be much valuable to us.
/ 223
/ 223
/ 223
/ 223
/ 223
/ 223
Content Lesson 0 Installing IDE ............................................................................................................. 12 Lesson 1 Add Libraries and Open Serial Monitor ................................................................... 23 Lesson 2 Blink ........................................................................................................................... 32 Lesson 3 LED ..............................................................................................
Lesson 28 Four Digital Seven Segment Display .....................................................................186 Lesson 29 DC Motors .............................................................................................................191 Lesson 30 Relay ......................................................................................................................201 Lesson 31 Stepper Motor ...................................................................................................
Lesson 0 Installing IDE Introduction The Arduino Integrated Development Environment (IDE) is the software side of the Arduino platform. In this lesson, you will learn how to setup your computer to use Arduino and how to set about the lessons that follow. The Arduino software that you will use to program your Arduino is available for Windows, Mac and Linux. The installation process is different for all three platforms and unfortunately there is a certain amount of manual work to install the software.
STEP2:Download the development software that is compatible with the operating system of your computer. Take Windows as an example here. Click Windows Installer. Click JUST DOWNLOAD.
Also version 1.8.0 is available in the material we provided, and the versions of our materials are the latest versions when this course was made. Installing Arduino (Windows) Install Arduino with the exe. Installation package.
Click Next You can press Browse… to choose an installation path or directly type in the directory you want.
Click Install to initiate installation Finally, the following interface appears, click Install to finish the installation.
Double-click to enter the desired development environment You may directly choose the installation package for installation and skip the contents below and jump to the next section. But if you want to learn some methods other than the installation package, please continue to read the section.
/ 223
However, this installation method needs separate installation of driver. The Arduino folder contains both the Arduino program itself and the drivers that allow the Arduino to be connected to your computer by a USB cable. Before we launch the Arduino software, you are going to install the USB drivers. Plug one end of your USB cable into the Arduino and the other into a USB socket on your computer. The power light on the LED will light up and you may get a 'Found New Hardware' message from Windows.
Right-click on the device and select the top menu option (Update Driver Software...). You will then be prompted to either ‘Search Automatically for updated driver software’ or ‘Browse my computer for driver software’. Select the option to browse and navigate to the X\arduino1.8.0\drivers.
Click 'Next' and you may get a security warning, if so, allow the software to be installed. Once the software has been installed, you will get a confirmation message. Windows users may skip the installation directions for Mac and Linux systems and jump to Lesson 1. Mac and Linux users may continue to read this section. Installing Arduino (Mac OS X) Download and Unzip the zip file, double click the Arduino.
Installing Arduino (Linux) You will have to use the make install command. If you are using the Ubuntu system, it is recommended to install Arduino IDE from the software center of Ubuntu. TIPS: If you have problems in installing the drivers, please refer to the UNO R3, MEGA, NANO DRIVER FAQ.
Lesson 1 Add Libraries and Open Serial Monitor Installing Additional Arduino Libraries Once you are comfortable with the Arduino software and using the built-in functions, you may want to extend the ability of your Arduino with additional libraries. What are Libraries? Libraries are a collection of code that makes it easy for you to connect to a sensor, display, module, etc. For example, the built-in LiquidCrystal library makes it easy to talk to character LCD displays.
Then the library manager will open and you will find a list of libraries that are already installed or ready for installation. In this example we will install the Bridge library. Scroll the list to find it, then select the version of the library you want to install. Sometimes only one version of the library is available. If the version selection menu does not appear, don't worry: it is normal. There are times you have to be patient with it, just as shown in the figure. Please refresh it and wait.
Finally click on install and wait for the IDE to install the new library. Downloading may take time depending on your connection speed. Once it has finished, an Installed tag should appear next to the Bridge library. You can close the library manager. You can now find the new library available in the Include Library menu. If you want to add your own library open a new issue on Github. Importing a .zip Library Libraries are often distributed as a ZIP file or folder.
You will be prompted to select the library you would like to add. Navigate to the .zip file's location and open it.
Return to the Sketch > Import Library menu. You should now see the library at the bottom of the drop-down menu. It is ready to be used in your sketch. The zip file will have been expanded in the libraries folder in your Arduino sketches directory. NB: the Library will be available to use in sketches, but examples for the library will not be exposed in the File > Examples until after the IDE has restarted. Those two are the most common approaches. MAC and Linux systems can be handled likewise.
"ArduinoParty", uncompress ArduinoParty.zip. It should contain a folder calledArduinoParty, with files like ArduinoParty.cpp and ArduinoParty.h inside. (If the .cpp and .h files aren't in a folder, you'll need to create one. In this case, you'd make a folder called "ArduinoParty" and move into it all the files that were in the ZIP file, like ArduinoParty.cpp and ArduinoParty.h.) Drag the ArduinoParty folder into this folder (your libraries folder). Under Windows, it will likely be called "My Documents\Ardui
Arduinos and other microcontrollers, they decided to include a serial terminal with the software. Within the Arduino environment, this is called the Serial Monitor. Making a Connection Serial monitor comes with any and all version of the Arduino IDE. To open it, simply click the Serial Monitor icon. Selecting which port to open in the Serial Monitor is the same as selecting a port for uploading Arduino code. Go to Tools -> Serial Port, and select the correct port.
Once open, you should see something like this: 30 / 223
Settings The Serial Monitor has limited settings, but enough to handle most of your serial communication needs. The first setting you can alter is the baud rate. Click on the baud rate drop-down menu to select the correct baud rate. (9600 baud) Last, you can set the terminal to Autoscroll or not by checking the box in the bottom left corner. Pros The Serial Monitor is a great quick and easy way to establish a serial connection with your Arduino.
Lesson 2 Blink Overview In this lesson, you will learn how to program your MEGA2560 R3 controller board to blink the Arduino’s built-in LED, and how to download programs by basic steps. Component Required: (1) x Elegoo Mega2560 R3 Principle The MEGA2560 R3 board has rows of connectors along both sides that are used to connect to several electronic devices and plug-in 'shields' that extends its capability. It also has a single LED that you can control from your sketches.
You may find that your MEGA2560 R3 board's 'L' LED already blinks when you connect it to a USB plug. This is because the boards are generally shipped with the 'Blink' sketch pre-installed. In this lesson, we will reprogram the MEGA2560 R3 board with our own Blink sketch and then change the rate at which it blinks. In Lesson 0, you set up your Arduino IDE and made sure that you could find the right serial port for it to connect to your MEGA2560 R3 board.
When the sketch window opens, enlarge it so that you can see the entire sketch in the window. The example sketches included with the Arduino IDE are 'read-only'. That is, you can upload them to an MEGA2560 R3 board, but if you change them, you cannot save them as the same file. Since we are going to change this sketch, the first thing you need to do is save your own copy. From the File menu on the Arduino IDE, select 'Save As..' and then save the sketch with the name 'MyBlink'.
/ 223
You have saved your copy of 'Blink' in your sketchbook. This means that if you ever want to find it again, you can just open it using the File > Sketchbook menu option.
Attach your Arduino board to your computer with the USB cable and check that the 'Board Type' and 'Serial Port' are set correctly.
/ 223
Note: The Board Type and Serial Port here are not necessarily the same as shown in picture. If you are using 2560, then you will have to choose Mega 2560 as the Board Type, other choices can be made in the same manner. And the Serial Port displayed for everyone is different, despite COM 26 chosen here, it could be COM3 or COM4 on your computer. A right COM port is supposed to be COMX (arduino XXX), which is by the certification criteria.
Finally, the staus will change to 'Done'. The other message tells us that the sketch is using 928 bytes of the 32,256 bytes available.After the 'Compiling Sketch..' stage you could get the following error message: It can mean that your board is not connected at all, or the drivers have not been installed (if necessary) or that the wrong serial port is selected. If you encounter this, go back to Lesson 0 and check your installation.
Single line comments start with // and everything up until the end of that line is considered a comment. The first line of code is: int led = 13; As the comment above it explains, this is giving a name to the pin that the LED is attached to. This is 13 on most Arduinos, including the MEGA2560 and Leonardo. Next, we have the 'setup' function. Again, as the comment says, this is executed when the reset button is pressed.
This delay period is in milliseconds, so if you want the LED to blink twice as fast, change the value from 1000 to 500. This would then pause for half a second each delay rather than a whole second. Upload the sketch again and you should see the LED start to blink more quickly.
Lesson 3 LED Overview In this lesson, you will learn how to change the brightness of an LED by using different values of resistor. Component Required: (1) x Elegoo Mega2560 R3 (1) x 5mm red LED (1) x 220 ohm resistor (1) x 1k ohm resistor (1) x 10k ohm resistor (2) x M-M wires (Male to Male jumper wires) Component Introduction BREADBOARD MB-102: A breadboard enables you to prototype circuits quickly, without having to solder the connections. Below is an example.
Breadboards come in various sizes and configurations. The simplest kind is just a grid of holes in a plastic block. Inside are strips of metal that provide electrical connection between holes in the shorter rows. Pushing the legs of two different components into the same row joins them together electrically. A deep channel running down the middle indicates that there is a break in connections there, meaning, you can push a chip in with the legs at either side of the channel without connecting them together.
If you do not use a resistor with an LED, then it may well be destroyed almost immediately, as too much current will flow through, heating it and destroying the 'junction' where the light is produced. There are two ways to tell which is the positive lead of the LED and which the negative. Firstly, the positive lead is longer. Secondly, where the negative lead enters the body of the LED, there is a flat edge to the case of the LED.
Unlike LEDs, resistors do not have a positive and negative lead. They can be connected either way around. If you find this approach method too complicated, you can read the color ring flag on our resistors directly to determine its resistance value. Or you may use a digital multimeter instead.
Connection Schematic 47 / 223
Wiring diagram 48 / 223
The MEGA2560 is a convenient source of 5 volts, which we will use to provide power to the LED and the resistor. You do not need to do anything with your MEGA2560, except to plug it into a USB cable. With the 220 Ω resistor in place, the LED should be quite bright. If you swap out the 220 Ω resistor for the 1kΩ resistor, then the LED will appear a little dimmer. Finally, with the 10 kΩ resistor in place, the LED will be just about visible.
Lesson 4 RGB LED Overview RGB LEDs are a fun and easy way to add some color to your projects. Since they are like 3 regular LEDs in one, how to use and connect them is not much different. They come mostly in 2 versions: Common Anode or Common Cathode. Common Anode uses 5V on the common pin, while Common Cathode connects to ground. As with any LED, we need to connect some resistors inline (3 total) so we can limit the current being drawn.
Component Introduction RGB: At first glance, RGB (Red, Green and Blue) LEDs look just like regular LEDs. However, inside the usual LED package, there are actually three LEDs, one red, one green and yes, one blue. By controlling the brightness of each of the individual LEDs you can mix pretty much any color you want. We mix colors the same way you would mix paint on a palette - by adjusting the brightness of each of the three LEDs.
Here on the photographs you can see 4 electrode LED. Every separate pin for Green or Blue or Red color is called Anode. You will always connect “+” to it. Cathode goes to “-“ (ground). If you connect it other way round the LED will not light. The common negative connection of the LED package is the second pin from the flat side. It is also the longest of the four leads and will be connected to the ground.
COLOR: The reason that you can mix any color you like by varying the quantities of red, green and blue light is that your eye has three types of light receptor in it (red, green and blue). Your eye and brain process the amounts of red, green and blue and convert it into a color of the spectrum. In a way, by using the three LEDs, we are playing a trick on the eye. This same idea is used in TVs, where the LCD has red, green and blue color dots next to each other making up each pixel.
Theory (PWM) Pulse Width Modulation (PWM) is a technique for controlling power. We also use it here to control the brightness of each of the LEDs. The diagram below shows the signal from one of the PWM pins on the MEGA2560. Roughly every 1/500 of a second, the PWM output will produce a pulse. The length of this pulse is controlled by the 'analogWrite' function.
Connection Schematic 55 / 223
Wiring diagram 56 / 223
Code After wiring, please open the program in the code folder- Lesson 4 RGB LED, and click UPLOAD to upload the program. See Lesson 2 for details about program uploading if there are any errors. Our code will use FOR loops to cycle through the colors. The first FOR loop will go from RED to GREEN. The second FOR loop will go from GREEN to BLUE. The last FOR loop will go from BLUE to RED. Try the sketch out and then we will dissect it in some detail......
blueValue = 0; This function takes three arguments, one for the brightness of the red, green and blue LEDs. In each case the number will be in the range 0 to 255, where 0 means off and 255 means maximum brightness. The function then calls 'analogWrite' to set the brightness of each LED. If you look at the 'loop' function you can see that we are setting the amount of red, green and blue light that we want to display and then pausing for a second before moving on to the next color.
Lesson 5 Digital Inputs Overview In this lesson, you will learn to use push buttons with digital inputs to turn an LED on and off. Pressing the button will turn the LED on; pressing the other button will turn the LED off. Component Required: (1) x Elegoo Mega2560 R3 (1) x 830 Tie-points Breadboard (1) x 5mm red LED (1) x 220 ohm resistor (2) x push switches (7) x M-M wires (Male to Male jumper wires) Component Introduction PUSH SWITCHES: Switches are really simple components.
Connection Schematic 60 / 223
Wiring diagram 61 / 223
Although the bodies of the switches are square, the pins protrude from opposite sides of the switch. This means that the pins will only be far enough apart when they are placed correctly on the breadboard. Remember that the LED has to have the shorter negative lead to the left. Code After wiring,please open program in the code folder- Lesson 5 Digital Inputs, and press UPLOAD to upload the program. If errors are prompted, see Lesson 2 for details about the tutorial on program upload.
{ digitalWrite(ledPin, LOW); } } In the 'loop' function there are two 'if' statements. One for each button. Each does an 'digitalRead' on the appropriate input. Remember that if the button is pressed, the corresponding input will be LOW, if button A is low, then a 'digitalWrite' on the ledPin turns it on. Similarly, if button B is pressed, a LOW is written to the ledPin.
Lesson 6 Active buzzer Overview In this lesson, you will learn how to generate a sound with an active buzzer. Component Required: (1) x Elegoo Mega2560 R3 (1) x Active buzzer (2) x F-M wires (Female to Male DuPont wires) Component Introduction BUZZER: Electronic buzzers are DC-powered and equipped with an integrated circuit. They are widely used in computers, printers, photocopiers, alarms, electronic toys, automotive electronic devices, telephones, timers and other electronic products for voice devices.
Connection Schematic 65 / 223
Wiring diagram 66 / 223
Code After wiring, please open the program in the code folder- Lesson 6 Making Sounds and click UPLOAD to upload the program. See Lesson 2 for details about program uploading if there are any errors.
Lesson 7 Passive Buzzer Overview In this lesson, you will learn how to use a passive buzzer. The purpose of the experiment is to generate eight different sounds, each sound lasting 0.5 seconds: from Alto Do (523Hz), Re (587Hz), Mi (659Hz), Fa (698Hz), So (784Hz), La (880Hz), Si (988Hz) to Treble Do (1047Hz).
Connection Schematic 69 / 223
Wiring diagram 70 / 223
Wiring the buzzer connected to the MEGA2560 R3 board, the red (positive) to the pin8, black wire (negative) to the GND. Code After wiring, please open the program in the code folder- Lesson 7 Passive Buzzer and click UPLOAD to upload the program. See Lesson 2 for details about program uploading if there are any errors. Before you can run this, make sure that you have installed the library or re-install it, if necessary. Otherwise, your code won't work.
Lesson 8 Tilt Ball Switch Overview In this lesson, you will learn how to use a tilt ball switch in order to detect small angle of inclination. Component Required: (1) x Elegoo Mega2560 R3 (1) x Tilt Ball switch (2) x F-M wires (Female to Male DuPont wires) Component Introduction Tilt sensor: Tilt sensors (tilt ball switch) allow you to detect orientation or inclination. They are small, inexpensive, low-power and easy-to-use. If used properly, they will not wear out.
Connection Schematic 73 / 223
Wiring diagram 74 / 223
Code After wiring, please open the program in the code folder- Lesson 8 Ball Switch and click UPLOAD to upload the program. See Lesson 2 for details about program uploading if there are any errors.
Lesson 9 Servo Overview Servo is a type of geared motor that can only rotate 180 degrees. It is controlled by sending electrical pulses from your 2560 R3 board. These pulses tell the servo what position it should move to. The Servo has three wires, of which the brown one is the ground wire and should be connected to the GND port of 2560, the red one is the power wire and should be connected to the 5v port, and the orange one is the signal wire and should be connected to the Dig #9 port.
Connection Schematic 77 / 223
Wiring diagram 78 / 223
Code After wiring, please open the program in the code folder- Lesson 9 Servo and click UPLOAD to upload the program. See Lesson 2 for details about program uploading if there are any errors. Before you can run this, make sure that you have installed the < Servo> library or re-install it, if necessary. Otherwise, your code won't work. For details about loading the library file, see Lesson 1.
Lesson 10 Ultrasonic Sensor Module Overview Ultrasonic sensor is great for all kind of projects that need distance measurements, avoiding obstacles as examples. The HC-SR04 is inexpensive and easy to use since we will be using a Library specifically designed for these sensor.
Connection Schematic 81 / 223
Wiring diagram 82 / 223
Code Using a Library designed for these sensors will make our code short and simple. We include the library at the beginning of our code, and then by using simple commands we can control the behavior of the sensor. After wiring, please open the program in the code folder- Lesson 10 Ultrasonic Sensor Module and click UPLOAD to upload the program. See Lesson 2 for details about program uploading if there are any errors.
Open the monitor then you can see the data as blow: Click the Serial Monitor button to turn on the serial monitor. The basics about the serial monitor are introduced in details in Lesson 1.
Lesson 11 Membrane Switch Module Overview In this project, we will go over how to integrate a keyboard with an MEGA2560 R3 board so that the MEGA2560 R3 can read the keys being pressed by a user. Keypads are used in all types of devices, including cell phones, fax machines, microwaves, ovens, door locks, etc. They're practically everywhere. Tons of electronic devices use them for user input.
Connection Schematic 86 / 223
Wiring diagram 87 / 223
When connecting the pins to the MEGA2560 R3 board, we connect them to the digital output pins, D9-D2. We connect the first pin of the keypad to D9, the second pin to D8, the third pin to D7, the fourth pin to D6, the fifth pin to D5, the sixth pin to D4, the seventh pin to D3, and the eighth pin to D2. These are the connections in a table: Code After wiring, please open the program in the code folder- Lesson 11 Membrane Switch Module and click UPLOAD to upload the program.
Example picture 89 / 223
With this code, once we press a key on the keypad, it should show up on the serial monitor of the Arduino software once the code is compiled and uploaded to the MEGA2560 R3 board. Click the Serial Monitor button to turn on the serial monitor. The basics about the serial monitor are introduced in details in Lesson 1.
Lesson 12 DHT11 Temperature and Humidity Sensor Overview In this tutorial we will learn how to use a DHT11 Temperature and Humidity Sensor. It’s accurate enough for most projects that need to keep track of humidity and temperature readings. Again we will be using a Library specifically designed for these sensors that will make our code short and easy to write.
excellent long-term stability. The sensor includes a resistive sense of wet components and a NTC temperature measurement devices, and connects with a high-performance 8-bit microcontroller. Applications: HVAC, dehumidifier, testing and inspection equipment, consumer goods, automotive, automatic control, data loggers, weather stations, home appliances, humidity regulator, medical and other humidity measurement and control.
Connection Schematic 93 / 223
Wiring diagram 94 / 223
As you can see we only need 3 connections to the sensor, since one of the pin is not used. The connections are: Voltage, Ground and Signal which can be connected to any Pin on our MEGA2560. Code After wiring, please open the program in the code folder- Lesson 12 DHT11 Temperature and Humidity Sensor and click UPLOAD to upload the program. See Lesson 2 for details about program uploading if there are any errors.
Upload the program then open the monitor, we can see the data as below: (It shows the temperature of the environment, we can see it is 22 degree) Click the Serial Monitor button to turn on the serial monitor. The basics about the serial monitor are introduced in details in Lesson 1.
Lesson 13 Analog Joystick Module Overview Analog joysticks are a great way to add some control in your projects. In this tutorial we will learn how to use the analog joystick module. Component Required: (1) x Elegoo Mega2560 R3 (1) x Joystick module (5) x F-M wires (Female to Male DuPont wires) Component Introduction Joystick The module has 5 pins: VCC, Ground, X, Y, Key. Note that the labels on yours may be slightly different, depending on where you got the module from.
Connection Schematic 98 / 223
Wiring diagram 99 / 223
We need 5 connections to the joystick. The connections are: Key, Y, X, Voltage and Ground. “Y and X” are Analog and “Key” is Digital. If you don’t need the switch then you can use only 4 pins. Code After wiring, please open the program in the code folder- Lesson 13 Analog Joystick Module and click UPLOAD to upload the program. See Lesson 2 for details about program uploading if there are any errors. Analog joysticks are basically potentiometers so they return analog values.
Open the monitor then you can see the data as blow: Click the Serial Monitor button to turn on the serial monitor. The basics about the serial monitor are introduced in details in Lesson 1.
Lesson 14 IR Receiver Module Overview Using an IR Remote is a great way to have wireless control of your project. Infrared remotes are simple and easy to use. In this tutorial we will be connecting the IR receiver to the MEGA2560, and then use a Library that was designed for this particular sensor. In our sketch we will have all the IR Hexadecimal codes that are available on this remote, we will also detect if the code was recognized and also if we are holding down a key.
IR detectors are digital out - either they detect 38KHz IR signal and output low (0V) or they do not detect any and output high (5V). Photocells act like resistors, the resistance changes depending on how much light they are exposed to. What You Can Measure As you can see from these datasheet graphs, the peak frequency detection is at 38 KHz and the peak LED color is 940 nm. You can use from about 35 KHz to 41 KHz but the sensitivity will drop off so that it won't detect as well from afar.
Connection Schematic 104 / 223
Wiring diagram 105 / 223
There are 3 connections to the IR Receiver. The connections are: Signal, Voltage and Ground. The “-” is the Ground, “S” is signal, and middle pin is Voltage 5V. Code After wiring, please open the program in the code folder- Lesson 14 IR Receiver Module and click UPLOAD to upload the program. See Lesson 2 for details about program uploading if there are any errors. Before you can run this, make sure that you have installed the < IRremote > library or re-install it, if necessary.
Open the monitor then you can see the data as blow: Click the Serial Monitor button to turn on the serial monitor. The basics about the serial monitor are introduced in details in Lesson 1.
Lesson 15 MAX7219 LED Dot Matrix Module Overview In this tutorial we will connect a MAX7219 and scroll the text across. Since these modules use the MAX7219 LED driver chip, we will be able to turn on and off the 64 LEDs of each module, using only 3 pins on our MEGA2560.
Connection Schematic 109 / 223
Wiring diagram 110 / 223
VCC and Ground are connected to the Arduino. Pin 12 is connected to DIN, Pin 11 is connected to CS and Pin 10 is connected to CLK. Code Our Sketch will make use of the “Maxmatrix” Library to communicate with the MAX7219 modules. After wiring, please open the program in the code folder- Lesson 15 MAX7219 LED Dot Matrix Module and click UPLOAD to upload the program. See Lesson 2 for details about program uploading if there are any errors.
Lesson 16 GY-521 Module Overview In this lesson, we will learn how to use GY-521 module which is one of the best IMU (Inertia Measurement Unit) sensors, compatible with Arduino. IMU sensors like the GY-521 are used in self balancing robots, UAVs, smart phones, etc. Component Required: (1) x Elegoo Mega2560 R3 (1) x GY-521 module (4) x F-M wires Component Introduction GY-521 SENSOR The InvenSense GY-521 sensor contains a MEMS accelerometer and a MEMS gyro in a single chip.
IMU sensors are one of the most inevitable type of sensors used today in all kinds of electronic gadgets. They are seen in smart phones, wearables, game controllers, etc. IMU sensors help us in getting the attitude of an object, attached to the sensor in three dimensional space. These values usually in angles, thus help us to determine its attitude. Thus, they are used in smart phones to detect its orientation.
An accelerometer works on the principle of piezo electric effect. Here, imagine a cuboidal box, having a small ball inside it, like in the picture above. The walls of this box are made with piezo electric crystals. Whenever you tilt the box, the ball is forced to move in the direction of the inclination, due to gravity. The wall with which the ball collides, creates tiny piezo electric currents. There are totally, three pairs of opposite walls in a cuboid.
How does a gyroscope work? Gyroscopes work on the principle of Coriolis acceleration. Imagine that there is a fork like structure, which is in constant back and forth motion. It is held in place using piezo electric crystals. Whenever, you try to tilt this arrangement, the crystals experience a force in the direction of inclination. This is caused as a result of the inertia of the moving fork. The crystals thus produce a current in consensus with the piezo electric effect, and this current is amplified.
Connection Schematic 116 / 223
Wiring diagram 117 / 223
Next, we need to set up the I2C lines. For this connect the pin labelled as SDA on the GY-521 to the Arduino’s analog pin 4 (SDA). And the pin labelled as SCL on the GY-521 to the Arduino’s analog pin 5 (SCL). And that’s it, you have finished wiring up the Arduino GY-521. Libraries needed MPU-6050 The Code The short example sketch is a very short sketch and it shows all the raw values (accelerometer, gyro and temperature). It should work on Arduino MEGA2560, Nano, Leonardo, and also Due.
Example picture 119 / 223
Open the monitor then you can see the data as blow: Click the Serial Monitor button to turn on the serial monitor. The basics about the serial monitor are introduced in details in Lesson 1.
Lesson 17 HC-SR501 PIR Sensor Overview In this lesson you will learn how to use a PIR movement detector with an MEGA2560. The MEGA2560 is the heart of this project. It 'listens' to the PIR sensor and when motion is detected, instructs the LED to light on or shut off.
Pin or Control Function Time Delay Adjust Sets how long the output remains high after detecting motion.... Anywhere from 5 seconds to 5 minutes. Sensitivity Adjust Sets the detection range.... from 3 meters to 7 meters Trigger Selection Jumper Set for single or repeatable triggers. Ground pin Ground input Output Pin Low when no motion is detected.. High when motion is detected. High is 3.
HC SR501 PIR Functional Description The SR501 will detect infrared changes and if interpreted as motion, will set its output low. What is or is not interpreted as motion is largely dependent on user settings and adjustments. Device Initialization The device requires nearly a minute to initialize. During this period, it can and often will output false detection signals. Circuit or controller logic needs to take this initialization period into consideration.
HC SR501 View Area PIR Range (Sensitivity) Adjustment As mentioned, the adjustable range is from approximately 3 to 7 meters. The illustration below shows this adjustment. HC SR501 Sensitivity Adjust Time Delay Adjustment The time delay adjustment determines how long the output of the PIR sensor module will remain high after detection motion. The range is from about 3 seconds to five minutes.
HC SR501 Time Delay Adjustment 3 Seconds Off After Time Delay Completes – IMPORTANT The output of this device will go LOW (or Off) for approximately 3 seconds AFTER the time delay completes. In other words, ALL motion detection is blocked during this three second period. For Example: Imagine you’re in the single trigger mode and your time delay is set 5 seconds. The PIR will detect motion and set it high for 5 seconds. After five seconds, the PIR will sets its output low for about 3 seconds.
Trigger Mode Selection Jumper The trigger mode selection jumper allows you to select between single and repeatable triggers. The affect of this jumper setting is to determine when the time delay begins. SINGLE TRIGGER – The time delay begins immediately when motion is first detected. REPEATABLE TRIGGER – Each detected motion resets the time delay. Thus the time delay begins with the last motion detected.
Example One In this first example, the time delay is set to three seconds and the trigger mode is set to single. As you can see in the illustration below, the motion is not always detected. In fact, there is a period of about six seconds where motion can not be detected. Feel free to click on the image to enlarge. Example Two In the next example, the time delay is still at three seconds and the trigger is set to repeatable. In the illustration below, you can see that the time delay period is restarted.
Connection Schematic 128 / 223
Wiring diagram 129 / 223
Connecting PIR sensors to a microcontroller is really simple. The PIR acts as a digital output so all you need to do is listen for the pin to flip high (detected) or low (not detected). It’s likely that you'll want retriggering, so be sure to put the jumper in the H position! Power the PIR with 5V and connect ground to ground. Then connect the output to a digital pin. In this example, we'll use pin 7.
Lesson 18 Water Level Detection Sensor Module Overview In this lesson, you will learn how to use a water level detection sensor module. This module can perceive the depth of water and the core component is an amplifying circuit which is made up of a transistor and several pectinate PCB routings. When put into the water, these routings will present a resistor that can change along with the change of the water’s depth.
It has low power consumption, and high sensitivity. Features: 1、Working voltage: 5V 2、Working Current: <20ma 3、 Interface: Analog 4、Width of detection: 40mm×16mm 5、Working Temperature: 10℃~30℃ 6、Output voltage signal: 0~4.
Wiring diagram 133 / 223
Wiring tips: Power supply (+) is connected to 5V of MEGA2560 R3 board, ground electrode (-) is connected to GND. Signal output (S) is connected to the ports (A0A5) which have function of inputting analog signal in MEGA2560 R3 board, random one is OK, but it should define the same demo code as the routine. Code After wiring, please open the program in the code folder- Lesson 18 Water Level Detection Sensor Module and click UPLOAD to upload the program.
Open the monitor then you can see the data as below: Click the Serial Monitor button to turn on the serial monitor. The basics about the serial monitor are introduced in details in Lesson 1.
Lesson 19 Real Time Clock Module Overview In this lesson, you will learn how to use the DS3231, clock module that displays the year, month, day, hour, minute, second and week. Support is via a backup battery trickle charger, which can be used unless being connected to MEGA2560 with only three data cables. Component Required: (1) x Elegoo Mega2560 R3 (1) x DS3231 RTC module (4) x F-M wires (Female to Male DuPont wires) Component Introduction DS3231 The DS3231 is a simple time-keeping chip.
Connection Schematic 137 / 223
Wiring diagram 138 / 223
Set up according to the following image. Ignore the 32K and SQW pins; you will not need them. Plug the SCL pin into your MEGA2560 R3 board SCL port, and the SDA pin into the SDA port. The VCC pin plugs into the 5V port, and the GND plugs into the GND port. Code After wiring, please open program in the code folder- Lesson 19 Real Time Clock Module and click UPLOAD to upload the program. See Lesson 2 for details about program uploading if there are any errors.
Open the monitor then you can see the module can read the time as below: Click the Serial Monitor button to turn on the serial monitor. The basics about the serial monitor are introduced in details detail in Lesson 1.
Lesson 20 Sound Sensor Module Overview In this lesson, you will learn how to use a sound sensor module. This module has two outputs: AO: analog output, real-time output voltage signal of microphone DO: when the intensity of the sound reaches a certain threshold, the output is a high or low level signal. The threshold sensitivity can be achieved by adjusting the potentiometer.
capacitor and works on the principle of a variable capacitance. It consists of two plates, one fixed (called the back plate) and the other moveable (called the diaphragm) with a small gap between them. An electric potential charges the plate. When sound strikes the diaphragm it starts moving, thereby changing the capacitance between the plates which in turn results in a variable electric current to flow.
Connection Schematic 143 / 223
Wiring diagram 144 / 223
The code After wiring, please open the program in the code folder- Lesson 20 Sound Sensor Module and click UPLOAD to upload the program. See Lesson 2 for details about program uploading if there are any errors. This module provides two signal output modes, for which we wrote two codes: digital_signal_output and analog_signal_output.
Open the monitor then you can see the data as below: Click the Serial Monitor button to turn on the serial monitor. The basics about the serial monitor are introduced in details in Lesson 1.
Lesson 21 RC522 RFID Module Overview In this lesson, you will learn to how to apply the RC522 RFID Reader Module on MEGA2560 R3. This module uses the Serial Peripheral Interface (SPI) bus to communicate with controllers such as Arduino, Raspberry Pi, beagle board, etc. Component Required: (1) x Elegoo Mega2560 R3 (1) x RC522 RFID module (7) x F-M wires (Female to Male DuPont wires) Component Introduction RC522 The MFRC522 is a highly integrated reader/writer for contactless communication at 13.56 MHz.
Connection Schematic 148 / 223
Wiring diagram 149 / 223
Code After wiring, please open the program in the code folder- Lesson 21 RC522 RFID Module and press UPLOAD to upload the program. See Lesson 2 for details about program uploading if there are any errors. Before you can run this, make sure that you have installed the < rfid > library or reinstall it, if necessary. Otherwise, your code won't work. For details about loading the library file, see Lesson 1.
Open the monitor then you can see the data as blow: Click the Serial Monitor button to turn on the serial monitor. The basics about the serial monitor are set out in detail in Lesson 1.
Lesson 22 LCD Display Overview In this lesson, you will learn how to wire up and use an alphanumeric LCD display. The display has an LED backlight and can display two rows with up to 16 characters on each row. You can see the rectangles for each character on the display and the pixels that make up each character. The display is just white on blue and is intended for showing text.
Connection Schematic 153 / 223
Wiring diagram 154 / 223
The LCD display needs six Arduino pins, all set to be digital outputs. It also needs 5V and GND connections. There are a number of connections to be made. Lining up the display with the top of the breadboard helps to identify its pins without too much counting, especially if the breadboard has its rows numbered with row 1 as the top row of the board. Do not forget, the long yellow lead that links the slider of the pot to pin 3 of the display. The 'pot' is used to control the contrast of the display.
The first sets the cursor position (where the next text will appear) to column 0 & row 1. Both column and row numbers start at 0 rather than 1. The second line displays the number of milliseconds since the Arduino was reset.
Lesson 23 Thermometer Overview In this lesson, you will use an LCD display to show the temperature. Component Required: (1) x Elegoo Mega2560 R3 (1) x LCD1602 Module (1) x 10k ohm resistor (1) x Thermistor (1) x Potentiometer (1) x 830 tie-points Breadboard (18) x M-M wires (Male to Male jumper wires) Component Introduction Thermistor A thermistor is a thermal resistor - a resistor that changes its resistance with temperature.
Connection Schematic 158 / 223
Wiring diagram 159 / 223
The breadboard layout is based on the layout from Lesson 22, so it will simplify things if you still have this on the breadboard. There are a few jumper wires near the pot that have been moved slightly on this layout. The 10 kΩ resistor and thermistor are all new additions to the board. Code After wiring, please open the program in the code folder- Lesson 23 Thermometer and click UPLOAD to upload the program. See Lesson 2 for details about program uploading if there are any errors.
lcd.setCursor(0, 0); lcd.print("Temp C "); lcd.setCursor(6, 0); lcd.print(tempF); The rather strange comment serves to remind you of the 16 columns of the display. You can then print a string of that length with spaces where the actual reading will go. To fill in the blanks, set the cursor position for where the reading should appear and then print it.
Lesson 24 Eight LED with 74HC595 Overview In this lesson, you will learn how to use eight large red LEDs with an MEGA2560 without needing to give up 8 output pins! Although you could wire up eight LEDs each with a resistor to an MEGA2560 pin you would rapidly start to run out of pins on your MEGA2560. If you don't have a lot of stuff connected to your MEGA2560. It's OK to do so - but often times we want buttons, sensors, servos, etc. and before you know it you've got no pins left.
/ 223
The clock pin needs to receive eight pulses. At each pulse, if the data pin is high, then a 1 gets pushed into the shift register; otherwise, a 0. When all eight pulses have been received, enabling the 'Latch' pin copies those eight values to the latch register. This is necessary; otherwise, the wrong LEDs would flicker as the data is being loaded into the shift register. The chip also has an output enable (OE) pin, which is used to enable or disable the outputs all at once.
Wiring diagram 165 / 223
As we have eight LEDs and eight resistors to connect, there are actually quite a few connections to be made. It is probably easiest to put the 74HC595 chip in first, as pretty much everything else connects to it. Put it so that the little U-shaped notch is towards the top of the breadboard. Pin 1 of the chip is to the left of this notch.
which of our eight LEDs are on or off. byte leds = 0; The 'setup' function just sets the three pins we are using to be digital outputs. void setup() { pinMode(latchPin, OUTPUT); pinMode(dataPin, OUTPUT); pinMode(clockPin, OUTPUT); } The 'loop' function initially turns all the LEDs off, by giving the variable 'leds' the value 0. It then calls 'updateShiftRegister' that will send the 'leds' pattern to the shift register so that all the LEDs turn off. We will deal with how 'updateShiftRegister' works later.
Bit' (LSB). The last parameter is the actual data to be shifted into the shift register, which in this case is 'leds'. void updateShiftRegister() { digitalWrite(latchPin, LOW); shiftOut(dataPin, clockPin, LSBFIRST, leds); digitalWrite(latchPin, HIGH); } If you wanted to turn one of the LEDs off rather than on, you would call a similar Arduino function (bitClear) with the 'leds' variable.
Lesson 25 The Serial Monitor Overview In this lesson, you will build on Lesson 24, adding the facility to control the LEDs from your computer using the Arduino Serial Monitor. The serial monitor is the 'tether' between the computer and your MEGA2560. It lets you send and receive text messages, handy for debugging and also controlling the MEGA2560 from a keyboard! For example, you will be able to send commands from your computer to turn on LEDs.
The following window will open. Click the Serial Monitor button to turn on the serial monitor. The basics about the serial monitor are introduced in details in Lesson 1. This window is called the Serial Monitor and it is part of the Arduino IDE software. Its job is to allow you to both send messages from your computer to an MEGA2560 board (over USB) and also to receive messages from the MEGA2560. The message “Enter LED Number 0 to 7or 'x' to clear” has been sent by the Arduino.
Type x again and press ‘Send’ to turn off all LEDs. Code After wiring, please open program in the code folder- Lesson 25 The Serial Monitor and click UPLOAD to upload the program. See Lesson 2 for details about program uploading if there are any errors. As you might expect, the sketch is based on the sketch used in Lesson 24. So, we will just cover the new bits here. You will find it useful to refer to the full sketch in your Arduino IDE.
while (! Serial); // Wait until Serial is ready - Leonardo Serial.println("Enter LED Number 0 to 7 or 'x' to clear"); } Firstly, we have the command 'Serial.begin(9600)'. This starts serial communication, so that the MEGA2560 can send out commands through the USB connection. The value 9600 is called the 'baud rate' of the connection. This is how fast the data is to be sent. You can change this to a higher value, but you will also have to change the Arduino Serial monitor to the same value.
Serial.println("Cleared"); } } } Everything that happens inside the loop is contained within an 'if' statement. So unless the call to the built-in Arduino function 'Serial.available()' is 'true' then nothing else will happen. Serial.available() will return 'true' if data has been send to the MEGA2560 and is there ready to be processed. Incoming messages are held in what is called a buffer and Serial.available() returns true if that buffer is Not empty.
The next two lines write back a confirmation message to the Serial Monitor. Serial.print("Turned on LED "); Serial.println(led); The first line uses Serial.print rather than Serial.println. The different between the two is that Serial.print does not start a new line after printing whatever is in its parameter. We use this in the first line, because we are printing the message in two parts. Firstly the general bit: 'Turned on LED ' and then the number of the LED.
Lesson 26 Photocell Overview In this lesson, you will learn how to measure light intensity using an Analog Input. You will build on lesson 25 and use the level of light to control the number of LEDs to be lit. The photocell is at the bottom of the breadboard, where the pot was above.
The resistor and photocell together behave like a pot. When the light is very bright, then the resistance of the photocell is very low compared with the fixed value resistor, and so it is as if the pot were turned to maximum. When the photocell is in dull light, the resistance becomes greater than the fixed 1 kΩ resistor and it is as if the pot were being turned towards GND. Load up the sketch given in the next section and try covering the photocell with your finger, and then holding it near a light source.
Connection Schematic 177 / 223
Wiring diagram 178 / 223
Code After wiring, please open the program in the code folder- Lesson 26 Photocell and click UPLOAD to upload the program. See Lesson 2 for details about program uploading if there are any errors. The first thing to note is that we have changed the name of the analog pin to be 'lightPin' rather than 'potPin' since we no longer have a pot connected.
Lesson 27 74HC595 And Segment Display Overview After learning Lesson 24、25 and Lesson 26, we will use the 74HC595 shift register to control the segment display. The segment display will show number from 9-0. Component Required: (1) x Elegoo Mega2560 R3 (1) x 830 tie-points breadboard (1) x 74HC595 IC (1) x 1 Digit 7-Segment Display (8) x 220 ohm resistors (26) x M-M wires (Male to Male jumper wires) Component Introduction Seven segment display Below is the seven-segment pin diagram.
0-9 ten digits correspond with each segment are as follows (the following table applies common cathode seven segment display device, if you are using a common anode, the table should be replaced every 1 0 0 should all replaced by 1): Display digital dp a b c d e f g 0 0 1 1 1 1 1 1 0 1 0 0 1 1 0 0 0 0 2 0 1 1 0 1 1 0 1 3 0 1 1 1 1 0 0 1 4 0 0 1 1 0 0 1 1 5 0 1 0 1 1 0 1 1 6 0 1 0 1 1 1 1 1 7 0 1 1 1 0 0 0 0 8 0 1 1 1 1 1
Connection Schematic 182 / 223
Wiring diagram 183 / 223
The following table shows the seven-segment display 74HC595 pin correspondence table: 74HC595 pin Seven shows remarkable control pin (stroke) Q0 7 (A) Q1 6 (B) Q2 4 (C) Q3 2 (D) Q4 1 (E) Q5 9 (F) Q6 10 (G) Q7 5 (DP) Step one: Connect 74HC595 First, the wiring is connected to power and ground: VCC (pin 16) and MR (pin 10) connected to 5V GND (pin 8) and OE (pin 13) to ground Connection DS, ST_CP and SH_CP pin: DS (pin 14) connected to MEGA2560 R3 board pin 2 (the figure below the yellow lin
Code After wiring, please open the program in the code folder- Lesson 27 74HC595 And Segment Display and click UPLOAD to upload the program. See Lesson 2 for details about program uploading if there are any errors.
Lesson 28 Four Digital Seven Segment Display Overview In this lesson, you will learn how to use a 4-digit 7-segment display. When using 1-digit 7-segment display please notice that if it is common anode, the common anode pin connects to the power source; if it is common cathode, the common cathode pin connects to the GND. When using 4-digit 7-segment display, the common anode or common cathode pin is used to control which digit is displayed.
Component Introduction Four Digital Seven segment display 187 / 223
Connection Schematic 188 / 2 23
Wiring diagram 189 / 223
Code After wiring, please open the program in the code folder- Lesson 28 Four Digital Seven Segment Display and click UPLOAD to upload the program. See Lesson 2 for details about program uploading if there are any errors.
Lesson 29 DC Motors Overview In this lesson, you will learn how to control a small DC motor using an MEGA2560 R3 and a transistor. Component Required: (1) x Elegoo Mega2560 R3 (1) x 830 tie-points breadboard (1) x L293D IC (1) x Fan blade and 3-6v motor (5) x M-M wires (Male to Male jumper wires) (1) x Power Supply Module (1) x 9V1A adapter Component Introduction Breadboard Power Supply The small DC motor is likely to use more power than an MEGA2560 R3 board digital output can handle directly.
Product Specifications: Locking On/Off Switch LED Power Indicator Input voltage: 6.5-9v (DC) via 5.5mm x 2.1mm plug Output voltage: 3.3V/5v Maximum output current: 700 mA Independent control rail output. 0v, 3.3v, 5v to breadboard Output header pins for convenient external use Size: 2.1 in x 1.4 in USB device connector onboard to power external device Setting up output voltage: The left and right voltage output can be configured independently.
Important note: Make sure that you align the module correctly on the breadboard. The negative pin(-) on module lines up with the blue line(-) on breadboard and that the positive pin(+) lines up with the red line(+). Failure to do so could result in you accidently reversing the power to your project L293D This is a very useful chip. It can actually control two motors independently.
Product Specifications: • Featuring Unitrode L293 and L293D Products Now From Texas Instruments • Wide Supply-Voltage Range: 4.5 V to 36 V • Separate Input-Logic Supply • Internal ESD Protection • Thermal Shutdown • High-Noise-Immunity Inputs • Functionally Similar to SGS L293 and SGS L293D • Output Current 1 A Per Channel (600 mA for L293D) • Peak Output Current 2 A Per Channel (1.
VCC1 1 1 0 1 16 2 15 1 0 M 1 M 3 14 4 13 5 12 6 11 2 1 0 7 8 3 10 9 1 0 1 0 M VCC2 I got fed up with indecipherable pinout diagrams within datasheets, so have designed my own that I think gives more pertinent information. There are 3 wires connected to the Arduino, 2 wires connected to the motor, and 1 wire connected to a battery. To use this pinout: The left hand side deals with the first motor, the right hand side deals with a second motor.
255 is 196 / 223
max speed. M1 direction 0/1 and M1 direction 1/0 - Connect these two to two digital Arduino pins. Output one pin as HIGH and the other pin as LOW, and the motor will spin in one direction. Reverse the outputs to LOW and HIGH, and the motor will spin in the other direction.
Connection Schematic 197 / 223
Wiring diagram 198 / 223
The code below does not use a separate power supply (ie a battery), it uses instead the 5v power from the Arduino. Note that this would be risky without the L293D controlling it. You should _never_ connect a motor directly to the Arduino, because when you switch a motor off you get an electrical feedback. With a small motor, this will damage your Arduino, and with a large motor, you can watch an interesting flame and sparks effect.
Example picture 299 / 223
Lesson 30 Relay Overview In this lesson, you will learn how to use a relay.
Component Introduction Relay: A relay is an electrically operated switch. Many relays use an electromagnet to mechanically operate a switch, but other operating principles are also used as in solid-state relays. Relays are used where it is necessary to control a circuit by a lowpower signal (with complete electrical isolation between control and controlled circuits), or where several circuits must be controlled by one signal. The first relays were used in long-distance telegraph circuits as amplifiers.
Connection Schematic 203 / 223
Wiring diagram 204 / 223
Code After wiring, please open the program in the code folder- Lesson 30 Relay and click UPLOAD to upload the program. See Lesson 2 for details about program uploading if there are any errors. After program loading, turn on all the power switches. The relay will pick up with a ringing sound. Then, the motor will rotate. After a period of time, the relay will be released, and the motor stops.
Lesson 31 Stepper Motor Overview In this lesson, you will learn a fun and easy way to drive a stepper motor. The stepper we are using comes with its own driver board making it easy to connect to our MEGA2560.
A stepper motor is an electromechanical device which converts electrical pulses into discrete mechanical movements. The shaft or spindle of a stepper motor rotates in discrete step increments when electrical command pulses are applied to it in the proper sequence. The motors rotation has several direct relationships to these applied input pulses. The sequence of the applied pulses is directly related to the direction of motor shafts rotation.
Interfacing circuits The bipolar stepper motor usually has four wires coming out of it. Unlike unipolar steppers, bipolar steppers have no common center connection. They have two independent sets of coils instead. You can distinguish them from unipolar steppers by measuring the resistance between the wires. You should find two pairs of wires with equal resistance. If you’ve got the leads of your meter connected to two wires that are not connected (i.e.
ULN2003 Driver Board Product Description o Size: 42mmx30mm o Use ULN2003 driver chip, 500mA o A. B. C. D LED indicating the four phase stepper motor working condition. o White jack is the four phase stepper motor standard jack. o Power pins are separated o We kept the rest pins of the ULN2003 chip for your further prototyping. The simplest way of interfacing a unipolar stepper to Arduino is to use a breakout for ULN2003A transistor array chip.
The sequence would go like this: Here are schematics showing how to interface a unipolar stepper motor to four controller pins using a ULN2003A, and showing how to interface using four com 210 / 223
Connection Schematic 211 / 223
Wiring diagram 212 / 223
We are using 4 pins to control the Stepper. Pin 8-11 are controlling the Stepper motor. We connect the Ground from to MEGA2560 to the Stepper motor. Code After wiring, please open the program in the code folder- Lesson 31 Stepper Motor and click UPLOAD to upload the program. See Lesson 2 for details about program uploading if there are any errors. Before you can run this, make sure that you have installed the < Stepper > library or re-install it, if necessary. Otherwise, your code won't work.
Lesson 32 Controlling Stepper Motor With Remote Overview In this lesson, you will learn a fun and easy way to control a stepper motor from a distance using an IR remote control. The stepper we are using comes with its own driver board making it easy to connect to our MEGA2560. Since we don’t want to drive the motor directly from the MEGA2560, we will be using an inexpensive little breadboard power supply that plugs right into our breadboard and power it with a 9V 1Amp power supply.
Connection Schematic 215 / 223
Wiring diagram 216 / 223
We are using 4 pins to control the Stepper and 1 pin for the IR sensor. Pins 8-11 are controlling the Stepper motor and pin 12 is receiving the IR information. We connect the 5V and Ground from the MEGA2560 to the sensor. As a precaution, use a breadboard power supply to power the stepper motor since it can use more power and we don’t want to damage the power supply of the MEGA2560.
Lesson 33 Controlling Stepper Motor With Rotary Encoder Overview In this lesson, you will learn how to control stepper motors using a rotary encoder. We will use the inexpensive and popular stepper motor that comes with its own control board: the 28BYJ-48 stepper motor with the ULN2003 board. The 28BYJ-48 motor is not very fast or very strong, but it’s great for beginners to start experimenting with controlling a stepper motor with an Arduino.
Component Introduction Rotary encoder A rotary encoder, also called a shaft encoder, is an electro-mechanical device that converts the angular position or motion of a shaft or axle to an analog or digital code. There are two main types: absolute and incremental (relative). The output of absolute encoders indicates the current position of the shaft, making them angle transducers.
Connection Schematic 220 / 223
Wiring diagram 221 / 223
We are using 4 pins to control the Stepper and 3 pins for the rotary encoder module. Pins 8-11 are controlling the Stepper motor and pins 2-4 are receiving information from the rotary encoder. We connect the 5V and Ground from to MEGA2560 to the rotary encoder and as a precaution, use a breadboard power supply to power the stepper motor since it can use more power that the MEGA2560 can provide. We also connect the MEGA2560 Ground to the breadboard to serve as a reference.
Example picture 223 / 223