Elegoo Mega2560 User manual

THE MOST COMPLETE STARTER KIT
TUTORIAL FOR MEGA2560
V1.0.17.7.9

2
/
223
Our Company
Preface
Established in 2011, Elegoo Inc. is a thriving technology company dedicated to open-
source 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.8’’ TFT touch and STM32. In the
future we would devote more energy and investment to 3D printer products and so
on. All of our products comply with international quality standards and are greatly
appreciated in a variety of different markets throughout the world.
Official website: http://www.elegoo.com
US Amazon storefront: http://www.amazon.com/shops/A2WWHQ25ENKVJ1
CA Amazon storefront: http://www.amazon.ca/shops/A2WWHQ25ENKVJ1
UK Amazon storefront: http://www.amazon.co.uk/shops/A1780XYQ9DFQM6
DE Amazon storefront:http://www.amazon.de/shops/A1780XYQ9DFQM6
FR Amazon storefront: http://www.amazon.de/shops/A1780XYQ9DFQM6
ES Amazon storefront: http://www.amazon.de/shops/A1780XYQ9DFQM6
IT Amazon storefront:http://www.amazon.de/shops/A1780XYQ9DFQM6
Our Tutorial
This tutorial is designed for beginners. You will learn all the basic information about
how to use Arduino controller board, sensors and components. If you want to study
Arduino in more depth, we recommend that you read the Arduino Cookbook written
by Michael Margolis.
Some codes in this tutorial is edited by Simon Monk. Simon Monk is author of a
number of books relating to Open Source Hardware. They are available in Amazon:
Programming Arduino, 30 Arduino Projects for the Evil Genius and Programming the
Raspberry Pi.
Customer Service
As a continuous and fast growing technology company we keep striving our best to

3
/
223
offer you excellent products and quality service as to meet your expectation and you
[email protected]. We look forward to hearing from you and any of your critical
comment or suggestion would be much valuable to us.
And any of problems and questions you have with our products will be promptly
replied by our experienced engineers within 12 hours (24hrs during holiday)

4 / 223

5 / 223

6 / 223

7 / 223

8 / 223

9 / 223

10
/
223
Content
Lesson 0 Installing IDE .............................................................................................................12
Lesson 1 Add Libraries and Open Serial Monitor ...................................................................23
Lesson 2 Blink...........................................................................................................................32
Lesson 3 LED.............................................................................................................................43
Lesson 4 RGB LED.....................................................................................................................50
Lesson 5 Digital Inputs.............................................................................................................59
Lesson 6 Active buzzer.............................................................................................................64
Lesson 7 Passive Buzzer...........................................................................................................68
Lesson 8 Tilt Ball Switch...........................................................................................................72
Lesson 9 Servo..........................................................................................................................76
Lesson 10 Ultrasonic Sensor Module ......................................................................................80
Lesson 11 Membrane Switch Module.....................................................................................85
Lesson 12 DHT11 Temperature and Humidity Sensor............................................................91
Lesson 13 Analog Joystick Module..........................................................................................97
Lesson 14 IR Receiver Module...............................................................................................102
Lesson 15 MAX7219 LED Dot Matrix Module.......................................................................108
Lesson 16 GY-521 Module .....................................................................................................112
Lesson 17 HC-SR501 PIR Sensor ............................................................................................121
Lesson 18 Water Level Detection Sensor Module................................................................131
Lesson 19 Real Time Clock Module .......................................................................................136
Lesson 20 Sound Sensor Module...........................................................................................141
Lesson 21 RC522 RFID Module ..............................................................................................147
Lesson 22 LCD Display............................................................................................................152
Lesson 23 Thermometer........................................................................................................157
Lesson 24 Eight LED with 74HC595........................................................................................162
Lesson 25 The Serial Monitor ................................................................................................169
Lesson 26 Photocell ...............................................................................................................175
Lesson 27 74HC595 And Segment Display ............................................................................180

11
/
223
Lesson 28 Four Digital Seven Segment Display.....................................................................186
Lesson 29 DC Motors .............................................................................................................191
Lesson 30 Relay......................................................................................................................201
Lesson 31 Stepper Motor ......................................................................................................206
Lesson 32 Controlling Stepper Motor With Remote ............................................................214
Lesson 33 Controlling Stepper Motor With Rotary Encoder ................................................218

12
/
223
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.
STEP 1: Go to https://www.arduino.cc/en/Main/Software and find below page.
The version available at this website is usually the latest version, and the actual
version may be newer than the version in the picture.

13
/
223
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.

14
/
223
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 wasmade.
Installing Arduino (Windows)
Install Arduino with the exe. Installation package.
Click I Agree to see the following interface

Click Next
You can press Browse… to choose an installation path or directly type in the
directory you want.
15 / 223

16
/
223
Click Install to initiate installation
Finally, the following interface appears, click Install to finish the installation.
Next, the following icon appears on the desktop

17
/
223
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.
Unzip the zip file downloaded, Double-click to open the program and enter the
desired development environment

18
/
223

19
/
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. Ignore this message and cancel any
attempts that Windows makes to try and install drivers automatically for you.
The most reliable method of installing the USB drivers is to use the Device Manager.
This is accessed in different ways depending on your version of Windows. In
Windows 7, you first have to open the Control Panel, then select the option to view
Icons, and you should find the Device Manager in the list.
Under ‘Other Devices’, you should see an icon for ‘unknown device’ with a little
yellow warning triangle next to it. This is your Arduino.

20
/
223
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.
Table of contents