This project is an Arduino-based alarm to monitor if the computer is working. In case the computer freezes, it will emit a warning sound signal.
The project is composed from two parts: a program which runs on the computer, and an Arduino connected in an USB port.
The computer programs sends a predefined character to the Arduino, at 1 second interval. Arduino reads from the data sent from the computer. If it doesn't receive any character for 10 seconds, it makes a sound from a buzzer attached to pin 10.
The computer program is written in Visual Basic. It is a simple Windows Forms Application, containing a Form (Form1), a label (Label1) and a timer (Timer1).
The Timer1 Interval is set to 1000 ms.
The source code of the computer program:
Imports System.IO.Ports
Public Class Form1
Dim port As SerialPort
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
port = New SerialPort("COM4", 9600) 'Set your board COM
port.Open()
End Sub
Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing
port.Close()
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
On Error GoTo error1
port.Write("1") 'character to send to COM port, wich the Arduino will expect.
Label1.Text = Now() & " - Sent ""1"" on COM4 baud 9600 - Success!"
Exit Sub
error1:
Label1.Text = Now() & " - " & ErrorToString()
End Sub
End Class
The Arduino program source code:
char incomingChar = 0; // for incoming serial data
int NoSignalCounter = -60; // delay to allow for computer startup time
void setup() {
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
}
void loop() {
while (Serial.available() > 0) {
NoSignalCounter = 0;
incomingChar = Serial.read();
if (incomingChar == '1') { // '1' is the character expected from the computer
noTone(10);
}
else {
tone(10, 2400); // alarm: the character sent from the computer is different from the expected character
}
}
NoSignalCounter++;
if (NoSignalCounter >= 10) { // alarm: no character was received from the computer in the last 10 seconds
NoSignalCounter = 0;
tone(10, 2400); //(pin,frequency)
}
delay(1000);
}
Comments