Arduino Interfacing with Visual Studio to read Temperature



Today I'm going to show you how  Arduino interfacing with Visual studio to read temperature.
If you don’t know to start visual studio program click here





Part 1 – C# program using visual studio

Create a form first.

You can drag and drop toolbox items into Form1 as follows.



Next go to Form1.cs file and edit the code as follows

==============================================================

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;

namespace _3_arduinotovisual
{
    public partial class Form1 : Form
    {

        public Form1()
        {
            InitializeComponent();
            serialPort1.Open();

        }

        private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
        {
            string data = serialPort1.ReadLine();

            //MessageBox.Show(serialPort1.ReadLine());
            this.textBox1.Text = "" + data;

        }

     
    }
}

===============================================================


Part 2 – Arduino coding


Open the Arduino IDE and write the following code

==============================================================

const int analogInPin = A0;  // Analog input pin that the potentiometer is attached to


void setup() {
  // initialize serial communications at 9600 bps:
  Serial.begin(9600);
}

void loop() {
  // read the analog in value:
double   sensorValue = analogRead(analogInPin);

float mvValue = ( sensorValue/1024.0)*5000;
float celValue = mvValue/10;

  // print the results to the serial monitor:
  Serial.print("sensor = " );
  Serial.println(celValue);

  // wait 2 milliseconds before the next loop
  // for the analog-to-digital converter to settle
  // after the last reading:
  delay(2);
}

===============================================================


Part 3 - Circuit Diagram


In my case I used LM35DZ , check the data sheet  and connect your sensor.







Now all coding parts are finished.
   Go to Aduino IDE à Tools à Port and check the port number





  Then upload the Arduino code.
  Now go to visual studio and Right click on Serial Port and go to properties.


  Then change the port name similar to Arduino port name. 



Finally go to Debug and click Start without Debugging in visual studio or simply press Ctrl + F5.




  • Thank you very much for reading this tutorial.
  • If you have problems regarding this tutorial feel free to make a comment below or contact us by sending message through our facebook page or by sending email to this address progtpoint@gmail.com 
  • Follow us on facebook and Twitter also subcirbe us youtube

5 comments:

  1. Niyamai ..
    Oya widiyata create karana project ekak pc software ekak widiyata save karaganna widiya leson ekak karanna puluwan nam gadak watinawa ...
    Thanx

    ReplyDelete
  2. Niyamai ..
    Oya widiyata create karana project ekak pc software ekak widiyata save karaganna widiya leson ekak karanna puluwan nam gadak watinawa ...
    Thanx

    ReplyDelete
  3. kodi firestick install is now really easy, you can find more steps following above link page.

    ReplyDelete
  4. Nicely explain
    can i do text to speech using arduino & visual studio with serially connection.

    ReplyDelete

Social