TechnicalEngineer
Published © GPL3+

Temperature Plot Using Processing and Arduino

The main aim of this project is to show how to plot a variable graph using processing environment and Arduino.

IntermediateFull instructions provided6,804
Temperature Plot Using Processing and Arduino

Story

Read more

Schematics

Temperature Plot Using Processing and Arduino

Code

Temperature Plot Using Processing and Arduino

C/C++
// Arduino Code

#include<LiquidCrystal.h>
#define sensor A0
float analog_value;
LiquidCrystal lcd(2,3,4,5,6,7);

byte degree[8] =
              {
                0b00011,
                0b00011,
                0b00000,
                0b00000,
                0b00000,
                0b00000,
                0b00000,
                0b00000
              };

void setup()
{
   lcd.createChar(1, degree);
  lcd.begin(16,2);
  Serial.begin(9600);
  pinMode(sensor, INPUT);
 
  lcd.setCursor(0,0);
  lcd.print("Temperature Plot");
  lcd.setCursor(0,1);
  lcd.print("Using Proccesing");
  delay(2000);
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print(" By Saddam Khan ");
  lcd.setCursor(0,1);
  lcd.print("ENGINEERS GARAGE");
  delay(2000);
  lcd.clear();
}

void loop()
{
  float reading=analogRead(sensor);
  analog_value=reading*(5.0/1023.0)*100;
 
  lcd.setCursor(0,0);
  lcd.print("  Temperature  ");
  lcd.setCursor(4,1);
  lcd.print(analog_value);
  lcd.write(1);
  lcd.print("C");
  Serial.println(analog_value);
  delay(700);
}



// ------------------------------------------------------------------------------------
// Processing Code

 import processing.serial.*;
 PFont f;
 PFont F;
 Serial myPort;        // The serial port
 int xPos = 40;         // horizontal position of the graph
 
 void setup () {
 // set the window size:  and Font size
 f = createFont("Arial",12,true);
 F = createFont("Arial",24,true);
 size(700, 600);        
 
 // List all the available serial ports
 println(Serial.list());
 myPort = new Serial(this, Serial.list()[0], 9600);
  myPort.bufferUntil('\n');
 // set inital background:
 background(70);
 }
 void draw () 
 {
   // everything happens in the serialEvent()
 }
 
 void serialEvent (Serial myPort) {
 // get the ASCII string:
 String inString = myPort.readStringUntil('\n');
 
 if (inString != null) {
 // trim off any whitespace:
 
 print("Temperature: ");
 print(inString);
 println("Degree Celcius");
 inString = trim(inString);
 
 // convert to an int and map to the screen height:
 float inByte = float(inString+(char)9); 
 inByte = map(inByte, 0,117, 0, height);
 
 println(inByte);
 
  stroke(175);                       // temperature line
  line(40,height-40,40,0);
  
  stroke(175);                          // Time line
  line(40,height-40,width,height-40);
  
  stroke(100,100,255);                          // 30 degree line
  line(40,height-194,width,height-194);
 
 stroke(100,100,255);                          // 60 degree line
  line(40,height-344,width,height-344);
 
  textFont(F);       
  fill(255);
 
 textAlign(RIGHT);
  text("Temperature Plot Using Proccessing",680,40); 
  
  textAlign(RIGHT);
  text("And Arduino By Saddam Khan",653,70); 
  
  textAlign(RIGHT);
  text("Engineers Garage",580,100); 
 
   textAlign(RIGHT);
  text("TEMP",70,40);                         
  
  textAlign(RIGHT);
  text("TIME --->",650,580);    
  
  
  
   textAlign(RIGHT);
  text(inString,500,200);
 
   textAlign(RIGHT);
  text(" Degree Celsuis",560,230);
  
  
  fill(0);
 // int j;
  stroke(255);   
  for(int j=500;j>430;j--)
  {
  line(j,height-398,j,height-425);
  }
  stroke(0,0,0);
  textAlign(RIGHT);
  text(inString,495,200); 
 
  
 fill(240);
 textFont(f); 
 
  textAlign(RIGHT);
  text("(In Degree)",140,40); 
  
  textAlign(RIGHT);                 // 100 degree
  text("100 -",40,60);
  
   textAlign(RIGHT);                // 90 degree
  text("90 -",40,110);
  
   textAlign(RIGHT);                // 80 degree
  text("80 -",40,160);
  
   textAlign(RIGHT);                 // 70 degree
  text("70 -",40,210);
  
   textAlign(RIGHT);                // 60 degree
  text("60 -",40,260);
  
   textAlign(RIGHT);               // 50 degree
  text("50 -",40,310);
  
   textAlign(RIGHT);                 // 40 degree
  text("40 -",40,360);
  
   textAlign(RIGHT);
  text("30 -",40,410);
  
   textAlign(RIGHT);
  text("20 -",40,460);
  
   textAlign(RIGHT);
  text("10 -",40,510);
  
  textAlign(RIGHT);
  text("0 -",40,560);
 
 /*---- scale between 30 degree to 40 degree------*/
  
  textAlign(RIGHT);
  text("   -",40,370);
  
  textAlign(RIGHT);
  text("   -",40,380);
  
  textAlign(RIGHT);
  text("   -",40,390);
  
  textAlign(RIGHT);
  text("   -",40,400);
  
 // textAlign(RIGHT);
 // text("0 -",40,360);
 
 // draw the line:
 int shift=40;            // set trace origin
 stroke(255,0,0);              // trace colour
 for(int i=0;i<2;i++)
 {
// line(xPos, height-inByte-1, xPos, height - inByte);
   line(xPos, height-inByte-(shift+2), xPos, height-inByte-shift);
   xPos++;
 }
 if (xPos >= width)         //  go back to begining
 {
 xPos = 40;
 background(100); 
 } 
 }
 }

Credits

TechnicalEngineer
4 projects • 51 followers

Comments