How to make a heat sensor at home?

In this section, I will tell you how to measure values such as heat and humidity. Basically, we have some requirements.

Arduino Uno or make connections to the device as shown in the figure. Then open the Arduino IDE and compile the project in the Arduino IDE and transfer it to the device using the following codes.

#include <dht11.h>
int DHT11_pin=2;
dht11 DHT11_sensor;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  int chk = DHT11_sensor.read(DHT11_pin);
  

  int data=Serial.read();

  if(data=='1')
  {
    Serial.println((float)DHT11_sensor.humidity, 2);
  }
  else if(data=='2')
  {
    Serial.println((float)DHT11_sensor.temperature, 2);
  }
  else if(data=='3')
  {
    Serial.println(DHT11_sensor.dewPoint(), 2);
  }
}

When you enter “1” value from the serial port screen and enter, it will give the humidity value. If you type 2 through the serial port screen, it will give the temperature. We used dewPoint function as a third option. You can improve too. The values you receive are a 3. in the batch application, you can start using it by connecting to the serial port screen.

We wrote a program in Turkish. Name of the program: Temperature Sensor.

This program is a simple program that automatically reads values through Arduino Uno. Values async as realtime as Form1.in our cs file, we read from the serial port and print live to the screen.

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;
using System.Threading;
using System.Globalization;

namespace HararetSensoru
{
    public partial class Form1 : Form
    {
        SerialPort sp;
        float nem;
        float sicaklik;
        float cig;
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            string[] ports = SerialPort.GetPortNames();

            foreach(string port in ports)
            {
                listBox1.Items.Add(port);
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            button1.Enabled = false;

            if (listBox1.SelectedItem != null)
            {
                sp = new SerialPort(listBox1.SelectedItem.ToString(), 9600, Parity.None, 8, StopBits.One);
                sp.Open();

                ReadValues();
            }
            else
            {
                button1.Enabled = true;
                MessageBox.Show("Port seçtin mi?", "ROM port hatası", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }

        }

        private async void ReadValues()
        {
            await Task.Run(() =>
            {
                while (true)
                {
                    SetStatus("Okunuyor...");
                    sp.Write("1");
                    nem = (float)Math.Round(float.Parse(sp.ReadLine(), CultureInfo.InvariantCulture.NumberFormat));
                    ChangeLabel1Text(nem.ToString()+" %");
                    ChangeProgressBar1((int)(nem));

                    sp.Write("2");
                    sicaklik = (float)Math.Round(float.Parse(sp.ReadLine(), CultureInfo.InvariantCulture.NumberFormat));
                    ChangeLabel2Text(sicaklik.ToString()+" 'C");
                    ChangeProgressBar2((int)(sicaklik));

                    sp.Write("3");
                    cig = (float)Math.Round(float.Parse(sp.ReadLine(), CultureInfo.InvariantCulture.NumberFormat));
                    ChangeLabel3Text(cig.ToString()+" %");
                    ChangeProgressBar3((int)(cig));
                    SetStatus("Okundu.");

                    System.Threading.Thread.Sleep(1000); // time to sleep thread
                }
            });
        }

        private void ChangeLabel1Text(string value)
        {
            if (label1.InvokeRequired)
            {
                label1.Invoke(new Action<string>(ChangeLabel1Text), value);
                return;
            }
            label1.Text = value;
        }


        private void ChangeLabel2Text(string value)
        {
            if (label2.InvokeRequired)
            {
                label2.Invoke(new Action<string>(ChangeLabel2Text), value);
                return;
            }
            label2.Text = value;
        }

        private void ChangeLabel3Text(string value)
        {
            if (label3.InvokeRequired)
            {
                label3.Invoke(new Action<string>(ChangeLabel3Text), value);
                return;
            }
            label3.Text = value;
        }

        private void ChangeProgressBar1(int value)
        {
            if (progressBar1.InvokeRequired)
            {
                progressBar1.Invoke(new Action<int>(ChangeProgressBar1), value);
                return;
            }
            if(value > 100)
            {
                value = 100 / (value / 100);
            }
            progressBar1.Value = value;
        }

        private void ChangeProgressBar2(int value)
        {
            if (progressBar2.InvokeRequired)
            {
                progressBar2.Invoke(new Action<int>(ChangeProgressBar2), value);
                return;
            }
            if (value > 100)
            {
                value = 100 / (value / 100);
            }
            progressBar2.Value = value;
        }

        private void ChangeProgressBar3(int value)
        {
            if (progressBar3.InvokeRequired)
            {
                progressBar3.Invoke(new Action<int>(ChangeProgressBar3), value);
                return;
            }
            if (value > 100)
            {
                value = 100 / (value / 100);
            }
            progressBar3.Value = value;
        }

        private void SetStatus(string value)
        {
            toolStripStatusLabel1.Text = value;
        }


        .....
    }
}

As you can see, the Program simply lists serial ports, reads the selected ROM, sends 1,2,3 values to the device, measures the values, and prints them on the screen.

You can download the project files below.

Good improvements.

Leave a Reply