Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CM2306 Security System
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Kieran Williams
CM2306 Security System
Merge requests
!1
Update Arduino_SecuritySystem.ino
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Update Arduino_SecuritySystem.ino
c1930510-main-patch-70252
into
main
Overview
0
Commits
1
Pipelines
0
Changes
1
Merged
Kieran Williams
requested to merge
c1930510-main-patch-70252
into
main
3 years ago
Overview
0
Commits
1
Pipelines
0
Changes
1
Expand
0
0
Merge request reports
Compare
main
main (base)
and
latest version
latest version
873b5425
1 commit,
3 years ago
1 file
+
113
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Arduino_SecuritySystem.ino
0 → 100644
+
113
−
0
Options
#include
<SoftwareSerial.h>
// Connect your Bluetooth Module to D8
#define RxD 8
#define TxD 9
#define PIR_MOTION_SENSOR 2
const
int
ledPin
=
3
;
// the number of the LED pin, D3
const
int
buttonPin
=
4
;
// the number of the pushbutton pin, D4
int
buttonState
;
// the state of the button
int
ledState
=
LOW
;
// the state of the LED
bool
systemState
=
false
;
SoftwareSerial
blueToothSerial
(
RxD
,
TxD
);
void
setup
()
{
Serial
.
begin
(
9600
);
while
(
!
Serial
){
;
}
Serial
.
print
(
"Started
\n
"
);
pinMode
(
PIR_MOTION_SENSOR
,
INPUT
);
pinMode
(
RxD
,
INPUT
);
pinMode
(
TxD
,
OUTPUT
);
setupBlueToothConnection
();
Serial
.
flush
();
blueToothSerial
.
flush
();
pinMode
(
buttonPin
,
INPUT
);
pinMode
(
PIR_MOTION_SENSOR
,
INPUT
);
pinMode
(
ledPin
,
OUTPUT
);
digitalWrite
(
ledPin
,
ledState
);
}
void
loop
()
{
char
recvChar
;
static
unsigned
char
state
=
0
;
if
(
blueToothSerial
.
available
()
>
0
){
char
newState
=
blueToothSerial
.
read
();
Serial
.
println
(
"State Change: "
+
String
(
newState
));
if
(
String
(
newState
)
==
"0"
){
systemState
=
false
;
}
if
(
String
(
newState
)
==
"1"
)
{
systemState
=
true
;
}
}
if
(
digitalRead
(
PIR_MOTION_SENSOR
)
&&
systemState
==
true
){
blueToothSerial
.
println
(
"Movement"
);
Serial
.
println
(
"Movement"
);
}
buttonState
=
digitalRead
(
buttonPin
);
// button not clicked
if
(
buttonState
==
HIGH
){
if
(
systemState
==
false
)
{
analogWrite
(
ledPin
,
1
);
Serial
.
println
(
"off"
);
blueToothSerial
.
println
(
"off"
);
}
else
{
analogWrite
(
ledPin
,
255
);
Serial
.
println
(
"on"
);
blueToothSerial
.
println
(
"on"
);
}
}
// button clicked
else
{
Serial
.
println
(
"============== buttonClick"
);
if
(
systemState
==
false
)
{
Serial
.
println
(
"============== turn system on"
);
systemState
=
true
;
}
else
{
Serial
.
println
(
"============== turn system off"
);
systemState
=
false
;
}
}
delay
(
200
);
}
/***************************************************************************
* Function Name: setupBlueToothConnection
* Description: initilizing bluetooth connction
***************************************************************************/
void
setupBlueToothConnection
()
{
blueToothSerial
.
begin
(
9600
);
blueToothSerial
.
print
(
"AT"
);
delay
(
2000
);
blueToothSerial
.
print
(
"AT+BAUD4"
);
delay
(
2000
);
blueToothSerial
.
print
(
"AT+ROLES"
);
delay
(
2000
);
blueToothSerial
.
print
(
"AT+NAMEBluegum"
);
// set the bluetooth name as "Slave" ,the length of bluetooth name must less than 12 characters.
delay
(
2000
);
blueToothSerial
.
print
(
"AT+AUTH1"
);
delay
(
2000
);
blueToothSerial
.
flush
();
Serial
.
print
(
"Finished
\n
"
);
}
Loading