Some new stuff
  1. Arduino Park Control
  2. Arduino USB2serial programming the bare bone
  3. Arduino Projects Videos added
  4. Arduino Xbee projects
  5. Arduino dB Meter 
  6. Trying to get the IOIO going. 
  7. IOIO is going....bluetooth
  8. Attiny 2313 bluetooth bee RC car
  9. Compass and temperature added
  10. AVR programmer
  11. USB2Serial and Ethernet POE
  12. Arduino LPG Sensor
  13. Program the Arduino Mini 05
  14. Lipo Rider Pro in action
  15. EZ Robot Builder kit arrived 10 Nov 2012
  16. Arduino VA Meter!
  17. 05 Nov 2012 Project Sentry Gun.
  18. Attiny85 PIR Sensor 10 Dec 2012 
  19. 0-30VDC3A and 2-28VDC10A bench PSU's
  20. 19 Dec 2012 Arduino Voltmeter LCD
  21. 29 Dec 2012 Arduino Tachometer&Speedometer LCD
  22. 03 Jan 2013 Arduino AC Phase Control. 
  23. 18 Jan 2013 Arduino Distance Meter
  24. 22 Jan 2013 Arduino Digital Clock and Date
  25. 31 Jan 2013 Arduino Digital Clock and Date 8x2 LCD
  26. Feb 2013 LCD and Backpack
  27. Feb 2013 7 Segment Serial Clock Sparkfun. Distance Sensor with "newping" library
  28. Feb 2013 Lelo Remote
  29. 01/03/2013 Arduino Adafruit 7 Seg Digital Clock with RTC and backpack 
  30. Arduino Frequency Meter 26/03/2013
  31. Another RC  Car controlled by Arduino 06/04/2013
  32. My quadcopter project update 25 April 2013
  33. My Aqua Quad Copter Flying 26 April 2013enlightened
  34. Another monster RC truck;strong one! 11July2013cool
  35. X-Frame Quad Copter 31 July 2013cool
  36. Arduino GSM Sheild added.28/8/2013
  37. 1.8inch TFT screen 13/09/2013cool
  38. 04/11/2014 added PID Soldering Iron Control
  39. Added bluetooth servo control 04/11/2014
  40. ESP8266 first try.16/03/2015
  41. Arduino Uno Quadcopter 19 May 2015
  42. IOT WemosD1 Amp Meter

 

 



 

 

 

 

 

 

 

16 Jan 2013

Arduino Processing LM35 Temp Sensor

Arduino Code:

//declare variables

float tempC;

int tempPin = 0;

void setup()

{

Serial.begin(9600); //opens serial port, sets data rate to 9600 bps

}

void loop()

{

tempC = analogRead(tempPin);           //read the value from the sensor

tempC = (5.0 * tempC * 100.0)/1024.0;  //convert the analog data to temperature

Serial.write(tempC);//NOTE! And not Serial.print((byte)tempC);

//Serial.println(tempC);

delay(500);                           //wait one second before sending new data

}

Processing Code:

I noticed some internet users fins it difficult to resolve the verdana-12.vlw data file. It also took me some time to figure out why?

In Processing IDE, click on tools. Select Verdana. Change number to 12/24 and click OK. 

Also, dont forget to change the Processing code Comm Port number accordingly to what you use for the Arduino comm port!

//import Serial communication library

import processing.serial.*;

//init variables

Serial commPort;

float tempC;

float tempF;

int yDist;

PFont font12;

PFont font24;

float[] tempHistory = new float[100];

void setup()

{

  //setup fonts for use throughout the application

  font12 = loadFont("Verdana-12.vlw"); 

  font24 = loadFont("Verdana-24.vlw"); 

   //set the size of the window

  size(210, 200);

   //init serial communication port

  commPort = new Serial(this, "COM20", 9600);

   //fill tempHistory with default temps

  for(int index = 0; index<100; index++)

    tempHistory[index] = 0;

}

void draw()

{

  //get the temp from the serial port

  while (commPort.available() > 0) 

  {

    tempC = commPort.read();

     //refresh the background to clear old data

    background(123);

    //draw the temp rectangle

    colorMode(RGB, 160);  //use color mode sized for fading

    stroke (0);

    rect (49,19,22,162);

    //fade red and blue within the rectangle

    for (int colorIndex = 0; colorIndex <= 160; colorIndex++) 

    {

      stroke(160 - colorIndex, 0, colorIndex);

      line(50, colorIndex + 20, 70, colorIndex + 20);

    }

      //draw graph

    stroke(0);

    fill(255,255,255);

    rect(90,80,100,100);

    for (int index = 0; index<100; index++)

    {  

      if(index == 99)

        tempHistory[index] = tempC;

      else

        tempHistory[index] = tempHistory[index + 1];

      point(90 + index, 180 - tempHistory[index]); 

    }

      //write reference values

    fill(0,0,0);

    textFont(font12); 

    textAlign(RIGHT);

    text("212 F", 45, 25); 

    text("32 F", 45, 187);

      //draw triangle pointer

    yDist = int(160 - (160 * (tempC * 0.01)));

    stroke(0);

    triangle(75, yDist + 20, 85, yDist + 15, 85, yDist + 25);

      //write the temp in C and F

    fill(0,0,0);

    textFont(font24); 

    textAlign(LEFT);

    text(str(int(tempC)) + " C", 115, 37);

    tempF = ((tempC*9)/5) + 32;

    text(str(int(tempF)) + " F", 115, 65);

  }

}

The LM35 Temp Sensor:

Text towards front.

Left pin +5V Arduino.Middle pin A0 Arduino and right pin ground Arduino

Back Back to top