Using System
Using System
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 lm35
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
BeginInvoke((Action)delegate
{
string Rec_data = "";
Rec_data = serialPort1.ReadLine();
Rec_data = Rec_data.Trim();
int str_len = Rec_data.Length;
if (str_len > 0)
{
if ((Rec_data[0] == '@') && (Rec_data[str_len - 1] == '#'))
{
if (Rec_data[1] == 'X')
{
int pos_T = 2;
txtTemp.Text = Rec_data.Substring(3, str_len - (pos_T + 1));
}
}
}
});
}
}
}
int sensorPin=A0;
int data=0;
float x;
void setup() {
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
for (int i=0;i<=10;i++)
{
data+=analogRead(sensorPin);
delay(10);
}
x=data/10;
float volt=(x*5.0)/1024.0;
float temp=(volt*1000.0);
Serial.println("@XT"+String(temp)+"#");//gui nhiet do theo khung truyen
delay(400);
data=0;
}