Download as pdf or txt
Download as pdf or txt
You are on page 1of 71

RGX Starter Kit Projects Guide

CONTENTS

Getting Started........................................................................................................................................................ 2
Kit Description ..................................................................................................................................................... 2
Components List .................................................................................................................................................. 2
Getting Started with Mixly .................................................................................................................................. 7
Getting Started with your Projects ................................................................................................................... 10
Project 1: Traffic Light Controller .......................................................................................................................... 12
Project 2: Handheld Fan........................................................................................................................................ 16
Project 3: Servo Motor Control with Potentiometer ............................................................................................ 18
Project 4: LED dimming ......................................................................................................................................... 20
Project 5: Rating Tool ............................................................................................................................................ 22
Project 6: Dare Game ............................................................................................................................................ 25
Project 7: Lightwave Radar ................................................................................................................................... 28
Project 8: Smart Street Light System .................................................................................................................... 30
Project 9: Simple Horn .......................................................................................................................................... 34
Project 10: Distance Meter ................................................................................................................................... 36
Project 11: LED Distance Indicator........................................................................................................................ 39
Project 12: Automatic Door Opener ..................................................................................................................... 43
Project 13: Intrusion Detection System ................................................................................................................ 46
Project 14: Countdown Timer ............................................................................................................................... 49
Project 15: Arduino Weather Station ................................................................................................................... 52
Project 16: Automatic Fan Control System ........................................................................................................... 55
Project 17: Water Level Monitoring ..................................................................................................................... 57
Project 18: Stopwatch ........................................................................................................................................... 61
Project 19: Melody Player ..................................................................................................................................... 64
Project 20: Coffee Machine .................................................................................................................................. 68

1
Getting Started
This project guide will introduce you to a wide range of electronic devices such as sensors,
actuators, and many others. The next projects are a great way to get started in the field of
robotics and offer a solid base for learning Arduino programming. The projects have a variety of
aims; some projects teach you how to collect readings from sensors to monitor the
environment, others represent real-life applications that you experience in your daily life and
also some are a great source of fun.

Kit Description
The RGX starter kit is built based on Arduino Nano which is the most popular and widely used
open-source microcontroller.
It is designed with an Easy Plug feature to provide a simple and easy way to start learning and
tinkering with electronics and coding even if you don’t have prior knowledge in this field.
This kit offers everything you’ll need to build innovative projects in the robotics world, from
sensors to actuators and controls along with guiding you to read and control a wide set of
modules.
RGX kit also comes with an ultimate guide with 20 different projects to lead the way of getting
started with your own projects.

Components List

The RGX1 board is an I/O shield for


Arduino Nano. It has 8 Digital ports
labeled as P1, P7, P9 to P14 (of which 3
can be used as PWM outputs), 5 Analog
inputs labeled from P2 to P6, and 1 dual
RGX Control Board analog-digital interface labeled as P8.
RGX1 Along with a USB connection and a power
input. In addition to a voltage regulator
that generates fixed 5V/5A output, which
maintains the performance of the
Arduino no matter how many devices are
connected.

2
Sensors
Name & Code Type Description Picture

A simple mechanical device


Easy plug potentiometer that provides a varying
module Analog amount of resistance when
S01.1 its shaft is turned.

A light-dependent resistor
or a photoresistor is a
Easy plug LDR module resistor whose resistance
Analog
S01.2 varies in accordance with
the variation in light
intensity.

A distance measuring
sensor. It emits an
Dual ultrasonic at 40kHz that
Easy plug ultrasonic sensor
analog- travels through the air and
S04
digital bounces back to the
module if it hits an object
or obstacle

A basic digital temperature


and humidity sensor that
Easy plug DHT11 sensor measures the surrounding
Digital
S06.1 air with a capacitive
humidity sensor and a
thermistor

It is designed for water


detection, which can be
Easy plug water sensor
Analog used in sensing rainfall,
S08
water level, and even
liquid leakage

3
Controls
Name and Code Description Picture

Push-Button Used to complete an electric


C01.1 circuit when you press on it.

It can be considered as a
Limit-Switch contact sensor that is used
C01.2 to detect the presence or
the position of an object.

A switch that can be


Switch
integrated and connected
C02.1
with the Arduino pins.

A switch that is actuated by


moving the slider from the
Switch
open position (ON) to the
C02.2
closed position (OFF).

A module that is used to


MOSFET Switch allow the control of a DC
C05 motor by turning it ON or
OFF

4
Actuators
Name and Code Description Picture

A light source module which


Easy plug LED module
has 3 shiny colors: Red,
A01
Green, and Blue

A tiny speaker that can be


Buzzer used to make sounds by
A02 using tone.

A module with 3 pins fully


Servo Module compatible with servo motor
A03 pins.

Monitor
Name and Code Description Picture

A device that has two rows,


Easy plug LCD module each can accommodate 16
M01 characters to allow users to
display data.

5
Motors
Name and Code Description Picture

A fan that uses a driver to


control the propeller ON and
DC Fan
OFF.

A device that has an output


shaft that could be
Servo Motor positioned to a specific
angular position.

Cables
Name and Code Picture

Mini USB Cable

RJ11

Power Cable

6
Getting Started with Mixly
Mixly is a free open-source graphical Arduino programming software, based on Google’s Blockly
graphical programming framework, and developed by Mixly Team.
It is a free open-source graphical programming tool for creative electronic development; a
complete support ecosystem for creative e-education; a stage for maker educators to realize
their dreams.
All 20 projects in this course will be implemented using Mixly.

Category Description

Blocks that control the analog/digital pins on the


In/Out Arduino boards. Such as digital write/read, analog
write/read, multifunctional button, and interrupts.

7
Blocks that determine the way the program executes.
Control Such as if / else statements, delays, and loops.

Blocks that provide mathematical functions such as


map function, random number generator, increment &
Math
decrement functions, and other mathematical
operations.

Blocks that are used for logical comparison. Such as


Logic
equals, or/and & true/false.

Blocks that provide text, text comparison, and text


Text
manipulation

Lists Blocks that create lists and list access.

Blocks that create Global/Local variables and allow


Variables
accessing it.

8
Blocks for creating functions. Functions or subroutines
are a block of code that serves a specific purpose and is
Functions
separated from the main code for ease of
understanding, re-usability, and organization.

Blocks to configure, use, and read/write to the Serial


Serial Port
Port.

Blocks for reading from a sensor such as ultrasonic and


Sensor
DHT sensor

Actuator Blocks for motors, buzzers, and RGB LED

Monitor Blocks for LCD and other displays

Blocks for storage of data on an SD card (SD module


Storage
needed) or onboard EEPROM

9
Getting Started with your Projects

Let’s get started with a “Hello, World” project.


• As shown in the code below, set the baud rate to 9600 then print “Hello, World!” message
on the serial monitor.

• Select the Board (Arduino Nano[atmega328]/[atmega328old]) and Port.

10
• Connect the Arduino to your PC via a USB cable and upload the code, then open the
monitor to observe the message printed on the serial monitor.

11
Project 1: Traffic Light Controller
Overview:
Traffic lights are signaling devices that are used to control the flow of traffic by providing
instructions to the users by displaying lights. The three colors used in traffic lights are Red,
Yellow, and Green. In this project, three LEDs are used in a way to model a traffic signal and
controlled by the Arduino nano.

Circuit Diagram

Components Required
● RGX1 board
● Arduino Nano
● Easy plug LED module *3 (Red, Yellow, and Green)
● RJ11 cable *3
● USB cable
● Battery

12
Procedure

1. Start by declaring variables so that you can refer to the lights by their color rather than a
pin number.

2. Turn the green LED off and the yellow LED on for 3 seconds

3. Turn off the yellow, then switch on the red for 5 seconds

4. Let the red and yellow turn on for 2 seconds

5. The last step is to turn off the red and yellow LEDs, and switch on the green LED.

13
6. Upload the full code and give it a try!

14
Results
Done uploading, the program will do the following steps:
• Green off, Yellow on for 3 secs
• Yellow off, Red on for 5 secs
• Yellow on, Red on for 2 secs
• Green on, yellow off, red off for 3 secs

15
Project 2: Handheld Fan
Overview:
In this project, we will learn how to use a limit switch and a DC-motor fan to turn a handheld
battery fan on and off.

Circuit Diagram

Components Required
● RGX1 board
● Arduino Nano
● Easy plug Limit Switch module
● Easy plug MOSFET switch module
● DC Fan
● RJ11 cable *2
● USB cable
● Battery

16
Procedure
1. Define the fan and limit switch pins.

2. Now, as long as the L-switch is pressed, the fan motor should be turned on, and when the
switch is released, the fan should turn off. So, the switch output will be written to the fan
pin.

Results
At the end of this tutorial, you’ll be able to control the fan by turning it on as long as you press
the limit switch.

17
Project 3: Servo Motor Control with Potentiometer
Overview:
In this project, we’ll learn how to use a potentiometer to regulate the rotation of a servomotor,
and how to configure the position angle of a servo based on the potentiometer output value.

Circuit Diagram

Components Required
● RGX1 board
● Arduino Nano
● Easy plug potentiometer module
● Easy plug servo shield
● Servo motor
● RJ11 cable *2
● USB cable
● Battery

18
Procedure

1. Define two variables, one for storing the potentiometer output value and the other for
storing the servo motor position angle.

2. Read the value of the potentiometer.

3. Using the map function, scale the value above to be between 0 and 180.

4. Set the servo position according to the angle.

5. Full code is provided below.

Results
Using the procedures outlined above, the servo motor is rotated by rotating a potentiometer
and in the same direction.
19
Project 4: LED dimming
Overview:
This project will teach you how to read and write analog values. We will create a LED with
adjustable brightness. Following the instructions in this project, The LED brightness will be
controlled by a potentiometer position.

Circuit Diagram

Components Required
● RGX1 board
● Arduino Nano
● Easy plug potentiometer module
● Easy plug switch module
● Easy plug LED module
● RJ11 cable *2
● USB cable
● Battery

20
Procedure
1. Define two variables to hold the values of the potentiometer and the brightness.

2. Read the values from the potentiometer connected to port A3

3. When reading an analog value, it will be between 0 and 1023, whereas writing an analog
value must be between 0 and 255. Now, to dim the LED based on the value read from the
potentiometer, we must first scale it between 0 and 255.

4. The last step is to write the brightness value to the port attached to the LED but also if
the switch connected to pin 7 is turned on.

5. Upload the full code below.

Results
Finally, you are able now to control the lighting in your room by adjusting the potentiometer.

21
Project 5: Rating Tool
Overview:
In this project, we’ll build a basic rating tool out of Arduino, a potentiometer, and LEDs, with the
rating, is equal to the number of LEDs turned on by the user through a potentiometer.

Circuit Diagram

Components Required
● RGX1 board
● Arduino Nano
● Easy plug potentiometer module
● Easy plug LED module *3
● Easy plug switch
● RJ11 cable *4
● USB cable
● Battery

22
Procedure
1. Start with creating a list containing the pins attached to the LEDs. In addition, define a
variable to store the number of LEDs that will be turned on.

2. Next, read the potentiometer value and map it to a number between 1 and 3 to decide
how many LEDs should be turned on out of three.

3. Turn on the specified number of LEDs. So, for example, if the value read from the
potentiometer is mapped to 2, this implies that the first two defined in the pins list above,
which are attached to pins 7 and 8, should be turned on, while the LED attached to pin 12
should be turned off.

4. Upload the full code below.

23
Results
By the end of this project, you’ll have a great and simple rating tool. All it takes is to rotate the
potentiometer to light 1 LED for a poor rating, 2 LEDs for a good rating, and 3 LEDs for an
outstanding rating.

24
Project 6: Dare Game
Overview:
In this project, you’ll be able to make a simple fun dare game using Arduino. All you need is your
friends and the Arduino, which will show you the daring orders.

Circuit Diagram

Components Required
● RGX1 board
● Arduino Nano
● Easy plug Button module
● Easy plug LCD
● RJ11 cable *2
● USB cable
● Battery

25
Procedure

1. First, define two variables, one of which is “start” to determine whether the button is
pressed or not. The other variable is “number”, which will hold the order number.

2. Now, create a list and fill it with orders of your choice. We’ve prepared a list of ten
different commands but you could definitely add many more.

3. Moving to the principle of the game, if the button is clicked, a number between 1 and the
length of the orders list is chosen randomly. On the LCD, the order stored at the index of
the randomly selected number will be shown.

4. Upload the full code below and enjoy the game with your friends.

26
Results
This game is ideal for a game night! By clicking on the button, each player will receive an order
to complete.

27
Project 7: Lightwave Radar
Overview:
In this project, we’ll use Arduino Nano and LDR to measure the light intensity.

Circuit Diagram

Components Required
● RGX1 board
● Arduino Nano
● Easy plug LDR sensor
● Easy plug LCD module
● RJ11 cable *2
● USB cable
● Battery

Procedure
1. Define a new variable to hold the light intensity value.

28
2. Get the LDR measurements by reading the analog values of the pin attached to the sensor.

3. Finally, display the light intensity values on the LCD.

Results
The light wave radar can get the light intensity which truly helps in various electrical, industrial,
and agricultural projects.

29
Project 8: Smart Street Light System
Overview:
In this project, a LED module represents a street light which will be controlled by an LDR sensor.
So basically, the system automatically turns ON the streetlight in the absence of sunlight and
switches it OFF when the light falls on the LDR sensor.

Circuit Diagram

Components Required
● RGX1 board
● Arduino Nano
● Easy plug LDR sensor
● Easy plug LED module
● RJ11 cable *2
● USB cable
● Battery

Procedure
1. Declare a new variable to store the value of the LDR sensor readings.

30
2. Upload the code below to get the value of the light intensity and display it on the monitor
window.

3. Done uploading the code, check the analog value displayed on the monitor and notice its
change while covering the LDR.

31
4. Now, we want to set a condition in which when light intensity value goes below a specified
threshold, then the LED should be automatically turned ON. Otherwise, the LED should be
turned OFF as shown in the code below.
Note that the threshold value is chosen based on your room condition.

5. Upload the full code and test it

32
Results
When testing the system, the LED should be turned off if the LDR is not covered or if there is a
presence of light intensity with a value greater than the threshold. However, when the LDR
detects an intensity less than the specified threshold, the LED is automatically turned ON.

33
Project 9: Simple Horn
Overview:
In this project, you will learn how to use an Arduino and a piezo buzzer to generate a ton, more
precisely, how to use it as a horn.

Circuit Diagram

Components Required
● RGX1 board
● Arduino Nano
● Easy plug buzzer module
● Easy plug limit switch module
● RJ11 cable *2
● USB cable
● Battery

Procedure
1. The first step is to continuously check the state of the pin attached to the limit switch. If
the limit switch is pressed, this means that the pin state is HIGH.

34
2. Next, if the switch is pressed, the buzzer should generate a tone as long as the switch is
held down. Otherwise, no tone should be produced.

Results
By the end of this tutorial, you will have a horn that works in the same way as those seen in
vehicles and bicycles.

35
Project 10: Distance Meter
Overview:
In this project, we’ll create a distance meter by utilizing an ultrasonic sensor to determine the
distance of an object from the sensor.

Circuit Diagram

Components Required
● RGX1 board
● Arduino Nano
● Easy plug Ultrasonic sensor
● Easy plug LCD module
● RJ11 cable *2
● USB cable
● Battery

Procedure
1. Declare two float variables to hold the distance value in centimeter and meter.

36
2. Get the distance measurement (in cm) from the ultrasonic and then divide it by 100 to
get the distance in meters.

3. Display the above values on the LCD. Note that distance in cm is cast to integer data type.

4. Upload the full code below.

5. On another note, some characters from previous readings’ values may not be cleared
each time the value changes with a different number of digits. Add the following criteria
to your code to fix this issue.

37
Results
Using an ultrasonic sensor, this Arduino-based distance meter can measure the distance
between the sensor and an object from 2cm to 400cm along with displaying it on an LCD.

38
Project 11: LED Distance Indicator
Overview:
In this project, we’ll use an ultrasonic sensor to measure the distance from an object, and then
we’ll use three LEDs of different colors as distance indicators to identify how close the object is.

Circuit Diagram

Components Required
● RGX1 board
● Arduino Nano
● Easy plug Ultrasonic sensor
● Easy plug LED module *3
● RJ11 cable *4
● USB cable
● Battery

39
Procedure
1. Declare a variable named distance, to store the value of ultrasonic sensor readings.
Also, define the pin attached to each LED

2. Use the ultrasonic ranging block and set the Trig and Echo pins of ultrasonic to
measure the distance in cm.

3. Three LEDs with different colors are now connected; Green, Blue, and Red. We
want to turn on a LED based on the distance measurements. So, if the object is too far
away from the ultrasonic, a Green LED should be switched ON. Else, if the object gets
close to the sensor, the Blue LED should light up. But, in case the object is really close to
the ultrasonic sensor, the Red LED will automatically turn ON.
It's important to know that, depending on your project, you might use other distance
thresholds than those specified below

40
4. Upload the full code and test the outcomes.

41
Results
When moving an object in front of the ultrasonic sensor, if the object is within 4 cm of the
sensor, the Red LED will light up and the other LEDs remain OFF. If the distance from the sensor
to the object is between 5 and 12 cm, the Blue LED will illuminate and the other LEDs remain
OFF. However, if the object is more than 13 cm away from the sensor, the Green LED will turn
ON while the other LEDs will switch off.

42
Project 12: Automatic Door Opener
Overview:
You may have seen Automatic Door Opener Systems in shopping malls, where the door
automatically slides open as soon as a person approaches it. After a short period of time, the
door closes by sliding in the opposite direction. This project will teach you how to build an
Automatic Door Opener System based on an Ultrasonic Sensor and Arduino that automatically
opens and closes the door based on the detection of a person or object.

Circuit Diagram

Components Required
● RGX1 board
● Arduino Nano
● Easy plug Ultrasonic sensor
● Easy plug servo shield
● Servo motor
● Switch screw
● RJ11 cable *2
● USB cable
● Battery

43
Procedure
1. Set a variable named distance to store the distance value measured by the ultrasonic.

2. Set the Trig and Echo pin of the ultrasonic sensor. Then assign the distance measured by
the ultrasonic to the distance variable.

3. If a person is within 8 cm of the ultrasonic, the servo position is adjusted to 90 degrees,


indicating that the door is open, however, if the distance is greater than 8 degrees, the
servo position is set to 180 degrees, indicating that the door is closed.

4. Upload the full code below to observe the results.

44
Results
Whenever someone walks in front of the ultrasonic sensor, the sensor is triggered and the signal
is sent to the Arduino, which controls the servo motor and adjusts its position to open or close
the door.

45
Project 13: Intrusion Detection System
Overview:
In this project, a smart ultra-sonic sensor is used to monitor your place. So, if the presence of an
unauthorized individual is detected, a buzzer should sound to warn you.

Circuit Diagram

Components Required
● RGX1 board
● Arduino Nano
● Easy plug Ultrasonic sensor
● Easy plug Buzzer module
● Easy plug Red LED module
● Easy plug switch screw
● RJ11 cable *3
● USB cable
● Battery

46
Procedure
1. Declare a variable to store the distance measured by the ultrasonic. In addition, define
the buzzer and LED pins.

2. Get the distance measured and store it in the “distance” variable.

3. As soon as a person is detected by the ultrasonic, the buzzer and the LED will be
automatically turned on.

47
4. Upload the full code below.

Results
The intrusion detection system can effectively protect your valuables by alerting you when
someone tries their luck with your stuff.

48
Project 14: Countdown Timer
Overview:
In this project, we'll show you how to use Arduino to create a simple countdown timer. The
timer in this project is set to 60 seconds, and when it reaches zero, an alert sound will be
generated using a buzzer.
Circuit Diagram

Components Required
● RGX1 board
● Arduino Nano
● Easy plug LCD module
● Easy plug Buzzer module
● Easy plug push-button module
● RJ11 cable *3
● USB cable
● Battery

49
Procedure

1. Declare a variable “timer” to store the time duration of the timer, then define the button
and buzzer pins.

2. The timer should count down from 60 seconds to zero seconds. Assign 60 to the “time”
variable, then if the start button is pressed, set a counter from 1 to 60 to handle this. In
each iteration, a one-second delay should be set, followed by decrementing the “time”
variable by one. The code below means that for every one second that passes, a one-
second countdown will occur.

3. Display the countdown process on the LCD

4. When the 60-sec timer finishes, a buzzer will sound to tell you that time is up.

50
5. Full code is provided below.

Results
As soon as you press the button, the timer begins counting down from 60 seconds, and when
time 0 is reached, the buzzer activates for 1 second.

51
Project 15: Arduino Weather Station
Overview:
Temperature and humidity are two major metrics used to measure environmental conditions.
In this project, we'll use a DHT11 sensor to monitor ambient temperature and humidity and
show the results on a 16x2 LCD screen.

Circuit Diagram

Components Required
● RGX1 board
● Arduino Nano
● Easy plug DHT11 sensor
● LCD
● RJ11 cable *2
● USB cable
● Battery

52
Procedure
1. Declare two variables, temperature, and humidity, to store the readings of the DHT11
sensor.

2. Assign the value of the getTemperature function to the “temperature” variable and the
value of the getHumidity function to the “humidity” variable. Next, print the output values of
temperature and humidity on the serial monitor window to test the below code.

3. Now, we want to display the temperature and humidity levels on the LCD. To do so, set
the LCD 1602 address and then enter the temperature and humidity values on LCD line 1 and
line 2. Upload the code below and test it.
Note that the temperature is automatically in the Celsius scale.

53
Results
The temperature and humidity of the surrounding environment will be presented in real-time
on the LCD while the system is being tested.

54
Project 16: Automatic Fan Control System
Overview:
The goal of this project is to create an automatic fan control system that will turn on and off the
fan based on the temperature in the room. Using a temperature sensor and a DC motor-
controlled fan, we can make the fan activated when a high temperature is sensed in the
surrounding.

Circuit Diagram

Components Required
● RGX1 board
● Arduino Nano
● Easy plug DHT11 sensor
● Easy plug MOSFET switch
● DC Fan
● RJ11 cable *2
● USB cable
● Battery

55
Procedure
1. Create a variable “temperature” to store the output of the DHT11 sensor module.

2. Get the temperature value and assign it to the “temperature” variable.

3. Set a temperature threshold above which the fan should turn on automatically if the
measured temperature exceeds the threshold. However, when the temperature falls
below the threshold, the fan turns off.

Results
When you install this system in your room, the fan turns on once the temperature rises above
25 ℃, and the fan turns off when the temperature falls below the threshold.

56
Project 17: Water Level Monitoring
Overview:
One way of addressing water wastage control is by implementing a water level monitoring
system. This system alerts the users to the level of water and prevents it from overflowing. In
this project, you’ll learn how to create your own water level monitoring system using Arduino.

Circuit Diagram

Components Required
● RGX1 board
● Arduino Nano
● Easy plug water sensor module
● Easy plug LED module *3
● RJ11 cable *4
● USB cable
● Battery

57
Procedure

1. Declare a new variable to store the value of the resistance output by the water sensor.
Then, define the pins connected to the LEDs.

2. Get the output value by the water sensor.

3. Now, when the water level rises, the resistance perceived by the water level sensor rises
as well. So, if the output of the water sensor is above 450, it signifies that the tank is about
full, and we need to light up the Red LED. Otherwise, if the readings’ value is between 400
and 450, it signifies the tank is half filled, and we should turn on the blue LED. While
readings between 200 and 400 show that the water level is almost a quarter of the way
up the tank, we turn on the green LED. Finally, if the readings are less than 200, the tank
is empty or nearly empty and w turn off all the LEDs.
Note that you may use your own thresholds depending on the obtained readings, you can
also map these values to be in another scale for a more precise output.

58
4. Full code is shown below.

59
Results
Done uploading, the system implemented above can detect the liquid level and inform the user
by LEDs indicator.

60
Project 18: Stopwatch
Overview:
The goal of this project is to create a stopwatch using an Arduino Nano and an LCD. So just by
pressing the start button, the time elapsing starts. Simply hold down the button for a long press
to stop the timer.

Circuit Diagram

Components Required
● RGX1 board
● Arduino Nano
● Easy plug LCD module
● Easy plug push-button module
● RJ11 cable *2
● USB cable
● Battery

61
Procedure
1. Initialize a variable “time” to store the tome elapsed value.

2. Set up a time interrupt function, that increments the “time” variable by one each 1000
milliseconds.

3. Start the timer when a start button is pressed, then set a “flag” variable to one to signal
that the counting action has begun, and clear any previous characters on the LCD.

4. Display the time elapsed on the LCD when the flag is set to 1.

5. Now, when a long press is detected, we want to stop the stopwatch, therefore the timer
should be stopped.

62
6. Upload the full code below.

Results
We created a simple stopwatch using Arduino and an LCD with a Start/Stop button. A stopwatch
will always have two modes, start, and stop mode. The elapsed time (in seconds) is displayed
on the LCD in the start mode. The stopwatch is stopped by pressing the button for a period of
time. To reset the stopwatch, click on the Arduino’s reset button.

63
Project 19: Melody Player
Overview:
In this project, we’ll use the Arduino tone() function to play melodies of theme songs like Crazy
frog and Pirates of Caribbean.

Circuit Diagram

Components Required
● RGX1 board
● Arduino Nano
● Easy plug push-button module
● Easy plug Buzzer module
● RJ11 cable *2
● USB cable
● Battery

64
Procedure
To play a melody with Arduino, we must first understand what these melodies are constituted
of. The three main attributes necessary to play a theme are as follows:
• Note value
• Note Duration
• Tempo
1. Define a list of notes frequencies for each theme song

“He is a Pirate”: {294, 294, 294, 294, 294, 294, 294, 294, 294, 294, 294, 294, 294, 294, 294,
294, 294, 294, 294, 294, 294, 294, 294, 294, 220, 262, 294, 294, 294, 330,
349,349,349,392, 330, 330, 294, 262, 262, 294, 0, 220, 262, 247, 294, 247, 330, 349,
349,262, 262, 262, 262, 294, 262, 294, 0, 0, 220, 262, 294, 294, 294, 349, 392, 392, 392,
440, 440, 440, 440, 392, 440, 294, 0, 294, 165, 349,349,392, 440, 294, 0, 294, 349,330,
330, 349,294}

“Crazy Frog”: {294, 0, 349, 294, 0, 294, 392, 2944, 262,294, 0,440,294, 0, 294,
466,440,349,294, 440, 587, 294, 262, 0, 262, 220, 330, 294,0,294,297}

2. Next, specify the duration for each note.

“He is a Pirate”: {4,8,4,8,4,8,8,8,8,4,8,4,8,4,8,8,8,8,4,8,4,8,


4,8,8,8,8,4,4,8,8,4,4,8,8,4,4,8,8,8,4,8,8,8,4,4,8,8,4,4,8,8,4,4,8,4,
4,8,8,8,8,4,4,8,8,4,4,8,8,4,4,8,8, 8,4,8,8,8,4,4,4,8,4,8,8,8,4,4,8,8}

“Crazy Frog”: {8, 8, 6, 16, 16, 16, 8, 8, 8,8, 8, 6, 16, 16, 16, 8, 8, 8,8, 8, 8, 16, 16, 16, 16, 8,
8, 2, 8,4,4}

3. To play the Crazy Frog melody, begin by playing each note in the previously defined list of
notes at a time duration already given in a previously defined list. The delay function
shown below represents the Tempo, which specifies how fast the melody should be
played.

65
4. Same steps are followed for the “He is a Pirate” melody.

5. Call play_CrazyFrog function when the button is pressed once, however, double click calls
play_Pirates function.

6. Upload the full code below and enjoy the melodies!

66
Results
Using this project, a single click on the button causes the buzzer to play the “Crazy Frog” melody,
while a double click plays the “He is a Pirate” melody.

67
Project 20: Coffee Machine
Overview:
In this project, you’ll learn how to make a coffee orders machine using Arduino. A user may
order a coffee from the available selections then checkout using this machine.

Circuit Diagram

Components Required
● RGX1 board
● Arduino Nano
● Easy plug push-button module
● Easy plug limit switch module
● Easy plug servo shield
● Servo motor
● Easy plug LCD module
● RJ11 cable *4
● USB cable
● Battery

68
Procedure
1. First, on the LCD, display the available coffee choices while informing the user of the
required action to order a specific coffee.
In the below code, users are asked to order Mocha with a single click on the push button,
Latte with a double click, and hot chocolate with a long press.

2. Inform the user that his coffee has been served, along with its price.

3. Moving on to the final stage, check out, where the user pays for the coffee by pressing
the limit switch, and the servo motor position should change to indicate that the coffee
has been handed to the user.

69
4. The full code is provided below.

Results
By applying the above instruction, you’ll have a machine that allows users to order their favorite
coffee, as well as check out and hand it over.

70

You might also like