Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
IoT Project
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ollie Rhodes
IoT Project
Commits
05140a2f
Commit
05140a2f
authored
Feb 02, 2021
by
Ollie Rhodes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Arduino Code
parent
0b3e5d1b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
72 additions
and
0 deletions
+72
-0
Project.ino
Project.ino
+72
-0
No files found.
Project.ino
0 → 100644
View file @
05140a2f
#include <WiFiNINA.h>
#include "ThingSpeak.h"
char
ssid
[]
=
"SKYACDWV_2GEXT"
;
//network SSID
char
pass
[]
=
"tCNGqxviKrBK"
;
//private network password
unsigned
long
channelID
=
1295506
;
const
char
*
apiKey
=
"VL6RQ2RMEKEEXW0K"
;
WiFiClient
client
;
int
ledPin
=
12
;
int
lightPin
=
A1
;
bool
doorOpen
=
false
;
void
setup
()
{
// put your setup code here, to run once:
Serial
.
begin
(
9600
);
pinMode
(
ledPin
,
OUTPUT
);
//pinMode(lightPin, INPUT);
ThingSpeak
.
begin
(
client
);
//Initialize ThingSpeak
}
void
loop
()
{
// put your main code here, to run repeatedly:
if
(
WiFi
.
status
()
!=
WL_CONNECTED
)
{
//for connecting or reconnecting to wifi
Serial
.
print
(
"Attempting to connect to SSID: "
);
Serial
.
println
(
ssid
);
while
(
WiFi
.
status
()
!=
WL_CONNECTED
)
{
WiFi
.
begin
(
ssid
,
pass
);
Serial
.
print
(
"."
);
delay
(
5000
);
}
Serial
.
println
(
"
\n
Connected."
);
}
float
lightsensor
=
analogRead
(
lightPin
);
//reads light level
Serial
.
println
(
lightsensor
);
//prints light level
if
(
lightsensor
>
400
)
{
//if in light - door open
if
(
!
doorOpen
)
{
//preventing repeating reports
Serial
.
println
(
"Door Opened"
);
int
x
=
ThingSpeak
.
writeField
(
channelID
,
1
,
String
(
"Door Opened"
),
apiKey
);
//write to channel 1
if
(
x
==
200
)
{
Serial
.
println
(
"Door Reported"
);
}
else
{
Serial
.
println
(
"Error code "
+
String
(
x
));
}
}
doorOpen
=
true
;
for
(
int
i
=
0
;
i
<
25
;
i
++
)
{
//flash and wait if door open
digitalWrite
(
12
,
LOW
);
delay
(
100
);
digitalWrite
(
12
,
HIGH
);
delay
(
100
);
}
}
else
{
digitalWrite
(
12
,
HIGH
);
//just wait if door closed
doorOpen
=
false
;
delay
(
5000
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment