Arduino Visual Basic Wireless Temperature Humidity Control
We can see Arduino using 433 MHz RF with instantaneous display of temperature and humidity values as we do with the visual basic program. Let’s start with temperature and humidity before our project then let us interface with the visual basic program.
Materials:
- 2 Number Arduino (no matter nano models will suffice.)
- RF module 433 MHz (433 MHz, we used in this project. You can also use modules of different frequencies)
- Temperature Humidity Meter Module
Transmitter Circuit:
Temperature and humidity values will be sent to the transmitter circuit and the receiver circuit.
Pin connector of the circuit:
Tx signal pin >> Arduino’s digital 3.pin
Temperature-Humidity Sensor Data Pin >> Arduino’s digital 2.Pin
Receiver Circuit:
Our circuit will be transferred to the PC by taking the data receiver from the transmitter.
Circuit Connections:
Rx signal pin >> Arduino’s digital 11.p We have completed our transmitter and receiver circuits. Now let’s start writing our interface with the visual basic program.
Visual Basic Interface Program:
You can design the form as shown in figure.
Tools Required to our form:
- 3 Piece Button
- 2 Number combobox
- 2 Number Progressbar
- 11 Number Label
- 2 Number Picturebox
- 1 Piece SerialPort
- 1 Piece Timor
Add the system libraries
Imports System Imports System.ComponentModel Imports System.Threading Imports System.IO.Ports
Let’s define our Serial Port object
Dim myPort As Array ‘port name identification Delegate Sub SetTextCallback(ByVal As String)
Let’s define our Form Loader Part.
myPort = IO.Ports.SerialPort.GetPortNames() ComboBox2.Items.Add(9600) ComboBox2.Items.Add(19200) ComboBox2.Items.Add(38400) ComboBox2.Items.Add(57600) ComboBox2.Items.Add(115200) For i = 0 To UBound(myPort) ComboBox1.Items.Add(myPort(i)) Next ComboBox1.Text = ComboBox1.Items.Item(0) ComboBox2.Text = ComboBox2.Items.Item(0 )Button2.Enabled = False
Let’s define our butonu necessary to enable us to connect our ports to receive data.
Timer1.Start()SerialPort1.PortName = ComboBox1.Text SerialPort1.BaudRate = ComboBox2.Text SerialPort1.Parity = IO.Ports.Parity.None SerialPort1.StopBits = IO.Ports.StopBits.One SerialPort1.DataBits = 8SerialPort1.Open() Label10.Text = “Connected sensors” Button1.Enabled = FalseButton2.Enabled = True TextBox4.ForeColor = Color.GreenLabel11.Text = “Receiving Data…”
Let’s define our butonu disconnect necessary to stop the data acquisition.
Timer1.Stop()SerialPort1.Close() Button1.Enabled = TrueButton2.Enabled = FalseText Box3.ForeColor = Color.Red Label10.Text = “Disconnected.” Label11.Text = “Data Stopped.”
Let us define one of our combobox to select the port.
If SerialPort1.IsOpen = False Then SerialPort1.PortName = ComboBox1.Text Else MsgBox(“Port while you can not change”, vbCritical)End If
Let us define for us to select the required baud rate value.
If SerialPort1.IsOpen = False Then SerialPort1.BaudRate = ComboBox2.Text Else MsgBox(“Port while you can not change”, vbCritical) End If
Finally, the serial data will allow us to do our part identification is necessary to time.
Dim str As Stringstr = “1” SerialPort1.Write(str) Dim receiveddata As Integer = SerialPort1.ReadLine() Label7.Text = receiveddata If receiveddata < 0 Then ProgressBar1.Value = -receiveddata Else ProgressBar1.Value = receiveddata End If System.Threading.Thread.Sleep(500) Dim receiveddata2 As Integer = SerialPort1.ReadLine() Label8.Text = receiveddata2 ProgressBar2.Value = receiveddata2 System.Threading.Thread.Sleep(500)
Arduino Transmitter Software:
#include <VirtualWire.h> #include <dht11.h> .#define DHT11PIN 2 dht11 DHT11;char msg[6]; void setup() { vw_setup(2400); vw_set_tx_pin(3); } void loop() { int chk = DHT11.read(DHT11PIN); int sicaklik =DHT11.temperature; int nem = DHT11.humidity; sprintf(msg, “%d,%d”, sicaklik, nem); vw_send((uint8_t *)msg, strlen(msg)); vw_wait_tx(); delay(1000); }
Arduino Receiver Software:
#include <VirtualWire.h> int sicaklik; int nem; int i; char x; char StringReceived[6]; void setup(){ Serial.begin(115200); vw_set_rx_pin(11); vw_setup(2400); vw_rx_start(); } void loop() { if(Serial.available()>0) x=Serial.read(); uint8_t buf[VW_MAX_MESSAGE_LEN]; uint8_t buflen = VW_MAX_MESSAGE_LEN; if(x==’1′) { if( vw_get_message(buf, &buflen) ) { for (i = 0; i < buflen; i++) { StringReceived[i]= char(buf[i]); } sscanf(StringReceived, “%d,%d”,&sicaklik, &nem); Serial.println(sicaklik); delay(500); Serial.println(nem); delay(500); memset( StringReceived, 0, sizeof( StringReceived)); } } }
500 millisecond delay is happening with data acquisition software.If the timer of the form System.Threading.Thread.Sleep(500) change this value should also change the value. Otherwise you will get the wrong values.
http://www.robimek.com/arduino-ve-visual-basic-ile-rf-uzerinden-sicaklik-nem-olcumu/
HI >>>>>
i wonder if this code is suitable for VB6 !!!! it isnot >> isn’t it ?
i have a question please help me dear ):
i want to interfacing RF Module with Arduino and Visual Basic 6.0.
acctualy my project is to receive data ( current and voltage ) from smart meter wirelessly to another arduino( connected with my PC ) and dispaly those data in VB6 like LCD work in smart meters >>> how can i do these >>>>
pleeeeeeeeeeeeez help