Saturday 8 October 2016

Temperature on GUI using visual studio and arduino

In this post, first we will interface LM35 with arduino uno and then  upload this data through serial communication. With the help of visual studio we can make computer gui application and though this gui application, we can do lot of stuffs like temperature logger, humidity monitoring. The

Stuff we require:

  1. Arduino uno with usb cable
  2. LM35
  3. Jumper wires
  4. Visual Studio (I had used VS 2012)
Make connections as follows:

How to interface temperature sensor, lm35 with arduino
LM35 interfacing with arduino



Simply provide, Vcc and GND to temperature sensor (LM35) and it's output should be connected to A0 of arduino. You can connect it to any channel from A0 to A5.

Calculation part:

There is little bit calculation. LM35 gives analog output. It's linearity is 10 mV/°C
which literally means for rise in temperature of 1°C, there be an increment of mV from output of lm35. It's graph is linear. It's temperature range is from: -55°C to +150°C.
Since, we are using LM35 it is calibrated in terms of degree celsius. There are other variants available like lm235 and lm335.

Arduino Code: 

The code is very simple

/*
Code Starts
*/


float val=0.0;

void setup() {
Serial.begin(9600);
}

void loop() 
{
val=analogRead(A0);
val=(0.4887*val);
Serial.println("VALUE OF TEMPERATURE IS: " + String(val) );
delay(1500);
}

/*
Code Ends
*/

VS Code:

/* Code starts here

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO.Ports;


namespace LM335
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            getAvailablePorts();
        }

        void getAvailablePorts()
        {
            String[] ports = SerialPort.GetPortNames();
            comboBox1.Items.AddRange(ports);

        }

        private void button3_Click(object sender, EventArgs e)
        {
            textBox1.Text = "";
            try
            {
                if (comboBox1.Text == "" || comboBox2.Text == "")
                {
                    textBox1.Text = "Please select your port settings";
                }

                else
                {
                    serialPort1.PortName = comboBox1.Text;
                    serialPort1.BaudRate = Convert.ToInt32(comboBox2.Text);
                    serialPort1.Open();
                    progressBar1.Value = 100;
                    button1.Enabled = true;
                    button2.Enabled = true;
                    textBox2.Enabled = true;
                    button3.Enabled = false;
                    button4.Enabled = true;
                }
            }

            catch(UnauthorizedAccessException)
            {
                textBox1.Text = "Unauthorized Access";

            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            serialPort1.Close();
            progressBar1.Value = 0;
            button1.Enabled = false;
            button2.Enabled = false;
            textBox2.Enabled = false;
            button3.Enabled = true;
            button4.Enabled = false;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            serialPort1.Write(textBox2.Text);
            textBox2.Text = "";
        }


        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                textBox1.Text = serialPort1.ReadLine();
//                textBox1.Text = serialPort1.ReadLine();
            }

            catch (TimeoutException)
            {
                textBox1.Text = "Timeout Exception";

            }
        }


    }

}

*/ Code Ends here



Check out the video:


Visit this blog for more updates !!








5 comments:

  1. Where is your studio code? Nothing is shown in the video that you have managed to do this.

    ReplyDelete
    Replies
    1. updated the vs code. Hope you will find it useful

      Delete
  2. do you have a vs code for interfacing ultrasonic sensor ?

    ReplyDelete
  3. Trying the C# code but no labels on the buttons dont know which one is button 1,2, 3 text box 1 and 2

    ReplyDelete
  4. It is actually a great and useful piece of information.
    I'm happy that you simply shared this helpful information with us. Please stay us up to date like this. Thank you for sharing."
    data logger Distributor

    ReplyDelete