You are on page 1of 46

1.

LilyPad Arduino

OBJECTIVE:
To sew the LilyTiny board in a fabric and to make the connected LEDs blink and
glow.

REQUIREMENTS:
1. LilyTiny board
2. Red,White, Green LEDs
3. Lilypad battery holder
4. Coin shape battery
5. Conductive threads

BACKGROUND INFORMATION:
The LilyPad Arduino is a microcontroller board designed for wearable and e-
textiles.

The LilyTiny is a tiny LilyPad board that can make LEDs twinkle and blink in
different patterns. We don’t have to program the board. It comes pre-programmed to
generate fading, blinking, and flickering patterns. Each pin has a different behavior.

PIN BEHAVIOUR
0 LED fades in and out
1 LED thumps in a heartbeat pattern
2 LED steadily blinks on and off
3 LED flickers like an artificial candle
Table-1: LED behavior when connected to the pins on LilyTiny board
CIRCUIT DIAGRAM:

PROCEDURE:
1. Sew the LilyPad Battery holder on the fabric using the conductive thread..
2. Sew and connect the (+)ve and (-)ve terminals of the battery holder with the (+)ve and
(-)ve pins of the LilyTiny board.
3. Place the LED’s on the fabric and connect the (+)ve end of LEDs with different pin of the
LilyTiny board by sewing.
4. Connect all the (-)ve ends of the LEDs with the (-)ve ends of the LilyTiny board.
5. After completing the sewing, place the coin shape battery onto the battery holder and
move the switch to the ON position.
6. When the battery is switched ON, the connected LED’s glow according to its behavior
functionality listed in table-1.

REFERNCES:
1. Lilypad LilyTiny:
http://lilypadarduino.org/?p=523
2. E-Sewing Lilypad Arduino
http://lilypadarduino.org/?page_id=1260
2. Environmental Monitoring with Arduino Uno
Aim:

To measure air quality using Arduino and low cost air quality sensor.

Requirements

1. Arduino Uno microcontroller board


2. Grove- Air Quality Sensor v1.0
3. Jumper Wires

Background information

Air Quality sensor v1.0 is designed for indoor air quality testing. The main gases detected are,
CO, alcohol, acetone, formaldehyde and other slightly toxic gases. In this demo, we define four
stages for reference. They are:
A. Air fresh -- indicating a good air condition
B. Low pollution -- indicating a rather low concentration of target gases exist.
C. High pollution-indicating high pollution level.
D. Very High pollution- Instant measures should be taken to improve the air quality.
The air quality sensor can be easily interfaced to Arduino and responsive to a wide scope
of target gases and cost efficient and it is durable.

Connecting the sensor:

There are four pins available on the sensor and they are connected as follows:

1. Sensor Ground (black colour wire) to the GND pin of Arduino


2. Sensor VCC (red colour wire) to the 5V pin of Arduino
3. Sensor signal (yellow colour wire) to the analog pin A0 of Arduino
4. The pin between the Vcc and the signal pin is to be left without any connection

Circuit diagram:

Procedure:

1. Copy the “Air quality sensor” file into library files of the Arduino (i.e) “your
path/arduino/library”
2. Open the Arduino IDE and select the board and COM port
3. Under examples select the Air quality example and upload.
4. After the upload is complete click on serial monitor
5. The serial monitor will now display “sys_starting”
6. Wait for sensor initialization confirmation
7. After successful initialization, the serial monitor will display the air quality as one of four
different values.

Coding

#include"AirQuality.h"
#include"Arduino.h"

Air Quality airqualitysensor;


int current_quality =-1;

void setup()
{
Serial.begin(9600);
airqualitysensor.init(14);
}

void loop()
{
current_quality=airqualitysensor.slope();
if (current_quality >= 0)// if a valid data returned.
{
if (current_quality==0)
Serial.println("High pollution! Force signal
active");
else if (current_quality==1)
Serial.println("High pollution!");
else if (current_quality==2)
Serial.println("Low pollution!");
else if (current_quality ==3)
Serial.println("Fresh air");
}
}

ISR(TIMER2_OVF_vect)
{
if(airqualitysensor.counter==122)//set 2 seconds as a
detected duty
{

airqualitysensor.last_vol=airqualitysensor.first_vol;
airqualitysensor.first_vol=analogRead(A0);
airqualitysensor.counter=0;
airqualitysensor.timer_index=1;
}
else
{
airqualitysensor.counter++;
}
}

Output:
Results and discussion

Using air quality sensors GIS has been obtained for Madurai city as shown in below

References
http://www.seeedstudio.com/wiki/File:AirQuality_Sensor.zip

https://github.com/TheThingSystem/steward/tree/master/things/examples/arduino/
GroveAQ

http://www.howmuchsnow.com/arduino/airquality
3. Automatic Door Alarm using Ultrasonic Sensor

Objective:

To build a own door alarming system using ultrasonic sensor which is a very
affordable proximity/distance sensor that is used mainly for object detection.

Requirements:

• Arduino Uno
• Ultrasonic sensor HC-SR04
• Buzzer
• Breadboard
• Jumper wires (Male)

Background Information:

• Connect the Vcc of ultrasonic sensor to Vin, GND to GND, Trigger pin to pin 12, Echo
pin to pin 13.
• Use a piezo buzzer or an 8-ohm speaker, basically connect ground to ground and power
to pin 8.
• After connected, upload the program in Arduino IDE what you have already installed in
your system.
Now, check the result.

Circuit diagram:
Coding:

#define trigPin 12
#define echoPin 13

int Buzzer = 8;

void setup() {
Serial.begin (9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(Buzzer, OUTPUT);
}

void loop() {
int duration, distance;
digitalWrite(trigPin, HIGH);
delayMicroseconds(1000);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1;

if (distance >= 200 || distance <= 0){


Serial.println("no object detected");
digitalWrite(Buzzer, LOW);
}

else {
Serial.println("object detected");
tone(Buzzer, 400); // play 400 Hz tone for 500 ms
delay(500);
tone(Buzzer, 800); // play 800Hz tone for 500ms
delay(500);
tone(Buzzer, 400); // play 400 Hz tone for 500 ms
delay(500);
tone(Buzzer, 800); // play 800Hz tone for 500ms
delay(500);
tone(Buzzer, 400); // play 400 Hz tone for 500 ms
delay(500);
tone(Buzzer, 800); // play 800Hz tone for 500ms
delay(500);
noTone(Buzzer);
}
delay(300);
}
Additional Questions:

1. What's the resolution of the ultrasonic sensor used? Within what range does it sense
the object?

2. Can you send an SMS alert to the user, when it senses the object?

References:

 http://www.instructables.com/id/SIMPLE-ARDUINO-ULTRASONIC-SENSOR-DOOR-
ALARM-/
 http://arduino.cc/en/Tutorial/Ping?from=Tutorial.UltrasoundSensor#.Ux02hj-SyM4
 http://www.tautvidas.com/blog/2012/08/distance-sensing-with-ultrasonic-sensor-and-
arduino/
 http://www.youtube.com/watch?v=PG2VhpkPqoA
4. Remote control of Arduino Uno using Raspberry Pi
Objective:
To remotely control Arduino Uno through Raspberry Pi using VNC server.

Requirements:

Software Requirements:
1. VNC server for Linux
2. VNC viewer for Windows
3. URL for downloading - http://www.realvnc.com/download/vnc/
4. Arduino IDE for Linux
5. Putty

Hardware Requirements:
1. Raspberry Pi board
2. Ethernet cable (wired)
3. Wi-Fi dongle (wireless)
4. Arduino Uno
5. USB cable for interfacing

Background Information:

The Raspberry Pi is a credit-card-sized single-board computer developed in the UK by


the Raspberry Pi Foundation with the intention of promoting the teaching of basic computer
science in schools. The Raspberry Pi has a Broadcom BCM2835 system on a chip (SoC) which
includes an ARM1176JZF-S 700 MHz processor,VideoCore IV GPU,[12] and was originally
shipped with 256 megabytes of RAM, later upgraded to 512 MB.[4][13] It does not include a built-
in hard disk or solid-state drive, but uses an SD card for booting and persistent storage.

Setting up your Raspberry Pi:

Raspberry Pi OS (Raspbian) installation:

Requirements:
 Raspberry Pi board model B
 Pi Camera board

 HDMI to VGA adapter


 SD card (min 4GB , max 16GB size)
 Wi-Fi dongle
 USB hub
 Keyboard and mouse
Software:
 NOOBS - New out of box Software (www.raspberrypi.org./archives/tag/noobs
1. Wheezy Raspbian
2. Raspbian
3. Pidora
4. RISC OS
5. Rasp VNC

Preparing SD card for Raspberry Pi:


 Insert the SD card into your computer and format it.
 Extract the NOOBS zip folder from your computer and paste it into the SD card.

SD card formatting

Windows
 Download the SD Association’s Formatting tool from
http://www.sdcard.org/download/formatter_4/eula_windows/
 Install and run the formatting tool on your machine.
 Set “FORMAT SIZE ADJUSTMENT” option to “ON” in the “options”
menu.
 Check that the SD card you inserted matches the one selected by the Tool.
 Click the “Format” button

Raspberry Pi setup

 Connect the HDMI port to the VGA to display the output by using HDMI to VGA
converter.
 For power supply connect to the battery.
 Connect the keyboard, mouse USB and pi camera module to the Raspberry pi.
 Now boot up the Raspberry Pi OS.
 Change the settings to enable the camera from pi board.
How to interface Raspberry Pi with Arduino:

1. Open the LX terminal


2. Enter the following commands:

$ sudo apt-get update


$ sudo apt-get install arduino

VNC server installation in your Raspberry Pi board:


VNC allows you to see your Pi’s desktop and control it remotely using another computer
running MAC OS X, Windows and Linux.
The VNC server software runs on your RPi, access it by running VNC client software on
your other device.
The VNC server:

Install tight VNC: “sudo apt-get install tightvncserver”


Run the program: “tightvncserver”
Start a VNC session: “vncserver :1

References:
1. http://www.raspberrypi.org/quick-start-guide
2. http://gettingstartedwithraspberrypi.tumblr.com/post/24142374137/setting-up-a-vnc-
server
3. http://en.wikipedia.org/wiki/Raspberry_Pi
4. http://www.raspberrypi.org/archives/1171

Additional Exercises:

1. Control the Arduino through Raspberry Pi to make the LED to blink.


2. Drive the stepper motor through Raspberry Pi.

5. Traffic Light Simulation

Objective:
To control the traffic light signal with Arduino board.

Requirements:
1. Arduino
2. USB cable
3. PCB board
4. LED-12 Nos.
5. Soldering iron
6. Connecting wires

Background Information:
The normal function of traffic lights requires complicated control and coordination to
ensure that traffic moves as smoothly and safely as possible and that pedestrians are protected
when they cross the roads. A variety of different control systems are used to accomplish this,
ranging from simple clockwork mechanisms to sophisticated computerized control and
coordination systems that self-adjust to minimize delay to people using the road. In this
experiment LEDs can be used with Arduino to control traffic light system. We can do many
things by connecting Arduino with LED lights not only the traffic light signals. We can also do
the n x n cube with different colors. We can also do smart lighting using LED.

Layout to Simulate Traffic Light Signal


Procedure:

1. For the construction of traffic light signal, first we construct LEDs (Red, Yellow,
Green) on the four sides (left, Right, Up, Down) of the PCB board.
2. The shorter pins of all the LEDs are soldered to the PCB board.
3. The longer pins of all the LEDs are soldered to the PCB board.
4. The longer pin of green LEDs in left side and right side of the PCB board is
connected together. Longer pin of yellow LEDs in left side and right side of the PCB
board is connected together. Longer pin of red LEDs in left side and right side of the
PCB board is connected together.
5. Likewise longer pin of green LED in upper side of the PCB board are connected to
the downside of the green LED in PCB board. Longer pin of yellow LED in upper
side of the PCB board are connected to the downside of the yellow LED in PCB
board. Longer pin of red LED in upper side of the PCB board are connected to the
downside of the red LED in PCB board.
6. The connecting wire from red, yellow, green LED in right side of PCB board is
connected to the digital pin 2, 3, 4 of Arduino board.
7. The connecting wire from green, yellow, red LED in downside of PCB board is
connected to the digital pin 5, 6, 7 of Arduino board.
8. Connect the shorter pins of all LEDs to GND of Arduino board.
9. After giving the connection as per the circuit diagram, the USB power cable of
Arduino could be connected to the PC/laptop.
10. In our PC/laptop the Arduino IDE is opened and run the proper traffic light
simulation program.
11. After the program is uploaded to the Arduino board, the traffic signals are simulated.
PCB

LED

Fig: Circuit to Simulate Traffic Light Signal


Coding:
/*Blink
Turns on an LED on for one second, then off for one
second, repeatedly.This example code is in the public
domain.
*/
// Pin 9 has an LED connected on most Arduino boards.
// give it a name:

int led2 = 2;
int led3 = 3;
int led4 = 4;
int led5 = 5;
int led6 = 6;
int led7 = 7;
int timer=10000;

// the setup routine runs once when you press reset:


void setup() {
// initialize the digital pin as an output.
pinMode(led2, OUTPUT); //red light
pinMode(led3, OUTPUT); //yellow light
pinMode(led4, OUTPUT); //green light
pinMode(led5, OUTPUT); //green light
pinMode(led6, OUTPUT); //yellow light
pinMode(led7, OUTPUT); //red light
}

// the loop routine runs over and over again forever:


void loop()
{
digitalWrite(led4, HIGH);
digitalWrite(led7, HIGH);
digitalWrite(led5, LOW);
digitalWrite(led3, LOW);
delay(timer);
digitalWrite(led6, HIGH); // wait for a second
digitalWrite(led4, HIGH);
digitalWrite(led7,LOW);
delay(5000); // wait for a second
digitalWrite(led6, LOW);
digitalWrite(led4, LOW);
digitalWrite(led5, HIGH);
digitalWrite(led2, HIGH);
delay(timer);
digitalWrite(led5, HIGH);
digitalWrite(led2, LOW);
digitalWrite(led3, HIGH);
delay(5000);
}

Results and Discussions:

1. How can we do 5 signal traffic light using multiple loops?


2. How to trigger traffic lights to change from red to green?
3. How can we further implement this for pedestrian crossing?

References:
1.http://forum.arduino.cc/index.php?topic=140208.0
2. http://mods-n-hacks.wonderhowto.com/how-to/trigger-traffic-lights-change-from-
red-green-78256/

3. www.youtube.com/watch?v=JTwu5DeoHBI
Arduino LED Cube 3x3x3

Aim:
To construct a 3x3x3 LED cube and control it with Arduino.

Components Required:
1. Arduino
2. USB cable
3. LED – 27 Nos.
4. Soldering iron
5. PCB board
6. Connecting wires

Background Information:
Arduino is an open-source electronics prototyping platform based on flexible,
easy-to-use hardware and software. Arduino can be used to develop stand-alone
interactive objects or can be connected to software on our computer. We can control any
circuit with the help of Arduino and Arduino software. The very simple circuit to control
by Arduino is that, controlling a Light Emitting Diode (LED). The construction of
Arduino LED Cube 3x3x3 is the next step to show how these multiple LEDs are
controlled using Arduino. It can be extended by LED lighting to music, control the color
of LEDs, etc.

Construction of LED cube:

Procedure:
1. For the construction of 3x3x3 LED cube, first three 3x3 matrices will be constructed.
2. First take 9 LEDs, bend the shorter pins of LED to 900.

Figure 1 Model of one LED 3x3 matrix


3. Solder the shorter pins of LEDs and then we get a one 3x3 LED matrix. Likewise, the
steps are repeated for two more 3x3 matrices.
4. Finally, we are going to stack up the three 3x3 LED matrices one above the other and
solder the longer pins of LEDs.
5. We have completed the 3x3x3 LED cube.
6. Mount the cube on the PCB board and solder it.
7. Connect the longer pins of LEDs to digital pins 13, 12, 11, 10, 9, 8, 7, 6, 5 of Arduino
and shorter pins to GND of Arduino.
8. The connection part is over and we have to upload the code to Arduino. The LED cube
glows as per the code pattern.

Figure 2 Prototype of 3x3x3 LED cube

Coding:
/*
LED cube coding
Turns on an LED on for one second, then off for one second, repeatedly. This example code is in
the public domain.
*/
// Pin 13, 12, 11, 10, 9, 8, 7, 6, 5 have LEDs connected to Arduino board.
// give it a name:

int led13 = 13;


int led12=12;
int led11=11;
int led10=10;
int led9=9;
int led8=8;
int led7=7;
int led6=6;
int led5=5;
// the setup routine runs once when you press reset:
void setup()
{
// initialize the digital pin as an output.
pinMode(led13, OUTPUT);
pinMode(led12, OUTPUT);
pinMode(led11, OUTPUT);
pinMode(led10, OUTPUT);
pinMode(led9, OUTPUT);
pinMode(led8, OUTPUT);
pinMode(led7, OUTPUT);
pinMode(led6, OUTPUT);
pinMode(led5, OUTPUT);
}

// the loop routine runs over and over again forever:


void loop()
{
digitalWrite(led13, HIGH);
delay(1000); // wait for a second
digitalWrite(led13, LOW);
delay(1000); // wait for a second
digitalWrite(led12, HIGH); // turn the LED on
delay(1000); // wait for a second
digitalWrite(led12, LOW);
delay(1000); // wait for a second
digitalWrite(led11, HIGH);
delay(1000); // wait for a second
digitalWrite(led11, LOW);
delay(1000); // wait for a second
digitalWrite(led10, HIGH);
delay(1000); // wait for a second
digitalWrite(led10, LOW);
delay(1000); // wait for a second
digitalWrite(led9, HIGH);
delay(1000); // wait for a second
digitalWrite(led9, LOW);
delay(1000); // wait for a second
digitalWrite(led8, HIGH);
delay(1000); // wait for a second
digitalWrite(led8, LOW);
delay(1000); // wait for a second
digitalWrite(led5, HIGH);
delay(1000); // wait for a second
digitalWrite(led5, LOW);
delay(1000); // wait for a second
digitalWrite(led6, HIGH);
delay(1000); // wait for a second
digitalWrite(led6, LOW);
delay(1000); // wait for a second
digitalWrite(led7, HIGH);
delay(1000); // wait for a second
digitalWrite(led7, LOW);
delay(1000); // wait for a second
digitalWrite(led10, HIGH);
delay(500); // wait for a second
digitalWrite(led10, LOW);
delay(500); // wait for a second
digitalWrite(led11, HIGH);
delay(500); // wait for a second
digitalWrite(led11, LOW);
delay(500);
digitalWrite(led12, HIGH);
delay(500); // wait for a second
digitalWrite(led12, LOW);
delay(500); // wait for a second
digitalWrite(led13, HIGH);
delay(500); // wait for a second
digitalWrite(led13, LOW);
delay(500); // wait for a second
}

Results and Discussions:

1. Use temperature sensor with Arduino in LED cube, so that the lighting changes according
to the sensor values.
(Hint: Use RGB LED and control the colors according to sensor values. For e.g.: For high
temperature, red color LED glows; for low temperature, orange light glows; for medium
temperature, green light glows.)

References:
http://www.youtube.com/watch?v=dfRveTPIfAo&feature=youtu.be&hd=1
http://www.youtube.com/watch?v=ea8aG2aQ5FY&hd=1
http://www.instructables.com
http://www.ladyada.net/learn/arduino/
http://duino4projects.com/

Web Based control a Motor Speed Using Arduino


Objective:
To Control a DC Motor remotely using Arduino Uno via web browser.
Requirements:
Hardware Requirements:
1. Arduino Uno.
2. L293D motor drive.
3. 5V DC motor.
4. USB Cable (Interface).

Software Requirements:
1. Python IDE.
2. PySerial (exe for interface).
3. Macromedia Dream viewer.
4. Arduino IDE

Background information:
Python is an easy to learn, powerful programming language. It has efficient high-
level data structures and a simple but effective approach to object-oriented programming.
Python’s elegant syntax and dynamic typing, together with its interpreted nature, make it
an ideal language for scripting and rapid application development in many areas on most
platforms.
The Python interpreter is easily extended with new functions and data types
implemented in C or C++ (or other languages callable from C). Python is also suitable as
an extension language for customizable applications.
PySerial module encapsulates the access for the serial port. It provides backends
for Python running on Windows, Linux, BSD (possibly any POSIX compliant system),
Jython and IronPython (.NET and Mono). The module named “serial” automatically
selects the appropriate backend.
 It is released under a free software license, see LICENSE for more details.
 Same class based interface on all supported platforms.
 Access to the port settings through Python properties.

Circuit Diagram:
We need to configure to correctly wire the motor and the motor driver IC. You
need to plug the L293D motor driver first, in the middle of your breadboard. You can
start by connecting the power for this integrated circuit: connect pins 8 and 9 to the 5V of
the Arduino board, and the pin 5 to the ground pin of the Arduino board. Then, there are
3 inputs pin we need to connect, and 2 output pins. The output part is easy: you just need
to connect the two output pins to the terminal of the DC motor. The output pins we want
to use are pins 3 and 6. The first input pin to connect is pin number 1, which is called the
Enable pin. This is the pin we will use to set the motor on and off, and to change the
speed of the motor. Connect this pin to the pin number 6 of the Arduino board. Finally,
we want to connect pins number 2 and 7 of the L293D to pins number 4 and 5 of the
Arduino board. These pins will be used to change the direction of the motor.
Coding:
<!doctype html> 40px;" id="speedText">
<html lang="en"> <input type="button"
id="submitButton"
<head>
style="border:1px solid #000;
<meta charset="utf-8"> font-size:40px;" value="submit"
<title>Remote control</title> onClick="sendCommand()"/>

<scripttype="text/javascript" </form>
src="script.js"></script> <?php
</head> $speed = $_GET["speed"];
<body> $myFile = "motorCommand.txt";

<form id="speedForm" $fh = fopen($myFile, 'w') or


die("can't open file");
action="remote_control.php"
method="GET"> fwrite($fh, $speed);
<span style="font- fclose($fh);
size:40px;">Motor speed: ?>
</span><input type="text"
</body>
name="speed" style="font-size:
</html> int input;

int motorPinPlus = 4;
import serial int motorPinMinus = 5;
import time int motorPinEnable = 6;
try:
print "Trying..." int motorDir;
arduino= int motorSpeed;
serial.Serial('/dev/tty.usbmodem141
1', 114000)
const int NB_OF_VALUES = 2;
time.sleep(1)
int valuesIndex = 0;
arduino.flush()
int values[NB_OF_VALUES];
except:
print "Failed to connect"
// Setup of the board
sleeptime = 0.1
void setup() {
speed = 0
// Initialize pins
while True:
pinMode(motorPinPlus, OUTPUT);
try:
pinMode(motorPinMinus,
# Open a file
OUTPUT);
fo = open("motorCommand.txt",
pinMode(motorPinEnable,
"r+")
OUTPUT);
speed = fo.read()
# Close opend file
// Initialize serial port
fo.close()
Serial.begin(114000);
arduino.write('H,1,' + speed)
time.sleep(sleeptime)
motorDir = 1;
except:
motorSpeed = 200;
print "Failed !"
}

// Main loop
void loop() {

if (Serial.available())
{
Arduino Code: if (Serial.read() == 'H')
// Input {
for(valuesIndex = 0; valuesIndex
< NB_OF_VALUES; valuesIndex++)
{
values[valuesIndex] =
Serial.parseInt();
}
motorDir = values[0];
motorSpeed = values[1];
valuesIndex = 0;
}
setMotor(motorDir, motorSpeed);

}
}

// Function to control the motor


void setMotor(int forward, int speed){
if (forward == 0){
digitalWrite(motorPinPlus,
HIGH);
digitalWrite(motorPinMinus,
LOW);
}
else {
digitalWrite(motorPinPlus, LOW);
digitalWrite(motorPinMinus,
HIGH);
}

analogWrite(motorPinEnable,
speed);
}
Results and Discussion:
1) Installation of pyserial

From PyPI
pySerial can be installed from PyPI, either manually downloading the files and installing as
described below or using:

pip install pyserial


or
easy_install -U pyserial

From source (tar.gz or checkout)

Download the archive from http://pypi.python.org/pypi/pyserial. Unpack the archive, enter


the pyserial-x.y directory and run:

python setup.py install

Reference:
 http://www.intorobotics.com/controlling-arduino-board-php-web-based-script-tutorials/
 http://www.youtube.com/watch?v=7VE0yM8Lfws
 http://www.codeproject.com/Articles/699986/An-Arduino-Library-to-Control-the-BYJ-
Stepper

Future Experiments:
1. Try to control the motor with varying speeds.

PAGE \* MERGEFORMAT 47
Temperature sensing using MIT App Inventor

Objective:
To develop a mobile app for reading temperature using MIT App Inventor.

Requirements:
1. Arduino Microcontroller (Arduino Uno)
2. USB Cable
3. Temperature sensor,LM35
4. MIT App Inventor 2(software)

Circuit diagram:

Background Information:
Introduction:
App Inventor is a cloud based tool which helps you to build mobile apps
using scratch. It provides a helpful guide on how to setup your device and computer to use
MIT App Inventor and to understand different components, blocks, and concepts. You
can download the software from the following link :
ai2.appinventor.mit.edu

Steps for installing MIT App Inventor 2 Setup on Windows

1.Installing the App Inventor Setup software package. This step is the same for all
Android devices, and is the same for Windows Vista,7 and 8.
2.If you choose to use the USB cable to connect to a device, then you have to install
Windows drivers for your Android phone.
3.Download the installer.
4.Locate the file AppInventor_Setup_Installer_v_2_1.exe (~101 MB) in your Downloads
folder
PAGE \* MERGEFORMAT 47
Student/mitapp .
5.Open the file.
6.Click through the steps of the installer. Do not change the installation location but note
down the installation directory, because you might need it to check drivers later.
7.You may be asked if you want to allow a program from an unknown publisher to make
changes to this computer. Click yes.

8 .If you are going to run your app using Emulator launch aistarter
9. After launching emulator set up from App Inventor’s menu select Connect ->Emulator
option to connect with the emulator.

Procedure:

1. For creating a new project go to Projects -> Start New Project.


2. Type your project name and click Ok.

3.A screen appears with various user interface and properties.

PAGE \* MERGEFORMAT 47
4.On the left hand side you have the user interface tab which has various options.
5.In that select Button,TextBox and Webviewer.Set the properties for them in the right
hand side accordingly.
6.Give the name for the button as Temperature sensor reading.

7.On the right side of the page there is a tab named Blocks. When you open the Blocks
tab you will find the drag and drop tags for the Button,TextBox,WebViewer you created.

PAGE \* MERGEFORMAT 47
The exact block for sensing the temperature is as follows:

8.Now connect the Arduino board with your laptop using the USB cable.
9.Upload the code to the Arduino IDE.
Specify the Arduino URL in the Webviewer.
10.Start the emulator which has been installed already.
11. From the Connect menu in the App Inventors menu select Emulator.

PAGE \* MERGEFORMAT 47
The emulator will start within 3 minutes.
After connecting the emulator will show the screen as follows:

Coding:
#include <SPI.h>
#include <WiFi.h>
char ssid[] = "itstaff";
char pass[] = "itstaff";
int keyIndex = 0;
int status = WL_IDLE_STATUS;
WiFiServer server(80);
void setup() {

PAGE \* MERGEFORMAT 47
Serial.begin(9600);
while (!Serial) {
;
}
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println("WiFi shield not present");
while(true);
}
while ( status != WL_CONNECTED) {
Serial.print("Attempting to connect to SSID: ");
Serial.println(ssid);
status = WiFi.begin(ssid, pass);
delay(3000);
}
server.begin();
printWifiStatus();
}
void loop() {
WiFiClient client = server.available();
if (client) {
Serial.println("new client");
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
Serial.write(c);
if (c == '\n' && currentLineIsBlank) {
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connnection: close");
client.println();
client.println("<!DOCTYPE HTML>");
client.println("<html>");
client.println("<meta http-equiv=\"refresh\" content=\"5\">");
client.print("Temperature is : ");
client.print(GetTemp());
client.print(" 'C");
client.println("<br>");
client.println("</html>");
break;
}
if (c == '\n') {
currentLineIsBlank = true;
}
else if (c != '\r') {
currentLineIsBlank = false;
}
}
}
delay(1);
client.stop();
Serial.println("client disonnected");

PAGE \* MERGEFORMAT 47
}
}

void printWifiStatus() {
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
long rssi = WiFi.RSSI();
Serial.print("signal strength (RSSI):");
Serial.print(rssi);
Serial.println(" dBm");
}
double GetTemp(void)
{
unsigned int wADC;
double t;
ADMUX = (_BV(REFS1) | _BV(REFS0) | _BV(MUX3));
ADCSRA |= _BV(ADEN);
delay(20);
ADCSRA |= _BV(ADSC);
while (bit_is_set(ADCSRA,ADSC));
wADC = ADCW;
t = (wADC - 324.31 ) / 1.22;
return (t);
}

Results & Discussions:


 Develop an app which will convert your text to speech.

 Develop a mobile app to control the blinking of your LED.

References:
http://appinventor.mit.edu/explore/ai2/setup-emulator.html#step2
http://ai2.appinventor.mit.edu/#6400869956321280

PAGE \* MERGEFORMAT 47
9. Arduino with Music Shield
Objective:
To play music using Arduino Uno with Music Shield.
Requirements:
5. Arduino Uno
6. Music Shield
7. USB Cable
8. SD Card
9. Headphone

Background:
The Music Shield is a professional audio codec. An audio codec is a device or computer program
that can capable of coding or decoding a digital data stream of audio and it can be used to convert audio
signals into digital signals for transmission or storage. Music Shield can work with Arduino, Seeeduino,
Seeeduino Mega and Arduino Mega. It is based on VS1053b IC, and can play a variety of music formats
stored on MicroSD cards with the SEEED provide Arduino library.
There are two versions for you to choose:

Music Shield V1.0 Music Shield V2.0

The following table compares the two versions of Music Shield:

Music Shield V1.0 Music Shield V2.0


Parameter
Voltage +5V +5V
Audio Interface 3.5mm Audio Jack 3.5mm headphone jack

Micro SD Card (the Micro SD Card


Supported SD
maximum size SD card is (the maximum size SD card is
Card
2GB) 2GB)

PAGE \* MERGEFORMAT 47
Standard Shield No Yes
Supported MP3,WAV,MIDI,Ogg MP3,WAV,MIDI,Ogg
music formats Vorbis Vorbis
Arduino,Seeeduino, Arduino,Seeeduino,
Compatibility Arduino Mega, and Arduino Mega, and
Seeeduino Mega Seeeduino Mega
only Seeeduino Mega only Seeeduino Mega
Recording
and Arduino Mega and Arduino Mega
function
support support
MIDI Function do not support Support
Control Volume 2 control-push buttons
a Multifunction button
and Select songs and 1 knob switch

Music Shield Specification:

Diagram:

PAGE \* MERGEFORMAT 47
Procedure:
1. First, insert SD card (containing music) into Music Shield and mount it on Arduino Uno
board.
2. Download the music shield library file from Arduino website.
3. Keep that library in the following location C:/Program Files/Arduino/Libraries.
4. With the help of USB cable, connect Arduino board to PC/Laptop.
5. In PC/Laptop open the Arduino IDE, choose File then click Examples then select
Music_shield_library and click Music player and then select createList.
6. Select Verify/Compile button to correct the errors in sketch and click the Upload button
to execute.
7. Finally, connect the Headphone with Music Shield then hear the music which is playing.

Coding:
/*To play music with the help of Arduino Uno and Music Shield */
#include <Fat16.h>
#include <Fat16Util.h>
#include <NewSPI.h>

PAGE \* MERGEFORMAT 47
#include <arduino.h>
#include "pins_config.h"
#include "vs10xx.h"
#include "newSDLib.h"
#include "MusicPlayer.h"
MusicPlayer myplayer;

void setup()
{
Serial.begin(9600);
myplayer.begin(); //will initialize the hardware and set default mode to be
normal.
}

void loop()
{
myplayer.setPlayMode(MODE_SHUFFLE); //set mode to play shuffle
myplayer.creatPlaylist(); //If the current playlist is empty, it will add all the
songs in the root directory to the
playlist.
//Otherwise it will add the current song to the new
playlist.
myplayer.playList();
while(1);
}

Results & Discussions:


1. Construct a 4 × 4 × 4 LED cube and program it to produce flashing LEDs according to
playing music in PC/Laptop using Arduino code.
2. To play music with changing RGB LED colors using Arduino code.

Reference Link:

1. http://www.seeedstudio.com/wiki/Music_Shield
2. http://www.seeedstudio.com/wiki/Music_Shield_V2.0
3. http://www.youtube.com/watch?v=RKXKm9-zPHk – Music Player Shield for Arduino
4. http://learn.adafruit.com/adafruit-wave-shield-audio-shield-for-arduino - Wave Shield

http://www.youtube.com/watch?v=RjJbDg-5eEA – Arduino with Musical Instrument Shield

PAGE \* MERGEFORMAT 47
DC Motor Control using Arduino Uno with Visual Studio GUI

Objective:
To control the direction and speed of a DC Motor using Arduino Uno and Arduino
Motor Shield with Visual Studio GUI.

Requirements:
 Arduino UNO
 Arduino Motor shield
 Jumper Wires
 Visual Studio 2012
Background information:
Connectivity details:
 Connect the Motor shield with Aurdino UNO
 Connect the DC Motor Red wire to Motor shield ‘A’ channel +ve pin and DC Motor
Black wire to Motor shield ‘A’ channel -ve pin
 Connect the Arduino to the Computer via USB cable.

GUI details:
 Create a Visual C# Window form application project to control the speed and
direction of the DC Motor.
 Include the following controls in the windows form.
o TraceBar – used to control the speed of DC motor by supplying different
voltage.
o Two button control (say Forward and Backward) – used to control the

PAGE \* MERGEFORMAT 47
direction of DC motor. By clicking those buttons, signal will be initiated via
serial port of Arduino UNO.

Coding:
Aurdino Code (to communicate Visual C# Code
with Visual Studio via Serial Port)
using System;
int ct; using System.Collections.Generic;
void setup() using System.ComponentModel;
{ using System.Data;
Serial.begin(9600); using System.Drawing;
pinMode(12,OUTPUT); //Dir using System.Linq;
pinMode(9,OUTPUT); //Brake using System.Text;
} using System.Threading.Tasks;
using System.Windows.Forms;
void loop() using System.IO;
{ using System.IO.Ports;
if (Serial.available())
{ namespace DCMotorControlUsingArduino
delay(100); {
while(Serial.available()>0) public partial class Form1 : Form
{ {
ct=Serial.read(); SerialPort ss = new SerialPort(); //Declare Serial Port
if(ct=='0') public Form1()
{ {
digitalWrite(12,HIGH); InitializeComponent();
digitalWrite(9,LOW); }
analogWrite(3,0);
} private void Form1_Load(object sender, EventArgs e)
if(ct=='1') {
{ label1.Text = "0";
digitalWrite(12,HIGH); ss.Close();
digitalWrite(9,LOW); ss.PortName="COM5";
analogWrite(3,51); ss.BaudRate=9600;
} ss.DataBits=8;
else if(ct=='2') ss.Parity=Parity.None;
{ ss.StopBits = StopBits.One;
digitalWrite(12,HIGH); ss.Handshake = Handshake.None;
digitalWrite(9,LOW); ss.Encoding = System.Text.Encoding.Default;
analogWrite(3,102); }
}
else if(ct=='3') private void trackBar1_Scroll(object sender,
{ EventArgs e)

PAGE \* MERGEFORMAT 47
digitalWrite(12,HIGH); {
digitalWrite(9,LOW); label3.Text = trackBar1.Value.ToString();
analogWrite(3,153); }
}
else if(ct=='4') //Forward Button Control
{ private void button1_Click(object sender, EventArgs
digitalWrite(12,HIGH); e)
digitalWrite(9,LOW); {
analogWrite(3,204); label4.Text = label3.Text;
} ss.Open();
else if(ct=='5') ss.Write(label3.Text);
{ ss.Close();
digitalWrite(12,HIGH); }
digitalWrite(9,LOW);
analogWrite(3,255); //Backward Button Control
} private void button2_Click(object sender, EventArgs
else if(ct=='A') e)
{ {
digitalWrite(12,LOW); int x;
digitalWrite(9,LOW); x = Convert.ToInt16(label3.Text);
analogWrite(3,0); if (x == 0)
} label4.Text = "A";
else if(ct=='B') else if(x==1)
{ label4.Text="B";
digitalWrite(12,LOW); else if (x == 2)
digitalWrite(9,LOW); label4.Text = "C";
analogWrite(3,51); else if (x == 3)
} label4.Text = "D";
else if(ct=='C') else if (x == 4)
{ label4.Text = "E";
digitalWrite(12,LOW); else if (x == 5)
digitalWrite(9,LOW); label4.Text = "F";
analogWrite(3,102); ss.Open();
} ss.Write(label4.Text);
else if(ct=='D') ss.Close();
{ }
digitalWrite(12,LOW); }
digitalWrite(9,LOW); }
analogWrite(3,153);
}
else if(ct=='E')
{
digitalWrite(12,LOW);
digitalWrite(9,LOW);
analogWrite(3,204);
}
else if(ct=='F')
{
digitalWrite(12,LOW);
digitalWrite(9,LOW);
analogWrite(3,255);
}
}
}
}

PAGE \* MERGEFORMAT 47
Results and Discussion:
Q1. Can you control the DC motor via Bluetooth?
Q2. How many bytes can be sent through serial port?
Q3. Is there any alternative method for this technique?
Q4. Which data type is supported by the serial port of Arduino?
Q5. How do you send the stream of data to Arduino Uno from VS GUI?

References:
1. http://arduino.cc/en/Tutorial/DueMotorShieldDC#.Ux_g_87Bpdg
2. http://www.instructables.com/id/Arduino-Control-DC-Motor-via-Bluetooth/
3. http://arduino.cc/en/reference/serial#.Ux_hc87Bpdg
4. http://arduino.cc/en/Tutorial/SoftwareSerialExample#.Ux_he87Bpdg
5. http://arduino.cc/en/Reference/Stream#.Ux_hp87Bpdg

PAGE \* MERGEFORMAT 47
LCD Interface with Arduino

Objective:
The main objective of this experiment is to demonstrate how you can display sensor
readings from an Arduino.

Liquid Crystal Display (LCD):


An LCD is a small low-cost display. It is easy to interface with a microcontroller
because of an embedded controller (the black blob on the back of the board). This
controller is standard across many displays (HD 44780) which means many micro-
controllers (including the Arduino) have libraries that make displaying messages as easy
as a single line of code.
Requirements:
10 k potentiometer
Wires
Breadboard
Arduino
Connection cable for Arduino

Background Information:
Testing
Testing your LCD with an Arduino is really simple. Wire up your display using the
Schematic or breadboard layout sheet. Then open the Arduino IDE and open the
Example program.
File > Sketchbook > Examples > Library-LiquidCrystal > IT VCET
Upload to your board and watch as "hello, world!" is shown on your display. If
no message is displayed the contrast may need to be adjusted. To do this turn
the potentiometer.

Library Summary
(here's a summary of the LCD library for a full reference visit
Liquid Crystal (rs, rw, enable, d4, d5, d6, d7) - create a new
Liquid Crystal object using a 4 bit data bus
Liquid Crystal (rs, rw, enable, d0, d1, d2, d3, d4, d5, d6, d7) - create

PAGE \* MERGEFORMAT 47
a new Liquid Crystal object using an 8 bit data bus
Clear () - Clears the display and moves the cursor to upper left corner
Home () - Moves the cursor to the upper left corner
Set Cursor (col, row) - moves the cursor to column col and row row
Write (data) - writes the char data to the display
Print (data) - prints a string to the display

The16 pin LCD display that can show a total of 32 characters.(16 Columns and 2 rows).

Next, you wire up your LCD to a breadboard and to your Arduino.All of these parallel
LCD modules have the same pin-out and can be wired in one of two modes: 4 pin or8 pin
mode. These pins for enabling the display, setting the display to command mode or
character mode, and for setting it to read/write mode.

The pin connections are:


1. The contrast adjustment pin changes how dark the displays are. It connects to the center
pin of a potentiometer.
2. The register selection pin sets the LCD to command or character mode, so it knows how
to interpret the next set of data that is transmitted via the data lines, Based on the state of
this pin, data sent to the LCD is either interpreted as a command.

PAGE \* MERGEFORMAT 47
3. The RW pin is always tied to ground in this implementation, meaning that you are only
writing to the display and never reading from it
4. The En pin is used to tell the LCD when data is ready,
5. Data pins 4-7 are used for actually transmitting data and data pins 0-3 are left
unconnected.
6. You can illuminate the backlight by connections the anode pin to 5v and the cathode pin
to ground if you are using an LCD with a built resistor for the backlight. If you are not,
you must put a current limiting resistor in line with the anode or cathode pin,. The
datasheet for your device will generally tell you if you need to do this.

Circuit Diagram:

Fig-(i)

Connections (Arduino and LCD):

PAGE \* MERGEFORMAT 47
Fig-(ii)

Coding:
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("IT, VCET");
}
void loop() {
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);
// print the number of seconds since reset:
lcd.print(millis()/1000);
}

Results and Discussion:

1.Write the function of LiquidCrystal - display() and noDisplay()

The Liquid Crystal Library allows you to control LCD displays that are compatible with
the Hitachi HD44780 driver. There are many of them out there, and you can usually tell
them by the 16-pin interface.
This example sketch shows how to use the display () and no Display () methods to turn

PAGE \* MERGEFORMAT 47
on and off the display. The text to be displayed will still be preserved when you use no
Display () so it's a quick way to blank the display without losing everything on it.

References:
1. www.exploring arduino.com
2. www.jeremyblum.com/2011/07/13/tutorial-13-for-arduino-liquid- crystal-displays
3.http://tinyurl.com/met7ol
4.www.youtube.com/watch?v=X1BCvjxIDHM

PAGE \* MERGEFORMAT 47

You might also like