Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
arduino2
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
bryan.quispe
arduino2
Commits
d0364108
Commit
d0364108
authored
Jan 24, 2024
by
bryan.quispe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Initial commit
parents
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
122 additions
and
0 deletions
+122
-0
sketch_jan28.ino
sketch_jan28.ino
+122
-0
No files found.
sketch_jan28.ino
0 → 100644
View file @
d0364108
#include <Wire.h>
#include <SoftwareSerial.h>
#include <WiFiNINA.h>
#include "ThingSpeak.h" // Always include ThingSpeak header file after other header files and custom macros
char
ssid
[]
=
"Pixel_7931"
;
// network SSID (name)
char
pass
[]
=
"norbert1"
;
// network password
int
keyIndex
=
0
;
// Your network key Index number (needed only for WEP)
WiFiClient
client
;
unsigned
long
myChannelNumber
=
"2408902"
;
const
char
*
myWriteAPIKey
=
"AGU3FZ7L5ZZFL5VX"
;
int
number
=
0
;
// Grove Temperature Sensor
int
temperaturePin
=
A0
;
// Grove Dust Sensor
int
dustPin
=
8
;
unsigned
long
dustDuration
;
unsigned
long
dustStartTime
;
unsigned
long
dustSampleTime_ms
=
30000
;
// sample 30s ;
unsigned
long
dustLowPulseOccupancy
=
0
;
float
dustRatio
=
0
;
float
dustConcentration
=
0
;
// Grove Buzzer Sensor
int
buzzerPin
=
2
;
void
setup
()
{
Serial
.
begin
(
9600
);
while
(
!
Serial
);
// Wait for serial port to connect
// Check for the WiFi module
if
(
WiFi
.
status
()
==
WL_NO_MODULE
)
{
Serial
.
println
(
"Communication with WiFi module failed!"
);
while
(
true
);
}
String
fv
=
WiFi
.
firmwareVersion
();
if
(
fv
!=
"1.0.0"
)
{
Serial
.
println
(
"Please upgrade the firmware"
);
}
ThingSpeak
.
begin
(
client
);
// Initialize ThingSpeak
pinMode
(
temperaturePin
,
INPUT
);
pinMode
(
dustPin
,
INPUT
);
pinMode
(
buzzerPin
,
OUTPUT
);
dustStartTime
=
millis
();
// get the current time;
}
void
loop
()
{
// Connect or reconnect to WiFi
if
(
WiFi
.
status
()
!=
WL_CONNECTED
)
{
Serial
.
print
(
"Attempting to connect to SSID: "
);
Serial
.
println
(
ssid
);
while
(
WiFi
.
status
()
!=
WL_CONNECTED
)
{
WiFi
.
begin
(
ssid
,
pass
);
// Connect to WPA/WPA2 network. Change this line if using open or WEP network
Serial
.
print
(
"."
);
delay
(
5000
);
}
Serial
.
println
(
"
\n
Connected."
);
}
// Read Temperature
int
temperatureValue
=
analogRead
(
temperaturePin
);
float
voltage
=
temperatureValue
*
5.0
/
1023.0
;
float
temperature
=
(
voltage
-
0.5
)
*
100.0
;
// Read Dust Sensor
dustDuration
=
pulseIn
(
dustPin
,
LOW
);
dustLowPulseOccupancy
=
dustLowPulseOccupancy
+
dustDuration
;
// If the sample time is reached (30s)
if
((
millis
()
-
dustStartTime
)
>
dustSampleTime_ms
)
{
dustRatio
=
dustLowPulseOccupancy
/
(
dustSampleTime_ms
*
10.0
);
// Integer percentage 0=>100
dustConcentration
=
1.1
*
pow
(
dustRatio
,
3
)
-
3.8
*
pow
(
dustRatio
,
2
)
+
520
*
dustRatio
+
0.62
;
// using spec sheet curve
// Print dust sensor data
Serial
.
print
(
"Dust: "
);
Serial
.
print
(
dustLowPulseOccupancy
);
Serial
.
print
(
","
);
Serial
.
print
(
dustRatio
);
Serial
.
print
(
","
);
Serial
.
println
(
dustConcentration
);
// Reset dust sensor values
dustLowPulseOccupancy
=
0
;
dustStartTime
=
millis
();
}
// Control Buzzer based on temperature
if
(
temperature
>
25.0
)
{
// If temperature is above 25 degrees Celsius, turn on the buzzer
digitalWrite
(
buzzerPin
,
HIGH
);
}
else
{
// Otherwise, turn off the buzzer
digitalWrite
(
buzzerPin
,
LOW
);
}
// Print temperature data
Serial
.
print
(
"Temperature: "
);
Serial
.
println
(
temperature
);
// Write to ThingSpeak
int
x
=
ThingSpeak
.
writeField
(
myChannelNumber
,
1
,
temperature
,
myWriteAPIKey
);
if
(
x
==
200
)
{
Serial
.
println
(
"ThingSpeak update successful."
);
}
else
{
Serial
.
println
(
"Problem updating ThingSpeak. HTTP error code "
+
String
(
x
));
}
// Change the value
number
++
;
if
(
number
>
99
)
{
number
=
0
;
}
delay
(
20000
);
// Wait 20 seconds to update ThingSpeak channel again
}
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