I have developed a small system whereby I am using an LM35 temperature sensor to monitor room temperature. I f the temperature goes below a user defined value, a red LED should light simulating a heater. If the temperature goes above the user defined value, a blue LED comes on simulating a cooler.
The user inputs the preffered room temperature in a textbox in a visual basic application. the problem is that whatever value is send to the serial port, only the heater comes on. It seems the arduino is receiving something different than what I am typing in the application. The system is however working perfectly when I use a stativ temperature value in the code. i.e without using the visual basic 2010 application. here is the code:
visual basic:
[Imports System.IO
Imports System.IO.Ports
Imports System.Threading
Public Class Form1
Shared _continue As Boolean
Shared _serialPort As SerialPort
Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click
End Sub
Private Sub Label2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label2.Click
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim value As Integer
SerialPort1.Open()
value = TextBox1.Text
SerialPort1.Write(value)
SerialPort1.Close()
MsgBox("Your system has been updated", MsgBoxStyle.OkOnly, Title:="updated")
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
SerialPort1.Close()
SerialPort1.PortName = "com36"
SerialPort1.BaudRate = 9600
SerialPort1.DataBits = 8
SerialPort1.Parity = Parity.None
SerialPort1.StopBits = StopBits.One
SerialPort1.Handshake = Handshake.None
SerialPort1.Encoding = System.Text.Encoding.Default
End Sub
End Class]
this is the arduino code:
[#include <SoftwareSerial.h>
const int lm35= A0;
SoftwareSerial mySerial(lm35,13);
const int fan = 8;
const int heater = 7;
int value ;
void setup(){
pinMode(fan, OUTPUT);
pinMode(heater, OUTPUT);
Serial.begin(9600);
// mySerial.begin(9600);
pinMode(lm35, INPUT);
}
void loop(){
int temp1= analogRead(lm35);
int temp=(5.0temp1100)/1024;
delay (10000);
//Serial.println(temp);
if (Serial.available()){
delay(1000);
while (Serial.available()>0){
value=Serial.read();
delay(100);
if(temp > value){
digitalWrite(fan,HIGH);
digitalWrite(heater, LOW);}
else if(temp<value){
digitalWrite(fan, LOW);
digitalWrite(heater,HIGH);}
else if(temp==value){
digitalWrite(fan, LOW);
digitalWrite(heater, LOW);}
}
}
}]