1. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com i
Magnet Code 3.0
Smartphone Controller
with Arduino Companion
Solution for Advanced and Creative Projects
Integrate existing Microcontroller or Laptop
projects with Smartphone Controller to
transform all past project topics or ideas to
become much more advanced and creative
project topics.
By installing a Magnet Code platform in your
Smartphone, you can easily apply all the
features in your Smartphone to develop
various types of advanced and creative
projects.
www.magnetcode.com
2. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com ii
Disclaimer
Magnet Code software and this workshop note are owned by Bizchip Technology Centre and are
protected by law and international copyright. Therefore, you should treat this workshop note like any
other copyrighted material (e.g. book). The manual and the compiler must not be copied, partially or
as whole without the written consent from Bizchip Technology Centre. The PDF-edition of the
workshop note can be printed for private or local use, but not for distribution. Modifying the manual or
Magnet Code software is strictly prohibited.
High Risk Activities
The Magnet Code software is not fault-tolerant and is not designed, manufactured or intended for use
or resale as an online control equipment in hazardous environments requiring fail safe performance,
such as in the operation of nuclear facilities, aircraft navigation or communication system, air traffic
control, direct life support machines or weapons systems, in which the failure of the Software could
lead directly to death, personal injury or severe physical or environmental damage (“High Risk
Activities”). Bizchip and its suppliers specifically disclaim any express or implied warranty of fitness
for high risk activities.
License Agreement
By using the Magnet Code software, you agree to the terms of this agreement. Only one person may
use a licensed version of the Magnet Code software at one time.
This manual covers Magnet Code version 3.0 and the related topics. Newer versions may contain
change without prior notice.
Software bug reports
The Magnet Code software has been carefully tested and debugged. It is however not possible to
guarantee a 100% error free product. If you would like to report a bug, please contact us at
info@magnetcode.com. Please include the following information in your bug report:
- Your phone‟s IMEI number
- Your phone‟s operating system
- Description of a bug
Contact Us
Bizchip Technology Centre
Phone: +6012-297 9320 Fax: +603-89487451
Web: www.magnetcode.com Email: info@magnetcode.com
3. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com iii
Table of Contents
Chapter 1: Introduction to Magnet Code
1.1 Types of Smartphone Apps 1
1.2 Why use Smartphone? 1
1.3 How to use Smartphone control devices? 1
1.4 The power of fusion 2
1.5 Smartphone VS Microcontroller VS Laptop 3
1.6 Tips to transform old projects with Smartphone 4
1.7 What is Magnet Code? 6
1.8 Magnet Coe interfacing 6
1.9 Smartphone requirement 7
1.10 Magnet Code 3.0 basic features 7
1.11 Magnet Code 3.0 add on toolbox 8
1.12 Steps to get Magnet Code 3.0 9
Chapter 2: Graphical User Interface
2.1 Main page 11
2.2 Setting page 12
2.3 About page 13
2.4 Background 13
2.5 Button 14
2.6 Command box 15
2.7 Email 16
2.8 File 18
2.9 Layout 19
2.10 LCD 20
2.11 SMS 21
2.12 Startup Screen 22
2.13 Title 23
2.14 Transfer License 23
2.15 Color setting 24
2.16 Text font setting 25
2.17 Select picture setting 25
4. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com iv
2.18 Text size setting 26
Chapter 3: Getting Started
3.1 Setup Magnet Code station 27
3.2 Test Arduino Microcontroller 30
3.3 Test App-Link Bluetooth module 33
3.4 Magnet Code command format 36
3.5 Initialize Magnet Code interfacing 36
3.6 Send Magnet Code command 37
3.7 Receive Magnet Code data 38
Chapter 4: Output Toolbox
4.1 Output toolbox command list 39
4.2 Project 1: Alert user with vibration and turn on camera LED when door
is open
Objective: Control phone vibration using Camera LED
40
Chapter 5: LCD Toolbox
5.1 LCD toolbox command list 43
5.2 Project 2: Show alert message on LCD when intruder is detected
Objective: Change LCD properties
47
5.3 Project 3: Visitor counter which shows the total number of visitors on
the Smartphone
Objective: Show Variable on LCD
49
5.4 Project 4: Show patient temperature on Smartphone
Objective: create data list on LCD
52
Chapter 6: Button Toolbox
6.1 Button toolbox command list 54
6.2 Project 5: Fire alarm which is able to show system status on
Smartphone
Objective: Change button properties
54
6.3 Project 6: Control bulb on/off using Smartphone
Objective: Single byte control using button
58
5. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com v
6.4 Project 7: Control motor direction using Smartphone
Objective: String control using button
61
Chapter 7: Audio Toolbox (optional add on)
7.1 Audio toolbox command list 63
7.2 Project 8: Wheelchair timer for rehabilitation purpose
Objective: Play an audio file
65
7.3 Project 9: Communication device for patient who is unable to speak
properly
Objective: Record and play an audio file
68
7.4 Project 10: Remote control for speaker sound volume
Objective: Control speaker sound volume
72
Chapter 8: Photo Toolbox (optional add on)
8.1 Photo toolbox command list 74
8.2 Project 11: Security system for the computer lab
Objective: Capture image and record
76
Chapter 9: Video Toolbox (optional add on)
9.1 Video toolbox command list 80
9.2 Project 12: Record and play back video when room door is open
Objective: Record and play video
82
Chapter 10: Sensor Toolbox (optional add on)
10.1 Sensor toolbox command list 84
10.2 Project 13: Power failure detector using Smartphone
Objective: Apply charging sensor
87
10.3 Project 14: Safety helmet with drowsy detection
Objective: Apply acceleration sensor
89
6. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com vi
Chapter 11: GPS Toolbox (optional add on)
11.1 GPS toolbox command list 93
11.2 Project 15: Car speed detector
Objective: Apply GPS speed detection device
94
Chapter 12: Speech Toolbox (optional add on)
12.1 Speech toolbox command list 98
12.2 Project 16: Visitor counter with greeting
Objective: Apply test to speech feature
99
Chapter 13: SMS Toolbox (optional add on)
13.1 SMS toolbox command list 101
13.2 Project 17: Fire alarm with SMS alert
Objective: Sent SMS
106
13.3 Project 18: Paddy field water level controller
Objective: Control single output using SMS
107
13.4 Project 19: Smart home monitoring system
Objective: Receive and send SMS
108
13.5 Project 20: Smart lighting system
Objective: Control multi-output using sms
109
Chapter 14: Email Toolbox (optional add on)
14.1 Email toolbox command list 117
14.2 Project 21: Lecturer office alarm
Objective: Send email with attachment file
118
Chapter 15: Database Toolbox (optional add on)
15.1 Sensor toolbox command list 120
15.2 Project 22: Environment brightness recorder
Objective: Save data in excel file
127
Chapter 16: Magnet Code Project Topics
16.1 Magnet Code for agriculture 130
16.2 Magnet Code for biomedical 132
16.3 Magnet Code for building automation 133
16.4 Magnet Code for transportation 136
7. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
1
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com
Chapter 1 Introduction to Magnet Code
1.1 Types of Smartphone Apps
1.2 Why use Smartphone?
1.3 How to use Smartphone control devices?
8. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 2
1.4 The power of fusion
Smartphone Controller
It can turn on the ceiling, control panel,
desktop...
9. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 3
1.5 Smartphone Vs Microcontroller Vs Laptop
Features Smartphone Microcontroller Laptop
Price Min $50 Min $3 Min $200
Weight Around 100g Around 5g Around 1Kg
LCD Screen Around 4” No LCD Around 10”
Keypad Virtual Keyboard No Yes
Speed Min 1GHz (Multi
Processors)
4MHz to 48MHz
(Single Processor)
Min 1GHz (Multi
Processors)
Storage 1GByte Few KBytes 10GBytes
RAM Few MBytes Few Bytes Few MBytes
Camera Yes No Yes
GPS Yes No No
Bluetooth Yes No Yes
Serial Port No Yes Yes
Wifi Yes No Yes
Acceleration
Sensor
Yes No No
Proximity Sensor Yes No No
Speaker Yes No Yes
Digital I/O No Yes No
Analog I/O No Yes No
10. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 4
1.6 Tips to transform old projects with Smartphone
Examples
11. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 5
Old 1: Inventory system = PC (Visual Basic) + Arduino + Barcode scanner + LCD
New 1: Inventory system = PC (Visual Basic) + Magnet Code
Old 2: Fire alarm with SMS notification = Microchip PIC + GSM modem + Siren
New 2: Fire alarm with SMS notification = Microchip PIC + Magnet Code
Old 3: Home security with video recorder = Raspberry Pi + Video Recorder + Siren
New 3: Home security with video recorder = Arduino + Magnet Code
Old 4: Temperature recorder with Email = Atmel ATmega + PC (Visual C++)
New 4: Temperature recorder with Email = Atmel ATmega + Magnet Code
Old 5: Use laptop to control socket on/off = Microchip PIC + PC (Visual Basic)
New 5: Use laptop to control socket on off = Microchip PIC + Magnet Code
Exercise 1
A. Upgrade an existing project with outstanding features in
Smartphone.
Example 1. Attendance system using QR code login.
Example 2. Take photo and Email to owner when an intruder is
detected.
1. __________________________________________________
2. __________________________________________________
12. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 6
B. Replace existing modules by features in Smartphone.
Example 1. Replace GSM modem by Smartphone.
Example 2. Replace TV or Radio remote control by Smartphone.
1. __________________________________________________
2. __________________________________________________
1.7 What is Magnet Code?
Magnet Code is a prototyping platform to develop App for control purpose.
Thus the platform is installed in the Smartphone (with Android OS) to interface a Smartphone
with a Microcontroller or a computer.
Magnet Code is developed to upgrade each Smartphone with the controller feature. The
platform comes with user friendly commands and user interface. Use can interact with the
Smartphone through a Bluetooth communication. Through the commands, user can easily
control any module in the Smartphone, e.g. take photo, record video, vibrate or send SMS.
Magnet Code also provides user friendly graphical user interface. User can easily create
layout for their App.
1.8 Magnet Code interfacing
13. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 7
1.9 Smartphone requirement
Processor: Quad Core, 1.2GHz
OS: Android 4.2
Bluetooth: 2.0
RAM: 1GB
Storage: 50MB
IMEI: Yes
Front Camera: Yes
Rear Camera: Yes
Touch Screen Size: 4 inches
1.10 Magnet Code 3.0 basic features
1. Title bar setting
2. Customizable About page
3. Responsive LCD with vertical scroll bar
4. 18 responsive buttons
5. Splash screen with background music
6. Background setting
7. Command box
8. LCD toolbox (group: lcd_)
9. Button toolbox (group: but_)
10. Output toolbox (group: out_)
15. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 9
1.12 Steps to get Magnet Code 3.0
Place order at
www.bizchip-components.com
We will email you a setup file
Magnetcode3.apk
Bank in / Transfer payment to our:
Maybank Acc: 5122 3183 4795
Name: Bizchip Technology Centre
(Keep transaction receipt)
Copy magnetcode3.apk into your
Smartphone
(make sure it is min Android 4.2)
Unblock your phone to install offline
apk file. Then install
magnetcode3.apk
Turn on Magnet Code 3.0 and
submit your registration information
(turn on the Internet connection)
1
2
3
4
5
6
16. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 10
We will approve your registration in
24 hours
Turn on Magnet Code 3.0 again
after 24 hours to receive license
(turn on the Internet connection)
Done! In the future you can use
Magnet Code 3.0 with / without
Internet connection
7
8
9
17. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 11
Chapter 2 Graphical User Interface
2.1 Main page
Main page is the worksheet for your project design. You can add components into the main
page through the „Setting‟ page.
At the right side of the main page title, you can press a menu icon to drop down menu.
Run: „Run‟ button is used to connect Magnet Code to device through Bluetooth interfacing.
Stop: „Stop‟ button is used to disconnect Magnet Code with the connected device.
Setting: „Setting‟ button is used to set graphical user interface for the main page.
About: „About‟ button is used to show the „About Page‟. This button will only appear if all
settings in „About Page‟ are not empty.
Exit: „Exit‟ button is used to close the Magnet Code App.
18. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 12
2.2 Setting page
Setting page is a place where you can do all the graphical
settings for the main page.
You can scroll up and down to see the setting for all
components.
You can press any item to do the setting for the particular
component.
To exit „Setting‟ page and back to the main page, you only
need to press the „Back‟ button (at the bottom right of the
phone).
2.3 About page
In the „Setting‟ page, press the ‟About Page‟ button to enter the „About Page Setting‟ page.
Inside the „About Page Setting‟ page, you can insert the description and the contact
information for your project.
Besides inserting the page details, you can also set the text color, text font and back color for
the „About‟ page. (Refer to point 2.15 for text color and back color setting, point 2.16 for text
font setting.)
The color and font preview of the „About‟ page is at the bottom of the page.
‘Save’ button: Press the „Save‟ button to save all the settings and back to the „Setting‟
page.
‘Back’ button: Press the „Back‟ button to quit the current page and back to the „Setting‟ page
without saving anything.
19. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 13
2.4 Background
In the „Setting‟ page, press the ‟Background‟ button to enter the „Background Setting‟ page.
In the „Background Setting‟ page, you can set the background of the main page as color
mode or image mode.
(Refer to point 2.15 for text color and back color setting, point 2.17 for select picture setting.)
‘Save’ button: Press „Save‟ button to save all settings and back to the „Setting‟ page.
‘Back’ button: Press „Back‟ button to quit the current page and back to the „Setting‟ page
without saving anything.
20. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 14
2.5 Button
There are 18 buttons in Magnet Code.
The buttons are arranged into 3 columns and 6 rows.
Row 1 with button A1, B1, C1
Row 2 with button A2, B2, C2
Row 3 with button A3, B3, C3
Row 4 with button A4, B4, C4
Row 5 with button A5, B5, C5
Row 6 with button A6, B6, C6
You can use button for output or input purpose.
You can press any button in the „Setting‟ page to access the button‟s setting page.
Following shows the setting for the buttons:
‘Show’ option: After selecting this option, the button will be shown on the main page.
‘Hide’ option: After selecting this option, the button will not be shown on the main page.
‘Enable Send Data’ option: After selecting this option, data will be sent once the button is
pressed.
‘Disable Send Data’ option: After selecting this option, data will not be sent when the button
is pressed.
‘Button Text’ textbox: The content in this textbox will be shown on the button when the
„Show‟ option is selected.
‘Data to Send Out’ textbox: The content in this textbox will be sent to the connected device
after the button is pressed.
You can also set text size, text color, text font and back color for the button.
(Refer to point 2.15 for text color and back color setting, point 2.16 for text font setting, point
2.18 for text size setting.)
The preview of the button is at the bottom of the page.
‘Save’ button: Press „Save‟ button to save all settings and back to the „Setting‟ page.
‘Back’ button: Press „Back‟ button to quit the current page and back to the „Setting‟ page
without saving anything.
Note:
The width of the button can be set to fixed width or dynamic width. Refer to point 2.9 for
details.
21. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 15
2.6 Command box
In the „Setting‟ page, press the ‟Command Box‟ button to enter the „Command Box Setting‟
page. Command box is used to show any command received from the connected device.
Following shows the setting for the command box:
‘Show’ option: After selecting this option, the command box will be shown on the main
page.
‘Hide’ option: After selecting this option, the command box will not be shown on the main
page.
‘Save’ button: Press „Save‟ button to save all settings and back to the „Setting‟ page.
‘Back’ button: Press „Back‟ button to quit the current page and back to the „Setting‟ page
without saving anything.
22. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 16
2.7 Email
In the „Setting‟ page, press the ‟Email‟ button to enter the „Email Setting‟ page. „Email Setting‟
page is used to set Email content you want to send to receivers, e.g. subject, message and
attachment.
Following shows the setting for the Email feature:
‘Together’ option: After selecting the „Together‟ option, Magnet Code will send Email to all
receivers in the list simultaneously. Each receiver will be able tosee the emails of the other
receivers in the „To‟ textbox.
‘One By One’ option: After selecting the „One By One‟ option, Magnet Code will send Email
to each receiver in the receiver list one by one. Each receiver will only see their respective
Email in the „To‟ textbox.
‘Reply After Sent To All’ checkbox: When the checkbox is ticked, Magnet Code will send
a 5 bytes acknowledge code (EM1rn) to the connected device after an Email has been sent
to all receivers.
‘Sender Name’ textbox: This is the name you want to show in the receiver‟s Email.
‘Email’ textbox: It is the sender‟s Email account. Magnet Code will send Email through this
Email account.
‘Password’ textbox: This is the password of the sender Email account.
‘POP Server’ textbox: This is the POP server address of your Email account. E.g.
smtp.gmail.com.
‘Port ID’ textbox: This is the port ID of your Email account. E.g. 465.
‘To’ textbox: This is the receiver Email addresses. Each receiver‟s Email address is
separated using „,‟.
‘Cc’ textbox: This is the Email addresses you want to Cc- to. Each receiver‟s Email address
is separated using „,‟.
‘Bcc’ textbox: This is the receiver‟s Email address you want to Bcc- to. Each receiver‟s
Email is separated using „,‟.
‘Subject’ textbox: This is the subject of your Email.
‘Message’ textbox: This is your Email content. Multi lines are supported.
‘Attachment’ textbox: If you have any file that you wish to attach with the Email, you can
add in the file name here. Multi file attachment is supported. Each file is separated using „,‟.
‘Send’ button: After pressing this button, Magnet Code will send the Email according to your
setting.
23. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 17
‘Clear All’ button: After this button is pressed, all setting in this page will be reset.
‘Save’ button: Press the „Save‟ button to save all settings and back to the „Setting‟ page.
‘Back’ button: Press the „Back‟ button to quit the current page and back to the „Setting‟ page
without saving anything.
Note:
1. You need an Internet connection when you wish to send an Email.
2. Please make sure that your Email account supports software login. You may need to do
some setting in your Email account.
24. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 18
2.8 File
In the „Setting‟ page, press the ‟File‟ button to enter the „File Setting‟ page.
In the „File Setting‟ page, you can do the following things:
‘Save or Open’ textbox: If you click the textbox for the 1st
time, you can key in the file name
that you wish to save or open. No file name extension is required. If you click the textbox for
the 2nd
time, you will see a list of files in the operating folder. You can select any file name
from the list.
‘Operating Folder’ textbox: This is the path for the Magnet Code operating folder. All the
files required in your design (e.g. abc.jpg, def.mp3, test.xls) must be stored in this operating
folder. Default operating folder is set to: /storage/emulated/0/mc. You can click the textbox to
set it to any other folders you wish in the internal storage.
‘Save’ button: Press the „Save‟ button to save all settings and back to the „Setting‟ page.
‘Open’ button: Press the „Open‟ button to open the file name you wish in the „Save‟ or the
„Open‟ textbox. If the file is valid, Magnet Code will open the file and back to the main page.
‘Back’ button: Press the „Back‟ button to quit the current page and back to the „Setting‟ page
without saving anything.
‘Reset All’ button: Press the „Reset All‟ button to reset all settings you did earlier.
Note:
1. This feature is only available for Enterprise License.
2. The file you saved is in the xml format. It is saved in the Magnet Code operating folder.
3. „Operating Folder‟ only supports folders in the internal storage. External storage is not
supported.
25. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 19
2.9 Layout
In „Setting‟ page, press ‟Layout‟ button to enter „Layout Setting‟ page.
In „Layout Setting‟ page you are able to „Lock‟ and „Unlock‟ buttons in each row.
‘Lock’ option: After this option is selected, all buttons in this row will have a fixed width
when shown in the main page.
‘Unlock’ option: After this option is selected, buttons in this row will have a variable width
when shown in the main page. The more buttons in the same row, the thinner is the button.
‘Save’ button: Press „Save‟ button to save all settings and back to the „Setting‟ page.
‘Back’ button: Press „Back‟ button to quit the current page and back to the „Setting‟ page
without saving anything.
26. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 20
2.10 LCD
In „Setting‟ page, press ‟LCD‟ button to enter the „LCD Setting‟ page.
In „LCD Setting‟ page you are able to set the LCD as text mode or image mode.
The height of the LCD in main page is dynamic. The height will be automatically reduced
when more items appear on the main page.
‘Text Mode’ option: Under the text mode option, you can key in text you wish to show on
the LCD. The LCD supports multi rows data. You can scroll up and down while editing the
LCD.
You can also set the text alignment, text size, text color, text font and back color for the LCD.
(Refer to point 2.15 for text color and back color setting, point 2.16 for text font setting, point
2.18 for text size setting.)
‘Image Mode’ option: Under image mode option, you can select picture you wish to show
on the LCD. (Refer to point 2.17 for select picture setting.)
‘Slider On’ or ‘Slider Off’ option: When „Image Mode‟ is selected and slider is „On‟, you can
browse all JPG files in the operating folder through the LCD in the main page.
‘Save’ button: Press „Save‟ button to save all settings and back to the „Setting‟ page.
‘Back’ button: Press „Back‟ button to quit the current page and back to the „Setting‟ page
without saving anything.
27. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 21
2.11 SMS
In „Setting‟ page, press the ‟SMS‟ button to enter the „SMS Setting‟ page. „SMS Setting‟ page
is used to set the SMS content you wish to send to the receivers.
Following shows the setting for the SMS feature:
‘Recipients’ textbox: This is the receiver‟s phone number. Each receiver‟s phone number is
separated using „,‟.
‘Message’ textbox: This is your SMS content. Multi lines are supported.
‘Send’ button: After this button is pressed, Magnet Code will send the SMS according to
your setting.
‘Clear All’ button: After this button is pressed, all setting in this page will be reset.
‘Save’ button: Press „Save‟ button to save all settings and back to the „Setting‟ page.
‘Back’ button: Press „Back‟ button to quit the current page and back to the „Setting‟ page
without saving anything.
Note:
You need an active SIM card if you wish to send an SMS.
28. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 22
2.12 Startup screen
In „Setting‟ page, press the ‟Startup Screen‟ button to enter the „Startup Screen Setting‟ page.
In „Startup Screen Setting‟ page you are able to set the startup screen with image and music
you wish. Besides, you can also set the time to turn on the startup screen.
Following shows the setting for the startup screen:
‘Show’ option: After selecting this option, the startup screen will pop out when you turn on
Magnet Code.
‘Hide’ option: After selecting this option, the startup screen will not pop out when you turn
on Magnet Code.
‘Save’ button: Press „Save‟ button to save all settings and back to the „Setting‟ page.
‘Back’ button: Press „Back‟ button to quit the current page and back to the „Setting‟ page
without saving anything.
29. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 23
2.13 Title
In the „Setting‟ page, press ‟Title‟ button to enter the „Title Setting‟ page.
In „Title Setting‟ page you can set title of your project in the main page.
You can also set text size, text color, text font and back color for the LCD.
(Refer to point 2.15 for text color and back color setting, point 2.16 for text font setting, point
2.18 for text size setting.)
2.14 Transfer License
In „Setting‟ page, press the ‟Transfer License‟ button to enter the „Transfer License‟ page.
In „Transfer License‟ page you are able to transfer the license from your current device to the
new device by inserting the new IMEI of the new device.
Press „Transfer License‟ after you have filled in the IMEI for the new device.
30. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 24
Note:
1. You need to contact us to enable this license transfer when you wish to transfer the
license to the new device.
2. You need an Internet connection when you wish to transfer the license.
2.15 Color setting
There are 2 methods for you to set the text color or the back color:
a. Select color from color picker: Through color picker. You do not need to memorize any
color code.
b. Key in color code: The color code presents the color you selected. If you wish to have
the same color appearing in other components, you can copy the color value and paste the
value in the other components.
Note:
Make sure that the text color and the back color are not the same. Else, you will not be able
to see the text.
31. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 25
2.16 Text font setting
You can scroll up and down to select the text font you need.
2.17 Select picture setting
„Select Picture‟ textbox is used to select picture for component when the image mode is
selected.
You can double click the „Select Picture‟ textbox to browse all the JPG files available in the
operating folder.
32. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 26
2.18 Text size setting
„Text Size‟ setting is used to set text size for the related components.
After you click the textbox, you will see a numeric keypad.
You can key in any number into the textbox.
Exercise 2
Create the following graphical interface for the main page.
Design Design 2 Design 3
33. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 27
Chapter 3 Getting Started
3.1 Setup Magnet Code station
Smartphone
+
Magnet Code
+
App-Link Bluetooth
Module
Computer
+
Arduino IDE 1.6.6
+
USB B connector
Arduino UNO
+
Male-male jumper
+
Bread Boards, GL No.12
Arduino IDE 1.6.6 available at https://www.arduino.cc/en/Main/Software
34. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 28
Arduino Microcontroller
Arduino Microcontroller main specification:
Microcontroller : ATmega328
Operating Voltage : 5V
Input Voltage (recommended) : 7-12V
Digital I/O Pins : 14 (of which 6 provide PWM output)
Analog Input Pins : 6
DC Current per I/O Pin : 40 mA
DC Current for 3.3V Pin : 50 mA
Flash Memory : 32 KB (ATmega328)
SRAM : 2 KB (ATmega328)
EEPROM : 1 KB (ATmega328)
Clock Speed : 16 MHz
35. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 29
App-Link Bluetooth Module
a. Power: 3.3VDC, Range: 30 feet, Speed: 9600bps.
b. The name and password you set in the App-Link module
will be forever saved in the module until you send a new
command to change it.
c. You must connect Bluetooth to the controller to rename
the module, and not through a wireless communication.
d. The default name of the Bluetooth module is APP-LINK. Rename APP-LINK to a
meaningful name.
e. A Bluetooth module with the same name can appear together, and there would not be
any clash because each module would have a different address code.
f. The default password for the Bluetooth module is 1234. Rename it to increase the
security, because a user is unable to connect to the module without a correct password.
g. Use command „AT+NAME‟ to rename the App-Link module e.g. AT+NAMEabc.
h. Use command „AT+PIN‟ to change the password of the App Link module e.g.
AT+PIN1234.
36. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 30
3.2 Test Arduino Microcontroller
1. Open Arduino IDE
2. Go to “File‟ “Example” “Digital” “Button”
3. Design an Arduino program for the following flow chart.
Open Arduino IDE Go to Button
Example
Set up the
circuit
Upload the code to
Arduino
Start
Detect door open or
close status
Door open?
No
Yes
Off red LED at Pin13
On red LED at Pin13
37. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 31
Circuit Connection
NOTE: PLEASE CONNECT A PULL DOWN RESISTOR ACROSS BUTTON PIN
Arduino IDE Program
const int buttonPin = 2; // set buttn pin=2
const int ledPin = 13; // set ledPin=13
int buttonState = 0; // Set buttonState=0
void setup()
{
pinMode(ledPin, OUTPUT); //set pin 13 as output
pinMode(buttonPin, INPUT); //set pin2 as input
}
void loop()
{
buttonState = digitalRead(buttonPin); //read the value of digital pin
if (buttonState == HIGH) // door closed
{
digitalWrite(ledPin, HIGH); // turn LED on:
}
Tips
Output high will
give 5V DC
through the pin.
Output low will
give 0V DC
through the pin.
When button is
pressed, LED will
turn on.
When button is
released,
LED will turn off.
38. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 32
else // door opened
{
digitalWrite(ledPin, LOW); // turn LED off:
}
}
4. Verify the sketch and save it inside a folder.
5. Click upload to upload the program into Arduino microcontroller
6. You will see the LED 13 turn on when button is pressed.
7. Congratulations, done!
39. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 33
3.3 Test App-Link Bluetooth module
Change Name: AT+NAMEabcrn
Why rename? To more easily understand and
identify your device.
Change Pin / Password: AT+PIN1234rn
Why change pin? For security purposes
WARNING: Remember to connect the Resistor as shown below to
avoid damage of Bluetooth devices
Before we proceed further...
Note down your App-Link module new name
AT+NAME__________rn
Note down your App-Link module new PIN (4 bytes)
AT+PIN__________rn
Tips:
Magnet Code commands
ends with rn
ASCII Code 0x0D = r
=cariage return
ASCII Code 0x0A = n
= new line
40. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 34
Steps to Rename + Change Password
#include <SoftwareSerial.h> // initialize software serial library
SoftwareSerial mySerial(10, 11); // RX, TX
// pin 11 as arduino TX pin10 as arduino RX
// Bluetooth RX connect TX(pin11),
//Bluetooth TX connect RX(pin10)
void setup()
{
Serial.begin(9600); // set data speed 9600 bps
pinMode(9,OUTPUT); //set pin9 as output
digitalWrite(9,HIGH); // initialize pin 9 as HIGH
Serial.println("Enter AT commands:"); // Serial Monitor should display “Enter AT
//commands”
mySerial.begin(9600); //set data speed =9600
}
void loop()
{
// Coding below enable user to run AT-command using software serial
if (mySerial.available())
Serial.write(mySerial.read());
if (Serial.available())
mySerial.write(Serial.read());
}
Connect circuit as
shown below
Generate the
programming below
Upload to
arduino
Start to rename
password and name
of Bluetooth
41. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 35
1. Open Serial monitor of Arduino IDE. You should see something like this
2. Now, to change name key in following command
AT+NAMEMagnetCode
NOTE: The Highlight part is your Bluetooth name. You can change to desire name.
3. You should see “setname” appear in serial monitor indicate the name of Bluetooth is
changes
4. Now, to key change password. Key in following command
AT+PIN2468
NOTE: 2468 is your new password of Bluetooth. You can change to desire password.
5. Congratulations, done!
42. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 36
3.4 Magnet Code command format
Group name (3 bytes) + _ + Sub Command 1 (3 bytes) + Sub
Command 2 (1 to 3 bytes) + <value> (optional,accept „#‟ as enter or
data splitter) + rn
Example:
out_vibonrn
pho_froman<myphoto>rn
aud_plaon<siren>rn
lcd_shotex<Hello#How are you?>rn
ema_wriatt<photo1.jpg#mydata.xls>rn
3.5 Initialize Magnet Code interfacing with Arduino
In Arduino IDE,always remember initialize Serial monitor
void setup()
{
Serial.begin(9600); // set data speed at 9600 bps
}
void loop()
{
}
Tips:
Use following parameters if
you want to send variables:
%x: hexa output, 00 to FF
%u: unsign integer, 0 to 255
%d: signed integer, -128 to
127
%c: character output: 0-9, A-Z,
a-z
%lu: unsign long integer, 0 to
65535
43. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 37
3.6 Send Magnet Code command
Int count1=123; //<=255 use int
Long int count2=1234; // >255 use long int
//send commands with fixed value
Serial.println(“out_vibonrn”);
Serial.println(“lcd_shotex<Hello!>rn”);
Serial.println(“vid_froman<myfile>rn”);
//send commands with variable value
To print magnet code command, a character data type array is requires
char buf[30];
sprintf(buf,"lcd_bactex<#temp:%d>rn",temp);
Serial.print(buf);
3.7(a) Receive Magnet Code data in character data type
void setup ()
{
Serial.begin(9600);
}
void loop ()
{
//Get the number of bytes (characters) available for reading from the serial port.
// To receive singe character data, we use “if “in serial available function
if(Serial.available() > 0)
{
char data = Serial.read(); // read the character
if (data == '1') // if data received „1‟
{
// do task 1
}
else if (data == '2') //if data received „2‟
{
// do task 2
}
}
}
44. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 38
3.7(b) Receive Magnet Code data in String data type
void setup()
{
Serial.begin(9600); // Set data speed =9600 bps
Serial.flush(); //clear serial monitor
}
void loop()
{
String input = ""; // clear the string every time loop finished
// Get the number of bytes (Strings) available for reading from the serial port
// To receive Strings data, we use “while “in serial available function
while (Serial.available() > 0)
{
input += (char) Serial.read(); // Read the Strings
delay(5); // Delay for 5 ms so the next char has time to be received
if (input == "FWD") // if input received string data “FWD”
{
// do task 1
}
else if (input == "STP") // if input received string data”STP”
{
//do task 2
}
else if(input=="REV") // if input received string data “REV”
{
// do task3
}
}
}
45. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 39
Chapter 4 Output Toolbox
Output toolbox is used to control vibration, camera LED and the sound volume for the loud
speaker.
4.1 Output toolbox command list
Following are available commands in this toolbox:
Ref. Command Function
1 out_vibonrn Turn on vibration
2 out_viboffrn Turn off vibration
3 out_ledon<mode>rn Turn on the camera LED.
<mode>: <0> to always turn on the camera LED. <1> to
turn on the camera LED when taking photo or recording
video.
Example:
out_ledon<0>: Always turn on the camera LED.
out_ledon<1>: Turn on the camera LED when taking photo
or recording video.
4 out_ledoffrn Turn off the camera LED.
5 out_audvol<value>rn Control the sound volume of the loud speaker
<value>: Percent of sound volume. Range from 0 to 100.
Example:
out_audvol<0>: Turn off the loud speaker.
out_audvol<50>: Turn on the loud speaker with 50%
sound volume.
out_audvol<100>: Turn on the loud speaker with 100%
sound volume.
46. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 40
4.2 Project 1: Alert user with vibration and turn on the camera LED
when door is open
Objective: Control phone vibration and camera LED
Start
Detect door open or
close status
Door open? No
Yes
Wait for 1sec
Vibrate phone
Turn on the camera LED
Stop to vibrate phone
Turn off the camera LED
47. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 41
Circuit Connection
Project 1 Answer (Refer p1.ino)
const int ledpin=13; //set ledpin=13
const int Button=2; // set Button =2;
int en=0; //set en =0
int buttonState=0; // Set buttonState=0
void setup()
{
pinMode(ledpin,OUTPUT); // define pin13 as digital Output
pinMode(Button, INPUT); // define pin2 as digital Input
Serial.begin(9600);
}
Tips:
Connect LED to pin 13.
Connect door switch to
pin 2.
48. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 42
void loop()
{
buttonState=digitalRead(Button); //reads the value from a specified digital pin,
if(buttonState == LOW && en ==0) //if door open and en=0
{
digitalWrite(ledpin,HIGH); // led on
Serial.println("out_vibonrn"); //phone vibration on
Serial.println("out_ledon<0>rn"); // camera led on
en=1;
}
else if (buttonState == HIGH && en==1) // if close and en=1
{
digitalWrite(ledpin,LOW); // led off
Serial.println("out_viboffrn") ; // phone vibration off
Serial.println("out_ledoffrn"); // camera led off
en=0;
}
delay(1000); //delay 1 second
}
49. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 43
Chapter 5 LCD Toolbox
LCD toolbox is used to show text, date, time on LCD.
5.1 LCD toolbox command list
Following are available commands in this toolbox:
Ref Command Function
1 lcd_shooffrn Hide LCD.
2 lcd_siztex<value>rn Set text size on LCD.
<value>: Size of text. Any positive number.
Example:
lcd_sizetex<20>: Set LCD text size to 20pt.
lcd_sizetex<60>: Set LCD text size to 60pt.
3 lcd_shotex<text>rn Clear current content on the LCD and show the new text.
<text>: Message you want to show on LCD. Add „#‟ in
<text> to move following message to next row.
Example:
lcd_shotex<Hello>: Show „Hello‟ on LCD.
lcd_shotex<Hello#How are you?>: Show „Hello‟ on LCD 1st
row. Show „How are you?‟ on LCD 2nd
row.
4 lcd_cletexrn Clear text on LCD.
5 lcd_frotex<text>rn Add new text before current text.
6 lcd_bactex<text>rn Add new text behind current text.
7 lcd_shodatrn Clear content on LCD and show phone date. Date format in
dd-mm-yyyy.
8 lcd_frodatrn Add phone date before current text on LCD. Date format in
dd-mm-yyyy.
9 lcd_bacdatrn Add phone date behind current text on LCD. Date format in
dd-mm-yyyy.
10 lcd_shotimrn Clear content on LCD and show phone time. Time format in
hh:mm:ss.
11 lcd_frotimrn Add phone time before current text on LCD. Time format in
hh:mm:ss.
12 lcd_bactimrn Add phone date behind current text on LCD. Time format in
50. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 44
hh:mm:ss.
13 lcd_baccol<color
code>rn
Change background color of LCD. Refer to point 2.15 for
color code details.
Example:
lcd_baccol<-1>: Change background color of LCD to white
color.
14 lcd_frocol<color
code>rn
Change text color of LCD. Refer to point 2.15 for color code
details.
Example:
lcd_frocol<-1>: Change text color of LCD to white color.
51. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 45
5.2 Project 2: Show alert message on LCD when intruder is detected
Objective: Change LCD properties
Start
Detect door open or
close status
Door open? No
Yes
Show date, time, „Open‟ on
LCD. Change LCD to red
color
Show date, time, „Close‟
on LCD. Change LCD to
green color
53. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 47
Project 2 Answer (Refer to p2.ino)
const int ledpin=13; // set ledpin =13
const int Button=2; // set Buttton=2
int en=0; // set en=0
int buttonState=0; // set buttonState
void setup()
{
Serial.println("lcd_siztex<120>rn"); // set lcd text size to 120
pinMode(ledpin,OUTPUT); // set pin 13 as output
pinMode(Button, INPUT); //set pin 2 as input
Serial.begin(9600); //set data speed 9600 bps
}
void loop()
{
buttonState=digitalRead(Button); //read digital pin 2
Serial.println("lcd_shodatrn"); // Clear content on LCD and show phone date
Serial.println("lcd_bactex<#>rn"); //jump to next row
Serial.println("lcd_bactimrn"); //show time on lcd
Serial.println("lcd_bactex<#>rn"); //jump to next row
// if door is open
if(buttonState == LOW && en==0 ||buttonState == LOW && en==1 )
{
digitalWrite(ledpin,HIGH); // led on
Serial.println("lcd_baccol<-3275001>rn"); // lcd background color
Serial.println("lcd_bactex<Open>rn"); // lcd show text “Open”
en=1;
}
54. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 48
// if door is close
else if (buttonState == HIGH && en==1 || buttonState == HIGH && en==0 )
{
digitalWrite(ledpin,LOW); //led off
Serial.println("lcd_baccol<-11937254>rn"); //lcd background color
Serial.println("lcd_frocol<-16777216>rn"); //lcd text size
Serial.println("lcd_bactex<Close>rn"); //lcd show text”Close”
en=0;
}
delay(500);
}
55. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 49
5.3 Project 3: Visitor counter which shows the total numer of visitors
on the Smartphone
Objective: Show variable on LCD
Note: The circuit connection is the same as project 2.
Start
Detect door open or
close status
Door open? No
Yes
Show counter value on
LCD
Count=Count+1
56. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 50
Project 3 Answer (Refer to p3.ino)
const int led = 13; // set led=13
const int Button = 2; //set Button =2
int count = 0; // initialize counter as 0
int stab = 0; // initialize a variable for programming purpose
int buttonState=0; //set buttonStae=0
char buf[30] ; // Initialize character buffer of size 30
void setup()
{
Serial.println("lcd_siztex<50>rn"); // initialize lcd text size
pinMode(led,OUTPUT); // set pin 13 as output
pinMode(Button, INPUT); //set pin 2 as input
Serial.begin(9600) ; //set data speed =9600
}
void loop ()
{
buttonState = digitalRead(Button); // read button state
if(buttonState == LOW && stab == 1) // if door open
{ digitalWrite (led,HIGH);
count = count + 1; //count increase by 1
sprintf(buf,"lcd_shotex< Visitor: #%d>rn",count); // display visitor on lcd
Serial.println(buf);
stab = 0;
}
Tips:
Please refer Project 1
for circuit connection
Connect LED to pin13.
Connect door switch to
pin2.
57. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 51
else if (buttonState == HIGH && stab == 0) // if door close
{
digitalWrite (led,LOW); //led off
stab=1;
}
delay (250);
}
58. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 52
5.4 Project 4: Show patient temperature on Smartphone
Objective: Create data list on LCD
Circuit connection
Start
Detect temperature now
Show date, time, and
temperature on LCD
Tips:
Connect temperature sensor to
Pin A0.
59. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 53
Project 4 Answer(Refer p4.ino)
int tempPin = 0; // set temperaturePin =0
int buttonState=0; // set buttonState=0
char buf[30]; //initialize character buffer of size 30
void setup()
{
Serial.begin(9600); //set data speed =9600
Serial.println("lcd_siztex<50>rn"); //set text size to 50pt
Serial.println("lcd_bacdatrn"); //clear LCD and show date now on LCD
}
void loop()
{
int temp = analogRead(tempPin); // read temp sensor at pinA0
temp = temp /2;
Serial.println("lcd_bactimrn"); //show time now on LCD
Serial.println("lcd_bactex< >rn"); //add space
sprintf(buf,"lcd_bactex<temp:%d>rn",temp); //show temperature on LCD
Serial.print(buf);
Serial.println("lcd_bactex<#>rn"); // add space
delay(5000);
}
60. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 54
Chapter 6 Button Toolbox
Buttons can be used to send data and show data.
Send Data: You can set data you wish to send through each „Button Setting‟ page.
Show Data: You can use commands in the button toolbox to change the design of each
button.
6.1 Button toolbox command list
Following are available commands in this toolbox:
Ref Command Function
1 but_shoon<button ID>rn Show button.
Example:
but_shoon<A1>: This will show button A1.
but_shoon<B1>: This will show button B1.
2 but_shooff<button ID>rn Hide button.
Example:
but_shooff<A1>: This will hide button A1.
but_shooff<B1>: This will hide button B1.
3 but_shotex<button
ID#text>rn
Clear current content on the button and show the new text.
<button ID#ext>:„button ID‟ is the ID for the button e.g. A1,
A2, B2... ‟text‟ is the text you want to show on the button.
Example:
but_shotex<A1#Hello>: Show „Hello‟ on button A1
but_shotex<B1#Ok>: Show „Ok‟ on button B1
4 but_siztex<button
ID#value>rn
Set text size on each button.
<button ID#value>: „button ID‟ is the ID for the button e.g.
A1, A2, B2... Size of text. Any positive number.
Example:
but_sizetex<A1#20>: Set button A1 text size to 20pt.
but_sizetex<C3#60>: Set button C3 text size to 60pt.
5 but_baccol<button
ID#color code>rn
Change background color of button. Refer to point 2.15 for
color code details.
Example:
but_baccol<A1#-1>: Change background color of button A1
to white color.
61. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 55
6 but_frocol<button
ID#color code>rn
Change text color of button. Refer to point 2.15 for color
code details.
Example:
but_frocol<B2#-1>: Change text color of button B2 to white
color.
6.2 Project 5: Fire alarm which shows system status on the
Smartphone
Objective: Change button properties
NOTE: Circuit connection is the same as project 4
Start
Detect current
temperature
Temperature
>45C?
No
Yes
Button1 red color
Button 2 green color
Button1 green color
Button 2 red color
62. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 56
Project 5 Answer(please refer p5.ino)
int tempPin = 0; // set tempPin=0
void setup()
{
Serial.begin(9600); //set data speed 9600 bps
}
void loop()
{
Int temp = analogRead(tempPin); // read temperature sensor at pin A0
temp = temp /2; // calibrate temp sensor value
if( temp > 45)
{ // Show button
Serial.println ("but_shoon<a1>rn");
Serial.println ("but_shoon<c1>rn");
Serial.println ("but_shoon<a2>rn");
//Clear current content on the button and show the new text.
Serial.println ("but_shotex<a1# <=45C>rn");
Serial.println ("but_shotex<c1# >45C>rn");
Serial.println ("but_siztex<a2#60>rn");
Serial.println ("but_shotex<a2# Safety>rn");
Serial.println ("but_baccol<a1#-3275001>rn");
Serial.println ("but_baccol<c1#-11937254>rn");
delay (1000);
}
else
{ // Show button
Serial.println ("but_shoon<a1>rn");
Serial.println ("but_shoon<c1>rn");
Serial.println ("but_shoon<a2>rn");
//Clear current content on the button and show the new text.
Serial.println ("but_shotex<a1#<=45C>rn");
Serial.println ("but_shotex<c1#>45C>rn");
Serial.println ("but_siztex<a2#60>rn");
Serial.println ("but_shotex<a2#Danger>rn");
Serial.println ("but_baccol<a1#-11937254>rn");
Serial.println ("but_baccol<c1#-3275001>rn");
delay (500);
64. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 58
6.3 Project 6: Control bulb on/off using Smartphone
Objective: Single byte control using button
Start
Detect data from
Smartphone
Received „1‟? On LED at Pin13Yes
No
Received „0‟? Off LED at Pin 13Yes
No
66. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 60
Project 6 Answer (Refer to p6.ino)
void setup ()
{
pinMode(13,OUTPUT); //Set pin 13 as output
digitalWrite(13,HIGH); // initialize pin 13 as output high
Serial.begin(9600); // set data speed to 9600 bps
}
void loop ()
{
//Get the number of bytes (character) available for reading from the serial port
if(Serial.available() > 0)
{
char data = Serial.read(); // read incoming serial data
if (data == '0') // if data received „0‟
{
digitalWrite (13,LOW); // LED off
Serial.println ("OFF LED"); // The arduino Serial Monitor should display “OFF LED”
}
else if (data == '1')// if data received „1‟
{
digitalWrite (13,HIGH); // LED ON
Serial.println("ON LED"); // The arduino Serial Monitor should display “ON LED”
}
}
}
67. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 61
6.4 Project 7: Control motor direction using Smartphone
Objective: String control using button
Start
Detect data from
Smartphone
Received
“FWD”?
Forward Motor
(Pin13=1,
Pin12=0)
Yes
No
Received
“STP”?
Stop Motor
(Pin13=0,
Pin12=0)
)
Yes
No
Received
“REV”?
Reverse Motor
(Pin13=0,
Pin12=1)
Yes
No
68. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 62
Project 7 Answer (Refer to p7.ino)
int led = 13; // set led =13
int led2 =12; // set led2=12
void setup ()
{
pinMode(13,OUTPUT); //set pin 13 as output
digitalWrite(13,LOW); //initialize pin13 as output LOW
pinMode(12,OUTPUT);// set pin 12 as output
digitalWrite(12,LOW); // initialize pin12 as output LOW
Serial.begin(9600); // set data as 9600 bps
}
void loop ()
{
String input = " "; //clear the String
//Get the number of bytes (Strings) available for reading from the serial port.
while(Serial.available() > 0)
{
input += (char) Serial.read();// Reads the strings
delay(1000);
if (input == "FWD" ) //if received string data “FWD”
{
digitalWrite (13,HIGH); //led 1 on
digitalWrite (12,LOW); //led 2 off
Serial.println ("lcd_shotex< FORWARD >rn"); // LCD show FORWARD
}
else if (input== "STP") //if received string data “STP”
{
digitalWrite (13,LOW); //led 1off
digitalWrite (12,LOW); // led 2 off
Serial.println ("lcd_shotex< STOP >rn"); // LCD show STOP
}
else if (input=="REV")
{
digitalWrite (13,LOW); // led1 off
digitalWrite (12,HIGH); // led2 on
Serial.println ("lcd_shotex< REVERSE >rn"); // LCD show REVERSE
}
}
}
Tips:
Connect dual relay motor
driver to Pin13, Pin12. For
temporary use, you can use
LED to replace the relay
module.
Buttons A1, A2, A3 in this
example are used to send
data.
Set button A1, A2, A3 to
„Show‟ and „Enable Send
Data‟.
Data to send out:
For button A1: FWD
For button A2: STP
For button A3: REV
69. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 63
Chapter 7 Audio Toolbox (optional add on)
Audio toolbox is used to record and play sound.
7.1 Audio toolbox command list
Following are available commands in this toolbox:
Ref. Command Function
1 aud_recman<filename>rn Record audio file and save the audio file using the
filename you set.
<filename> does not need a file extension. Audio file will
be auto saved as a .mp3 file.
Example:
aud_recman<myaudio>: Record audio file and save it as
myaudio.mp3.
2 aud_recautrn Record audio file with the current date and time. The
format of the filename is ddmmyyyy_hhmmss.mp3.
Example:
Date: 25-08-2015, Time: 21:58:12
aud_recaut: Record audio file and save it as
25082015_215812.mp3.
4 aud_recoffrn Stop audio recording.
5 aud_plaon<filename>rn Play audio file for one time only.
<filename> does not need a file extension. It will auto use
filename you want with .mp3.
Example:
aud_plaon<myaudio>: Play myaudio.mp3 for one time
only.
6 aud_plaallrn Play all audio files.
Example:aud_plaall: Auto play all audio files in operatin
folder.
7 aud_plarep<filename>rn Repeat playing the same audio file.
<filename> does not need a file extension. It will auto
show filename you want with .mp3.
Example:
70. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 64
aud_plarep<myaudio>: Repeat play myaudio.mp3.
8 aud_plaoffrn Stop play audio file.
71. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 65
7.2 Project 8: Wheelchair timer for rehabilitation purpose
Objective: Play an audio file
Start
Detect the light dependent
resistor voltage
Dark?
No
Yes
Show counter value on
LCD
Timer=Timer-1sec
Set timer to 20sec
Stop playing the siren file
Timer=0?
Yes
No
Play a siren file
72. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 66
Circuit Connection
Project 8 Answer (Refer to p8.ino)
int lightPin = 0; // set lightPin=0
int stab = 1; //set stab= 1
int timer = 20; // set timer =20
char buf [50]; // initialize character buffer of size 50
void setup()
{
Serial.begin(9600); //set data speed 9600 bps
Serial.println("lcd_siztex<50>rn"); //set text size to 50pt
}
Tips:
Connect light
dependent resistor
(LDR) to pinA0.
Copy siren3.mp3 into
MC folder.
74. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 68
7.3 Project 9: Communication device for patient who is unable to
speak properly
Objective: Record and play an audio file
Start
Detect data from
Smartphone
Received „1‟? LED 1 On
Record 1.mp3 for
4 sec
Yes
No
Received „2‟? LED 2 ON
Record 2.mp3 for
4 sec
Yes
No
Received „3‟? LED 3 ON
Play 1.mp3 for
4 sec
Yes
No
Received „4‟? LED 4 ON
Play 2.mp3 for
4 sec
Yes
No
75. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 69
Circuit Connection
Tips:
Connect digital LED to pin13, pin12,pin11,pin10
Buttons A1, B1,A2, B2 in this example are used
to send data.
Set button A1, B1, A2, B2 to „Show‟ and „Enable
Send Data‟.
Data to send out:
For button A1: 1
For button B1: 2
For button A2: 3
For button B2: 4
Recorded audio save in MC folder
available for external application
76. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 70
Project 9 Answer (Refer to p9.ino)
void setup ()
{
pinMode(13,OUTPUT); // set pin 13 as output
digitalWrite(13,LOW); // initialize led1 as output LOW
pinMode(12,OUTPUT); // set pin12 as output
digitalWrite(12,LOW); // initialize led2 as output LOW
pinMode(11,OUTPUT); // set pin11 as output
digitalWrite(11,LOW); // initialize led3 as output LOW
pinMode(10,OUTPUT); // set pin10 as output
digitalWrite(10,LOW); // initialize led 4 as output LOW
Serial.begin(9600); // set data seed 9600 bps
}
void loop ()
{
//Get the number of bytes (character) available for reading from the serial port
if(Serial.available() > 0)
{
char data = Serial.read(); // read incoming serial data
if (data == '1') // if data received “1”
{
digitalWrite (13,HIGH); // led 1 on
Serial.println("aud_recman<1>rn"); // record 1.mp3 on
delay(4000);
Serial.println("aud_recoffrn"); // record 1.mp3 off
digitalWrite (13,LOW); // led 1 off
}
else if (data == '2') // if data received „2‟
{
digitalWrite (12,HIGH); // led 2 on
Serial.println("aud_recman<2>rn"); // record 2.mp3 on
delay(4000);
Serial.println("aud_recoffrn"); // record 2.mp3 off
digitalWrite (12,LOW); // led 2 off
}
else if (data == '3') // if data received „3‟
{
digitalWrite (11,HIGH); // led 3 on
Serial.println("aud_plaon<1>rn"); // play 1.mp3
delay(4000);
digitalWrite (11,LOW); // led 3 off indicate 1.mp3 stop
}
77. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 71
else if (data == '4')// if data received „4‟
{
digitalWrite (10,HIGH); // led 4 on
Serial.println("aud_plaon<2>rn");// play 2.mp3
delay(4000);
digitalWrite (10,LOW); // led 4 off indicate 2.mp3 stop
}
delay(200);
}
}
78. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 72
7.4 Project 10: Remote control for speaker sound volume
Objective: Control speaker sound volume
Start
Detect data from
Smartphone
Received „1‟? Play siren3.mp3Yes
No
Received „2‟? Stop play
siren3.mp3
Yes
No
No
Play mode?
Send variable
resistor value to
the Smartphone
Yes
No
Detect play or stop audio
mode
79. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 73
Project 10 Answer (Refer to p10.ino)
int stab = 0; // set stab=0
int volpin = 0; // set volpin=0
char buf [50]; // initialize character buffer of size 50
void setup ()
{
pinMode(11,OUTPUT); // set pin 11 as output
digitalWrite(11,LOW); // Initialize pin11 as output LOW
pinMode(10,OUTPUT); // set pin 10 as output
digitalWrite(10,LOW); // Initialize pin10 as output LOW
Serial.begin(9600); // set data speed 9600 bps
Serial.flush(); // clear Serial monitor
}
void loop ()
{
//Get the number of bytes (character) available for reading from the serial port.
if(Serial.available() > 0)
{
char direct = Serial.read(); //read the character
if (direct == '1') // If receive data „1‟
{
digitalWrite (11,HIGH); // on LED at pin 11
Serial.println ("aud_plaon<siren3>rn"); // play siren3.mp3
stab = 1;
}
else if (direct == '2') // if received data „2‟
{
digitalWrite (10,HIGH); // on LED at pin 10
Serial.println ("aud_plaoffrn"); // stop siren3.mp3
stab = 0;
}
}
if(stab==1)
{
int vol = analogRead(volpin)/10.23; // read potentiometer value at pin A0
sprintf(buf,"out_audvol<%d>rn",vol); // control smartphone volume
Serial.println(buf);
}
delay (1000);
}
Tips:
Connect LED to 11 and 10
Connect potentiometer
to A0.
Copy siren3.mp3 into the
MC folder.
Set button A1, A2 to
„Show‟ and „Enable Send
Data‟.
Text to show on button:
For button A1: Start
For button A2: Stop
Data to send out:
For button A1: 1
For button A2: 2
80. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 74
Chapter 8 Photo Toolbox (optional add on)
Photo toolbox is used to take and show photo.
8.1 Photo toolbox command list
Following are available commands in this toolbox:
Ref. Command Function
1 pho_froman<filename>rn Take photo from the front camera and save the photo file
using the filename you set.
<filename> does not need a file extension. Photo file will
be auto saved as a .jpg file.
Example:
pho_froman<myphoto>: Take photo from front camera
and save it as myphoto.jpg.
2 pho_bacman<filename>rn Take photo from back camera and save the photo file
using the filename you set.
<filename> does not need a file extension. Photo file will
be auto saved as a .jpg file.
Example:
pho_bacman<myphoto>: Take photo from back camera
and save it as myphoto.jpg.
3 pho_froautrn Take photo from the front camera and save the photo file
with the current date and time. The format of the
filename is ddmmyyyy_hhmmss.jpg.
Example:
Date: 25-08-2015, Time: 21:58:12
pho_froaut: will take a photo from front camera and save
it as 25082015_215812.jpg.
4 pho_bacautrn Take photo from the back camera and save the photo file
with the current date and time. The format of the
filename is ddmmyyyy_hhmmss.jpg.
Example:
Date: 25-08-2015, Time: 21:58:12
pho_bacaut: will take a photo from back camera and
81. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 75
save it as 25082015_215812.jpg.
5 pho_lcdon<filename>rn Show photo on LCD.
<filename> does not need a file extension. It will auto
show filename you want with .jpg.
Example:
pho_lcdon<myphoto>: Show myphoto.jpg on LCD.
6 pho_shoon<filename>rn Show photo on a pop out screen.
<filename> does not need a file extension. It will auto
show filename you want with .jpg.
Example:
pho_shoon<myphoto>: Show myphoto.jpg on pop out
screen.
7 pho_shooff<filename>rn Close the photo pop out screen.
82. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 76
8.2 Project 11: Security system for the computer lab
Objective: Capture image and record
Start
Detect door status
Door open? No
Yes
Take photo using back
camera
Count=Count+1
Show the photo on LCD
83. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 77
Circuit connection
Tips:
Connect LED to PIN 13.
Connect door switch to Pin 2.
Now we are using pull up resistor
instead of pull down resistor
Recorded audio save in
84. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 78
Project 11 Answer (Refer to p11.ino)
const int led = 13; //set led=13
const int Button = 2; // set Button =2
long int count = 0; // set count =0
int stab = 0; // set stab=0
int buttonState=0; //set buttonState=0
char buf[30]; // Initialize first character buffer
char nuf[30]; // Initialize second character buffer
void setup()
{
Serial.println("lcd_siztex<50>rn"); // set lcd text size into 50
pinMode(led,OUTPUT); //initialize pin13 as output
pinMode(Button, INPUT); // initialize pin 2 as input
Serial.begin(9600); // set data speed 9600 bps
}
void loop ()
{
buttonState = digitalRead(Button); // Read digital pin 2
if(buttonState == HIGH && stab == 1) //if door open and stab =1
{
digitalWrite (led,HIGH); //LED on
count = count + 1;
sprintf(buf,"pho_bacman<%lu>rn",count); //take photo from back camera
Serial.println(buf);
delay(5000);
sprintf(nuf,"pho_lcdon<%lu>rn",count); //show photo on lcd
Serial.println(nuf);
delay(5000);
stab = 0;
}
85. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 79
else if (buttonState == LOW && stab == 0) // if door close and stab =0
{
digitalWrite (led,LOW); // LED off
stab=1; // set stab =1
}
delay (250);
}
86. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 80
Chapter 9 Video Toolbox (optional add on)
Video toolbox is used to show control vibration, camera LED and loud speaker sound
volume.
9.1 Video toolbox command list
Following are available commands in this toolbox:
Ref. Command Function
1 vid_froman<filename>rn Record video from the front camera and save the video
file using the filename you set.
<filename> does not need a file extension. All videos will
be auto saved as a .mp4 file.
Example:
vid_froman<myvideo>: Record video from the front
camera and save it as myvideo.mp4.
2 vid_bacman<filename>rn Record video from the back camera and save the video
file using the filename you set.
<filename> does not need a file extension. All videos will
be auto saved as a .mp4 file.
Example:
vid_bacman<myvideo>: Record video from the back
camera and save it as myvideo.mp4.
3 vid_froautrn Record video from the front camera and save the video
file with the current date and time. The format of the
filename is ddmmyyyy_hhmmss.mp4.
Example:
Date: 25-08-2015, Time: 21:58:12
vid_froaut: will record a video from front camera and save
it as 25082015_215812.mp4.
4 vid_bacautrn Record video from the back camera and save the video
file with the current date and time. The format of the
filename is ddmmyyyy_hhmmss.mp4.
Example:
Date: 25-08-2015, Time: 21:58:12
87. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 81
vid_bacaut: will record a video from back camera and
save it as 25082015_215812.mp4.
5 vid_recoffrn Stop recording video from front or back camera.
6 vid_plaon<filename>rn Play video file on a pop out screen. Play the video file
only once.
<filename> does not need a file extension. It will
automatically show the filename you wish to open with
.mp4.
Example:
vid_plaon<myvideo>: Play myvideo.jpg on the pop out
screen only once.
7 vid_plarep<filename>rn Repeat playing the same video file on a pop out screen.
<filename> does not need a file extension. It will auto
show filename you want with .mp4.
Example:
vid_plarep<myvideo>: Repeat play myvideo.jpg on pop
out screen.
8 vid_plaallrn Play all video files on a pop out screen.
Example:
vid_plaall: Automatically play all video files in the
operating folder.
9 vid_plaoffrn Stop playing the video file and close the pop out screen.
88. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 82
9.2 Project 12: Record and play back video when room door is open
Objective: Record and play video
Start
Detect door open or
close status
Door open?
No
Yes
Record video using back camera
Wait for 10sec
Stop video recording
Increase counter value
Wait for 5sec
Play back recorded video
89. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 83
Project 12 Answer (Refer to p12.ino)
const int led = 13; //set led =13
const int Button = 2; // set Buttton =2
int count = 0; // set count =0
int stab = 0; // set stab=0
int buttonState=0; //set buttonState=0
char buf[50];/ /initialize first character buffer of size 50
char nuf [50]; //initialize second character buffer of size 50
void setup()
{
Serial.println("lcd_siztex<50>rn"); // set lcd textsize into 50
pinMode(led,OUTPUT); //set pin 13 as output
pinMode(Button, INPUT); //set pin 2 as input
Serial.begin(9600); // set data speed 9600 bps
}
void loop ()
{
buttonState = digitalRead(Button); //buttonState read digital pin 2
if(buttonState == HIGH && stab == 1) // if door open
{
digitalWrite (led,HIGH); //led on
count = count + 1;
sprintf(buf,"vid_froman<%d>rn",count); //record video from front camera
Serial.println(buf);
delay(10000);
Serial.println("vid_recoffrn"); // stop record
delay (5000);
sprintf(nuf,"vid_plaon<%d>rn",count); // play video
Serial.println(nuf);
stab = 0; // reset stab =0
}
else if (buttonState == LOW && stab == 0) // if door is close and stab =0
{
digitalWrite (led,LOW); //led off
stab=1; // reset stab =1
}
delay (250);
}
Tips:
Connect door switch to pin 2.
Please refer project 11 for
circuit connection
Recorded video is save in
MC folder available for
external application
90. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 84
Chapter 10 Sensor Toolbox (optional add on)
Sensor toolbox is used to read sensor value in the Smartphone. Make sure that your phone
has the sensor before you use any command.
10.1 Sensor toolbox command list
Following are available commands in this toolbox:
Ref. Command Function
1 inp_accxrn Read the x axis value of the acceleration sensor and send
to the connected device.
The value is in angle degree unit. It has 8 bytes. Its format
starts with AX, followed by + or -, a 3 digits number and
ends with „rn‟.
Example: AX+016rn or AX-012rn.
Following picture shows the method used in changing the
x axis value of the acceleration sensor.
2 inp_accyrn Read the y axis value of the acceleration sensor and send
to the connected device.
The value is in angle degree unit. It has 8 bytes. Its format
starts with AY, followed by + or -, followed by a 3 digits
number and ends with „rn‟.
Example: AY+016rn or AY-012rn.
Following picture shows the method to change the y axis
value of the acceleration sensor.
91. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 85
3 inp_acczrn Read the z axis value of the acceleration sensor and send
to connected device.
The value is in angle degree unit. It has 8 bytes. Its format
starts with AZ, followed by +, a 3 digits number (from 000
to 359) and ends with „rn‟.
Example: AZ+016rn or AZ+359rn.
Following picture shows the method to change z axis value
of the acceleration sensor.
4 inp_reamicrn Read the value of the microphone sound volume and send
to the connected device.
The value is in db unit. It has 7 bytes. Its format starts with
LS, followed by a 3 digits number and ends with „rn‟.
Example: LS075rn or LS092rn.
5 inp_reabatrn Read the Smartphone‟s battery voltage level and send to
the connected device.
The value is in percent unit. It has 7 bytes. Its format starts
92. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 86
with BL, followed by a 3 digits number (from 000 to 100)
and ends with „rn‟.
Example: BL023rn. or BL091rn.
6 inp_reacharn Read the Smartphone charging status and send to the
connected device.
When the Smartphone is not charging, it will send
BC000rn to the connected device.
When the Smartphone is charging, it will send BC111rn
to the connected device.
7 inp_reatimrn Read the current Smartphone‟s time and send to the
connected device.
The value has 10 bytes. Its format starts with TN, followed
by hhmmss and ends with „rn‟..
Example:
If the current time is 03:18:07, it will send TN031807rn to
the connected device.
If the current time is 15:02:11, it will send TN150211rn to
the connected device.
8 inp_readatrn Read the current Smartphone‟s date and send to the
connected device.
The value has 12 bytes. Its format starts with FN, followed
by ddmmyyyy and ends with „rn‟.
Example:
If the current date is 25-08-2012, it will send
FN25082012rn to the connected device.
If the current date is 01-06-2013, it will send
FN01062013rn to the connected device.
9 inp_readayrn Read the current Smartphone‟s day and send to the
connected device.
The value has 5 bytes. Its format starts with DN, followed
by number 0 (Sunday) to 6 (Saturday) and ends with „rn‟.
Example:
If the current day is Sunday, it will send DN0rn to the
connected device.
93. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 87
If the current date is Wednesday, it will send DN3rn to the
connected device.
10 inp_reaprorn Read the proximity sensor value and send to the
connected device.
The value has 5 bytes. Its format starts with DN, followed
by number 0 to 9 (depends on phone) and ends with „rn‟.
Example:
If nothing is detected on the proximity sensor, it will send
DP1rn to the connected device.
If an object is detected on the proximity sensor, it will send
DP0rn to the connected device.
10.2 Project 13: Power failure detector using Smartphone
Objective: Apply charging sensor
Start
Detect Smartphone
charging status
Power source
detected?
No
Yes
Turn off camera LED
Show the response on LCD
Turn on camera LED
94. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 88
Project 13 Answer (Refer p13.ino)
int led = 13; // set led =13
int en=0; // set en =0
void setup()
{
pinMode(led, OUTPUT); // Set pin 13 as digital output
Serial.begin(9600); //set data speed 9600 bps
Serial.flush(); // clear serial monitor
}
void loop()
{ Serial.println("inp_reacharn"); // read z-axis value of acceleration sensor
delay(500);
String input = ""; // clear the string
// Get the number of bytes (Strings) available for reading from the serial port
while (Serial.available() > 0)
{
input += (char) Serial.read(); // Read incoming serial data
delay(5); // Delay for 5 ms so the next char has time to be received
if (input == "BC111" ) // if input received data BC111
{
digitalWrite (13,HIGH); //on led
Serial.println("out_ledon<0>rn"); // on camera led
Serial.println("lcd_shotex<Power Failure!>rn"); //LCD show Power Failure
}
else if(input== "BC000" ) // if input received data BC000
{
digitalWrite (13,LOW); // off led
Serial.println("out_ledoffrn"); // off camera led
Serial.println ("lcd_shotex< POWER AVAILABlE >rn"); // LCD show Power Available
}
}
delay(500);
}
Tips:
Please refer project 6 for
circuit connection.
Connect LED to pin13.
96. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 90
Project 14 Answer (Refer p14.ino)
String input; //set input as string data type
int en=0; // set en =0
//set data1--->data3 as integer data type
int data1;
int data2;
int data3;
int count=0; //set count =0
long int total; //set total into long integer data type
char buf[30]; // initialize character buffer of size 30
void setup()
{
Serial.begin(9600); //set data speed 9600 bps
pinMode(13,OUTPUT); // set pin 13 as digital output
}
void loop()
{
input =""; // clear the string
//Read the z axis value of the acceleration sensor and substitute to String input
Serial.println("inp_acczrn");
delay(500);
Tips:
Please refer project 6 for
circuit connection
97. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 91
// Get the number of bytes (Strings) available for reading from the serial port
while(Serial.available() > 0)
{
input += (char) Serial.read(); //Read incomming Serial data
delay(5);
count++; // count will increase until desire information collected
if(count ==6) // Acquired 6 significant byte from String data type
{
en=1; // set en =1
count=0; //set count =0
}
}
if(en==1)
{
//data type conversion from character to integer
data1= input[3]-'0';
data2= input[4]-'0';
data3= input[5]-'0';
//value calibration
data1=data1*100;
data2=data2*10;
total= data1+data2+data3; // summarize angle in integer data type
delay(100);
sprintf(buf,"lcd_shotex<#Angle:%d>rn",total); // LCD disply z-axis angle
Serial.print(buf);
98. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 92
if(total >90) // if z-axis angle > 90
{
digitalWrite(13,HIGH); //LED 0n
Serial.println("aud_plaon<siren6>rn"); // play siren6.mp3
}
else // if z-axis < 90
{
digitalWrite(13,LOW); //LED off
Serial.println("aud_plaoffrn"); //stop siren6.mp3
}
en=0; // set en=0
}
delay(5000); // delay 5 second to assure system have time response smoothly
}
99. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 93
Chapter 11 GPS Toolbox (optional add on)
GPS toolbox is used to detect the current Smartphone coordinate and speed. Make sure that
GPS module is turned on when using this toolbox.
11.1 GPS toolbox command list
Following are available commands in this toolbox:
Ref. Command Function
1 gps_realonrn Read the longitude value from the GPS module and send
to the connected device.
The value has 23 bytes. Its format starts with LN, followed
by a 3 digits decimal number, a „.‟ and 15 digits floating
number and ends with „rn‟.
Example: LN003.123450123456789rn or
LN101.123450000000000rn.
2 gps_realatrn Read the latitude value from the GPS module and send to
the connected device.
The value has 23 bytes. Its format starts with LT, followed
by a 3 digits decimal number, a „.‟ and 15 digits floating
number and ends with „rn‟.
Example: LT003.123450123456789rn or
LT101.123450000000000rn.
3 gps_reaspdrn Read the moving speed value from the GPS module and
send to the connected device.
The value is in Km/h unit. It has 10 bytes. Its format starts
with GS, followed by a 3 digits decimal number, a „.‟ and 2
digits floating number and ends with „rn‟.
Example: GS015.12rn or GS36.45rn.
101. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 95
Project 15 Answer (Refer p15.ino)
String input; //Set data into String datta type
int en=0; // set en =0
//Set data1 -->data5 into integer data type
int data1;
int data2;
int data3;
int data4;
int data5;
int count=0; // set count =0
float myspeed; // set myspeed
char buf[30]; // set character buffer of size 30
void setup()
{
Serial.begin(9600); // set data speed 9600 bps
pinMode(13,OUTPUT); // set pin13 as output
}
void loop()
{
input =""; // clear the string
// read moving object speed and substitute into String input
Serial.println("gps_reaspdrn");
delay(500);
Tips:
Please refer project 6 for
circuit connection
Please open
Speed Warning app
on phone before running
this project with
magnet code
This project only available
when user in driving mode.
102. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 96
// Get the number of bytes (Strings) available for reading from the serial port
while(Serial.available() > 0)
{
input += (char) Serial.read(); // Read incoming serial data
delay(5);
count++; // count will increase until desire String information collected
if(count ==8) // Acquired 8 significant byte from the String
{
en=1; // set en=1
count=0; //set count =0
}
}
if(en==1)
{
//Display moving object speed from GPS on phone LCD
sprintf(buf,"lcd_shotex<Speed:#%c%c%c.%c%cKm/h>rn",input[2],input[3],input[4],input[6],i
nput[7]);
Serial.println(buf);
//data type conversion from character to integer
data1= input[2]-'0';
data2= input[3]-'0';
data3= input[4]-'0';
data4= input[6]-'0';
data5 =input[7]-'0';
//value calibration
data1=data1*100;
data2=data2*10;
103. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 97
myspeed= data1+data2+data3;// summarize speed in float datatype
delay(100);
Serial.println(myspeed);
if(myspeed >90) // if speed >90
{
digitalWrite(13,HIGH); // led on
Serial.println("lcd_baccol<-3275001>rn"); //led background color shown
}
else
{
digitalWrite(13,LOW); //led off
Serial.println("lcd_baccol<-11937254>rn"); // led background color shown
}
en=0; // set en= 0
}
delay(500); // delay 0.5 second to assure system have time response smoothly
}
104. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 98
Chapter 12 Speech Toolbox (optional add on)
Speech toolbox is used to convert speech to text or text to speech. Make sure an Internet
connection is available when you are using the speech to text feature.
12.1 Speech toolbox command list
Following are available commands in this toolbox:
Ref. Command Function
1 inp_texspe<text> Convert text to speech and play through Smartphone
speaker.
<text>: The text you wish to convert to speech.
Example:
Inp_texspe<Hello good morning>: It will play „Hello good
morning‟ through the Smartphone speaker.
2 inp_spetex Convert detected speech (through microphone) to tex and
send to the connected device.
The value has 5 bytes. Its format starts with VT, followed
by the converted text and ends with „rn‟.
105. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 99
12.2 Project 16: Visitor counter with greeting
Objective: Read out message we want
Start
Detect door open or
close status
Door open? No
Yes
Show on LCD
Counter + 1
Greet visitor
106. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 100
Project 16 Answer (Refer to p16.ino)
const int ledpin=13; //set ledpin =13
const int Button=2; //set Button =2
int counter=0;//set counter =0
int sta=1; //set sta=1
int buttonState=0; //set button State=0
char buf[50]; // first character buffer
char buf2[50]; // second character buffer
void setup()
{
pinMode(ledpin,OUTPUT); //set pin13 as output
pinMode(Button, INPUT); //set pin 2 as input
Serial.begin(9600); //set data speed as 9600 bps
}
void loop()
{
buttonState=digitalRead(Button); //read digital pin 2
If(buttonState == HIGH &&sta==1) //if door open and sta =1
{
digitalWrite(ledpin,HIGH); //led on
counter= counter +1; //counter increase by 1
sprintf(buf,"lcd_shotex<You are visitor: %d>rn",counter); // show visitor num on lcd
Serial.println(buf);
sprintf(buf2,"inp_texspe<You are visitor %d>rn",counter); //play speech
Serial.println(buf2);
delay(3000);
sta=0; //set sta=0
}
else if (buttonState == LOW) // if door close
{
digitalWrite(ledpin,LOW); //led off
sta=1; // set sta =1
}
delay(2000);
}
Tips:
Connect LED to pin13.
Connect door switch to pin2.
Pls refer Project 11 for circuit
connection
107. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 101
Chapter 13 SMS Toolbox (optional add on)
SMS toolbox is used to send and receive SMS. Make sure that the SIM card in your phone is
activated and with call credits.
13.1 SMS toolbox command list
Following are available commands in this toolbox:
Ref. Command Function
1 sms_wrinum<number>rn Besides using the „SMS Setting‟ page to set the SMS
receiver number, you can also use this command to set
the receiver number to send SMS.
<number>: Support multiple numbers. Each number is
separated by „#‟.
Example:
sms_wrinum<012345#67890#112233>: Set the receiver
numbers to 012345, 67890 and 112233.
2 sms_wrimes<text>rn Besides using the „SMS Setting‟ page to set the SMS
content, you also can use this command to set the SMS
content to send SMS.
<text>: Message you wish to send. Add „#‟ in <text> to
move the following message to the next row.
Example:
sms_wrimes<Hello#How are you?>: In the SMS content,
„Hello‟ will be in the 1st
row and „How are you?‟ will be in
the 2nd
row.
3 sms_senmesrn Send SMS to the receiver. Make sure that you have set a
receiver number and an SMS content before you execute
this command.
4 sms_ackonrn Turn on SMS acknowledgement when a new SMS is
received.
It will send „SINrn‟ to the connected device if any new
SMS is received.
5 sms_ackoffrn Turn off SMS acknowledgement when a new SMS is
received.
108. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 102
6 sms_fintot<mode>rn Find total number of SMS in the phone and send the value
to the connected device.
The data has 9 bytes. Its format starts with SA, followed
by a 5 digits number and ends with „rn‟.
<mode>: <0> is used to find all unread SMS in the phone.
<1> is used to find total read SMS in the phone. <2> is
used to find total read and unread SMS in the phone.
Example:
If phone has 3 unread SMS and 52 read.
sms_fintot<0>: It will send out „SA00003rn‟ to the
connected device.
sms_fintot<1>: It will send out „SA00052rn‟ to the
connected device.
sms_fintot<2>: It will send out „SA00055rn‟ to the
connected device.
7 sms_fintex<sms
ID#keyword>rn
Find keyword in specified SMS in the phone and send the
data to the connected device.
If the keyword is found in the SMS it will send „SC1rn‟ to
the connected device.
If the keyword is not found in the SMS it will send „SC0rn‟
to the connected device.
<sms ID#keyword>: The „sms ID‟ starts from 0. The earlier
SMS has a larger number. The last SMS will always have
sms ID=0. „keyword‟ is the keyword you wish to find in the
SMS. „keyword‟ is not case sensitive.
Example:
sms_fintex<0#Yes>: It will check whether the content of
the last SMS it received has a keyword „Yes‟. It will check
whether the content of the last SMS it received has a
keyword „Yes‟. If „Yes‟ is found it will send „SC1rn‟ to the
connected device, else, it will send „SC0rn‟ to the
109. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 103
connected device.
sms_fintex<1#ok>: It will check whether the content of the
2nd
last SMS it received has a keyword „ok‟. It will check
whether the content of the last SMS it received has a
keyword „ok‟. If „ok‟ is found it will send „SC1rn‟ to the
connected device, else it will send „SC0rn‟ to the
connected device.
8 sms_reatex<sms ID> Read the SMS content from a particular SMS.
Its format starts with SR, followed by the content in the
SMS and ends with „rn‟.
<sms ID>: The „sms ID‟ starts from 0. The earlier SMS has
a larger number. The last SMS is always sms ID=0.
Example:
If sms ID 0 has content „Yes, Jack‟.
sms_reatex<0>: It will send „SRYes,Jackrn‟ to the
connected device.
If sms ID 9 has content „Ok, have a nice day‟.
sms_reatex<0>: It will send „SROk, have a nice dayrn‟ to
the connected device.
9 sms_reanum<sms ID>rn Read the SMS sender number from a particular SMS.
The data has 18 bytes. Its format starts with SN, followed
by the 14 bytes sender phone number in the SMS and
ends with „rn‟.
If the sender number is less than 14 bytes, it will replace
the empty bytes by „X‟.
<sms ID>: The „sms ID‟ starts from 0. The earlier SMS has
a larger number. The last SMS is always sms ID=0.
Example:
If sms ID 0 sender number is „0123456789‟.
sms_reanum<0>: It will send out
110. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 104
„SNXXXX0123456789rn‟ to connected device.
If sms ID 5 sender number is „+60123456789‟.
sms_reanum<0>: It will send out
„SNXX+60123456789rn‟ to connected device.
10 sms_readat<sms ID>rn Read the SMS receive date from particular SMS.
The data has 12 bytes. Its format starts with „SD‟, followed
by date in ddmmyyyy and ends with „rn‟.
<sms ID>: The „sms ID‟ starts from 0. The earlier SMS has
a larger number. The last SMS is always sms ID=0.
Example:
If sms ID 0 receive date is on 26-12-2013.
sms_readat<0>: It will send „SD26122013rn‟ to the
connected device.
If sms ID 5 receive date is on 15-08-2015.
sms_readat<5>: It will send „SD15082015rn‟ to the
connected device.
11 sms_reatim<sms ID>rn Read the SMS receive time from a particular SMS.
The value has 10 bytes. Its format starts with „ST‟,
followed by date in hhmmss and ends with „rn‟.
<sms ID>: The „sms ID‟ starts from 0. The earlier SMS has
a larger number. The last SMS is always sms ID=0.
Example:
If sms ID 0 received time is on15:42:36.
sms_reatim<0>: It will send „ST154236rn‟ to the
connected device.
If sms ID 5 receive date is on 08:13:27.
sms_reatim<5>: It will send „ST081327rn‟ to the
connected device.
12 sms_reasta<sms ID>rn Read if the SMS status is read or unread from a particular
SMS.
If the SMS is unread, it will send „SB0rn‟ to the
connected device.
111. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 105
If the SMS is already read, it will send „SB1rn‟ to the
connected device.
<sms ID>: The „sms ID‟ starts from 0. The earlier SMS has
a larger number. The last SMS is always sms ID=0.
Example:
If sms ID 0 is unread. Upon receiving „sms_reasta<0>‟ it
will send „SB0rn‟ to the connected device.
If sms ID 5 has been read. Upon receiving
„sms_reasta<5>‟ it will send „SB1rn‟ to the connected
device.
112. Magnet Code 3.0 for Arduino Interface User‟s Manual www.magnetcode.com
Phone: +6012-297 9320 Fax: +603-8948 7451 Email: info@magnetcode.com 106
13.2 Project 17: Fire alarm with SMS alert
Objective: Send SMS
Start
Detect room
temperature
Temperature
>=45C?
No
Yes
Set SMS content and receivers
Send the SMS
Show temperature on LCD
On LED Off LED