Components and supplies
Arduino Nano R3
Buzzer
Tools and machines
Premium Female/Male Extension Jumper Wires, 40 x 6" (150mm)
Project description
Code
Arduino Code
arduino
1char incomingChar = 0; // for incoming serial data 2int NoSignalCounter = -60; // computer startup time 3 4void setup() { 5 Serial.begin(9600); // opens serial port, sets data rate to 9600 bps 6} 7 8void loop() { 9 while (Serial.available() > 0) { 10 NoSignalCounter = 0; 11 incomingChar = Serial.read(); 12 if (incomingChar == '1') { // '1' is the character expected from the computer 13 noTone(10); 14 } 15 else { 16 tone(10, 2400); // alarm: the character sent from the computer is different from the expected character 17 } 18 } 19 NoSignalCounter++; 20 if (NoSignalCounter >= 10) { // alarm: no character was received from the computer in the last 10 seconds 21 NoSignalCounter = 0; 22 tone(10, 2400); //(pin,frequency) 23 } 24 delay(1000); 25}
Computer Program
vb.net
1Imports System.IO.Ports 2 3Public Class Form1 4 5 Dim port As SerialPort 6 7 Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load 8 port = New SerialPort("COM4", 9600) 'Set your board COM 9 port.Open() 10 End Sub 11 12 Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing 13 port.Close() 14 End Sub 15 16 Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick 17 On Error GoTo error1 18 port.Write("1") 'character to send to COM port, wich the Arduino will expect. 19 Label1.Text = Now() & " - Sent ""1"" on COM4 baud 9600 - Success!" 20 Exit Sub 21 22error1: 23 Label1.Text = Now() & " - " & ErrorToString() 24 End Sub 25 26End Class
Arduino Code
arduino
1char incomingChar = 0; // for incoming serial data 2int NoSignalCounter 3 = -60; // computer startup time 4 5void setup() { 6 Serial.begin(9600); // 7 opens serial port, sets data rate to 9600 bps 8} 9 10void loop() { 11 while 12 (Serial.available() > 0) { 13 NoSignalCounter = 0; 14 incomingChar = Serial.read(); 15 16 if (incomingChar == '1') { // '1' is the character expected from the computer 17 18 noTone(10); 19 } 20 else { 21 tone(10, 2400); // alarm: the 22 character sent from the computer is different from the expected character 23 } 24 25 } 26 NoSignalCounter++; 27 if (NoSignalCounter >= 10) { // alarm: no character 28 was received from the computer in the last 10 seconds 29 NoSignalCounter = 0; 30 31 tone(10, 2400); //(pin,frequency) 32 } 33 delay(1000); 34}
Computer Program
vb.net
1Imports System.IO.Ports 2 3Public Class Form1 4 5 Dim port 6 As SerialPort 7 8 Private Sub Form1_Load(sender As Object, e As EventArgs) 9 Handles MyBase.Load 10 port = New SerialPort("COM4", 9600) 'Set your board 11 COM 12 port.Open() 13 End Sub 14 15 Private Sub Form1_FormClosing(sender 16 As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing 17 port.Close() 18 19 End Sub 20 21 Private Sub Timer1_Tick(sender As Object, e As EventArgs) 22 Handles Timer1.Tick 23 On Error GoTo error1 24 port.Write("1") 25 'character to send to COM port, wich the Arduino will expect. 26 Label1.Text 27 = Now() & " - Sent ""1"" on COM4 baud 9600 - Success!" 28 Exit Sub 29 30error1: 31 32 Label1.Text = Now() & " - " & ErrorToString() 33 End Sub 34 35End 36 Class
Downloadable files
untitled
untitled
Comments
Only logged in users can leave comments
mitty
0 Followers
•0 Projects
Table of contents
Intro
7
0