You are on page 1of 16

FACULTY OF MANUFACTURING ENGINEERING TECHNOLOGY

Individual Reading LM35 Temperature Sensor with LED Alert using


Assessment Task Arduino Uno and Visual Basic Programming Project

Course Code Course Name MANUFACTURING COMPUTER


BTM 3234
APPLICATION
Week/Session/Year 13/I/2021 Lecturer DR. ISMAYUZRI BIN ISHAK

Student Number Name


TA19086 MUGUNTHEN A/L SEVENDADASAN

Mark/Grade given (For official use only)


Marker's
Comments

Since this work counts toward your formal assessment for this course, please write your name and student
number where indicated above, and sign. Attach this cover sheet to the front of your submission, so
thatyour name and student number can be seen without any cover needing to be opened.

We declare that this assessment item is our own work, except where acknowledged, and has not been
submitted for academic credit elsewhere, and acknowledge that the assessor of this item may, for
thepurpose of assessing this item:
• Reproduce this assessment item and provide a copy to another member of the University ; and/or,
• Communicate a copy of this assessment item to a plagiarism checking service (which may then
retaina copy of the assessment item on its database for the purpose of future plagiarism checking).
We certify that we have read and understood the University Rules in respect of Student Academic
Misconduct.
Date:23/01/2022
TABLE OF CONTENT
NO CONTENT PAGE NO
1 TITLE 1
2 INTRODUCTION 1
3 FUNCTIONAL PARTS IN THE PROJECT 2-3
4 ARDUINO IDE PROGRAM 4

5 SCHEMATIC DRAWINGS 5-6

6 GRAPHICAL USER INTERFACE (GUI) 7

7 WINDOWS VISUAL BASIC 2022 PROGRAMING 8-9

8 PROGRAM FLOW 10

9 CONTROLS NAMING 11
10 ARDUINO UNO AND LM35 TEMPERATURE SENSOR WITH 12-13
LED ALERT SETUP
11 CONCLUSION 14
TITLE
Reading LM35 Temperature Sensor with LED Alert using Arduino Uno and
Visual Basic Programming

INTRODUCTION

The Arduino board can interface with the Arduino IDE's serial monitor, but it only has text and
numeric options. Visual Basic is the first thing that comes to mind when we think of a graphical
interface and control. Visual studio supports a variety of programming languages, and the
visual studio Arduino IDE is also available on the internet. I used Microsoft Visual Studio 2022
for my project, and the purpose is to use one windows application to take temperature reading
using a LM35 sensor and will tigger a Red LED when the readings exceed 40 degrees Celsius
once the temperature reading start to drop the red LED will stop light up. Visual Basic for
Windows programme development gives the best GUI (Graphical User Interface) as well as a
customisable Serial Port to control devices attached to the computer.

1|Page
FUNCTIONAL PARTS IN THE PROJECT:
1) Arduino Uno

2) LM35 Temperature Sensor

3) Jumper wire (male to male and male to female)

4) Red Led

2|Page
5) Breadboard

6) 220-ohm resistor

7) Power cable

3|Page
ARDUINO IDE PROGRAM

#define LM35 A0
#define RED 7

float lm_value;
float tempc;

void setup() {
Serial.begin(115200);
pinMode(RED, OUTPUT);

void loop() {
lm_value = analogRead(LM35);
tempc = (lm_value * 500) / 1023;
Serial.println(tempc);//Temperature in Celcius

//Condition
if (tempc > 40) {
digitalWrite(RED, HIGH);

}
else {
digitalWrite(RED, LOW);
}
delay(100);
}

4|Page
SCHEMATIC DRAWINGS

5|Page
6|Page
GRAPHICAL USER INTERFACE (GUI)

7|Page
WINDOWS VISUAL BASIC 2022 PROGRAMING

Imports System.IO.Ports

Public Class Form1


Dim WithEvents SerialPort1 As SerialPort
Private Sub BtnConn_Click(sender As Object, e As EventArgs) Handles
BtnConn.Click
If BtnConn.Text = "Connect" Then
SerialPort1 = New System.IO.Ports.SerialPort(CBPort.SelectedItem,
Val(CBBaudRate.SelectedItem), Parity.None, 8, StopBits.One)
Try
SerialPort1.Open()
BtnConn.Text = "Disconnect"
TBSerialSend.Enabled = True
GroupBox1.Enabled = False
Catch ex As Exception

End Try
Else
SerialPort1.Close()
TBSerialSend.Enabled = False
GroupBox1.Enabled = True
BtnConn.Text = "Connect"
End If
End Sub

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load


Windows.Forms.Control.CheckForIllegalCrossThreadCalls = False
Try
For Each port As String In SerialPort.GetPortNames()
CBPort.Items.Add(port)
Next
CBPort.SelectedIndex = 0
CBBaudRate.SelectedItem = "115200"
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

Private Sub TBSerialSend_KeyDown(sender As Object, e As KeyEventArgs) Handles


TBSerialSend.KeyDown
If e.KeyCode = Keys.Enter Then
SerialPort1.Write(TBSerialSend.Text)
TBSerialSend.Clear()
End If
End Sub

Private Sub SerialPort1_DataReceived(sender As Object, e As


SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
RTBReceiveSerial.Text &= SerialPort1.ReadExisting()
RTBReceiveSerial.SelectionStart = RTBReceiveSerial.Text.Length
RTBReceiveSerial.ScrollToCaret()

End Sub
Private Sub BtnClear_Click(sender As Object, e As EventArgs) Handles
BtnClear.Click
RTBReceiveSerial.Clear()
End Sub

8|Page
Private Sub BtnSave_Click(sender As Object, e As EventArgs) Handles
BtnSave.Click
If sfdSaveFile.ShowDialog = Windows.Forms.DialogResult.OK Then
Dim swrfile As System.IO.StreamWriter
swrfile = System.IO.File.CreateText(sfdSaveFile.FileName + ".txt")
For i As Integer = 0 To RTBReceiveSerial.Lines.Length - 2
swrfile.WriteLine(i.ToString + ") " + Format(Now, "hh-mm-ss") + "
(" + RTBReceiveSerial.Lines(i))
Next
swrfile.Close()

End If
MessageBox.Show("operation cancelled")
End Sub
End Class

9|Page
PROGRAM FLOW

10 | P a g e
CONTROLS NAMING

WINDOWS FORM DESIGN NAME TEXT NAME


Form 1 Form1 TEMPERATURE READING

GroupBox1 - CONNECTION
Label1 - PORT
Label2 - BAUDRATE
CombBox1 CBPort -
CombBox2 CBBaudRate -
Button1 BtnConn Connect
Button2 BtnSave SAVE TEXT
Button3 BtnClear CLEAR
TextBox TbSerialSend -
RichTextBox RTBReceiveSerial -
SaveFileDialog sfdSaveFile -

11 | P a g e
ARDUINO UNO AND LM35 TEMPERATURE SENSOR WITH LED ALERT SETUP

Temperature reading from Arduino IDE

12 | P a g e
Red LED trigged when the temperature readings exceed 40 degrees Celsius

13 | P a g e
CONCLUSION

As a conclusion, I have learned how to setup an Arduino uno with an input sensor which
I used is LM35 temperature sensor with red LED alert. In this project I have learned
how to custom graphical user interface (GUI) hardware and software to controlling an
LED and make the GUI run successfully by using windows visual basic 2022.I also
learned how to logging data in windows visual basic 2022 to save and clear a text. I ’ve
learned how to define tasks as state that can execute independently of other state.
The results demonstrated that the LM35 temperature sensor with red LED alert is
functioning as per intended design, and meeting the project objectives

14 | P a g e

You might also like