Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
ARDUIJIO
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
angel.rivera
ARDUIJIO
Commits
f883e637
Commit
f883e637
authored
Jan 24, 2024
by
angel.rivera
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Initial commit
parents
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
185 additions
and
0 deletions
+185
-0
launch.json
.theia/launch.json
+8
-0
sketch_jan11a.ino
sketch_jan11a.ino
+177
-0
No files found.
.theia/launch.json
0 → 100644
View file @
f883e637
{
//
Use
IntelliSense
to
learn
about
possible
attributes.
//
Hover
to
view
descriptions
of
existing
attributes.
"version"
:
"0.2.0"
,
"configurations"
:
[
]
}
sketch_jan11a.ino
0 → 100644
View file @
f883e637
#include <WiFiNINA.h>
#include <Buzzer.h>
#include <rgb_lcd.h>
#include <Wire.h>
#include <Seeed_SHT35.h>
#include <DHT.h>
#include "ThingSpeak.h"
// Function prototypes
float
readTemperature
();
int
readLightLevel
();
int
readSoundLevel
();
void
checkAlerts
(
float
temperature
,
int
light
,
int
sound
);
// Sensor and output pins
#define DHTPIN 2 // DHT sensor pin
#define DHTTYPE DHT11 // DHT 11 type
#define LIGHT_SENSOR_PIN A0
#define SOUND_SENSOR_PIN A1
#define TEMP_SENSOR_PIN A2
#define TEMP_LED_PIN 8 // LED for temperature alert
#define LIGHT_LED_PIN 9 // LED for light alert
#define SOUND_LED_PIN 10 // LED for sound alert
#define BUZZER_PIN 11 // Buzzer pin
// Initialize DHT sensor and RGB LCD display
DHT
dht
(
DHTPIN
,
DHTTYPE
);
rgb_lcd
lcd
;
WiFiClient
client
;
// Temperature sensor constants
const
int
B
=
4275
;
// B value of the thermistor
const
int
R0
=
100000
;
// R0 = 100k
const
int
pinTempSensor
=
A0
;
// Temperature sensor pin
char
ssid
[]
=
"Pixel_7931"
;
// Your network SSID (name)
char
pass
[]
=
"norbert1"
;
// Your network password
int
keyIndex
=
0
;
// Your network key Index number (needed only for WEP)
unsigned
long
myChannelNumber
=
"2409148"
;
// Replace YOUR_CHANNEL_NUMBER with your ThingSpeak channel number
const
char
*
myWriteAPIKey
=
"VHG57K7FOIXKMUJ9"
;
// Replace YOUR_WRITE_API_KEY with your ThingSpeak Write API Key
void
setup
()
{
Serial
.
begin
(
9600
);
while
(
!
Serial
)
{
;
}
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
// Initialize the DHT sensor
dht
.
begin
();
delay
(
2000
);
// Wait for the sensor to stabilize
// Initialize the RGB LCD
lcd
.
begin
(
16
,
2
);
lcd
.
setRGB
(
0
,
255
,
0
);
// Set initial backlight color to green
// Set sensor and LED pins as input/output
pinMode
(
TEMP_SENSOR_PIN
,
INPUT
);
pinMode
(
LIGHT_SENSOR_PIN
,
INPUT
);
pinMode
(
SOUND_SENSOR_PIN
,
INPUT
);
pinMode
(
TEMP_LED_PIN
,
OUTPUT
);
pinMode
(
LIGHT_LED_PIN
,
OUTPUT
);
pinMode
(
SOUND_LED_PIN
,
OUTPUT
);
pinMode
(
BUZZER_PIN
,
OUTPUT
);
// Set buzzer pin as output
}
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 sensor data
float
temp
=
readTemperature
();
int
lightLevel
=
readLightLevel
();
int
soundLevel
=
readSoundLevel
();
// Display data on RGB LCD
lcd
.
clear
();
lcd
.
setCursor
(
0
,
0
);
lcd
.
print
(
"Temp: "
);
lcd
.
print
(
temp
);
lcd
.
setCursor
(
0
,
1
);
lcd
.
print
(
"Light: "
);
lcd
.
print
(
lightLevel
);
lcd
.
setCursor
(
0
,
2
);
lcd
.
print
(
"Sound: "
);
lcd
.
print
(
soundLevel
);
// Print data to Serial Monitor
Serial
.
print
(
"Temperature: "
);
Serial
.
println
(
temp
);
Serial
.
print
(
"Light Level: "
);
Serial
.
println
(
lightLevel
);
Serial
.
print
(
"Sound Level: "
);
Serial
.
println
(
soundLevel
);
// Check thresholds and activate LEDs and buzzer
checkAlerts
(
temp
,
lightLevel
,
soundLevel
);
// Write to ThingSpeak
int
x
=
ThingSpeak
.
writeField
(
myChannelNumber
,
1
,
temp
,
myWriteAPIKey
);
if
(
x
==
200
)
{
Serial
.
println
(
"ThingSpeak update successful."
);
}
else
{
Serial
.
println
(
"Problem updating ThingSpeak. HTTP error code "
+
String
(
x
));
}
delay
(
20000
);
// Delay for 2 seconds
}
float
readTemperature
()
{
int
a
=
analogRead
(
pinTempSensor
);
float
R
=
1023.0
/
a
-
1.0
;
R
=
R0
*
R
;
float
temperature
=
1.0
/
((
log
(
R
/
R0
)
/
B
)
+
1.0
/
298.15
)
-
273.15
;
// convert to temperature via datasheet
return
temperature
;
}
int
readLightLevel
()
{
return
analogRead
(
LIGHT_SENSOR_PIN
);
}
int
readSoundLevel
()
{
return
analogRead
(
SOUND_SENSOR_PIN
);
}
void
checkAlerts
(
float
temperature
,
int
light
,
int
sound
)
{
const
float
TEMP_THRESHOLD
=
0.0
;
const
int
LIGHT_THRESHOLD
=
600
;
const
int
SOUND_THRESHOLD
=
400
;
const
int
SOUND_BUZZER_THRESHOLD
=
100
;
// Buzzer threshold for sound level
if
(
temperature
>
TEMP_THRESHOLD
)
{
digitalWrite
(
TEMP_LED_PIN
,
HIGH
);
lcd
.
setRGB
(
255
,
0
,
0
);
// Set backlight color to red for high temperature
}
else
{
digitalWrite
(
TEMP_LED_PIN
,
LOW
);
lcd
.
setRGB
(
255
,
0
,
0
);
// Set backlight color to green for normal temperature
}
if
(
light
>
LIGHT_THRESHOLD
)
{
digitalWrite
(
LIGHT_LED_PIN
,
HIGH
);
}
else
{
digitalWrite
(
LIGHT_LED_PIN
,
LOW
);
}
if
(
sound
>
SOUND_THRESHOLD
)
{
digitalWrite
(
SOUND_LED_PIN
,
HIGH
);
}
else
{
digitalWrite
(
SOUND_LED_PIN
,
LOW
);
}
// Activate buzzer if sound level is below the buzzer threshold
if
(
sound
<
SOUND_BUZZER_THRESHOLD
)
{
digitalWrite
(
BUZZER_PIN
,
HIGH
);
}
else
{
digitalWrite
(
BUZZER_PIN
,
LOW
);
}
}
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