Sunteți pe pagina 1din 7

DECLARATION

I hereby declare the following article and all the content associated with it to be my own original
work. I am submitting it for publication in Electronics for You magazine.

Deepankar Maithani
Temperature Monitor GUI and voice alerts using
Processing & Arduino.
Arduino
Introduction
Processing is a languagee and a development
environment used by artists, designers,
researchers and hobbyists to create amazing visual
arts and software. It is built on top of java, and it
has something for everyone no matter which
domain of software development you fall into. It
has various modes to cater the needs of different
domains of development like android mode,
python mode, JavaScript mode. These modes lets
you use the prior knowledge of that language and
additional processing specific syntax to create
innovative and intuitive software.
software Many people
don't know but Arduino IDE has come out from
processing. Hence it can be seamlessly integrated
into any Arduino project.

This article will go through the process to create a


GUI for displaying the temperature from a LM35
sensor on the GUI and give voice warnings when
the temperature is above a certain limit. The wiring
of LM35 with the Arduino
rduino is shown in figure.
figure
Below is the snapshot of the GUI. There
are two software involved in this project one is
written in processing language and the other one is
written in Arduino.
The Arduino is monitoring the output pin of the
LM35 and using the data obtained it is calculating
ambient temperature. Then it is sending the value
on the Serial port to which it is connected. The
processing software listens to the data coming on
the port and then displays it on the GUI. It also
checks the value of temperature if the
temperature is below 40 the he green LED glows else
red LED glows and a warning audio is pl played.
Software

Arduino Source Code

int val; // variable to store analog value


int tempPin = A0; // giving name to temp pin
float temperature;
void setup()
{
Serial.begin(9600); // start serial at 9600 baud rate
}
void loop()
{
val = analogRead(tempPin);
temperature = (val * 4.88)/10; //multiplication factor to convert the value
into ambient temp.
Serial.println(temperature);
delay(1000); // delay of 1s so that the serial doesn’t runs mad
}

Explanation:

Using its 10 bit ADC Arduino is monitoring the output of the LM35 through the A0 pin. Then it do
multiplication and division by a certain factor to give the actual temperature as shown below.

temperature = (val * 4.88)/10; //multiplication factor to convert the value


into temp.

The ADC on the Arduino gets a 5v as reference by default. So in order to calculate the step size
Stepsize= Vref/2^n n=no of bits
Here we have a 10bit ADC on Arduino.
Stepsize= 5/1024 =0.0048828 = 4.88mV
from data sheet of LM35 we know for every 1 degree C rise there is increase of 10mv in the
output. Hence
temperature= (val*4.88mV)/10mv.
Processing Source code

// This software is written by DeepankarMaithani. The code is


// is tested on PROCESSING 3.0 (REV 0246) - 30 September 2015
importddf.minim.*;// this library handles the audio file playback
importprocessing.serial.*; // this library handles the serial talk
Serial myPort; // Create object from Serial class
String data="" ; // empty string to gather the temperature values
floatConvertedData=0;
PFontmyFont; // object from the font class
booleanstateChange=true; // Boolean for storing the state
Minim minim; //object from minim class
AudioSample warning; // a name is assigned to the audio sample
AudioSample safe;
void setup()// this runs just once
{
size(500,500); // size of processing window
background(0);// setting background color to black
myPort = new Serial(this, "COM12", 9600);// giving parameters to object of
serial class,put the com to which your arduino is connected and the baud rate
myPort.bufferUntil('\n');// gathers data till new line character
myFont=loadFont("Arial-Black-48.vlw");// font type see the data folder of your
sketch
textFont(myFont,70);// font size
minim = new Minim(this); //we pass this to Minim so that it can load files from
the data directory
////////////////audio samples////////////////////////
warning = minim.loadSample("tempWar.mp3");// A .mp3 file is loaded to the
audiosample named warning
safe=minim.loadSample("tempSafe.mp3"); // A .mp3 file is loaded to the
audiosample named safe
}
void draw()
{
background(0);//refreshing background everytime the draw runs
noStroke();// disable drawing the outline of text
textAlign(CENTER);// align text to the centre of coordinates
fill(255);// fill white color to text
text(data,410,155);// display the data at 350,155 coordinate
textSize(40); // size of text
fill(#4B5DCE);// fillin blue color on the text
text("Temp. Reading",180,150);// write text "Temp. Reading" at the coordinates
180,150
noFill();//the upcoming rect will not have anything inside
strokeWeight(2);
stroke(#4B5DCE);// color of boader of rectangle
rect(5,100,470,80); //rectangle
Led();
}
Void serialEvent(Serial myPort)// whenever serial event happens it runs
{
data=myPort.readStringUntil('\n'); //gathering data from pot in a variable
ConvertedData=parseFloat(data);// converting string into float
;
}
void Led()
{
strokeWeight(5);// thickness of outline
stroke(255);// white color outline around LED
fill(#67F50A); //
ellipse(180,240,55, 55);// green LED
fill(#CE6668);
ellipse(280,240,55, 55); // Red LED
if(ConvertedData>40)
{
fill(#AED691);// green dull
ellipse(180,240,55, 55);
fill(#FC0004);// red bright
ellipse(280,240,55, 55);
if(stateChange==true)
{
warning.trigger();
println("Warning is given out");// for debugging
stateChange=false; // this Boolean takes care that the audio is played only when
temperature comes down from the threshold.
}
}
if(ConvertedData<40)
{
fill(#67F50A);// green bright
ellipse(180,240,55, 55);
fill(#CE6668);// red dull
ellipse(280,240,55, 55);
if(stateChange==false)
{
safe.trigger();
println("it is safe now");// for debugging
stateChange=true;
}
}
}

Explanation:
The processing IDE uses Cartesian coordinates and it assumes the top left corner of
the rectangular GUI window as having (0,0)
coordinates and all other coordinates are taken
with respect to it.
In order to achieve the desired functionality two
libraries are used. You need to import the serial
library and minim library which helps in playing
sound. It can be done by going to
Sketch>importlibrary>Serial I/O and
Sketch>import library>minim.
The minim library doesnot come preinstalled it
needs to be downloaded first by going to
sketch>importlibrary>add and then search for
minim in the search tab.
The code within setup() runs once and sets the
size of GUI window and loads the essential
dependencies. The code inside the draw loop
runs again and again repeatedly. The
serialEvent() function is called every time data comes on the serial port. Processing
reads it as string and stores it in variable named data. The LED function takes care of
turning on the RED or green LED based on the value of temperature. If the value is less
than 40*c green LED is on while when temperature exceeds 40*c the red LED glows. It
also plays the warning audio.
The hash code for colors can be obtained by going to tools>colorselector. And the font
used in the GUI should be selected from tools>createfont.
Save the sketch before running it and audio files to be played and font used should be
inside the data folder of sketch.
The application can also be exported to run as a stand alone app for Windows,Mac or
Linux platforms by going to file>exportapplication. Then chose the platform for which
you want to export and click Ok. The IDE will give you an exported application.
Note: Video of project is attached in the mail
Deepankar Maithani

S-ar putea să vă placă și