# Learn @ Arduino SA

The blog will teach you how to setup your Arduino and guide you through different projects you can create using Arduino

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-ec3f6833f39e5cc51758df40b8a83938aabe21d3%2FArduinoEducation_Logo-02.svg?alt=media)


# Arduino Introduction

### Arduino

Arduino is an open−source electronics platform based on easy−to−use hardware and software. It's intended for anyone making interactive projects. Usually, an Arduino project consists of circuit and code.

### Arduino Board

Arduino Board is a circuit board, with integrates micro controller, input, output interface and etc. Arduino Board can use the sensor to sense the environment and receive user's operation to control LED, motor rotation, etc. We just need to assembly circuit and write the code.

Currently, Arduino Board has several models, and the code between boards of different types is universal (some boards may not be completely compatible because of the differences in hardware). Popular boards include:

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-daf1c232bb370595635245f7405da012d0e62aad%2Fimage.png?alt=media)

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-0338af18e3c822d8aaab9e3149f262347d02e392%2Fimage.png?alt=media)

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-f93b4ca171a7f3cb62f7802e73cc68a45bf40dce%2Fimage.png?alt=media)

Digital I/O Ports is used to connect to other components or modules, to receive an input signal, or to send a control signal. Usually, we name it by adding a "D" in front of the number, such as D13.

* USB Interface is used to provide power, upload code or communicate with PC.
* LED L is connected to digital I/O port 13 (D13).
* LED TX, RX is used to indicate the state of the serial communication.
* DC Power Jack is connected DC power to provide power for the board.
* Power Ports can provide power for electronic components and modules.
* Analog I/O Ports can be used to measure analog signals.
* LED ON is used to indicate the power state.

### Arduino Software

Arduino Software (IDE) is used to write and upload the code for Arduino Board. First, install Arduino Software (IDE): visit <https://www.arduino.cc>, click "Download" to enter the download page.

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-5abbd85c6a22b54a565f67f4f7aa277b58afd9e3%2Fimage.png?alt=media)

Download corresponding installation program according to your operating system. If you are a Windows user, please select the "Windows Installer" to download and install the driver correctly.

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-2bd41a33e7793a07e1febf9d5e8cfd00368dd2e1%2Fimage.png?alt=media)

After the download completes, run the installer. For Windows users, there may pop up a installation dialog box of driver during the installation process. When it is popped up, please allow the installation. After installation is complete, an Arduino Software shortcut will be generated in the desktop. Run the Arduino Software.

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-93774b1b74d75d3c74bf7cd94dc1db99ac0b3320%2Fimage.png?alt=media)

The interface of Arduino Software is as follows:

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-78df86fd69b54b1cbfd99b18f90c964e04897850%2Fimage.png?alt=media)

Programs written using Arduino Software (IDE) are called sketches. These sketches are written in the text editor and are saved with the file extension .ino. The editor has features for cutting/pasting and for searching/replacing text. The message area gives feedback while saving and exporting and also displays errors. The console displays text output by the Arduino Software (IDE), including complete error messages and other information. The bottom righthand corner of the window displays the configured board and serial port. The toolbar buttons allow you to verify and upload programs, create, open, and save sketches, and open the serial monitor.

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-1be1c835da768ce17368626ca6b43f6536efa84c%2Fimage.png?alt=media)

Additional commands are found within the five menus: File, Edit, Sketch, Tools, Help. The menus are context sensitive, which means only those items relevant to the work currently being carried out are available.

### First Use

Open the example sketch "Blink" with Arduino Software.

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-dfd687bdfb8e24de8531fc4761d055159053323e%2Fimage.png?alt=media)

Select board "Arduino/Genuino Uno".

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-11ec96732ba769f2b78b7477dd6fdd347bfad950%2Fimage.png?alt=media)

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-b9dda894224a8b073509cfe34f65b97df3cfd807%2Fimage.png?alt=media)

Select the serial port. Your serial number may be different from the following figure. If it is not detected immediately, please wait for a while, then click "Tools" to check again.

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-c4fc08be7f77d07610eacde2e9af16cef6c17ec9%2Fimage.png?alt=media)

Click "Verify" button.

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-da6c19e4f7bb7c627a5cfd5ef75b73e12526d104%2Fimage.png?alt=media)

Wait a moment for the compiling to be completed. Figure below shows the code size and percentage of space occupation

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-447e11f63c859cf96cb25afa6b0f7b145ae8ea6b%2Fimage.png?alt=media)

Usually, when we write code, if it has a syntax error, the interface will prompt the error message. Then the compiling can't be completed. Click "Upload" button

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-6ac23877556e1c5c3daaf3909b63378aa34a67cb%2Fimage.png?alt=media)

Wait a moment, then the uploading is completed.

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-4f03dd2967e05887e8b3c78b9430630516f5c7ba%2Fimage.png?alt=media)

After that, we will see the LED marked with "L" on UNO starts blinking. It indicates that the code is running now!

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-49ceb62c38d68ef913e4547db4a193f59f101ea9%2Fimage.png?alt=media)


# Setup your Computer

When you get the UNO development board, first you should install the Arduino software and driver.

## Download Arduino IDE

Go to <http://arduino.cc/en/Main/Software> to download the installation file according to your operation system.

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-e8927cef260f6dc9af971807281d0fa5803ab659%2Fimage.png?alt=media)

For Windows users, please follow the instructions below. For Mac and Linux users, you can directly use the Arduino sketch by simply clicking on the file.

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-ca390c538125c743fdacc97147063daba9d539af%2Fimage.png?alt=media)

## Install the drivers

Installing drivers for the Arduino Plug in your board and wait for Windows to begin its driver installation process. After a few moments, despite its best efforts, the process will fail, but do not panic! Click on the Start Menu, and open up the Control Panel.

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-e9f96d7158df97957e233ba12298fde554578980%2Fimage.png?alt=media)

Find **Unknown Device** and then right click and select **Update Driver Software**.

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-64d374856479a464b6dc8ca92d3224c43a95bab1%2Fimage.png?alt=media)

Choose browse my computer for driver software to search for drivers manually

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-f8f8c8af771f80bfec2f5501fbc4feac8e3784e7%2Fimage.png?alt=media)

Click **Browse** and find the directory location of the Arduino IDE where the installation files are located. Inside this directory will be another directory named **Drivers**. Select it and click **Next** .

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-098aac7b54fcb65d302b18551126d022439ea85c%2Fimage.png?alt=media)

This dialog indicates successful installation. Hopefully this is what you will see! If not double check the steps and try again.

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-546de3513d7ea5ee9eb8bb1ca4605c20d2c3b707%2Fimage.png?alt=media)

If you go back to your device manager, the Arduino device should now be recognised by your computer.

Go to “**Device Manager**” >“**Ports (COM & LPT)**”. You should see “**Arduino no (COM#)**”. This is the COM port that your computer uses to transfer data to your Arduino. In our example the computer communicates with the Arduino on COM36

Remember your COM number as you will need it later.

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-0507a88ef2566ffbad19011ca410b90d7d401ec1%2Fimage.png?alt=media)

{% hint style="warning" %}
If the above does not work. Please download this [driver](https://bit.ly/CH340G-Win) install it on you PC and try the above again
{% endhint %}

## Upload a Blink program

Open Arduino IDE and take a moment to move your mouse along each icon to get to know their functions. Here we will use a very basic sample code, **Blink** to go through the whole process and test whether the controller is working.

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-d4f1a6512a043580a7aa47e321faef83ad071806%2Fimage.png?alt=media)

Open the LED blink example sketch. You will find it under **File > Examples > 01.Basics > Blink**.

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-da8e49f80ea25ad384060bc848785999c637f6e7%2Fimage.png?alt=media)

Click “**Verify**” to compile the code. The IDE changes the code from text into instructions that the computer can understand. This process is called **compiling**.

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-d5e8ae68f26d2fffc9338b30acb16fbeaa5864bd%2Fimage.png?alt=media)

Verifying....

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-99c2cdac65b32da3afc6b252434a9cb84303b1d2%2Fimage.png?alt=media)

Finished!

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-efcf39d4ff13acf8dcdceb156ae59896d95d44f0%2Fimage.png?alt=media)

The code we are using should not have errors since it is an example code. If a code does have errors in it it will fail to verify.

Time to download the code to your Arduino! Select your micro-controller by selecting “**Board > Arduino Uno**”

Then select your COM port by selecting “**Serial Port**” and selecting the COM port number you saw earlier. In our example **COM36** is in use.

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-2213953c27dcf863c5d3215b29a6f8a79cc593d4%2Fimage.png?alt=media)

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-ca02541202a58d2f1888dc86137f723cb864aab4%2Fimage.png?alt=media)

Click **Upload** to send the code via the USB to you Arduino Board

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-9767c8ebb24c542ce271f118c9dfd0d92322c339%2Fimage.png?alt=media)

After it is finished, the Arduino will run the code automatically and the onboard LED will start to blink, just as programmed!


# Adding 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. There are hundreds of additional libraries available on the Internet for download. The built-in libraries and some of these additional libraries are listed in the reference. To use the additional libraries, you will need to install them.

## How to Install a Library

#### Using the **Library Manager**

To install a new library into your Arduino IDE you can use the Library Manager (available from IDE version 1.8.9). Open the IDE and click to the "Sketch" menu and then Include Library > Manage Libraries.

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-803fcf7e68c1546e1b8c173fa2ca2d04c5f86af4%2Fimage.png?alt=media)

Then we check to see if the library is installed correctly.

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-0f9d7a7f7f4dfa42d57257f16754ef14827a9c88%2Fimage.png?alt=media)

Example: IRromote

Open arduino software -> project -> load library -> add a .zip library


# Setting up a ESP32

Please view the list of tutorials below to setup your ESP32

{% embed url="<https://randomnerdtutorials.com/installing-the-esp32-board-in-arduino-ide-windows-instructions/>" %}

{% embed url="<https://lastminuteengineers.com/esp32-arduino-ide-tutorial/>" %}


# Arduino Bluetooth Car

Follow the below guide to build your own bluetooth Arduino Car.

## Contents

* [What you will need](/arduino-robot-car/arduino-bluetooth-car/what-you-will-need)
* [Circuit Diagram](/arduino-robot-car/arduino-bluetooth-car/circuit-diagram)
* [Assembly](/arduino-robot-car/arduino-bluetooth-car/assembly-the-car)
* [Code upload](/arduino-robot-car/arduino-bluetooth-car/upload-the-code)
* [Test](/arduino-robot-car/arduino-bluetooth-car/bluetooth-setup-and-test)

## Support

* Please follow this [setup guide](/support/setup-your-computer) to setup your computer
* Please log all support queries on our [github page](https://github.com/RoboFactorySA/ArduinoSASupport/issues) or [email us](https://www.robofactory.co.za/contact-us)


# What you will need

This guide will show you how to setup a 4WD Arduino Robot car and control with your phone with Bluetooth

* 1 X [Arduino UNO](https://www.robofactory.co.za/arduino-boards/85-arduino-uno-r3-compatible.html)
* 1 X [HC-05 Bluetooth Module](https://www.robofactory.co.za/arduino-modules/88-bluetooth-transceiver-module.html)
* 1 X [Car Chassis kit](https://www.robofactory.co.za/arduino-kits/169-4wd-robot-car-chassis-kit.html)
* 1 X [L298N motor drive](https://www.robofactory.co.za/arduino-modules/124-l298n-dual-stepper-motor-driver-board-module.html)
* 2 x [18650 battery](https://www.robofactory.co.za/accessories/201-rakieta-37v-2000mah-18650-lithium-battery.html)
* 1 X [2 way 18650 battery holder](https://www.robofactory.co.za/accessories/409-2-x-18650-battery-storage-case-with-onoff-switch.html)
* 1X [Male To Male Jumper Wires](https://www.robofactory.co.za/accessories/120-male-to-male-breadboard-jumpers-40pcs-20cm.html)
* 1X [Male To Female Jumper Wires](https://www.robofactory.co.za/accessories/121-male-to-female-breadboard-jumpers-40pcs-20cm.html)

> You can purchase the above from [RoboFactory](https://www.robofactory.co.za/11-arduino)

## Software Required

* [Arduino IDE](https://www.arduino.cc/en/main/software)
* [Arduino Bluetooth RC Car Android App](https://play.google.com/store/apps/details?id=braulio.calle.bluetoothRCcontroller)


# Circuit Diagram

The entire Circuit will be as below:

<figure><img src="https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2FWPiRjHC2Ku9DqLwjStib%2F4wd%20bluetooth%20car%20-%20fritzing.png?alt=media&amp;token=2e7b0da4-ff1a-48ec-8526-13bb20584d4d" alt=""><figcaption></figcaption></figure>

The 2 Left motors will connect to Motor A on the driver board

The 2 Right motors will connect to Motor B on the driver board

A 2 X 18650 battery pack **positive** will be connect to the **VSS / 12V** terminal on the driver board and the **negative** will be connected to the **GND** terminal on the driver board.

The Arduino board will be powered by the same 2 x 18650 battery pack. Connect a jumper from the **VSS / 12v** terminal on the motor board to the **VIN** on the Arduino board. Connect another jumper from the **GND** on the motor driver to **GND** on the Arduino board

The Motor driver will be connected to the Arduino board as per below connections:

* Motor driver ENA -> PIN 9 on Arduino Board
* Motor driver IN1 -> PIN 8 on Arduino Board
* Motor driver IN2 -> PIN 7 on Arduino Board
* Motor driver ENB -> PIN 3 on Arduino Board
* Motor driver IN3 -> PIN 5 on Arduino Board
* Motor driver IN4 -> PIN 4 on Arduino Board

The bluetooth module will be connected to the Arduino board as per below connections:

* Bluetooth VCC -> 5v on Arduino Board
* Bluetooth GND -> GND on Arduino Board
* Bluetooth TX > PIN RX on Arduino Board
* Bluetooth RX -> PIN TX on Arduino Board


# Assembly the Car

## Solder the motors

Solder each motor with a black and a red wire and attach them with the chassis.

![](https://gblobscdn.gitbook.com/assets%2F-LskXJjPT2bXMIodrtZq%2F-MQ3XXL4wMmPzgMZKlI3%2F-MQ3YP_U33Y6vERbxWON%2Fimage.png?alt=media\&token=192b60d5-5ec4-48f8-b60a-926e2f958c1a)

## Attach the Motors

Attached the motors to the base of the car. Join the left side motor wires together as: **red wire --> red wire** and **black wire --> black wire,** similarly join the motors on right side together as: **red wire --> red wire** and **black wire --> black wire**

![](https://gblobscdn.gitbook.com/assets%2F-LskXJjPT2bXMIodrtZq%2F-MQ3XXL4wMmPzgMZKlI3%2F-MQ3YWs__YQTzIpUByj6%2Fimage.png?alt=media\&token=ddbd7110-08e4-400c-a085-57a55297f44)

## Attached the Wheels

Add the Wheels to the motors

![](https://gblobscdn.gitbook.com/assets%2F-LskXJjPT2bXMIodrtZq%2F-MQ3XXL4wMmPzgMZKlI3%2F-MQ3Z0Y9sPas3Kya28Ga%2Fimage.png?alt=media\&token=0edd9856-9de2-4306-8a1d-437b01a87988)

![](https://gblobscdn.gitbook.com/assets%2F-LskXJjPT2bXMIodrtZq%2F-MQ3XXL4wMmPzgMZKlI3%2F-MQ3Z4y2c9GO8VZV9M5n%2Fimage.png?alt=media\&token=9245c262-9bc3-480d-bd5f-6e342e0f896b)

***

You can also view the video below as a guide

{% embed url="<https://youtu.be/0YUQ4s5XZqY?list=PLVcrH7rfVz6vqat1z8NBMmJgz5W39i3GY>" %}

## Connect the Motor Driver

The Motor driver will be the **back** of the car. The Motor driver will have two connectors, one for Motor A and another for Motor B.

Looking at the car from behind, connect the **Left motors** to **Motor A** and the **Left motors** to **Motor B.**

Remember that the two left motors will connect to a single Motor A and two right Motors will connect to a single Motor B on the motor driver

{% hint style="info" %}
Remember that the two left motors will connect to a single Motor A and two right Motors will connect to a single Motor B on the motor drive
{% endhint %}

![](https://gblobscdn.gitbook.com/assets%2F-LskXJjPT2bXMIodrtZq%2F-MQ3XXL4wMmPzgMZKlI3%2F-MQ3_fncDlXcy_eLr_Sq%2Fimage.png?alt=media\&token=85ca89bc-471b-4d03-8002-9e7fb80eb7d0)

![](https://gblobscdn.gitbook.com/assets%2F-LskXJjPT2bXMIodrtZq%2F-MQ3XXL4wMmPzgMZKlI3%2F-MQ3_jLlskUhfU5hiqIg%2Fimage.png?alt=media\&token=13128219-0b40-4370-a1d3-d43354a2a71a)

![](https://gblobscdn.gitbook.com/assets%2F-LskXJjPT2bXMIodrtZq%2F-MQ3XXL4wMmPzgMZKlI3%2F-MQ3_m3MU0zQRFy7JA5Q%2Fimage.png?alt=media\&token=488eea99-f707-46d1-ae54-0a32f5a246e0)

## Connect the Motor Driver to the Arduino

![](https://gblobscdn.gitbook.com/assets%2F-LskXJjPT2bXMIodrtZq%2F-MQ3XXL4wMmPzgMZKlI3%2F-MQ3_J8o6_eKydScCz-Y%2Fimage.png?alt=media\&token=aa754123-763f-414f-ac56-6c08f84b3e49)

![](https://gblobscdn.gitbook.com/assets%2F-LskXJjPT2bXMIodrtZq%2F-MQ3XXL4wMmPzgMZKlI3%2F-MQ3_S1y2o7H8v7CMrUu%2Fimage.png?alt=media\&token=0a4f4f7f-0bcd-45da-b3f9-561d58faa428)

Connect the jumper wires as below:

**Please remove the jumper from ENA and ENB on the motor driver**

* Motor driver ENA -> PIN 9 on Arduino Board
* Motor driver IN1 -> PIN 8 on Arduino Board
* Motor driver IN2 -> PIN 7 on Arduino Board
* Motor driver ENB -> PIN 3 on Arduino Board
* Motor driver IN3 -> PIN 5 on Arduino Board
* Motor driver IN4 -> PIN 4 on Arduino Board

Connect the battery pack **positive** wire to the **VCC / 12V** terminal of the motor driver

Connect the battery pack **negative** battery to the **GND** terminal of the motor driver

Connect a jumper from the **VSS / 12v** terminal on the motor board to the **VIN** on the Arduino board. Connect another jumper from the **GND** on the motor driver to **GND** on the Arduino board

## Connect the Bluetooth Module to Arduino

Connect the Bluetooth module as shown below

![](https://gblobscdn.gitbook.com/assets%2F-LskXJjPT2bXMIodrtZq%2F-MQ3f84sxyjwYr7HLSxQ%2F-MQ3gHwoWBvJyYq9QdFh%2Fimage.png?alt=media\&token=843a33bb-cca9-4b25-a6e5-90bdb2869a65)

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-70a18453bd8b3160e927c9649f6f6cc014eea69e%2Fimage.png?alt=media)

Now you are done with the car assembly. Next you need to upload the code to the Arduino board, download the App and test.


# Upload the Code

## Code upload

Open up your Arduino IDE.

Connect your USB cable to your PC and Arduino board.

{% hint style="warning" %}
Please ensure that the TX and RX for the Bluetooth module is not connected. If this is connected then the code upload will fail.
{% endhint %}

Copy the code below to a new Arduino project and Click the upload button

```
// Motor A (Right) connections
#define ENA 9       // Enable/speed motor Right wheels
#define IN_1  8    // Right wheels
#define IN_2  7    // Right wheels

// Motor B (Left) connections
#define ENB 3       // Enable/speed motor Left Right
#define IN_3  5    		// Left wheels
#define IN_4  4    		// Left wheels

int command; 			      //Int to store app command state.
int speedCar = 255; 		// 50 - 255.

void setup() {

  pinMode(ENA, OUTPUT);
  pinMode(ENB, OUTPUT);
  pinMode(IN_1, OUTPUT);
  pinMode(IN_2, OUTPUT);
  pinMode(IN_3, OUTPUT);
  pinMode(IN_4, OUTPUT);

  Serial.begin(9600);

}

void goAhead() {

  digitalWrite(IN_1, HIGH);
  digitalWrite(IN_2, LOW);
  analogWrite(ENA, speedCar);

  digitalWrite(IN_3, LOW);
  digitalWrite(IN_4, HIGH);
  analogWrite(ENB, speedCar);
}

void goBack() {

  digitalWrite(IN_1, LOW);
  digitalWrite(IN_2, HIGH);
  analogWrite(ENA, speedCar);


  digitalWrite(IN_3, HIGH);
  digitalWrite(IN_4, LOW);
  analogWrite(ENB, speedCar);
}

void goRight() {

  digitalWrite(IN_1, HIGH);
  digitalWrite(IN_2, LOW);
  analogWrite(ENA, speedCar);


  digitalWrite(IN_3, LOW);
  digitalWrite(IN_4, LOW);
  analogWrite(ENB, speedCar);
}

void goLeft() {

  digitalWrite(IN_1, LOW);
  digitalWrite(IN_2, LOW);
  analogWrite(ENA, speedCar);

  digitalWrite(IN_3, LOW);
  digitalWrite(IN_4, HIGH);
  analogWrite(ENB, speedCar);

}

void stopRobot() {

  digitalWrite(IN_1, LOW);
  digitalWrite(IN_2, LOW);
  analogWrite(ENA, speedCar);


  digitalWrite(IN_3, LOW);
  digitalWrite(IN_4, LOW);
  analogWrite(ENB, speedCar);
}

void loop() {

  if (Serial.available() > 0) {
    command = Serial.read();
    stopRobot(); 			//Initialize with motors stopped.

    switch (command) {
      case 'F': goAhead(); break;
      case 'B': goBack(); break;
      case 'L': goLeft(); break;
      case 'R': goRight(); break;
      case '0': speedCar = 100; break;
      case '1': speedCar = 115; break;
      case '2': speedCar = 130; break;
      case '3': speedCar = 145; break;
      case '4': speedCar = 160; break;
      case '5': speedCar = 175; break;
      case '6': speedCar = 190; break;
      case '7': speedCar = 205; break;
      case '8': speedCar = 220; break;
      case '9': speedCar = 235; break;
      case 'q': speedCar = 255; break;

    }
  }
}


```

{% embed url="<https://github.com/RoboFactorySA/arduino-bluetooth-car/blob/main/bluetoothCarCode.ino>" %}


# Bluetooth setup and Test

## Pair With Bluetooth Module <a href="#pair-with-bluetooth-module" id="pair-with-bluetooth-module"></a>

Disconnect the USB cable and connect all the batteries.

Check that the LED of Bluetooth module is **blinking fast without pairing**

Open up the App, you will see the a red flashing circle on the left. This means the bluetooth is not paired.

Click on the Settings Icon and Select "Connect to Car". Select the **HC-05** bluetooth device and enter password **1234.**

Once the circle turns green, then the phone is connected. Use the Up, Down, Left, Right and Speed buttons to test your car.[<br>](https://docs.kidscode.co.za/arduino-robot-car/arduino-bluetooth-car/upload-the-code)


# 4WD Obstacle Avoidance

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-112b31daa5b829ebb24af952ace8c31f901e7865%2Fimage.png?alt=media)

## Contents

* [Introduction](/arduino-robot-car/4wd-obstacle-avoidance-car/introduction)
* [Component List](/arduino-robot-car/4wd-obstacle-avoidance-car/component-list)
* [Assembly](/arduino-robot-car/4wd-obstacle-avoidance-car/assembly)
* [Circuit Diagram](/arduino-robot-car/4wd-obstacle-avoidance-car/circuit-diagram)
* [Component Description](/arduino-robot-car/4wd-obstacle-avoidance-car/component-description)
* [Obstacle Avoidance Mode](/arduino-robot-car/4wd-obstacle-avoidance-car/obstacle-avoidance-mode)
* [Line Tracking Mode](/arduino-robot-car/4wd-obstacle-avoidance-car/line-tracking-mode)

## Support

* Please follow this [setup guide](/support/setup-your-computer) to setup your computer
* Please log all support queries on our [github page](https://github.com/RoboFactorySA/ArduinoSASupport/issues) or [email us](https://www.robofactory.co.za/contact-us)


# Introduction

**Welcome to use the DIY four way tracking and Ultrasonic obstacle avoidance car kit tutorial.**

Whether you are an experienced maker or a novice with a small amount of professional skills, this tutorial will help you make something very cool: A DIY four way tracking and Ultrasonic obstacle avoidance car.

The kit is based on the popular open source electronic platform Arduino. You can share and exchange your experiences and design ideas with fans all over the world. All components in the kit are individually packaged, including all the electronic components, modules and mechanical components required for these items. At the same time, there are detailed assembly and debugging instructions in this tutorial. To ensure that your smart car can be assembled and run smoothly, if you encounter difficult technical problems, you can contact us at any time, and we will provide you with high-quality technical support services for free as soon as possible.


# Component List

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2FPeNNOwV9W9g8nlToU0ui%2FPicture1.png?alt=media\&token=90f429fe-6328-4a7e-8ffe-8cf47f8b8182)


# Assembly

{% embed url="<https://www.youtube.com/watch?v=iajyaWi1Ln4>" %}


# Component Description

## L298N Module

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-6c3155e360cb29d2f27010354e4543d26f35b182%2Fimage.png?alt=media)

* Input voltage of logic part: 6 \~ 7V
* Input voltage of drive part vs: 4.8 \~ 46v
* Working current of logic part is: ≤ 36ma
* Working current of driving part IO: ≤ 2A
* Maximum dissipation power: 25W (t = 75 ℃)
* Control signal input level: high level: 2.3V ≤ VIN ≤ vs low level:- 0.3V ≤ VIN ≤ 1.5V
* Working temperature: - 25 ℃ \~ + 130 ℃
* Driving mode: double channel high power H-bridge drive

### How does L298N module work？

1. ENA, ENB control enable
2. Out1, Out2 and Out3, Out4 controls the motor,
3. IN1, IN2, IN3, IN4 connect control level, control positive and negative rotation.

| State   | ENA | ENB | IN1 | IN2 | IN3 | IN4 |
| ------- | :-: | :-: | :-: | :-: | :-: | :-: |
| Stop    |  0  |  0  |  X  |  X  |  X  |  X  |
| Break   |  1  |  1  |  0  |  0  |  0  |  0  |
| Forward |  1  |  1  |  1  |  0  |  1  |  0  |
| Back    |  1  |  1  |  0  |  1  |  0  |  1  |
| Left    |  1  |  1  |  0  |  0  |  1  |  0  |
| Right   |  1  |  1  |  1  |  0  |  0  |  0  |

## HC-SR04 Module

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-9f86c49e9fe6e2432f407f280f35803072a84c31%2Fimage.png?alt=media)

* Electrical parameters - HC-SR04 Ultrasonic module
* Working voltage - DC-5V
* Working current - 15mA
* Working frequency - 40KHz
* Maximum range - 4m
* Minimum range - 2cm
* Measuring angle - 15°
* Input trigger signal - 10 US TTL pulse
* Output echo signal - Output TTL level signal, proportional to the range
* Size - 45 \* 20 \*15

### How does ultrasonic obstacle avoidance work？

1. Transmitter (trigger pin) sending signal: high-frequency sound.
2. When a signal finds an object, it is reflected.
3. Receiver (echo pin) : Receives the signal reflected back from it

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-873e05db09b81ae525ad60874e0a935af8f707af%2Fimage.png?alt=media)

The HC-SR04 ultrasonic sensor detects how far ahead an obstacle has appeared.If there is an obstacle in your specified detection range, the car can make corresponding actions.For example, forward, back, turn left or turn right.

## Four channel tracking module

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-a6af7307a48e3c594b835da6504357d3d2025b22%2Fimage.png?alt=media)

| Description           | Value                        |
| --------------------- | ---------------------------- |
| Electrical parameters | Four channel tracking module |
| Working voltage       | DC 3.3V-5V                   |
| Working current       | 1A                           |
| Working temperature   | -10℃ to 50℃                  |
| Mounting aperture     | M3                           |
| Detect distance       | 1mm to 60cm                  |
| Size                  | 42\*38mm                     |
| Output signal         | TTL level                    |

### How does Four channel tracking module work？

The sensor belongs to infrared reflection detection, so the reflectivity and shape of the target is the key to the detection range. Among them, the black detection distance is the smallest and the white detection distance is the largest. Small area object distance is small, large area distance is big. Infrared detection method, that is, the use of infrared light in different colors of the object surface has different reflection intensity characteristics, in the process of the car constantly emitting infrared light to the ground, when the infrared light encounter white paper floor diffuse reflection, reflected light is installed in the car received by the receiving tube;If a black line is encountered, the infrared light is

Absorbed and the receiver tube on the car does not receive the infrared light. MCU on whether to receive the reflected infrared light as the basis to determine the location of the black line and car travel route.


# Circuit Diagram

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2FjcT0nl34UbXUdKHP9WUt%2FCircuitDiagram-v2.png?alt=media\&token=1a6dec99-ed5a-419f-acf1-1e13711b55be)


# Computer Setup

## Download Arduino IDE

Go to <http://arduino.cc/en/Main/Software> to download the installation file according to your operating system.

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-e8927cef260f6dc9af971807281d0fa5803ab659%2Fimage.png?alt=media)

For Windows users, please follow the instructions below. For Mac and Linux users, you can directly use the Arduino sketch by simply clicking on the file.

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-ca390c538125c743fdacc97147063daba9d539af%2Fimage.png?alt=media)

## Install the drivers

Installing drivers for the Arduino Plug in your board and wait for Windows to begin its driver installation process. After a few moments, despite its best efforts, the process will fail, but do not panic! Click on the Start Menu, and open up the Control Panel.

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-e9f96d7158df97957e233ba12298fde554578980%2Fimage.png?alt=media)

Find **Unknown Device** and then right click and select **Update Driver Software**.

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-64d374856479a464b6dc8ca92d3224c43a95bab1%2Fimage.png?alt=media)

Choose browse my computer for driver software to search for drivers manually

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-f8f8c8af771f80bfec2f5501fbc4feac8e3784e7%2Fimage.png?alt=media)

Click **Browse** and find the directory location of the Arduino IDE where the installation files are located. Inside this directory will be another directory named **Drivers**. Select it and click **Next** .

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-098aac7b54fcb65d302b18551126d022439ea85c%2Fimage.png?alt=media)

This dialog indicates successful installation. Hopefully this is what you will see! If not double check the steps and try again.

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-546de3513d7ea5ee9eb8bb1ca4605c20d2c3b707%2Fimage.png?alt=media)

If you go back to your device manager, the Arduino device should now be recognised by your computer.

Go to “**Device Manager**” >“**Ports (COM & LPT)**”. You should see “**Arduino no (COM#)**”. This is the COM port that your computer uses to transfer data to your Arduino. In our example the computer communicates with the Arduino on COM36

Remember your COM number as you will need it later.

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-0507a88ef2566ffbad19011ca410b90d7d401ec1%2Fimage.png?alt=media)

## Upload a Blink program

Open Arduino IDE and take a moment to move your mouse along each icon to get to know their functions. Here we will use a very basic sample code, **Blink** to go through the whole process and test whether the controller is working.

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-d4f1a6512a043580a7aa47e321faef83ad071806%2Fimage.png?alt=media)

Open the LED blink example sketch. You will find it under **File > Examples > 01.Basics > Blink**.

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-da8e49f80ea25ad384060bc848785999c637f6e7%2Fimage.png?alt=media)

Click “**Verify**” to compile the code. The IDE changes the code from text into instructions that the computer can understand. This process is called **compiling**.

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-d5e8ae68f26d2fffc9338b30acb16fbeaa5864bd%2Fimage.png?alt=media)

Verifying....

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-99c2cdac65b32da3afc6b252434a9cb84303b1d2%2Fimage.png?alt=media)

Finished!

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-efcf39d4ff13acf8dcdceb156ae59896d95d44f0%2Fimage.png?alt=media)

The code we are using should not have errors since it is an example code. If a code does have errors in it it will fail to verify.

Time to download the code to your Arduino! Select your micro-controller by selecting “**Board > Arduino Uno**”

Then select your COM port by selecting “**Serial Port**” and selecting the COM port number you saw earlier. In our example **COM36** is in use.

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-2213953c27dcf863c5d3215b29a6f8a79cc593d4%2Fimage.png?alt=media)

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-ca02541202a58d2f1888dc86137f723cb864aab4%2Fimage.png?alt=media)

Click **Upload** to send the code via the USB to you Arduino Board

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-9767c8ebb24c542ce271f118c9dfd0d92322c339%2Fimage.png?alt=media)

After it is finished, the Arduino will run the code automatically and the onboard LED will start to blink, just as programmed!


# Line Tracking Mode

In this mode, the car will follow a black solid line.

### Code

```
//define L298n module IO Pin
int ENA = 5;
int IN1 = 3;
int IN2 = 4;

int ENB = 6;
int IN3 = 2;
int IN4 = 7;

#define MotorASpeed 120
#define MotorBSpeed 120

int Sensor1 = 0;
int Sensor4 = 0;

void setup() {

  pinMode(ENA, OUTPUT);
  pinMode(IN1, OUTPUT);
  pinMode(IN2, OUTPUT);

  pinMode(ENB, OUTPUT);
  pinMode(IN3, OUTPUT);
  pinMode(IN4, OUTPUT);

  pinMode(Sensor1, INPUT);
  pinMode(Sensor4, INPUT);
  Serial.begin(9600);
}

void loop() {
  digitalWrite(ENA, HIGH);
  digitalWrite(ENB, HIGH);

  Sensor1 = digitalRead(8);
  Sensor4 = digitalRead(11);

  if (Sensor1 == HIGH && Sensor4 == HIGH) //IR is on black line
  {
    //Stop both Motors
    digitalWrite(IN1, LOW);
    digitalWrite(IN2, LOW);
    digitalWrite(IN3, LOW);
    digitalWrite(IN4, LOW);
    analogWrite (ENA, 0);
    analogWrite (ENB, 0);
    Serial.println("Both IR is on black line - stop");
  }
  else if (Sensor1 == LOW && Sensor4 == LOW) //IR not on black line
  {
    //Move both the Motors
    digitalWrite(IN1, HIGH);
    digitalWrite(IN2, LOW);
    digitalWrite(IN3, LOW);
    digitalWrite(IN4, HIGH);
    analogWrite (ENA, MotorASpeed);
    analogWrite (ENB, MotorBSpeed);
    Serial.println("IR not on black line - go foward");
  }

  else if (Sensor1 == LOW && Sensor4 == HIGH)
  {
    digitalWrite(IN1, HIGH);
    digitalWrite(IN2, LOW);
    digitalWrite(IN3, HIGH);
    digitalWrite(IN4, LOW);
    analogWrite (ENA, 255);
    analogWrite (ENB, 255);
    Serial.println("Move left");
  }

  else if (Sensor1 == HIGH && Sensor4 == LOW)
  {
    digitalWrite(IN1, LOW);
    digitalWrite(IN2, HIGH);
    digitalWrite(IN3, LOW);
    digitalWrite(IN4, HIGH);
    analogWrite (ENA, 255);
    analogWrite (ENB, 255);
    Serial.println("Move right");
  }

  else
  {
    //Stop both the motors
    digitalWrite(IN1, LOW);
    digitalWrite(IN2, LOW);
    digitalWrite(IN3, LOW);
    digitalWrite(IN4, LOW);
    analogWrite (ENA, 0);
    analogWrite (ENB, 0);
    Serial.println("stop");
  }
}
```

### Code Explanation


# Obstacle Avoidance Mode

In this mode, the car will move forward. If it detects an object in front of it, the car will stop, turn left and begin to move forward again until it detects another object.

### Install additional module

{% hint style="warning" %}
This program requires an addition module to be added to your Arduino IDE.

Please download the [AFMotor.zip](https://robofactorycdn.nyc3.cdn.digitaloceanspaces.com/public/AFMotor.zip) module and add it to your Arduino IDE
{% endhint %}

To Add the AFMotor to your Arduino IDE: Select **Sketch** -> **Include Library** -> **Add ZIP Library**, then select the downloaded file,

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-ac3f5c528877c4d9fccf5035a4e474a2d6cce528%2Fimage.png?alt=media)

### Code

```
#include <AFMotor.h>
#define Trig 12
#define Echo 13
#define ENA 5
#define ENB 6
#define IN1 3
#define IN2 4
#define IN3 2
#define IN4 7
float cm; //Distance variable
float temp; //

void setup() {
  Serial.begin(9600);
  pinMode(Trig, OUTPUT);
  pinMode(Echo, INPUT);

  pinMode(IN1, OUTPUT);
  pinMode(IN2, OUTPUT);
  pinMode(IN3, OUTPUT);
  pinMode(IN4, OUTPUT);

  pinMode(ENA, OUTPUT);
  pinMode(ENB, OUTPUT);
}

void loop() {
  digitalWrite(Trig, LOW);
  delayMicroseconds(2);
  digitalWrite(Trig, HIGH);
  delayMicroseconds(10);
  digitalWrite(Trig, LOW);

  temp = float(pulseIn(Echo, HIGH));
  cm = (temp * 17 ) / 1000;
  if (cm < 30 && cm > 10)
  {
    back();
    delay(500);
    Left();
    delay(200);
  }
  if (cm >= 30)
  {
    forward();
    delay(100);
  }


  if (cm < 10)
  {
    STOP();
  }
  Serial.print("Echo =");
  Serial.print(temp);
  Serial.print(" | | Distance = ");
  Serial.print(cm);
  Serial.println("cm");
  delay(100);
}

void forward() {
  analogWrite(ENA, 220);
  analogWrite(ENB, 220);

  digitalWrite(IN1, HIGH);
  digitalWrite(IN2, LOW);
  digitalWrite(IN3, LOW);
  digitalWrite(IN4, HIGH);
  Serial.println("Forward");
}

void back() {
  analogWrite(ENA, 220);
  analogWrite(ENB, 220);
  digitalWrite(IN1, LOW);
  digitalWrite(IN2, HIGH);
  digitalWrite(IN3, HIGH);
  digitalWrite(IN4, LOW);
  Serial.println("Back");
}


void Left() {
  analogWrite(ENA, 220);
  analogWrite(ENB, 220);
  digitalWrite(IN1, LOW);
  digitalWrite(IN2, HIGH);
  digitalWrite(IN3, LOW);
  digitalWrite(IN4, HIGH);
  Serial.println("Left");
}

void Right() {
  analogWrite(ENA, 220);
  analogWrite(ENB, 220);
  digitalWrite(IN1, HIGH);
  digitalWrite(IN2, LOW);
  digitalWrite(IN3, HIGH);
  digitalWrite(IN4, LOW);
  Serial.println("Right");
}

void STOP() {
  digitalWrite(ENA, LOW);
  digitalWrite(ENB, LOW);
  digitalWrite(IN1, LOW);
  digitalWrite(IN2, LOW);
  digitalWrite(IN3, LOW);
  digitalWrite(IN4, LOW);
  Serial.println("STOP");
}
```

### Code Explanation

When the transmitting pin of the ultrasonic module detects an obstacle in front, the reflected pin will receive the signal and transmit it to the MCU through IO pin. After the SIGNAL is received, the MCU will drive the L298N module to realize the corresponding action of the motor. For example, if an obstacle is detected in the front range less than 30cm and larger than 10cm, the MCU will control the car to retreat successively and then turn left; while in the front range less than 10cm, the car will stop, while in the front range greater than 30cm, the car will move forward without any obstacle detected.


# Smart Plant Watering Kit

Follow the below guide to build your Plant Watering System using an Arduino Uno

{% embed url="<https://www.robofactory.co.za/1196-large_default/automatic-smart-plant-watering-kit.jpg>" %}

## Contents

* [What you will need](/arduino-kits/smart-plant-watering-kit/what-you-will-need)
* [Wiring Diagram](/arduino-kits/smart-plant-watering-kit/wiring-diagram)
* [The Code](/arduino-kits/smart-plant-watering-kit/the-code)

## Support

Please follow this [setup guide](/support/setup-your-computer) to setup your computer

Please log all support queries on our [github page](https://github.com/RoboFactorySA/ArduinoSASupport/issues) or [email us](https://www.robofactory.co.za/contact-us)


# What you will need

**You will need the below items to get started**

1 × UNO with USB cable

1 × Soil detection sensor with conversion module

1 × 5vDC water pump with transparent water pipe

1 × 5V relay module

1 × 400-hole breadboard

1 × No. 5 battery box (with switch)

10 × Dupont line male to male 20cm

10 × DuPont female to female 20cm

10 × Dupont line male to female 20cm

You can purchase a full kit from Robofactory SA. Link to the product is [here](https://www.robofactory.co.za/arduino-kits/232-automatic-smart-plant-watering-kit.html).

{% embed url="<https://www.robofactory.co.za/1196-large_default/automatic-smart-plant-watering-kit.jpg>" %}


# Wiring Diagram

## Diagram

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-2a0a2c6685f174d3a437df2c435edeb8fa9dc63a%2Fplant-watering-system2.png?alt=media)

## How the circuit works?

The board is connected to 4 X AA Batteries. The Arduino is connected to a moisture sensor and relay via a breadboard. The Moisture sensor takes multiple readings from the soil each and when the moisture content drops below the pre-set value the relay is triggered sending power to the water pump. The power is cut again after 4 seconds.

The Arduino is the 'brains' of the system. Follow these steps below to wire up your circuit.

#### Wiring the power

1. Since the battery holder does not have a male pin at the end, connect 1 X Male-Female jumper to the positive end (red line) of the breadboard and another 1 X Male-Female to the negaivite end (blue line) of the breadboard. This will create a positive feed to all the breadboard slots at the red line and a negative feed at the opposite blue line.
2. Connect a male-male jumper wire to the pin hole marked '5v' on the Arduino board and connect the other male end to the positive end on the breadboard. Depicted by the blue wire in the diagram.
3. Connect a male-male jumper from the GND on the Arduino to the negative (blue) hole on the breadboard. Depicted by grey wire on diagram

#### Wiring the Relay

1. Connect a male-female jumper from the VCC pin on the relay to a positive hole on the breadboard. Depicted by purple wire on diagram.
2. Connect a male-female jumper from the GND pin on the relay to a negative hole on the breadboard. Depicted by brown wire on diagram.
3. Connect a male-male jumper from the COM pin on the relay to a positive hole on the breadboard. Depicted by pink wire on diagram.

#### Wiring the Water Pump

The Water pump wires do not have any pins on them. To connect them you can use male-female jumpers.

1. Connect a male-female jumper from a negative hole on the breadboard to the black wire on the water pump. This is depicted by the black wire on the diagram. You can push the water pump black wire into the female slot of the jumper wire or you can snip the female end off and join the wires, please ensure to insulate the wire afterwards if you decide to snip them.
2. Connect a male-female jumper from a NO pin on the relay to the red wire on the water pump. This is depicted by the red wire on the diagram. You can push the water pump red wire into the female slot of the jumper wire or you can snip the female end off and join the wires, please ensure to insulate the wire afterwards if you decide to snip them.

#### Wiring the Soil Moisture Sensor

1. Connect the soil moisture sensor to the sensor module using the jumper cable provided. The positive side of the sensor will be on the left side.
2. Connect a male-female jumper from the VCC pin on the soil moisture sensor module to a positive hole on the breadboard. Depicted by green wire on diagram
3. Connect a male-female jumper from the GND pin on the soil moisture sensor module to a negative hole on the breadboard. Depicted by orange wire on diagram
4. Connect a male-male jumper from the AO pin on the soil moisture sensor module to the A2 PIN on the Arduino board. Depicted by yellow wire on diagram.

#### Adding the Battery

* Insert the batteries into the battery holder and ensure the switch is off.
* Connect the Red wire from the battery holder to the positive jumper wire you added on step 1 above. You can either push the red wire into the female jumper or snip the wire. Remember to insulate if you snip.
* Connect the Black wire from the battery holder to the negative jumper wire you added on step 2 above. You can either push the black wire into the female jumper or snip the wire. Remember to insulate if you snip.

### You are now ready to upload the code


# The Code

{% hint style="info" %}
*If your UNO drivers aren’t installed automatically when using this kit, I will save you some time searching for the correct drivers by* [*downloading them here*](https://www.techstudio.co.za/wp-content/uploads/2021/08/CH341SER.zip)\_\_
{% endhint %}

Open up your Arduino IDE and connect your Arduino board to your PC.

Copy and paste the code below and upload the code.

{% hint style="danger" %}
Once the code is uploaded, disconnect the USB cable and switch on the battery. if you need to make changes to the code, please switch off the battery before you connect the USB cable to your PC.
{% endhint %}

```
//Original Code: https://www.instructables.com/Arduino-Plant-Watering-System/
//Amended by Armandus Basson
//For Arduino UNO
//Components / Kit: https://www.robofactory.co.za/home/232-automatic-smart-plant-watering-kit.html
 
int waterPump = 5; //Relay Pin = 5
 
void setup() {
  Serial.begin(9600);
  pinMode(waterPump, OUTPUT);
}
 
void loop() {
  int humidityRaw = analogRead(A2);
  int humidityReal = map(humidityRaw, 1023, 0 ,0, 100); //Convert raw sensor data to percentage
   
  //Print converted moisture sensor data (percentage) to the serial console
  Serial.print("Soil Moisture = ");
  Serial.print(humidityReal);
  Serial.println("%");
   
  delay(4000); //Delay before next sensor reading. Current set as 4 seconds
 
  if (humidityReal > 30) //Set threshold when relay must open for pump to feed water
  {
    digitalWrite(waterPump, HIGH);
    delay(5000); //Pump need to run for 5 seconds before the next sensor reading
  }else{
    digitalWrite(waterPump, LOW);
  }
}
```

### Credits

> Credit for this code needs to go to TechStudio
>
> <https://www.techstudio.co.za/2021/08/09/arduino-uno-smart-plant-watering-kit-code-driver/>
>
> Instructables Orignal Post
>
> <https://www.instructables.com/Arduino-Plant-Watering-System/>


# Pics

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-e6d6230d12bf442df8ff6f9bde6cd5bcdaa65c43%2F20211121_154751.jpg?alt=media) ![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-f02cf380c3c899caa31d80c3ee291c640eeeb279%2F20211121_154759.jpg?alt=media) ![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-a2599dd7a8d7ded050784f4bf65ee6780138c807%2F20211121_154811.jpg?alt=media) ![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-01bf06e5781348a9771c08e529a2515ae734deab%2F20211121_154754.jpg?alt=media) ![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-ca9f05b0572ac78a088d69ccdd0e35090a063fca%2F20211121_154733.jpg?alt=media)


# Basic Starter Kit

Interested in electronics and coding? The Uno basic starter kit has an advanced board with a robust platform and numerous accessories to help you get started with your journey.

<figure><img src="https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2FrJUKOgNWuoDyGj26xs9l%2Fbasic-starter-kit-front-robocentrix.png?alt=media&amp;token=f343742b-7a13-425b-99d4-dd0c2d9379e0" alt=""><figcaption></figcaption></figure>

<figure><img src="https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2FM7LC9ts5sMxiUmkXkqCA%2Fimage.png?alt=media&amp;token=af4b779b-b302-418f-a886-190578cb3953" alt=""><figcaption></figcaption></figure>

1. [Component View](/arduino-kits/basic-starter-kit/component-view)
2. [Installing the IDE](/arduino-kits/basic-starter-kit/installing-the-ide)
3. [Adding Libraries](/arduino-kits/basic-starter-kit/add-libraries)
4. [Blink](/arduino-kits/basic-starter-kit/blink)
5. [Button Control LED Delay Switch](/arduino-kits/basic-starter-kit/button-control-led-delay-switch)
6. [Active Buzzer](/arduino-kits/basic-starter-kit/active-buzzer)
7. [Passive Buzzer](/arduino-kits/basic-starter-kit/passive-buzzer)
8. [Servo](/arduino-kits/basic-starter-kit/servo)
9. [IR Remote and Receiver](/arduino-kits/basic-starter-kit/ir-remote-and-receiver)
10. [Stepper Motor](/arduino-kits/basic-starter-kit/stepper-motor)
11. [Eight LED with 74HC595](/arduino-kits/basic-starter-kit/eight-led-with-74hc595)
12. [LCD Display](/arduino-kits/basic-starter-kit/lcd)
13. [Digital tube with Traffic Light Experiment](/arduino-kits/basic-starter-kit/digital-tube-with-traffic-light-experiment)
14. [Four Digit Tube Display](/arduino-kits/basic-starter-kit/four-digit-tube-display)
15. [LM35D Temperature Sensor](/arduino-kits/basic-starter-kit/lm35d-temperature-sensor)
16. [LDR 5516 Experiment](/arduino-kits/basic-starter-kit/ldr-5516-experiment)
17. [Flame Sensor Experiment](/arduino-kits/basic-starter-kit/flame-sensor)
18. [8 \* 8 LED Module](/arduino-kits/basic-starter-kit/8-8-led-module)
19. [Controlling Stepper Motor With Remote](/arduino-kits/basic-starter-kit/controlling-stepper-motor-with-remote)


# Component View

This kit can be purchased from [Robofactory SA](https://www.robofactory.co.za/arduino-kits/66-arduino-uno-r3-basic-starter-kit.html)

<figure><img src="https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2FKAbZQMBYmWRqhufL2sB9%2FZYAT0020(22.4cmX14.8cm)-basic-starter-kit-back.png?alt=media&amp;token=ed177ff9-9289-468e-ba7c-752db99772c8" alt=""><figcaption></figcaption></figure>

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2FchvqXYBVer8TsVqVBZ16%2FZYAT0020\(1\).jpg?alt=media\&token=09651274-a293-453d-9a7b-77c8f1376df8)


# Installing the IDE

Follow this [guide](/support/setup-your-computer) to setup your IDE


# Add 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. There are hundreds of additional libraries available on the Internet for download. The built-in libraries and some of these additional libraries are listed in the reference. To use the additional libraries, you will need to install them.

## How to Install a Library

#### Using the **Library Manager**

To install a new library into your Arduino IDE you can use the Library Manager (available from IDE version 1.8.9). Open the IDE and click to the "Sketch" menu and then Include Library > Manage Libraries.

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-803fcf7e68c1546e1b8c173fa2ca2d04c5f86af4%2Fimage.png?alt=media)

Then we check to see if the library is installed correctly.

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-0f9d7a7f7f4dfa42d57257f16754ef14827a9c88%2Fimage.png?alt=media)

Example: IRromote

Open arduino software -> project -> load library -> add a .zip library


# Blink

In this lesson, you will learn how to program your UNO R3 controller board to blink the Arduino’s built-in LED, and how to download programs by basic steps.

### **Component Required**

1 x UNO R3

### **Principle:**

The UNO 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. This LED is built onto the UNO R3 board and is often referred to as the 'L' LED as this is how it is labelled on the board.

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-afe55698ba3df0f79d9ee744203fc1b6460fba0c%2Fimage.png?alt=media)

You may find that your UNO 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 UNO R3 board with our own Blink sketch and then change the rate at which it blinks.

In Lesson 1, you set up your Arduino IDE and made sure that you could find the right serial port for it to connect to your UNO R3 board. The time has now come to put that connection to the test and program your UNO R3 board.

The Arduino IDE includes a large collection of example sketches that you can load up and use. This includes an example sketch for making the 'L' LED blink.

Load the '**Blink**' sketch that you will find in the IDE's menu system under **File** > **Examples** > **01.Basics**

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-29ff50657a33f21e50c92a1066b747873167f316%2Fimage.png?alt=media)

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-74c5b3e853b9bbc3ffbd524850c23a49dea01c88%2Fimage.png?alt=media)

To Upload the code you need to select the board model Arduino Uno

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-6eb9755b90ac6d7810b82d40e1090b682f796cb3%2Fimage.png?alt=media)

The upload code function also needs to select the board port number. Our computer displays the port number of arduino as: "COM9 Arduino / Genuino Uno", yours may be another serial port number.

**Note: A correct COM port should be COMX (arduino) XXX), which is certified by the standard.**

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-e5de82b72afc36b522f059451d550e57ef641193%2Fimage.png?alt=media)

Note that a huge part of this sketch is composed of comments. These are not actual program instructions; rather, they just explain how the program works. They are there for your benefit. Everything between /\* and \*/ at the top of the sketch is a block comment; it explains what the sketch is for.

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 UNO and Leonardo.

Next, we have the 'setup' function. Again, as the comment says, this is executed when the reset button is pressed. It is also executed whenever the board resets for any reason, such as power first being applied to it, or after a sketch has been uploaded.

```
void setup()
{
    //initialize the digital pin as an output. pinMode(led, OUTPUT);
}
```

Every Arduino sketch must have a '**setup**' function, and the place where you might want to add instructions of your own is between the { and the }.

In this case, there is just one command there, which, as the comment states tells the Arduino board that we are going to use the LED pin as an output.

It is also mandatory for a sketch to have a '**loop**' function. Unlike the '**setup**' function that only runs once, after a reset, the 'loop' function will, after it has finished running its commands, immediately start again.

```
void loop() {
    digitalWrite(led, HIGH);	// turn the LED on (HIGH is the voltage level)
    delay(1000);	// wait for a second
    digitalWrite(led, LOW); // turn the LED off by making the voltage LOW delay(1000); // wait for a second 
}
```

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-20d03a9b5c564655bf33984275dbf247cd303fb5%2Fimage.png?alt=media)

This delay period is in milliseconds, so if you want the LED to blink twice as fast, change the value from 1000 to 200. 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.

After downloading the program, you can see that the little light connected to 13 ports is flashing faster.

And we're done.

Click the validate button to check the program syntax for errors.

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-9784de95b8ef1920c90da2262742bb9405000522%2Fimage.png?alt=media)

Click the upload button and download the program to UNO R3.

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-91c718d1881c4b0366c28f4659541937d4ada06b%2Fimage.png?alt=media)

The upload is complete and the LED is already flashing faster.

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-21cb7249d724c5fcba445e9be29ca84440e710c1%2Fimage.png?alt=media)


# Button Control LED Delay Switch

In this lesson, you will learn how to use the button control LEDs to implement the delay control function.

### **Component Required:**

* 1 x Uno R3
* 1 x 5mm red LED
* 1 x 220 ohm resistor
* 1 x 10k ohm resistor
* 1 x 830 Tie Points Breadboard
* 1 x button
* 5 x M-M wires (Male to Male jumper wires)

### **Component Introduction:**

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2FqCRmQj0xA6YHIapyHjTB%2Fled-bb.png?alt=media\&token=77247762-552b-4aaf-a3a1-37e30ecb1fc6)

#### **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.

Some breadboards have two strips of holes running along the long edges of the board that are separated from the main grid. These have stripes running down the length of the board inside and provide a way to connect a common voltage. They are usually in pairs for +5 volts and ground. These strips are referred to as rails and they enable you to connect power to many components or points in the board.

While breadboards are great for prototyping, they have some limitations. Because the connections are push-fit and temporary, they are not as reliable as soldered connections. If you are having intermittent problems with a circuit, it could be due to a poor connection on a breadboard.

#### **LED:**

LED (Light Emitting Diode), which converts electrical energy into light energy, also has unidirectional conductivity and a reverse breakdown voltage of about 5V. Its forward volt-ampere characteristic curve is very steep, and the current-limiting resistor must be connected in series. In a 5V circuit, a resistor of about 400 ohms is generally used.

The longer of the two pins of the LED is the positive pole.

There are two ways to connect the LED to the Arduino:

1. Connect the positive pole of the led through the current limiting resistor and Arduino\*\*.\*\* The I/O port is connected and the other end is grounded. At this time, when the Arduino output is high, the led is lit, and when the output is low, the led is off.
2. When the negative pole of the led is connected to the I/O port of the Arduino, the other end is connected to the 5V voltage through the current limiting resistor. At this time, Arduino when the output is low, the led is lit, and when the output is high, the led is off.

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fp8Hdj0YaZQOSeGeRCUpR%2Fled.png?alt=media\&token=3c3427cb-1e39-4d85-8d73-7c84f8008686)

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.

If you happen to have an LED that has a flat side next to the longer lead, you should assume that the longer lead is positive.

#### **RESISTORS:**

As the name suggests, resistors resist the flow of electricity. The higher the value of the resistor, the more it resists and the less electrical current will flow through it. We are going to use this to control how much electricity flows through the LED and therefore, how brightly it shines.

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2FhEkFncpDmHOoi4dAicc7%2Fled-res.png?alt=media\&token=55e504ff-9330-429d-af8c-9a30776d468a)

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 colour ring flag on our resistors directly to determine its resistance value. Or you may use a digital multimeter instead.

#### **Button:**

The button as an I/O port input device has seen the effect of the last use. It is actually used to control the on/off of the line, and the effect of changing the I/O port signal is achieved by adding a device such as a pull-up resistor.

### **Connection Diagram:**

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-d7ec3ad6a0e8a197dc57d1cd6fe9d487d740445d%2Fimage.png?alt=media)

### **Wiring schematic:**

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2FMyZCyQXwaaLeKkrEaiGJ%2Fbutton-controlled-LED.png?alt=media\&token=2e5e1f12-9176-47a0-aec6-a4df88db32b3)

### **Wiring Step by Step**

1. Connect a jumper from the **GND (Ground) PIN** on the UNO to the negative side of the breadboard. This will make the entire row (horizontally) negative. *See black jumper wire in diagram*.
2. Connect the LED to the breadboard as shown above. Pay attention to the positive and negative of the LED. Positive if the '**bend**' LED leg.&#x20;
3. Connect the 220 ohm resistor across the middle of the breadboard. One side should join the positive rail of the LED and the other side will be on the opposite side of the breadboard.
4. Connect a jumper wire from the negative side of the LED to any negative rail on the breadboard. This now make this connection a negative connection to the LED. *See grey jumper in diagram*
5. Connect a jumper wire from the LED resistor to **PIN 13** on the UNO board. This now allows you to communicate to the LED via PIN 13. *See yellow jumper in diagram*
6. Connect a switch to the middle of the breadboard as shown in the diagram above.
7. Connect the 10k resistor from the bottom right leg of the switch to the breadboard negative rail.&#x20;
8. Connect a jumper wire from that same leg to **PIN 4** on the UNO. *See blue jumper in diagram.*
9. Lastly connect a jumper wire from the bottom left leg of the switch to the **5V PIN** on the UNO. *See red jumper in diagram*

### **Physical wiring diagram:**

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-a00fd98eb9c2bd403a07e11128a5fbd63790a8de%2Fimage.png?alt=media)

### **Code:**

```
void setup (){
    pinMode(4,INPUT); //Set port 4 as input and port 13 as output mode
    pinMode(13,OUTPUT);
}

void loop(){
    int n = digitalRead(4);    //Create a variable n and assign it the state of the number 4 digital port.
    
    //To determine whether n is a high level, if the following statement is executed, then skip.
    if (n==HIGH){	      
        delay(1000);
        digitalWrite(13,HIGH);
        delay(5000);
        digitalWrite(13,LOW);
    }
}
```

You can download the code below

{% file src="/files/dDfeKlCoNoFKQzh2SrvD" %}


# Active Buzzer

In this lesson, you will learn how to generate a sound with an active buzzer.

### **Component Required:**

* 1 x Uno R3
* 1 x Active buzzer
* 1x 830 Tie Points Breadboard
* 2x M-M wires (Male to Male jumper wires)

#### **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. Buzzers can be categorized as active and passive ones. Turn the pins of two buzzers face up. The one with a green circuit board is a passive buzzer, while the other enclosed with a black tape is an active one.

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-4a7e375ac7d49559e66993eee1a1b11c3e72da14%2Fimage.png?alt=media)

### **Connection Diagram:**

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-ac8744493fa570087eacb417e03da6d13614be22%2Fimage.png?alt=media)

### **Wiring schematic:**

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2FOx9YrjE62bL3pAQFRFsS%2FActive-buzzer.png?alt=media\&token=f395a45e-b414-4350-98fa-3680247b8309)

### **Physical wiring diagram:**

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fm2IY6TbESGsuQBwxt4X1%2Factive-buzzer-wired.png?alt=media\&token=7ecd823e-077e-4977-9e0f-f0a4c04c885f)

### **Code:**

{% hint style="warning" %}
After wiring add the "pitches.h" library. Download this file below.

You can click [here](/arduino-kits/basic-starter-kit/add-libraries) to see how to add a library.
{% endhint %}

{% file src="/files/Xkixck8f25IUfx2S3RoA" %}

```
#include "pitches.h"// notes in the melody:
int melody[] = {
  NOTE_C5, NOTE_D5, NOTE_E5, NOTE_F5, NOTE_G5, NOTE_A5, NOTE_B5, NOTE_C6
};
int duration = 500;  // 500 miliseconds
void setup() {  }
void loop() {
  for (int thisNote = 0; thisNote < 12; thisNote++) {
    // pin12 output the voice, every scale is 0.5 sencond
    tone(12, melody[thisNote], duration);
    delay(100);
    // Output the voice after several minutes
    delay(100);
  } // restart after two seconds
  delay(200);
}
```

You can also download the code below

{% file src="/files/IzX8WDwWUBEgxyPKGi74" %}


# Passive Buzzer

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).

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2F44674HufhsHZkkulDwtW%2F13.jpg?alt=media\&token=215329f9-e5d4-4c40-b302-9fdcefb5e357)

### **Component Required:**

1x UNO R3

1 x Passive buzzer

1x F-M wires (Female to Male DuPont wires)

#### **Passive Buzzer:**

The working principle of passive buzzer is using PWM generating audio to make the air to vibrate. Appropriately changed as long as the vibration frequency, it can generate different sounds. For example, sending a pulse of 523Hz, it can generate Alto Do, pulse of 587Hz, it can generate midrange Re, pulse of 659Hz, it can produce midrange Mi. By the buzzer, you can play a song.

We should be careful not to use the UNO R3 board analog Write () function to generate a pulse to the buzzer, because the pulse output of analog Write () is fixed (500Hz).

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-3e050a34f02a0e215bd316552a78f7820c9f18ca%2Fimage.png?alt=media)

### **Connection Diagram:**

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-5959598566625b0da7cf29cdd18cb1e95ab7ae73%2Fimage.png?alt=media)

### **Wiring schematic:**

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2FilX1kGqqLhJb38TuLfZ0%2Fpassive-buzzer.png?alt=media\&token=85174a0b-d53b-4f39-acba-26459f5bc082)

### **Physical wiring diagram:**

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fl9rknWMwnSbCegHes525%2Fpassive-buzzer-wired.png?alt=media\&token=2b8b2f05-990e-4b70-bdba-8b8e81b34988)

### **Code：**

```
void setup()
{
}
void loop()
{
  for (int i = 200; i <= 800; i++) //Increase the frequency from 200HZ to 800HZ in a loop
  {
    pinMode(8, OUTPUT);
    tone(8, i); //Output frequency on port 8 delay(5);    //This frequency is maintained for 5 milliseconds
  }
  delay(4000);  //Hold for 4 seconds at the highest frequency
  for (int i = 800; i >= 200; i--)
  {
    pinMode(8, OUTPUT); tone(8, i);
    delay(10);
  }
}
```

You can also download the code below

{% file src="/files/iN3brLgRWICUbBogwFFM" %}


# Servo

The servo motor has three wires: power, ground, and signal. The power cord is usually red and should be connected to the 5V pin on the Arduino board. The ground wire is usually black or brown and should be connected to the ground pin on the Arduino board. The signal pins are usually yellow, orange or white and should be connected to the digital pins on the Arduino board. Please note that the servo system consumes considerable power, so if you need to drive more than one or two, you may need to use a separate power supply (ie the +5V pin on the Arduino) to power them. Be sure to connect the Arduino to the ground of the external power supply.

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2FVWV3AFsErW9kHLpUQdml%2F7.jpg?alt=media\&token=8e1c148b-e8fe-4b28-81cc-eea0c7298a8e)

### **Component Required:**

1 x Uno R3

1 x Servo (SG90)

3 x M-M wires (Male to Male jumper wires)

### **Connection Diagram:**

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2FNM4E26F67Ia2us43Bdib%2Fservo.png?alt=media\&token=85a11b85-0b58-414b-ac38-3fad5de46788)

### **Wiring schematic:**

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2F34myPCQ7HgOvgGtL2B1q%2Fservo.png?alt=media\&token=efbb68bc-a55e-434b-953c-a632defc81e6)

### **Physical wiring diagram:**

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2FQ9ta0Nr0Tv8oKnwvBlnV%2Fservo-wired.png?alt=media\&token=c51fd66a-5a09-44b0-9745-360d5e4d5611)

### **Code**

{% hint style="warning" %}
After wiring add the **Servo.zip** library. Download it below
{% endhint %}

{% file src="/files/1LpDl6jbMg0LGYLsIZHl" %}

```
#include <Servo.h>

Servo myservo;  // create servo object to control a servo
//  a maximum of eight servo objects can be created

int pos = 0;// variable to store the servo position

void setup() {
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
}

void loop(){

  for (pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees
  { // in steps of 1 degree
    myservo.write(pos); // tell servo to go to position in variable 'pos'
    delay(15);  // waits 15ms for the servo to reach the position
  }

  for (pos = 180; pos >= 1; pos -= 1) // goes from 180 degrees to 0 degrees
  {
    myservo.write(pos); // tell servo to go to position in variable 'pos'
    delay(15);  // waits 15ms for the servo to reach the position
  }
}
```

{% file src="/files/qBXViEkak1etZXNfYYDF" %}


# IR Remote and Receiver

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 UNO, 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.

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2F28YCk5vt2PsKFZ8Af1KV%2F5.jpg?alt=media\&token=4b0e9e36-d058-4f8f-95af-7a42d420c4ea) ![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2FUYMKiR11Lib5ZLP78lB3%2F23.jpg?alt=media\&token=89ad6602-e575-486c-bb86-254e9e5d3677)

### **Component Required:**

1 x Uno R3

1x IR receiver module

1 x IR remote

3 x F-M wires (Female to Male DuPont wires)

#### IR RECEIVER SENSOR:

IR detectors are little microchips with a photocell that are tuned to listen to infrared light. They are almost always used for remote control detection - every TV and DVD player has one of these in the front to listen for the IR signal from the clicker. Inside the remote control is a matching IR LED, which emits IR pulses to tell the TV to turn on, off or change channels. IR light is not visible to the human eye, which means it takes a little more work to test a setup.

There are a few difference between these and say a CdS Photocells:

IR detectors are specially filtered for IR light, they are not good at detecting visible light. On the other hand, photocells are good at detecting yellow/green visible light, and are not good at IR light.

IR detectors have a demodulator inside that looks for modulated IR at 38 KHz. Just shining an IR LED won't be detected, it has to be PWM blinking at 38KHz. Photocells do not have any sort of demodulator and can detect any frequency (including DC) within the response speed of the photocell (which is about 1KHz)

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**

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-60058735ca322e8b21ad630f62bb21c789ae24a9%2Fimage.png?alt=media)

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. Likewise, you can use 850 to 1100 nm LEDs but they won't work as well as 900 to 1000nm so make sure to get matching LEDs! Check the datasheet for your IR LED to verify the wavelength.

Try to get a 940nm - remember that 940nm is not visible light!

### **Connection Diagram:**

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2FLG35RKvhjeI1E3b744VC%2Fir-remore-connection.png?alt=media\&token=bcf384d0-47f7-4adf-abef-c2d1746e84a2)

### **Wiring schematic**

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2FLQkLtTxhwssbrr6QFMZG%2FIR-remote-rec.png?alt=media\&token=60f52aa8-be82-4ae5-abd4-ffd4a2839f7c)

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.

### **Physical wiring diagram:**

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2FsM7ssCAZzOZrKQ5pNQX8%2FIR-remote-rec-wired.png?alt=media\&token=929a7b57-872b-46fd-8556-a6d68477804e)

### **Code**

{% hint style="warning" %}
After wiring, install the IRRemote.zip library
{% endhint %}

{% file src="/files/C571UBttSUx8WIYWoBZB" %}

```
#include <IRremote.h>

int RECV_PIN = 11;

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); //Initialize infrared remote control
  pinMode(13,OUTPUT);
}

void loop() {
if (irrecv.decode(&results))
{
  if(results.value==16753245)   //Confirm the code of the first row of keys 1 received. //This code is the code of the keys read in advance.  {
  digitalWrite(13,1);                //Light up the LED
  Serial.println("turn on LED"); //Serial port display lights on
  }
 //Confirm the code for the first row of keys 2 received
  else if(results.value==16736925)  {
    digitalWrite(13,0);            //Put out the LED
    Serial.println("turn off LED");    //Serial port displays lights off
  }
    irrecv.resume(); // Receive the next value
  
}
```

{% file src="/files/mqCxoeRMCZ5LoynlocgM" %}

Open the serial monitor as follows:

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-54fa3133fc90968ea2910b8fd5a9575ad95a84ae%2Fimage.png?alt=media)


# Stepper Motor

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 UNO.

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Frk80OXK9wETEtxurGS6N%2F10.jpg?alt=media\&token=969dcdbc-6b11-4ed9-a822-af8720488a7e)

### Component Required:

1 x Arduino Uno R3

1 x 830 tie-points breadboard

1 x ULN2003 stepper motor driver module

1 x Stepper motor

1 x 9V1A Adapter

1 x Power supply module

6 x F-M wires (Female to Male DuPont wires) 1 x M-M wire (Male to Male jumper wire)

#### Stepper Motor:

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. The speed of the motor shafts rotation is directly related to the frequency of the input pulses and the length of rotation is directly related to the number of input pulses applied. One of the most significant advantages of a stepper motor is its ability to be accurately controlled in an open loop system. Open loop control means no feedback information about position is needed.

This type of control eliminates the need for expensive sensing and feedback devices such as optical encoders. Your position is known simply by keeping track of the input step pulses.

#### **ULN2003 Driver Board**

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-177328a337704450678eb86979e99b6cbb73a4d1%2Fimage.png?alt=media)

### **Connection Diagram:**

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-ec6ef6d28f5e3d06a6c0d5d89284d2668ac5339b%2Fimage.png?alt=media)

### **Wiring schematic:**

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-d906ed2537b1c4eedda3e4bbbdabd0614a5ec52f%2Fimage.png?alt=media)

### **Code**

After wiring\*\*,\*\* install the **Stepper.zip** library

{% file src="/files/KkSmC4LzHZVhvYCTraO2" %}

```
#include <Stepper.h>
const int stepsPerRevolution = 1500;
// change this to fit the number of steps per revolution
// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8, 10, 9, 11);
void setup()
{
  // set the speed at 20 rpm:
  myStepper.setSpeed(20);
  // initialize the serial port:
  Serial.begin(9600);
}
void loop() { // step one revolution  in one direction:
  Serial.println("clockwise");
  myStepper.step(stepsPerRevolution);
  delay(500);// step one revolution in the other direction:
  Serial.println("counterclockwise");
  myStepper.step(-stepsPerRevolution); delay(500);
}
```

{% file src="/files/POUzphZsMyklb2OSIirG" %}


# Eight LED with 74HC595

In this lesson, you will learn how to use eight LEDs with an UNO without needing to give up 8 output pins!

Although you could wire up eight LEDs each with a resistor to an UNO pin, you would rapidly start to run out of pins on your UNO. If you don't have a lot of stuff connected to your UNO. 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. So, instead of doing that, you are going to use a chip called the 74HC595 Serial to Parallel Converter. This chip has eight outputs (perfect) and three inputs that you use to feed data into it a bit at a time

This chip makes it a little slower to drive the LEDs (you can only change the LEDs about 500,000 times a second instead of 8,000,000 a second) but it's still really fast, way faster than humans can detect, so it's worth it!

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2FgyXlj1yyVN1nwP9xn2i3%2F9.jpg?alt=media\&token=53353f95-ec74-44c2-b578-cda5583f37d0)

### **Component Required:**

* 1 x Arduino Uno R3
* 1 x 830 tie-points breadboard
* 8 x LED's
* 8 x220 ohm resistors
* 1 x 74hc595 IC
* 14 x M-M wires (Male to Male jumper wires)

### **Component Introduction:**

**74HC595 Shift Register:**

The shift register is a type of chip that holds what can be thought of as eight memory locations, each of which can either be a 1 or a 0. To set each of these values on or off, we feed in the data using the 'Data' and 'Clock' pins of the chip.

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-cb50a50a58bbe08055769f49af11d5eb662d7de6%2Fimage.png?alt=media)

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. You could attach this to a PWM-capable UNO pin and use 'analogWrite' to control the brightness of the LEDs. This pin is active low, so we tie it to GND.

### **Connection Diagram:**

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2FotoiUjdO1vZfwHclpKRF%2F74hc-1.png?alt=media\&token=af0fb62b-8bfb-4485-bfb5-76b9891d62fa)

### **Wiring schematic:**

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2FIHCR6KabFzHq1Rrbvnjb%2F74hc595.png?alt=media\&token=88dd93a5-e342-4b6c-b72b-36e3fe30e013)

### **Physical wiring diagram:**

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-deff1356dd1367b68c574ac37a92c0942852d96c%2FLEDIC2.png?alt=media)

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.

Digital 12 from the UNO goes to pin #14 of the shift register

Digital 11 from the UNO goes to pin #12 of the shift register&#x20;

Digital 9 from the UNO goes to pin #11 of the shift register

All but one of the outputs from the IC is on the left side of the chip. Hence, for ease of connection, that is where the LEDs are, too.

After the chip, put the resistors in place. You need to be careful that none of the leads of the resistors are touching each other. You should check this again before you connect the power to your UNO. If you find it difficult to arrange the resistors without their leads touching, then it helps to shorten the leads so that they are lying closer to the surface of the breadboard.

Next, place the LEDs on the breadboard. The longer positive LED leads must all be towards the chip, whichever side of the breadboard they are on.

Attach the jumper leads as shown above. Do not forget the one that goes from pin 8 of the IC to the GND column of the breadboard.

Load up the sketch listed a bit later and try it out. Each LED should light in turn until all the LEDs are on, and then they all go off and the cycle repeats.

### **Code Explanation:**

The first thing we do is define the three pins we are going to use. These are the UNO digital outputs that will be connected to the latch, clock and data pins of the 74HC595.

```
int latchPin = 11;
int clockPin = 9; 
int dataPin = 12;
```

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.

The loop function pauses for half a second and then begins to count from 0 to 7 using the 'for' loop and the variable 'i'. Each time, it uses the Arduino function 'bitSet' to set the bit that controls that LED in the variable 'leds'. It then also calls 'updateShiftRegister' so that the leds update to reflect what is in the variable 'leds'. There is then a half second delay before 'i' is incremented and the next LED is lit.

```
void loop(){
    leds = 0; updateShiftRegister(); delay(500);
    for (int i = 0; i < 8; i++){
        bitSet(leds, i); updateShiftRegister(); delay(500);
    }
} 
```

The function 'updateShiftRegister', first of all sets the latch Pin to low, then calls the

UNO function 'shiftOut' before putting the 'latchPin' high again. This takes four parameters, the first two are the pins to use for Data and Clock respectively. The third parameter specifies which end of the data you want to start at. We are going to start with the right most bit, which is referred to as the 'Least Significant 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. This will set that bit of 'leds' to be 0 and you would then just need to follow it with a call to 'updateShiftRegister' to update the actual LEDs.

### **Code**

```
int latchPin = 11;
int clockPin = 9;
int dataPin = 12;
byte leds = 0;

void setup()
{
  pinMode(latchPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
}
void loop()
{
  leds = 0;
  updateShiftRegister();
  delay(500);
  for (int i = 0; i < 8; i++)
  {
    bitSet(leds, i); updateShiftRegister(); delay(500);
  }
}
void updateShiftRegister()
{
  digitalWrite(latchPin, LOW);
  shiftOut(dataPin, clockPin, LSBFIRST, leds);
  digitalWrite(latchPin, HIGH);
}
```

You can download the code below

{% file src="/files/CcCcWGSR9wrc6TvSBbso" %}


# LCD

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. In this lesson, we will run the Arduino example program for the LCD library

![LCD1](https://user-images.githubusercontent.com/77891891/146549503-6c0867a1-551f-4d83-a09f-a571b31b64c6.png)

### Component Required:

* 1 x Uno R3&#x20;
* 1 x LCD1602 module&#x20;
* 1 x Potentiometer (10k)&#x20;
* 1 x 830 tie-points Breadboard&#x20;
* 16 x M-M wires (Male to Male jumper wires)

### LCD1602:

Introduction to the pins of LCD1602:&#x20;

**VSS**: A pin that connects to ground&#x20;

**VDD**: A pin that connects to a +5V power supply&#x20;

**VO**: A pin that adjust the contrast of LCD1602&#x20;

**RS**: A register select pin that controls where in the LCD’s memory you are writing data to. You can select either the data register, which holds what goes on the screen, or an instruction register, which is where the LCD’s controller looks for instructions on what to do next.&#x20;

**R/W**: A Read/Write pin that selects reading mode or writing mode&#x20;

**E**: An enabling pin that, when supplied with low-level energy, causes the LDC module to execute relevant instructions.&#x20;

**D0-D7**：Pins that read and write data&#x20;

**A and K**: Pins that control the LED backlight

### **Connection Diagram:**

![LCD-connection-diagram](https://user-images.githubusercontent.com/77891891/146549865-727ff0ba-3b87-4025-82ed-56cf0649aca1.png)

### **Wiring schematic:**

![LCD-wiring-schematics](https://user-images.githubusercontent.com/77891891/146549929-12391bfb-d316-4b5f-9f36-5073b46d0ae3.png)

### **Physical Wiring Diagram:**

![LCD-physical-wiring](https://user-images.githubusercontent.com/77891891/146550045-9005e946-6057-4570-a098-92e9c7d7aa18.png)

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. You may find that your display is supplied without header pins attached to it. If so, follow the instructions in the next section.

### **Code**

After wiring, you need to install the relevant library file <**LiquidCrystal.h>** listed below:

{% file src="/files/b3oiBHtkGjgA3fL1t0mB" %}

```
/*
  LiquidCrystal Library - Hello World

 Demonstrates the use a 16x2 LCD display.  The LiquidCrystal
 library works with all LCD displays that are compatible with the
 Hitachi HD44780 driver. There are many of them out there, and you
 can usually tell them by the 16-pin interface.

 This sketch prints "Hello World!" to the LCD
 and shows the time.

  The circuit:
 * LCD RS pin to digital pin 7
 * LCD Enable pin to digital pin 8
 * LCD D4 pin to digital pin 9
 * LCD D5 pin to digital pin 10
 * LCD D6 pin to digital pin 11
 * LCD D7 pin to digital pin 12
 * LCD R/W pin to ground
 * LCD VSS pin to ground
 * LCD VCC pin to 5V
 * 10K resistor:
 * ends to +5V and ground
 * wiper to LCD VO pin (pin 3)

 Library originally added 18 Apr 2008
 by David A. Mellis
 library modified 5 Jul 2009
 by Limor Fried (http://www.ladyada.net)
 example added 9 Jul 2009
 by Tom Igoe
 modified 22 Nov 2010
 by Tom Igoe

 This example code is in the public domain.

 http://www.arduino.cc/en/Tutorial/LiquidCrystal
 */

// include the library code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

void setup() {
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("Hello, World!");
}

void loop() {
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 1);
  // print the number of seconds since reset:
  lcd.print(millis() / 1000);
}
```

{% file src="/files/AlnAR4SoUzWRvu6yeZsi" %}

### **Code Explained**

The first thing of note in the sketch is the line:

```
#include <LiquidCrystal.h>
```

This tells Arduino that we wish to use the Liquid Crystal library.

Next we have the line that we had to modify. This defines which pins of the Arduino are to be connected to which pins of the display.

```
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
```

After uploading this code, make sure the backlight is lit up, and adjust the potentiometer all the way around until you see the text message.

In the 'setup' function, we have two commands:

```
lcd.begin(16, 2); lcd.print("Hello, World!");
```

The first tells the Liquid Crystal library how many columns and rows the display has.

The second line displays the message that we see on the first line of the screen.

&#x20;In the 'loop' function, we also have two commands:

```
lcd.setCursor(0, 1); lcd.print(millis()/1000);
```

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.


# Digital tube with Traffic Light Experiment

This lesson will use the 74HC595 shift register in combination with the red and green LEDs and the yellow LED to create a traffic light.

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2FrGe2i4gj09xDZ6EYg22S%2Fdigialtube-pic.png?alt=media\&token=f27d372d-6577-4677-8bd5-fe11c36a1785)

### **Component Required**

* 1 x Uno R3
* 1 x 830 tie-points breadboard
* 1 x 1 Digit 7-Segment Display
* 10 X 220 ohm resistors
* 20 x M-M wire (Male to Male jumper wire)
* 1 x Red LED
* 1 x Yellow LED
* 1 x Green LED

### **Component Introduction**

#### Seven segment display

Below is the seven-segment pin diagram.

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2FomJxxZcaMj1UKcZvnLOL%2Fdigialtube-pic2.png?alt=media\&token=2faf5cfa-f2b8-4282-825a-51c265d91e3b)

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):

<table data-header-hidden><thead><tr><th width="150"></th><th width="150"></th><th width="150"></th><th width="150"></th><th width="150"></th><th width="150"></th><th width="150"></th><th width="150"></th><th></th></tr></thead><tbody><tr><td>Display</td><td>dp</td><td>a</td><td>b</td><td>c</td><td>d</td><td>e</td><td>f</td><td>g</td></tr><tr><td> </td><td> </td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td>digital</td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td></tr><tr><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td></tr><tr><td>0</td><td>0</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>0</td></tr><tr><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td></tr><tr><td>1</td><td>0</td><td>0</td><td>1</td><td>1</td><td>0</td><td>0</td><td>0</td><td>0</td></tr><tr><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td></tr><tr><td>2</td><td>0</td><td>1</td><td>1</td><td>0</td><td>1</td><td>1</td><td>0</td><td>1</td></tr><tr><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td></tr><tr><td>3</td><td>0</td><td>1</td><td>1</td><td>1</td><td>1</td><td>0</td><td>0</td><td>1</td></tr><tr><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td></tr><tr><td>4</td><td>0</td><td>0</td><td>1</td><td>1</td><td>0</td><td>0</td><td>1</td><td>1</td></tr><tr><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td></tr><tr><td>5</td><td>0</td><td>1</td><td>0</td><td>1</td><td>1</td><td>0</td><td>1</td><td>1</td></tr><tr><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td></tr><tr><td>6</td><td>0</td><td>1</td><td>0</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td></tr><tr><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td></tr><tr><td>7</td><td>0</td><td>1</td><td>1</td><td>1</td><td>0</td><td>0</td><td>0</td><td>0</td></tr><tr><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td></tr><tr><td>8</td><td>0</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td></tr><tr><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td></tr><tr><td>9</td><td>0</td><td>1</td><td>1</td><td>1</td><td>1</td><td>0</td><td>1</td><td>1</td></tr><tr><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td></tr></tbody></table>

### **Connection Diagram:**

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2FOrDgHVzFBTdbqc6bkR5g%2Fdigialtube-circuit.png?alt=media\&token=823f5f7b-f9e0-4851-af3a-c4845b7d55c7)

### **Wiring schematic:**

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2F73KfHxIpPgWpiCozSAW3%2Fdigital-tube-trafic-light_bb.png?alt=media\&token=c74641d5-742b-4583-9280-b6cc0cdec800)

### **Physical wiring diagram:**

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2FkkeSEPd1s8mibsTgrmGh%2Fdigialtube-physicl-wiring.png?alt=media\&token=37aeb813-f335-4224-b0a3-5ea4c1f09fa4)

```
int a = 7;
int b = 6;
int c = 5;
int d = 11;
int e = 10;
int f = 8;
int g = 9;

int ledG = 14;
int ledY = 15;
int ledR = 16;

//Display number 1
void digital_1(void)
{
  unsigned char j;
  digitalWrite(c, HIGH); //Lower the level of the digital 5 pin and light up segment c
  digitalWrite(b, HIGH); //Light section b
  for (j = 7; j <= 11; j++) //blanking
    digitalWrite(j, LOW);
}
//Display number 2
void digital_2(void)
{
  unsigned char j;
  digitalWrite(b, HIGH);
  digitalWrite(a, HIGH);
  for (j = 9; j <= 11; j++)
    digitalWrite(j, HIGH);
  digitalWrite(c, LOW);
  digitalWrite(f, LOW);
}
//Display number 3
void digital_3(void)
{
  unsigned char j;
  digitalWrite(g, HIGH);
  digitalWrite(d, HIGH);
  for (j = 5; j <= 7; j++)
    digitalWrite(j, HIGH);
  digitalWrite(f, LOW);
  digitalWrite(e, LOW);
}


//Display number 4
void digital_4(void)
{
  digitalWrite(c, HIGH);
  digitalWrite(b, HIGH);
  digitalWrite(f, HIGH);
  digitalWrite(g, HIGH);
  digitalWrite(a, LOW);
  digitalWrite(e, LOW);
  digitalWrite(d, LOW);
}
//Display number 5
void digital_5(void)
{
  unsigned char j;
  for (j = 7; j <= 9; j++)
    digitalWrite(j, HIGH);
  digitalWrite(c, HIGH);
  digitalWrite(d, HIGH);
  digitalWrite(b, LOW);
  digitalWrite(e, LOW);
}
//Display number 6
void digital_6(void)
{
  unsigned char j;
  for (j = 7; j <= 11; j++)
    digitalWrite(j, HIGH);
  digitalWrite(c, HIGH);
  digitalWrite(b, LOW);
}
//Display number 7
void digital_7(void)
{
  unsigned char j;
  for (j = 5; j <= 7; j++)
    digitalWrite(j, HIGH);
  for (j = 8; j <= 11; j++)
    digitalWrite(j, LOW);
}

//Display number 8
void digital_8(void)
{
  unsigned char j;
  for (j = 5; j <= 11; j++)
    digitalWrite(j, HIGH);
}
//Display number 9
void digital_9(void)
{
  digitalWrite(c, HIGH);
  digitalWrite(b, HIGH);
  digitalWrite(f, HIGH);
  digitalWrite(g, HIGH);
  digitalWrite(a, HIGH);
  digitalWrite(e, LOW);
  digitalWrite(d, HIGH);
}
//Pin setting and initialization
void setup()
{
  int i;//defined variable
  for (i = 5; i <= 16; i++)
    pinMode(i, OUTPUT); //Set pins 5 ~ 16 to output mode

}

void loop()
{
  while (1)
  {
    //red light
    digitalWrite(ledR, LOW);
    digitalWrite(ledY, HIGH);
    digitalWrite(ledG, HIGH);

    digital_9();  // Show 9
    delay(1000);   //Delay 1 s
    digital_8();  // Show 8
    delay(1000);   //Delay 1 s
    digital_7();  // Show 7
    delay(1000);   //Delay 1 s
    digital_6();  // Show 6
    delay(1000);   //Delay 1 s
    digital_5();  // Show 5
    delay(1000);   //Delay 1 s
    digital_4();  // Show 4
    delay(1000);   //Delay 1 s
    digital_3();  // Show 3
    delay(1000);   //Delay 1 s
    digital_2();  // Show 2
    delay(1000);   //Delay 1 s
    digital_1();  // Show 1
    delay(1000);   //Delay 1 s
    //green light
    digitalWrite(ledR, HIGH);
    digitalWrite(ledY, HIGH);
    digitalWrite(ledG, LOW);

    digital_9();  // Show 9
    delay(1000);   //Delay 1 s
    digital_8();  // Show 8
    delay(1000);   //Delay 1 s
    digital_7();  // Show 7
    delay(1000);   //Delay 1 s
    digital_6();  // Show 6
    delay(1000);   //Delay 1 s
    digital_5();  // Show 5
    delay(1000);   //Delay 1 s
    digital_4();  // Show 4
    delay(1000);   //Delay 1 s
    digital_3();  // Show 3
    delay(1000);   //Delay 1 s
    digital_2();  // Show 2
    delay(1000);   //Delay 1 s
    digital_1();  // Show 1
    delay(1000);   //Delay 1 s
    //yellow light
    digitalWrite(ledR, HIGH);
    digitalWrite(ledY, LOW);
    digitalWrite(ledG, HIGH);
    digital_3();  // Show 3
    delay(1000);   //Delay 1 s
    digital_2();  // Show 2
    delay(1000);   //Delay 1 s
    digital_1();  // Show 1
    delay(1000);   //Delay 1 s
  }
}
```

{% file src="/files/o9tAiaLfYAjGi79jl7qU" %}


# Four digit tube display

In this lesson, you will learn how to use a 4-digit 7-segment display.

### **Overview**

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. Even though there is only one digit working, the principle of Persistence of Vision enables you to see all numbers displayed because each the scanning speed is so fast that you hardly notice the intervals.

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2FtpmTyQE1tiXtq4NMsMci%2F4-digital-tube-pic.png?alt=media\&token=47e87084-6c28-4839-a267-31559da1af79)

### **Component Required:**

* 1 x Arduino Uno R3
* 1 x 830 tie-points breadboard
* 1 x 74HC595 IC
* 1 x 4 Digit 7-Segment Display
* 4 x 220 ohm resistors
* 23 x M-M wires (Male to Male jumper wires)

### **Component Introduction**

#### **Four Digital Seven segment display**

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2FM0aTjPzGNh0LlKRb5ouv%2F4-digital-tube-pic2.png?alt=media\&token=1fe03b47-2d7c-4eb1-ae3f-1748ecb50d91)

### **Connection Diagram:**

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2FkYd2JeYRAmbN9QzoKnr3%2F4-digital-tube-Connection%20Diagram.png?alt=media\&token=38d876b5-8441-4df3-870d-c8df7e926209)

### **Wiring schematic:**

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2FBpBvdG9zIEThTiiBVAVv%2F4-digital-tube-display.png?alt=media\&token=7b80ca95-2ef8-417f-b87b-7895486fcdb1)

### **Physical wiring diagram:**

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fah138ykzdrcjJkTSWzG4%2F4-digital-tube-Physical%20wiring%20diagram.png?alt=media\&token=ec4f5062-d490-4784-94ce-5dec2d3eb67d)

### **Code:**

```
int latch = 9; //74HC595  pin 9 STCP
int clock = 10; //74HC595  pin 10 SHCP
int data = 8; //74HC595  pin 8 DS

unsigned char table[] =
{ 0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f, 0x77, 0x7c
  , 0x39, 0x5e, 0x79, 0x71, 0x00
};

void setup() {
  pinMode(latch, OUTPUT);
  pinMode(clock, OUTPUT);
  pinMode(data, OUTPUT);
}
void Display(unsigned char num)
{

  digitalWrite(latch, LOW);
  shiftOut(data, clock, MSBFIRST, table[num]);
  digitalWrite(latch, HIGH);

}
void loop() {
  Display(1);
  delay(500);
  Display(2);
  delay(500);
  Display(3);
  delay(500);
  Display(4);
  delay(500);
  Display(5);
  delay(500);
  Display(6);
  delay(500);
  Display(7);
  delay(500);
  Display(8);
  delay(500);
  Display(9);
  delay(500);
  Display(10);
  delay(500);
  Display(11);
  delay(500);
  Display(12);
  delay(500);
  Display(13);
  delay(500);
  Display(14);
  delay(500);
  Display(15);
  delay(500);
}
```

{% file src="/files/VSq0hVZpkIbVLHd2TIrx" %}


# LM35D Temperature Sensor

This lesson will introduce you to the LM35D sensor

### **Component Required:**

* 1 x Arduino Uno R3
* 4 x M-M wires (Male to Male jumper wires)
* 1 x 830 tie-points breadboard

### **Component Overview**

LM35 is a very common and easy-to-use temperature sensor element. In the application of components, only one LM35 element is needed, and only one analog interface can be used. The difficulty lies in the algorithm to convert the analog value read into the actual temperature.

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2FnW0HD7cC7CNWOvVJi23t%2FLM35-pic.png?alt=media\&token=7f77e0a3-8a67-4432-bdc0-fddb3a4cca1c)

The LM35 is applied easily in the same way as other integrated-circuit temperature sensors. Glue or cement the device to a surface and the temperature should be within about 0.01 ° C of the surface temperature.This presumes that the ambient air temperature is almost the same as the surface temperature. If the air temperature were much higher or lower than the surface temperature, the actual temperature of the LM35 die would be at an intermediate temperature between the surface temperature and the air temperature, which is especially true for the TO-92 plastic package where the copper leads are the principal thermal path to carry heat temperature as the surface of interest. The easiest way to do this is to cover up these wires with a bead of epoxy which will insure that the leads and wires are all at the same temperature as the surface, and that the temperature of the LM35 die is not affected by the air temperature.

The TO-46 metal package can also be soldered to a metal surface or pipe without damage. Of course, in that case the V− terminal of the circuit will be grounded to that metal. Alternatively, mount the LM35 inside a sealed end metal tube, and then dip into a bath or screw into a threaded hole in a tank.

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2FQthJRd16BQZO7iq3LBeH%2FLM35-pic2.png?alt=media\&token=4e072a76-c6a4-40b4-890a-7eca16bd459f)

### **Connection Diagram:**

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2FcHeYWjmflCa4rbnByxy0%2FLM35-Connection%20Diagram.png?alt=media\&token=091d169d-363d-4a6d-b92a-4ce3ac9dcdd8)

### **Wiring schematic:**

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2FEYQOybPsG6OOVqguglvY%2FLM35-Wiring%20schematic.png?alt=media\&token=02506654-8492-4d8f-8f37-d0c7acd0950c)

### **Physical wiring diagram:**

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2FYKxOOhXT1xnyymRoQT2b%2FLM35-Physical%20wiring%20diagram.png?alt=media\&token=bdcd620d-fca3-4292-ba97-70bba01ddbf1)

### **Code:**

```
int potPin = A0; //Pin A0
void setup()
{
  Serial.begin(9600);//Set baud rate
}
void loop()
{
  int val;//
  int dat;//
  val = analogRead(0);
  // Read the analog value of the sensor and assign a value to Val
  dat = (125 * val) >> 8; //Temperature calculation formula
  Serial.print("Tep:");//The as-is output shows the Tep string for temperature
  Serial.print(dat);//The output shows the value of the DAT
  Serial.println("C");//The output displays the C string
  delay(500);//delay 500ms
}
```

{% file src="/files/7zXIlHzeJTjotCybfMxd" %}

You can open the serial monitor by going to **Tools > Serial Monitor** or by pressing the magnifying glass button in ARDUINO software window.

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2FPjDVNlgmwoCci3jMHLiC%2FLM35-serial.png?alt=media\&token=42856d97-7db4-42a6-9613-7a939b2e0d7f)


# LDR 5516 experiment

This lesson shows you how to use Arduino LDR photosensitive device to realize a light-emitting diode switch that can automatically control with ambient brightness

This lesson shows you how to use Arduino LDR photosensitive device to realize a light-emitting diode switch that can automatically control with ambient brightness. When the ambient brightness is relatively dark, the LED will turn on automatically.When the ambient brightness is relatively bright, the LED goes out automatically.

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fa425WV8alWrshFKZkDLP%2FLDR%205516.png?alt=media\&token=57d7273f-910b-404a-9e12-fc62d12c4c98)

### **Component Required:**

* 1 x Uno R3
* 1 x 830 tie-points breadboard
* 1 x Yellow LED
* 1 x LDR 5516
* 2 **x** resistances(330Ω)
* 7 x M-M wire (Male to Male jumper wire)

### **Component Introduction**

Photoresistor is a resistor which made of semiconductor material,and the conductance changes with luminance variation .The photoresistor can be manufactured with different figures and illuminated area based on this characteristic.Photoresistor is widely used in many industries, such as toys, lamps, camera, etc.

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2FG4Bk4lwQFsnVrhS5XDaQ%2FLDR%205516-pic.png?alt=media\&token=9ad68e81-a282-45d2-bcc9-aa28a603ad6a)

### **Connection Diagram:**

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2FL5S3VJca9H5x9Njl09t3%2FLDR%205516-Connection%20Diagram.png?alt=media\&token=264663ae-a466-4284-a6c2-af1be649f29c)

### **Wiring schematic:**

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2FSsMWf32pIpKNYGMtdMC0%2FLDR%205516-Wiring%20schematic.png?alt=media\&token=a0cf6824-7803-4fae-9392-545b0279c9a6)

### **Physical wiring diagram:**

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2FgS0Dg3jvsrOYQ2rKs4Qd%2FLDR%205516-Physical%20wiring%20diagram.png?alt=media\&token=b595e243-01f8-415b-814e-f2559748af4f)

### **Code:**

```
const int ledPin = 13;
const int ldrPin = A0;
void setup() {
  Serial.begin(9600);
  pinMode(ledPin, OUTPUT);
  pinMode(ldrPin, INPUT);
}
void loop() {
  int ldrStatus = analogRead(ldrPin);
  if (ldrStatus <= 200) {
    digitalWrite(ledPin, HIGH);
    Serial.print("Its DARK, Turn on the LED : ");
    Serial.println(ldrStatus);
  } else {
    digitalWrite(ledPin, LOW);
    Serial.print("Its BRIGHT, Turn off the LED : ");
    Serial.println(ldrStatus);
  }
}
```


# Flame Sensor

Flame sensor makes use of the characteristic that infrared ray is very sensitive to the flame, use the special infrared ray receiving tube to detect the flame, then convert the brightness of the flame to the level signal of high and low change, input to the CENTRAL processing unit, the central processing unit makes corresponding program processing according to the change of the signal.

&#x20;The flame sensor (infrared receiving triode) is a sensor specially used by the robot to search for the fire source. This sensor is especially sensitive to the flame.

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fug5DeCaLY4SAya37HmHc%2Fflame-sensor.png?alt=media\&token=33cdc1f3-20f7-411c-8d05-5d3293d89c75)

### **Component Required:**

* 1 x Uno R3
* 1 x The flame sensor
* 1 x Potentiometer (10k)
* 1 x 830 tie-points Breadboard
* 1 x Passive Buzzer
* 6 x M-M wires (Male to Male jumper wires)

### **Connection Diagram:**

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2FIKzTBckcZ0JzLWgqefja%2Fflame-sensor-Connection%20Diagram.png?alt=media\&token=06b99937-78b4-4b9d-a928-cde4bd3ee662)

### **Wiring schematic:**

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2F0pwbdvhwJTFew7j1Ud4R%2Fflame-sensorWiring%20schematic.png?alt=media\&token=61b83ee1-7465-4178-a6a2-25fb60fd492c)

### **Physical wiring diagram:**

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2F86AHUEIfzcAyMqmjuG0C%2Fflame-sensorPhysical%20wiring%20diagram.png?alt=media\&token=7376c17c-ec21-45a7-908a-02eda55c4837)

The short lead end of the infrared is negative, while the long lead end is positive. Connect the negative electrode to the 5V interface as shown in the figure below, then connect the positive electrode to the 10K resistor, connect the other end of the resistor to the GND interface, and finally connect a jumper wire from the positive extreme column of the flame sensor, and connect the other end of the jumper wire to the simulation mouth as shown in pic above.

&#x20;**Principles**

The voltage values read by the analog PIN vary with or without flame proximity. As measured by a multimeter, the voltage read by the simulated PIN was about 0.3V when there was no flame near. When a flame approached, the simulated PIN read a voltage of about 1.0V. The closer the flame approached, the greater the voltage.

So in the beginning, can store a first voltage value when no flame simulation, the analog port voltage value is continuously cyclically read and the difference value K = J-i and the difference value K = 0.6V are compared with the stored value. At odds with a difference of K at 0.6V (and at odds with 123), be at odds with flames and be at odds with a buzzer. If the difference is less than 0.6V, the buzzer will not sound.

### **Code:**

```
int flame = A0; //A0
int Beep = 8; //Define the buzzer interface as the pin 7
int val = 0; //
void setup()
{ pinMode(Beep, OUTPUT);
  pinMode(flame, INPUT);
  Serial.begin(9600);//Set the baud rate to 9600
}
void loop() {
  val = analogRead(flame);
  //Read the simulated value of the flame sensor
  Serial.println(val);//Output the analog value and print it out
  if (val >= 600) //The buzzer will sound when the simulation value is greater than 600
  {
    digitalWrite(Beep, HIGH);
  }
  else {
    digitalWrite(Beep, LOW);
  }
}
```

{% file src="/files/sWXWu9ob7PybyBZjiE2U" %}


# 8 \* 8 LED Module

### **Overview**

The internal structure and appearance of the lattice are as follows.&#x20;

The 8X8 lattice is composed of 64 LEDS, and each LED is placed at the intersection of the row line and the column line. When the corresponding row is set to level 1 and a column is set to level 0, the corresponding diode will light up.If you want to turn the first dot on, then 9 pins to high level 13 pins to low level, then the first dot will be on;If the first row is to be lit, the 9th pin is to be high, and (13, 3, 4, 10, 6, 11, 15, 16) these pins are to be low, then the first row is to be lit;If the first column is lit, the 13th pin is low, and (9, 14, 8, 12, 1, 7, 2, 5) is high, then the first column is lit.

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fdv2itUDaD7ikr3EpFaCO%2F8x8-led.png?alt=media\&token=b70eaa98-9381-42f2-91ba-e5786976d011)

### **Component Required:**

* 1 x Arduino Uno R3
* 1 x 8\*8 lattice model (LED Module)
* 1 x 830 tie-points breadboard
* 1 x tie-points breadboard( 82mmx53mm)
* 22 x M-M wires (Male to Male jumper wires)
* Potentiometer (220R)

### **Component Introduction**

LED generally adopts scanning display, which can be divided into three ways in practical application

&#x20;(1)  Point scanning

&#x20;(2)  Line scanning

16 × 64=1024Hz, the period is less than 1ms.If the second and third methods are used, the frequency must be greater than 16 × 8=128Hz and the period less than 7.8ms to meet the visual retention requirements.In addition, when driving one column or one row (8 leds) at a time, additional driving circuit is needed to increase the current, otherwise the LED brightness will be insufficient.

Therefore, the column codes formed are 00H, 00H, 3EH, 41H, 41H, 3EH, 00H, 00H;As long as these codes are sent to the corresponding column line in turn, the number of "0" can be achieved.

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2FzHRWKuGKZIFa7DBR8AbR%2F8x8-led1.png?alt=media\&token=f6e83d9b-86cf-47eb-8b1e-730d7351ddac)

### **Schematic of an 8 by 8 lattice**

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2FYanYScV58Eiwi82Qdc6w%2F8x8-led-schematic.png?alt=media\&token=83518225-eb85-4195-9d15-d7a19b2a2447)

### **Physical wiring diagram:**

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2F7Q1c7wIl6xqNUXgbA70e%2F8x8-ledPhysical%20wiring%20diagram.png?alt=media\&token=c6edfcbe-13fc-4ee0-893b-fc5127653936)

### **Code:**

```
unsigned char Text[] = {0x00, 0x1c, 0x22, 0x22, 0x22, 0x22, 0x22, 0x1c};
void Draw_point(unsigned char x, unsigned char y)
{
  clear_();
  digitalWrite(x + 2, HIGH);
  digitalWrite(y + 10, LOW);
  delay(1);
}
void show_num(void)//
{
  unsigned char i, j, data;
  for (i = 0; i < 8; i++)
  {
    data = Text[i];
    for (j = 0; j < 8; j++)
    {
      if (data & 0x01)Draw_point(j, i);
      data >>= 1;
    }
  }
}
void setup() {
  int i = 0 ;
  for (i = 2; i < 18; i++)
  {
    pinMode(i, OUTPUT);
  }
  clear_();
}
void loop()
{
  show_num();
}
void clear_(void)//clear screen
{
  for (int i = 2; i < 10; i++)
    digitalWrite(i, LOW);
  for (int i = 0; i < 8; i++)
    digitalWrite(i + 10, HIGH);
}
```

{% file src="/files/3Ta7P8Tv6N4C3jhLNdav" %}


# Controlling Stepper Motor With Remote

In this lesson, you will learn a fun and easy way to control a stepper motor from a distance using an IR remote control.

### **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 UNO R3.

The IR sensor is connected to the UNO R3 directly since it uses almost no power.

### **Component Required**

* 1 x Arduino UNO R3
* 1 x IR receiver module
* 1 x IR remote
* 1 x ULN2003 stepper motor driver module
* 1 x Stepper motor
* 7 x F-M wires (Female to Male DuPont wires)
* 2 x M-M wire (Male to Male jumper wire)

### **Connection Diagram**

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2FfV3LaEGaOGOjFxEYX3qW%2Fmotor-ir-remote-Connection%20Diagram.png?alt=media\&token=1e2b4508-35dc-47b7-ab14-b61629701075)

### **Wiring schematic**

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2FSWCVANkIqn4PnKjNK7NB%2Fmotor-ir-remote-Wiring%20schematic.png?alt=media\&token=cfa06036-14a0-4f33-9fc7-2a989bba8fee)

### **Physical wiring diagram**

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2FreukG9c73pFu8SXXmY6p%2Fmotor-ir-remote-Physical%20wiring%20diagram.png?alt=media\&token=5844cf18-79a7-4f24-b805-9e5387feee82)

### **Library Files Required**

{% hint style="info" %}
Please include the **Stepper.zip** and **IRremote.zip** to your **Library**. Download the files below
{% endhint %}

{% file src="/files/jgMdw5KACzb13IBBPWQ4" %}

{% file src="/files/eoWeDDrGOyJ2Zxu4sGfp" %}

### Code

```
#include "Stepper.h"
#include "IRremote.h"

/*----- Variables, Pins -----*/
#define STEPS  32   // Number of steps per revolution of Internal shaft
int  Steps2Take;  // 2048 = 1 Revolution
int receiver = 12; // Signal Pin of IR receiver to Arduino Digital Pin 6

/*-----( Declare objects )-----*/
// Setup of proper sequencing for Motor Driver Pins
// In1, In2, In3, In4 in the sequence 1-3-2-4

Stepper small_stepper(STEPS, 8, 10, 9, 11);
IRrecv irrecv(receiver);    // create instance of 'irrecv'
decode_results results;     // create instance of 'decode_results'

void setup()
{
  irrecv.enableIRIn(); // Start the receiver
}

void loop()
{
  if (irrecv.decode(&results)) // have we received an IR signal?
  {
    switch (results.value)
    {
      case 0xFFE01F:  // “—”button pressed
        small_stepper.setSpeed(500); //Max seems to be 500
        Steps2Take  =  2048;  // Rotate CW
        small_stepper.step(Steps2Take);
        delay(2000);
        break;

      case 0xFFA857: // “+” button pressed
        small_stepper.setSpeed(500);
        Steps2Take  =  -2048;  // Rotate CCW
        small_stepper.step(Steps2Take);
        delay(2000);
        break;
    }
    irrecv.resume(); // receive the next value
    digitalWrite(8, LOW);
    digitalWrite(9, LOW);
    digitalWrite(10, LOW);
    digitalWrite(11, LOW);
  }


}/* --end main loop -- */
```

{% file src="/files/BGdXncgrhvFl3TVvH1qN" %}


# Super Starter Kit

This is a cost-effective starter kit with newest Type C USB development board, including 830 points breadboard, ultrasonic sensor and joystick module and many more.

This kit can be purchased from [RoboFactory SA](https://www.robofactory.co.za/arduino-kits/394-arduino-uno-r3-super-starter-kit.html)

<figure><img src="https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fd3Z0mCRGrCpcjay450g9%2Fimage.png?alt=media&amp;token=b3fbb766-aef2-4595-9cdb-a9cfacf61326" alt=""><figcaption></figcaption></figure>

[Tutorials](/arduino-kits/super-starter-kit/tutorials)


# Tutorials

Download the Tutorials below

{% file src="/files/q237xfo6qZrjTkC0zgDO" %}


# Best Beginner Kit for Arduino

Get to learn the world of electronics and coding with the Best Beginner Kit for Arduino. It is specially designed with high quality components that is clearly marked. The kit includes 17 tutorial cards

This kit can be purchased from [RoboFactory SA](https://www.robofactory.co.za/arduino-kits/627-best-beginner-kit-for-arduino.html).&#x20;

<figure><img src="https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2FPggaPCSi3nfEW4aZxhHE%2Fimage.png?alt=media&amp;token=39ee2b01-b4c9-479d-9eb9-6e9727304936" alt=""><figcaption></figcaption></figure>


# Tutorials

You can download the full tutorials [here](https://cdn.robofactory.co.za/best-beginner-kit%2FBest%20Beginner%20Kit%20for%20Arduino%20Tutorial.pdf)


# Uno R3 RFID Kit

The Arduino Uno R3 RFID system learning kit is based on the Open source development board. Suitable for beginners to learn Intelligent Electronic Device (IED) programming and STEM application. The kit includes a variety of highly integrated sensors and electronic components.

### Component List

<figure><img src="https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2FzD53H6gBXTXos1EOdi8b%2Fimage.png?alt=media&amp;token=db18212f-e7be-44d0-91f8-f102ab63f36d" alt=""><figcaption></figcaption></figure>

### Tutorials

{% file src="/files/JVMglHVlQaDVwr62YTsq" %}


# WIFI ESP32 IOT Kit

content coming soon


# Arduino School STEM Kit

content coming soon


# Arduino Ultimate Starter Kit

content coming soon


# Beginner Lessons

Learn the basics of Arduino using block programming. Great lessons to get your started.

## Components needed

* Arduino compatible UNO R3 development board
* USB cable
* Mini 300TP breadboard
* Red, Green and Yellow LED's
* Push button switch
* Passive buzzer (piezo buzzer)
* Resistors
* Jumper Wire

## Lessons

* [Setting up mBlock](/blocking-coding-lessons/beginner-lessons/setting-up-mblock)
* [Blinking and LED](/blocking-coding-lessons/beginner-lessons/blinking-an-led)
* [LED Chasing](/blocking-coding-lessons/beginner-lessons/led-chasing)
* [Traffic Light](/blocking-coding-lessons/beginner-lessons/traffic-signal)
* [Using a Buzzer](/blocking-coding-lessons/beginner-lessons/buzzer)
* [Buzzer and Push Button](/blocking-coding-lessons/beginner-lessons/buzzer-+-push-button)
* [LED and Push Button](/blocking-coding-lessons/beginner-lessons/led-+-push-button)


# Setting up mBlock

## What will we do <a href="#what-will-we-do" id="what-will-we-do"></a>

In this lesson we will show you how to setup and use the the web based mBlock IDE.

To understand more about mBlock, please visit this [link](https://www.mblock.cc/doc/en/quick-start/quick-start.html)​

## Launching mBlock <a href="#launching-mblock" id="launching-mblock"></a>

Go to [https://ide.mblock.cc/](https://ide.mblock.cc) on a **chrome** browser.

Under the devices section, click **Add** and select **Arduino Uno** from the selection list

![](https://gblobscdn.gitbook.com/assets%2F-LskXJjPT2bXMIodrtZq%2F-M8tymYL7eqowqUT33a2%2F-M8u2Zj3e_-fENm16h0l%2Fmblock1.png?alt=media\&token=df1e9ea9-99d2-421d-ac5b-71dd7d67c316)

![](https://gblobscdn.gitbook.com/assets%2F-LskXJjPT2bXMIodrtZq%2F-M8tymYL7eqowqUT33a2%2F-M8u2l78BQXE_uQOUFi9%2Fmblock2.png?alt=media\&token=402bc4fc-635c-4295-bc68-28c9aeb3dec2)

## Install the WebLink <a href="#install-the-weblink" id="install-the-weblink"></a>

Install the **WebLink** and following the details in this link <https://www.mblock.cc/doc/en/part-one-basics/mlink-quick-start-guide.html>​

Once installed, test that you can connect to your device.

## Connect your Arduino Uno <a href="#connect-your-arduino-uno" id="connect-your-arduino-uno"></a>

Connect you Arduino to your PC using the USB Cable

Click in the **Connect** buttonClick on Connect

![](https://gblobscdn.gitbook.com/assets%2F-LskXJjPT2bXMIodrtZq%2F-M8u2n0RTB0Hwt41tfbr%2F-M8u92QkE7ucq6A-1lMw%2Fmblock3.png?alt=media\&token=5042732d-eead-4bc9-b0b8-28c439d6dac5)

Select on the check box and select your device

![](https://gblobscdn.gitbook.com/assets%2F-LskXJjPT2bXMIodrtZq%2F-M8u2n0RTB0Hwt41tfbr%2F-M8u9CRaWgocax9xbyCK%2Fmblock4.png?alt=media\&token=97935f7f-0187-4c16-9197-a8b204e7f36f)

## Troubleshooting <a href="#troubleshooting" id="troubleshooting"></a>


# Blinking an LED

## What will we do

Lets start by making our LED blink on and off. The way to make an LED blink is to follow this sequence of code instructions over and over again:

* Turn the LED on
* Delay for a period of time
* Turn the LED off
* Delay for a period of time

## Parts List

You will need the following parts:

* **1x** arduino uno
* **1x** arduino USB Cable
* **1x** Breadboard
* **2x** Jumper Wire
* **1x** LED
* **1x** Resistor

## Wiring it up

This example we use a red LED but you can use any colour LED you prefer.

![](https://gblobscdn.gitbook.com/assets%2F-LskXJjPT2bXMIodrtZq%2F-M6KHBUnLmM-6jNl9924%2F-M6KHTrk_yIYi1duHidc%2Farduino%20-%20blinking%20led.png?alt=media\&token=57c44282-de3a-45f4-ada5-2c9e67a912de)

Ensure that the LED are the right way around, with the longer positive leads (anodes) to the left.

## mBlock IDE

Launch the mBlock IDE (<https://ide.mblock.cc/#/>) and select the Arduino Uno Device.

## Install the KidsCode Extension

Click on the **Extensions** button

![](https://gblobscdn.gitbook.com/assets%2F-LskXJjPT2bXMIodrtZq%2F-M8u9rabTwe6GN62i0bu%2F-M8uBMB0jm_-3yp5yWJs%2Fmblock5.png?alt=media\&token=b88847e5-13c9-4b6f-9cea-7c93e8f5770b)

Search for **Kids Code** on the extension popup and **Add** the **Kids Code** extension

![](https://gblobscdn.gitbook.com/assets%2F-LskXJjPT2bXMIodrtZq%2F-M8u9rabTwe6GN62i0bu%2F-M8uB_6GFdx-58Cn_h6N%2Fmblock6.png?alt=media\&token=92d5573d-0ad6-4c39-bcf3-2183e2659160)

You will see the Kids Code blocks at the bottom.

![](https://gblobscdn.gitbook.com/assets%2F-LskXJjPT2bXMIodrtZq%2F-M8u9rabTwe6GN62i0bu%2F-M8uBikg1oFHvXTBDbgm%2Fmblock7.png?alt=media\&token=4d43856f-40d7-463b-b974-741962c53ab9)

## Block Coding

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-007109c32fd425ecfcf63c58af539bfff5890cb5%2Fimage.png?alt=media)

{% embed url="<https://ide.mblock.cc/#/?cloudProjectId=262516>" %}


# LED Switching

## What will we do

In this lesson we will learn how to switch two LED’s on and off one at a time. It will work in the following sequence

* Turn Red LED ON
* Wait for 1 second
* Turn Red LED OFF and Yellow LED ON
* Wait for 1 second

Run the above code for 8 times.

## Parts List

You will need the following parts:

* **1x** arduino uno
* **1x** arduino USB Cable
* **1x** Breadboard
* **3x** Jumper Wire
* **2x** LED (RED and Yellow)
* **2x** Resistor

## **Wiring it up**

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-4c09458d4aff6095615d0d650232d0a34f650328%2Fimage.png?alt=media)

Ensure that the LED are the right way around, with the longer positive leads (anodes) to the left.

## mBlock IDE

Launch the mBlock IDE (<https://ide.mblock.cc/#/>) and select the Arduino Uno Device and install the [Kids Code Extension](/blocking-coding-lessons/beginner-lessons/blinking-an-led#install-the-kidscode-extension) \*\*\*\*

## Block Coding <a href="#block-coding" id="block-coding"></a>

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-e6b201398bcf0c6023037547abaa1b89d4685025%2Fimage.png?alt=media)

{% embed url="<https://ide.mblock.cc/#/?cloudProjectId=262531>" %}


# LED Chasing

## What will we do

In this lesson we will add one more LED and create a light chasing effect. We will use 3 of the same color LED’s\*\*.\*\*

The sequence for the code will be as follows

* Turn LED1 ON
* Wait for 0.5 second
* Turn LED1 OFF and LED2 ON
* Wait for 0.5 second
* Turn LED2 OFF and LED3 ON
* Wait for 0.5 second
* Turn LED2 ON and LED3 OFF
* Wait for 0.5 second
* Turn LED2 OFF and LED1 ON

## Parts List <a href="#parts-list" id="parts-list"></a>

You will need the following parts:

* **1x** arduino uno
* **1x** arduino USB Cable
* **1x** Breadboard
* **3x** Jumper Wire
* **3x** LED (all same colour)
* **3x** Resistor

## **Wiring it up** <a href="#wiring-it-up" id="wiring-it-up"></a>

![](https://gblobscdn.gitbook.com/assets%2F-LskXJjPT2bXMIodrtZq%2F-M8uFvpZUQF6EAMa4V3F%2F-M8uHeu1tiNQC2aPMR7m%2Fled%20chasing.png?alt=media\&token=a35967f3-cd03-42e7-b9a2-e17f377c8af4)

Ensure that the LED are the right way around, with the longer positive leads (anodes) to the left.

## mBlock IDE <a href="#mblock-ide" id="mblock-ide"></a>

Launch the mBlock IDE (<https://ide.mblock.cc/#/>) and select the Arduino Uno Device and install the [Kids Code Extension](/blocking-coding-lessons/beginner-lessons/blinking-an-led#install-the-kidscode-extension)

## Block Coding <a href="#block-coding" id="block-coding"></a>

![](https://gblobscdn.gitbook.com/assets%2F-LskXJjPT2bXMIodrtZq%2F-M8uIg8-I0DOXGuIqp1S%2F-M8uIrp0mx1HIy1Qd1Dv%2Fled%20chasing%20-%20code.png?alt=media\&token=3c64d355-5f92-4109-a91c-44d5e5439303)

{% embed url="<https://ide.mblock.cc/#/?cloudProjectId=262546>" %}


# Traffic Signal

## What will we do

This example uses three LEDs to make a model traffic light signal. You can use all red LEDs if you like, but its more realistic if you use red, yellow and green.

The LEDs cycle around in the sequence red, green, yellow and then back to red again

## Parts List

You will need the following parts:

* **1x** arduino uno
* **1x** arduino uno USB Cable
* **1x** Breadboard
* **4x** Jumper Wire
* **1x** Red LED
* **1x** Yellow LED
* **1x** Green LED
* **3x** Resistors

## Wiring it up

To add the extra LEDs and resistors, wire them up as shown in the breadboard layout below.

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-e1b44f4459263d5de76cd8835b0c9b9f16d89fe3%2Fimage.png?alt=media)

Ensure that the LEDs are the right way around, with the longer positive leads (anodes) to the left.

## How does it work

Think of how a traffic light works.

* it starts from RED
* then turns to GREEN
* then turns YELLOW
* and back to RED

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-0f062a46bc94404dd32d2ea5155ca7b33f5b851b%2Fimage.png?alt=media)

Think about the how long the light stays on before it changes to the next colour

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-a0b3d68708173db2d1d7b01b85a4298d7c925883%2Fimage.png?alt=media)

This time that it takes before the light changes is called a WAIT in coding. So the program will **WAIT** for a specific number of seconds before the next light changes to the next colour

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-1a15f30629d96e771755ee575da1f960b426c3f9%2Fimage.png?alt=media)

In order to turn the light ON or OFF in code, we say that if we want the light on then we need to set it to HIGH and if we want the light OFF we setup it to LOW.

So to change the traffic lights we say

* to make the light ON, we set it to HIGH
* to make the light OFF, we set it to LOW

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-e113268eb6d5595fc981eb7823dbe9f20f076201%2Fimage.png?alt=media)

If you look at the wiring diagram above, you will see that we connected it as follows

* we connected **DIGITAL PIN 7** **(D7)** to the **RED** light
* we connect **DIGITAL PIN 6 (D6)** to the **YELLOW** light
* we connect **DIGITAL PIN 5 (D5)** to the **GREEN** light

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-0989e08ee0f52244b4f28db67f83df29fd046472%2Fimage.png?alt=media)

So In order for the program to work we will do the following

* set **D7** to **HIGH** (red light)
* set **D6** to **LOW** (yellow light)
* set **D5** to **LOW** (green light)
* ***WAIT** for 10 seconds*
* set **D7** to **LOW** (red light)
* set **D6** to **LOW** (yellow light)
* set **D5** to **HIGH** (green light)
* ***WAIT** for 10 seconds*
* set **D7** to **LOW** (red light)
* set **D6** to **HIGH** (yellow light)
* set **D5** to **LOW** (green light)
* ***WAIT** for 1 seconds*

## Block Coding <a href="#block-coding" id="block-coding"></a>

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-a018313a02b96a107a82dffbc22c2284dfbdc59c%2Fimage.png?alt=media)

{% embed url="<https://ide.mblock.cc/#/?cloudProjectId=262563>" %}


# Buzzer

## What will we do

This example will show you how to wire up a buzzer and play a sound.

## Parts List

You will need the following parts:

* **1x** arduino uno
* **1x** arduino uno USB Cable
* **1x** Breadboard
* **2x** Jumper Wire
* **1x** Piezo Buzzer

## Wiring it up <a href="#wiring-it-up" id="wiring-it-up"></a>

![](https://gblobscdn.gitbook.com/assets%2F-LskXJjPT2bXMIodrtZq%2F-M6PUI7Rw78wyY-sriVE%2F-M6PWD-XaglCAWCEkGyi%2Farduino%20-%20buzzer.png?alt=media\&token=71e7e155-738a-4da4-b724-11a057681f3c)

Ensure that the buzzer are the right way around, with the positive lead to the left.

## Block Coding <a href="#block-coding" id="block-coding"></a>

![](https://gblobscdn.gitbook.com/assets%2F-LskXJjPT2bXMIodrtZq%2F-M6PHk-NPMejaejAmPdb%2F-M6PT6ONvxHtboYJs59o%2Farduino%20-%20buzzer%20code.png?alt=media\&token=a3143a95-7e95-4eac-953f-ee84e0d82b1a)

{% embed url="<https://ide.mblock.cc/#/?cloudProjectId=218898>" %}


# Buzzer + Push Button

## What will we do

This example is an extension of the [buzzer tutorial](/blocking-coding-lessons/beginner-lessons/buzzer). We will now add a push button to restart the buzzer.

## Parts List

You will need the following parts:

* **1x** arduino uno
* **1x** arduino uno USB Cable
* **1x** Breadboard
* **4x** Jumper Wire
* **1x** Piezo Buzzer
* **1x** Push button switch
* **1x** Resistors

## Wiring it up <a href="#wiring-it-up" id="wiring-it-up"></a>

![](https://gblobscdn.gitbook.com/assets%2F-LskXJjPT2bXMIodrtZq%2F-M6PWGATcwRqUb5i6zZm%2F-M6PYfnVUVQ1tHgKcsws%2Fbuzzer%20%2B%20push%20button.png?alt=media\&token=eefd7647-076e-4858-9a3d-aff7f0dfbe47)

Ensure that the buzzer are the right way around, with the positive lead to the left.

## Block Coding <a href="#block-coding" id="block-coding"></a>

![](https://gblobscdn.gitbook.com/assets%2F-LskXJjPT2bXMIodrtZq%2F-M6PWGATcwRqUb5i6zZm%2F-M6PYjl7mKa65uzfdzsT%2Fbuzzer%20%2B%20push%20button%20code.png?alt=media\&token=c3d34839-eff6-44fb-9506-338bd13330ba)

{% embed url="<https://ide.mblock.cc/#/?cloudProjectId=218945>" %}


# LED + Push Button

This example uses 2 LEDs and a switch to make an ON/OFF door lock. When the RED LED is ON then the door lock is closed. When you press the BUTTON, door will open and the RED LED will be off and the GREEN LED will be ON.

## Parts List

You will need the following parts:

* **1x** arduino uno
* **1x** arduino uno USB Cable
* **1x** Breadboard
* **5x** Jumper Wire
* **1x** Red LED
* **1x** Green LED
* **1x** Push button switch
* **3x** Resistors

## Wiring it up <a href="#wiring-it-up" id="wiring-it-up"></a>

![](https://gblobscdn.gitbook.com/assets%2F-LskXJjPT2bXMIodrtZq%2F-M6P4jbJShCfxTkf9fUe%2F-M6PGee2UzMUQaU1Zzhm%2Farduino%20-%20push%20button.png?alt=media\&token=6560d5d4-3c82-4078-b5bc-0189c83b02c0)

Ensure that the LEDs are the right way around, with the longer positive leads (anodes) to the left.

## Block Coding <a href="#block-coding" id="block-coding"></a>

![](https://gblobscdn.gitbook.com/assets%2F-LskXJjPT2bXMIodrtZq%2F-M6M10kB3c5xeZ-_KHRp%2F-M6M1KjiCGa6nTusYnSj%2Farduino%20-%20push%20button%20code.png?alt=media\&token=2fbb324d-a51c-496c-b197-da811971fa02)

{% embed url="<https://ide.mblock.cc/#/?cloudProjectId=218454>" %}


# 37-in-1 Sensor Kit

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-ab715df33ef489f1872dcbc26fe7991c5bfeb32f%2Fimage.png?alt=media)


# Joystick

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-b3d296389f4ede893e90114b9ecf56336e12a085%2Fimage.png?alt=media)

**Introduction**

Lots of robot projects need joystick. This module provides an affordable solution. By simply connecting to two analog inputs, the robot is at your commands with X, Y control. It also has a switch that is connected to a digital pin. This joystick module can be easily connected to Arduino by IO Shield.

**Specification**

* Supply Voltage: 3.3V to 5V
* Interface: Analog x2, Digital x1

**Connection Diagram**\\

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-ef191c5cc721cc034f1a282b3ac67b7c28e8a4d7%2Fimage.png?alt=media)

**Sample Code**

```
int JoyStick_X = 0; //x
int JoyStick_Y = 1; //y
int JoyStick_Z = 3; //key
  void setup() 
{
  pinMode(JoyStick_Z, INPUT); 
  Serial.begin(9600); // 9600 bps
}
void loop() 
{
  int x,y,z;
  x=analogRead(JoyStick_X);
  y=analogRead(JoyStick_Y);
  z=digitalRead(JoyStick_Z);
  Serial.print(x ,DEC);
  Serial.print(",");
  Serial.print(y ,DEC);
  Serial.print(",");
  Serial.println(z ,DEC);
  delay(100);
}
```

**Result**

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-46c6487cd40b285e8dfab1f8301b384b37aac6ee%2Fimage.png?alt=media)

Wiring well and uploading the code, open the serial monitor and set the baud rate to 9600, push the joystick, you will see the value shown below.

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-4d8fd8b05e36fd56c6a403943e9118eea8e156ab%2Fimage.png?alt=media)


# Relay

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-9dc13978df7e0509e167f532df8bdba2423f8587%2Fimage.png?alt=media)

**Introduction**\
This single relay module can be used in interactive projects. It is active HIGH level. This module uses SONGLE 5v high-quality relay.\
It can also be used to control lighting, electrical and other equipment.\
The modular design makes it easy to expand with the Arduino board (not included). The relay output is by a light-emitting diode. It can be controlled through digital IO port, such as solenoid valves, lamps, motors and other high current or high voltage devices.

**Specification**

* Type: Digital
* Rated current: 10A (NO) 5A (NC)
* Maximum switching voltage: 150VAC 24VDC
* Digital interface
* Control signal: TTL level
* Rated load: 8A 150VAC (NO) 10A 24VDC (NO), 5A 250VAC (NO/NC) 5A 24VDC (NO/NC)
* Maximum switching power: AC1200VA DC240W (NO) AC625VA DC120W (NC)
* Contact action time: 10ms

**Connection Diagram**\
Firstly you need to prepare the following parts by yourself before testing.

* Arduino Board\*1
* Single relay module\*1
* LED module \*1
* USB Cable\*1
* Jumper Wire\*8

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-67bea793765e845311b867554f94c2381d7b564c%2Fimage.png?alt=media)

**Sample Code**\
Copy and paste the code below to Arduino software.\\

```
int Relay = 8;
  void setup()
{
  pinMode(13, OUTPUT);         //Set Pin13 as output
  digitalWrite(13, HIGH);     //Set Pin13 High
  pinMode(Relay, OUTPUT);     //Set Pin3 as output
}
void loop()
{
          digitalWrite(Relay, HIGH);   //Turn off relay
          delay(2000);
          digitalWrite(Relay, LOW);    //Turn on relay
          delay(2000);
}
```

**Test Result**\
This relay module is active HIGH level.\
Wire it up well, powered up, then upload the above code to the board.\
You will see the relay is turned on（ON connected, NC disconnected）for two seconds, then turned off for two seconds（NC closed,ON disconnected）, repeatedly and circularly.\
When the relay is turned on, external LED is on. If relay is turned off, external LED is off.

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-69d81d047134cca330ac1e9aad52c0cd4e00ba27%2Fimage.png?alt=media)


# Big Sound

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-b63dcf46d5af721e466de24ac8b42210b6d0a77a%2Fimage.png?alt=media)

**Introduction**\
The keyestudio microphone sensor is typically used in detecting the loudness in ambient environment. The Arduino can collect its output signal by analog input interface.\
The S pin is analog output, that is voltage signal real-time output of microphone. The sensor comes with a potentiometer, so that you can turn it to adjust the signal gain.\
It also has a fixed hole so that you can mount the sensor on any other devices. You can use it to make some interactive works, such as a voice operated switch.

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-2303f6e7bebb7af1535976056ca51d0b7467d4fd%2Fimage.png?alt=media)

**Specification**

* Operating voltage: 3.3V-5V（DC）
* Operating current: <10mA
* Interface：3PIN
* Output signal: Analog

**Connection Diagram**

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-bdaf2f380db75ff38cd958d48b43daf29a9b0967%2Fimage.png?alt=media)

**Sample Code**\\

```
int sensorPin =A0 ;  // define analog port A0
int value = 0;    //set value to 0
void setup() 
{
 Serial.begin(9600); //set the baud rate to 9600
} 
void loop() 
{
value = analogRead(sensorPin);  //set the value as the value read from A0
Serial.println(value, DEC);  //print the value and line wrap
delay(200);  //delay 0.2S
} 
```

\
**Test Result**\
Connect it up and upload the code successfully, then open the serial monitor on the right upper corner of Arduino IDE.\
The analog value will pop up on the monitor window. The greater the sound, the greater the analog value is.

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-262556015d8a70ae07886642775906f56b5c3b43%2Fimage.png?alt=media)


# Small Sound

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-099dc8cd42f2cc20947003fd888d3b8af3f1ba69%2Fimage.png?alt=media)

A microphone module with a small electret capsule. Output ‘DO’ (active high) is switched when the sound level exceeds a preset level. A pot allows adjustment of the level. The analog output signal is available at the ‘AO’ pin. Except for the smaller size of the capsule and its lower sensitivity the module is identical to the ‘Big Sound’ module.


# Tracking

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-12c41e04f34ded40b34213ae6d30e61cfb1a1ee7%2Fimage.png?alt=media)

IR light reflection switch, useful for obstacle avoidance or line following on models that move around the floor. An obstacle in front of the sender/receiver diodes will cause the ‘out’ pin to be pulled low (active low). A pot allows adjustment of the circuit’s sensitivity. The detection distance can be up to approximately 1 cm.


# Avoid

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-02ffbbcd7d6e9d94f4383ae5d9f4622a750bddfc%2Fimage.png?alt=media)

IR-reflection sensor, useful for obstacle avoidance applications. When an obstacle is in front of the IR sender/receiver the ‘Out’ pin is switched low (active low). The circuit sensitivity can be adjusted with a pot. The obstacle detection distance can be adjusted up to approximately 7cm. An enable (EN) jumper can be fitted for continuous operation. Removal of the EN jumper allows an external logic signal (at the EN pin) to switch the detector on and off (low = active, high = off).


# Flame

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-5d72908b3005c6b99a3878e53b3a6b7828714b8d%2Fimage.png?alt=media)

A sensor module to detect flames. The spectral sensitivity of the sensor is optimized to detect emissions from naked flames. The output signal ‘DO’ is pulled high (active high) when a flame is detected. The switching threshold is adjustable via a preset pot. An analog output signal from the sensor is available at pin ‘AO’.

* Typical spectral sensitivity: 720-1100nm
* Typical detection angle: 60°


# Linear Hall Sensor

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-20c4b8c6691adf5cd1ccf64de22ad95d111fcfa8%2Fimage.png?alt=media)

Linear Hall Sensor module to detect the presence of a magnetic field near the sensor. Variables such as field strength, polarity and position of the magnet relative to the sensor will affect point at which the ‘DO’ output switches to a high level (i.e. active high). The circuit sensitivity can be adjusted with a pot. An analog output signal from the sensor is available at pin ‘AO’.


# Touch

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-e533487df6f8230716ae31f5b23f1fe7d55f03e6%2Fimage.png?alt=media)

Touch sensitive switch. Touching the sensor pin produces an output at the ‘DO’ pin. The output is not a clean signal but includes 50 Hz mains induced signals (‘mains hum’). The output signal is ‘active high’ and the circuit sensitivity can be adjusted with a pot. An analog output signal from the sensor is available at pin ‘AO’.


# Digital Temperature

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-cb06a5b114fa72160f5a868b56dd49d9b4d453f9%2Fimage.png?alt=media)

Temperature sensing module using an NTC thermistor. The output signal at ‘DO’ switches high when the preset (adjustable) temperature is reached. An analog output signal from the sensor is available at pin ‘AO’


# Buzzer

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-7765055f1a3e32082e102c25d98a535b24ee7d36%2Fimage.png?alt=media)

Electronic buzzer for 5 V operation. **Ensure correct polarity!! Positive** supply to the ‘-’ pin and ground to the ‘S’ pin! Data: Typical operating frequency 4000Hz at 80dB min, 5V DC at 5mA typical TMB12A05 or equivalent.

Tip to avoid mix up: The buzzer housing is slightly taller than the loudspeaker housing and has a label showing the + pin ident.


# Passive Buzzer

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-12f67556ffccafb4041e3acbfa23d4c2cb92e9c3%2Fimage.png?alt=media)

Mini loudspeaker module ca. 16 Ohm Impedance, (maximum continuous current through the speaker coil is approximately 25 mA.) Don’t mix this one up with the buzzer module! The outer two pins connect to the speaker. Polarity is unimportant.

Tip to avoid mix up: The loudspeaker housing is not as tall as the buzzer housing.


# RGB LED

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-715a04e0fd2a5a911e73c75df455dcf8403981d2%2Fimage.png?alt=media)

RGB-LED with clear lens and built-in 150 ohm series resistor for 5 V operation. The PCB printing is incorrect, it shows the blue and red connections switched. The LED has a common cathode (the ‘-‘ Pin).


# SMD RGB

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-060f7340f96a8f3cd75f2c6ac46624570585c9d6%2Fimage.png?alt=media)

RGB-LED with an SMD housing and no series resistor. The PCB printing is incorrect, it shows the green and red connections switched. The LED has a common cathode (the ‘-‘ pin). A suitable resistor value would be 220 ohms.


# Two-Color 5mm

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-bab5dffba8af77f48ebe96d423c7858ad0076f8c%2Fimage.png?alt=media)

The 5mm LED has a common cathode connected to the ‘-‘ pin on the PCB. The centre pin connects to the red anode and the ‘S’ pin connects to the green anode. No series resistor is included in the circuit. A suitable value for low voltage operation would be 220 ohms.


# Two Color 3mm

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-cd39f5b17e012e15b74160ee13d86694bf1b55ba%2Fimage.png?alt=media)

The 3mm bi-color LED has a common cathode (- pin), connected with the ‘-’ pin on the PCB. The centre pin activates the red light and the ‘S’ pin the green light. No series resistor is included in the circuit. A suitable value for low voltage operation would be 220 ohms.


# Reed Switch

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-b278f229aeab5dff1eb851fe91a01a51a7c87c7d%2Fimage.png?alt=media)

This reed switch offers an analog as well as a digital interface. The ‘G’ pen is connected to GND, the ‘+’ pen to 5V DC, the ‘AO’ pen offers the analog output while the ‘DO’ offers the digital output. A potentiometer is used as a pull up resistor.


# Mini Reed

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-f103020e2e0ae3250ad7260979e2d48e6f2f0ef5%2Fimage.png?alt=media)

The reed switch is connected between the two outer pins on the PCB. Without a magnetic field the contacts remain open. A built-in 10 K ohm resistor is connected between the centre pin and the ‘S’ pin. It can be used as a pull up or pull down resistor.


# Heartbeat

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-5c1fba93b02abee43e4238ca54b8ed9dc3638999%2Fimage.png?alt=media)

This module consists of an IR-LED and a photo transistor which can be used to read a pulse when a fingertip is positioned between the LED and photo transistor. The module requires additional external circuitry. A 330 ohm series resistor for the LED is included. The 5 V supply connects to the centre pin, ground to the ‘-’ pin. The photo transistor signal is available on the ‘S’ pin which has a built-in pullup resistor.


# 7 color flash

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-70224982a51b315f322881a63af727932f90f3b3%2Fimage.png?alt=media)

Clear 5mm LED for direct operation from 5V. The LED color automatically cycles through a seven-color sequence. The 5 V supply connects to the ‘S’ pin and ground on the centre pin.


# Laser emitter

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-5bb2bd53186b4f50c7d2ff0ae92d945dfcb113e2%2Fimage.png?alt=media)

Red Laser module for direct connection to a 5 V supply. Connect the 5 V supply to the ‘S’ pin and ground to the ‘-’ pin. Transmission wavelength: 650nm


# PCB mounted push Button

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-5b755da52d7cc3ca30a8fff4756363631e99a9ef%2Fimage.png?alt=media)

A built-in 10 K ohm resistor is connected between the centre pin and the ‘S’ pin and can be used as a pull up or pull down resistor. The push button connects the two outer pins.

The Button.h library (available from Arduino) is suitable for use with this.


# Shock switch

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-c406b6e9607c84837081fe7a6f5f872e3be5917c%2Fimage.png?alt=media)

A built-in 10 K ohm resistor is connected between the centre pin and the ‘S’ pin and can be used as a pull up or pull down resistor. The switch contacts connect to the two outer pins.


# Rotary encoder

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-78388cb5319052d8c8b57039bc6ea311bd37e816%2Fimage.png?alt=media)

Rotary encoder useful for making an electronic pot etc. Connection idents are printed on the PCB.


# Light Cup

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-fe5fa7d03bd28ea9cd01c27a7c379d4dc02dfc92%2Fimage.png?alt=media)

This module incorporates a mercury tilt switch and clear red LED. ‘G’ is the common connection to the LED cathode and one terminal of the switch. ‘S’ is the other switch contact and ‘L’ connects to the LED anode (a series resister is required for the LED, 220 ohms for example). The ‘+’ pin connects to a 10 K ohm pullup resistor connected to ‘S’ of the switch.


# Tilt Switch

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-1010d50dddb522cf83c2012c22c3676a2840e644%2Fimage.png?alt=media)

Mercury tilt switch which makes or breaks depending on its attitude.


# Rolling ball tilt switch

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-65265a028d2ebdf17c8708cf8829d552afb833a5%2Fimage.png?alt=media)

A built-in 10 K Ohm resistor connected between the middle and ‘S’ pin is available for pull up or pull down use. The switch contacts connect to the two outer pins. Load switching max: 12VDC 50mA


# Photoresistor

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-a8c97dfeec9aead3e15b2ba9c3c808c8ff542a3c%2Fimage.png?alt=media)

LDR (Light Dependant Resistor). Dark resistance >20M Ohm, light <80 Ohm. The two outer pins connect to the LDR. A fixed 10 K ohm resistor connected between the middle pin and the ‘S’ pin is included on the module. This simplifies the building of a measurement bridge circuit.


# Temp and Humidity

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-c663bac715308603138739c506b30b5ece31e1cd%2Fimage.png?alt=media)

A module with a temperature/humidity sensor type DHT11, Temperature range : 0 - 50°C (+/-2°C), Rel. humidity: 20-95% (+/-5%), Supply voltage: 3 to 5.5V. With a built-in 10 K ohm pullup resistor. Library: DHT.h


# Analog Hall

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-625a5f08a8ab72302a104ca4e90865a2554999f3%2Fimage.png?alt=media)

The Hall-Sensor-Switch (bipolar) module features a 44E311, 3144EUA-S or 3144LUA-S sensor together with an LED and resistor. The LED switches on when a magnetic field is detected. The ground pin is marked ‘-’, centre pin is +5 V supply (Vs) and the output signal is on the ‘S’ pin.


# Hall Magnetic

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-ed7524de72ae783ae78508fabf17ff91a2d20c91%2Fimage.png?alt=media)

A Hall sensor module with analog output signal. The ground pin is marked ‘-’, centre pin is +5 V supply (Vs) and the output signal is on the ‘S’ pin.


# Temp

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-de1d7bd4374b9a7d6c173a6e58db1abdf64d440a%2Fimage.png?alt=media)

A module with a digital ‘One Wire’ temperature sensor (DS18B20). A 4.7K ohm pullup resistor is included for the bus signal. Additional sensors can be added to the bus and individually addressed. Only one pullup resistor should be connected to the bus, irrespective of the number of sensors connected.

* Temperature range: -55 to +125°C
* Typical accuracy: 0.5°C
* Resolution: 9-12Bit, depending on the program


# Analog Temp

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-8c3296f7e4d27db726ae2773cb552030b3fb3086%2Fimage.png?alt=media)

NTC Temperature sensor module. The sensor resistance is approximately 10 k ohm at room temperature. The NTC sensor is connected between the two outer pins. A fixed 10 K ohm resistor connected between the middle pin and the ‘S’ pin is included on the module. This simplifies the building of a measurement bridge circuit.

* Temperature range: -55°C to +125°C
* Accuracy: +/- 0.5°C


# IR Emission

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-ffd2c943fc6d38b7545089daab3a365699744a17%2Fimage.png?alt=media)

The IR-LED can be used to build a light barrier or an IR remote control signal transmitter.


# IR Receiver

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-863453e9cdcc6e2d767d85425078da008e60ceb1%2Fimage.png?alt=media)

Infrared sensor type 1838 for use with 38KHz IR signals.

* Supply voltage: 2.7 to 5.5 V
* Frequency: 37.9 KHz
* Receiver range: 18m (typical)
* Receiving angle: 90°

Library: <https://github.com/shirriff/Arduino-IRremote>


# Tap Module

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-bfb9108ff2873436247169f49d9ab337292134bc%2Fimage.png?alt=media)

Vibration sensor module. The momentary switch contacts are connected between the two outer pins.


# Light blocking

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-14c63777db1b933b28e1f3816de088d68d01cd05%2Fimage.png?alt=media)

Slotted light barrier. The middle pin connects to + 5 V supply and the pin marked ‘-’ connects to ground. The output signal (with a 10 K ohm pullup to +5 V) is available on the pin on the right.


