Skip to main content

Arduino Experiments: LM35 and Graph plotting

HELLO THERE!!!


     How are you guys? I hope everyone is fine always. This week, I am going to share to you guys about an experiment with LM35 (temperature sensor). Our main objectives are:

1. Obtain temperature value using LM35
2. Plot graphs from the value using Arduino Serial plotter and Processing

Ok, before we begin we need to know what hardware and software are used in this experiment.

Hardware:
1.Arduino UNO or Leonardo( I am using Leonardo)

2.LM35 temperature sensor

Software:
1. Arduino IDE ( Version 1.6.8)
2.Processing IDE


After obtaining the hardware and the software, we will assemble the circuit. The circuit assembly is pretty simple (use LM35 image above as reference):




The schematics of the circuit


Now for the Arduino code to read the temperature sensor:

int Temp = A0;//sensor output pin at A0
int val;



void setup() {
 Serial.begin(9600);//serial communication at 9600bps
}

void loop() {
 val = (5.0* analogRead(Temp)*100.0)/1024;//equation that is used to produce temperature value
 Serial.println(val);//serial print the temperature value
 delay(100);//a little delay

}


Upload the code above to the Arduino. For graph plotting, you guys can either use the Arduino serial plotter or use the processing IDE to plot the graph. There also other ways to plot graphs from Arduino such as using makerplot, python(instrumentino), and Matlab. For the simplest graph plotting, you can use Arduino serial plotter. If you don't have Arduino serial plotter in your IDE, I would recommend you guys to download the newer version of Arduino:

1.Open Up the serial plotter (tool ---> Serial plotter)

2. And your graphs will be plotted for you!!!!



You can also Processing IDE to plot a simple graph. Here is the code that is used to plot graph from Arduino output:

import processing.serial.*;

Serial myPort;        // The serial port
int xPos = 1;         // horizontal position of the graph
float inByte = 0;

void setup () {
  // set the window size:
  size(800, 500);

  // List all the available serial ports
  // if using Processing 2.1 or later, use Serial.printArray()
  println(Serial.list());

  // Open whatever port is the one you're using.
   myPort = new Serial(this, "COM16", 9600);

  // don't generate a serialEvent() unless you get a newline character:
  myPort.bufferUntil('\n');

  // set inital background:
  background(255,255,255);
}
void draw () {
  // draw the line:
  stroke(255, 0, 0);//rgb
  line(xPos, height-250, xPos, height-250 - inByte);// you can adjust the 250 into 0 or any value
                                                        //it will adjust vertical position of graph
  // at the edge of the screen, go back to the beginning:
  if (xPos >= width) {
    xPos = 0;
    background(255,255,255);//background color
  } else {
    // increment the horizontal position:
    xPos++;
  }
}


void serialEvent (Serial myPort) {
  // get the ASCII string:
  String inString = myPort.readStringUntil('\n');

  if (inString != null) {
    // trim off any whitespace:
    inString = trim(inString);
    // convert to an int and map to the screen height:
    inByte = float(inString);
    println(inByte);
    inByte = map(inByte, 0, 1023, 0, height);
  }
}


The output is shown below:
The value of the output received is constant (31 degrees) That is why the graph looks constant. Notice a small peak in the graph, that is when the temperature value rises to 32 degrees.



Allright folks!! That's all from me, there are many ways on upgrading or modifying the code. Maybe you guys can use bluetooth to send data to smartphone and plot the graph using MIT app inventor, or log the graph values to a .csv file and plot the graph in Excel or you can also send the .csv file to MySQl and SQlite. All I want to say is see you guys next week and HAPPY TINKERING!!!











Comments

Popular posts from this blog

Arduino and Multi Function Shield: Pots,LEDs and buzzers

HELLO THERE!!!!!    How are you guys? I hope everyone is fine and in good mood always. This week, I continue my tinkerings with the Multi Function Shield. In this experiment, I used the potentiometer in the shield to control the LEDs in the shield. Without further wasting time, let's jump in straight to the experiment!! HARDWARE 1.ARDUINO UNO  2.MULTI-FUNCTION SHIELD SOFTWARE: 1. ARDUINO IDE CIRCUIT ASSEMBLY    The circuit assembly is fairly simple. Just attach the multi function shield on top of Arduino properly. Please attach the shield properly as failure to do so would cause the shield  not to function as intended. CODING THE ARDUINO: Let's refer to the multi-function shield image below: Referring to the image of the shield, it can be seen that the potentiometer (blue object near buttons) is connected to pin A0 (analog 0)     int pot = A0; //declaring the pot and led pins int l1 = 13; int l2

Arduino Beginner Experiments: Arduino and Light Blocking Sensor

HELLO THERE!!!     How are you guys? I hope everyone is fine and in a good mood always. This week, I would like to share with you guys my experiment on Arduino and Light Blocking Sensor. The objective of this experiment is to receive feedback from the sensor ( Digital and Analog) What is Light Blocking Sensor?      A linear hall sensor is a type of sensor which responds when the sensor is blocked out from light. The sensor is different for LDR's as LDR's responds to the amount of light it received while the light blocking sensor responds if the light is blocked out or not from the sensor.It can be used for both digital and analog measurements. HARDWARE: 1.Arduino UNO 2. Light Blocking Sensor SOFTWARE: 1.Arduino IDE CIRCUIT ASSEMBLY   Let's refer to the image of the blocking sensor below: The Connection of the Sensor to the Arduino is shown below: SENSOR  ----->       ARDUINO Signal      ------>     Any Analog/Digital pin

Arduino Tinkering : Controlling multiple LED with multiple potentiometers

HELLO THERE!!!!            How are you guys? I hope everyone is fine and well always. For this week's post, I would like to share with you guys a simple tinkering on Arduino, LED, and potentiometers. The objective of the experiment is to light up different amount of LED's with different intensity by controlling two potentiometers. Before starting, of course, we need to know what items are needed. The items needed are: 1. Arduino UNO   2. 4 to 5 LEDs 3. 2 Potentiometers The software used in this experiment is: 1. Arduino IDE. Now that all the hardware and software are obtained, let's go to the schematics of the circuit. The circuit is quite simple actually. The long legs of the LED's were connected to PWM pins while the shorter legs were connected to ground. The potentiometers however have three legs. The middle leg is connected to the analog pins (A0, A1) while the other two legs were connected to 5V and GND respectively. Don't w