Combine both codes or make it work with 2 separate tabs. I am using Arduino Ethernet Shield W5100 with Arduino UNO trying to send a notification to PushSafer. Each code works individually
Combine both codes or make it work with 2 separate tabs. I am using Arduino Ethernet Shield W5100 with Arduino UNO trying to send a notification to PushSafer. Each code works individually but I cannot get to work together.
Combine both codes or make it work with 2 separate tabs. I am using Arduino Ethernet Shield W5100 with Arduino UNO trying to send a notification to PushSafer. Each code works individually but I cannot get to work together.
Pushsafer.ino
#include <SPI.h>
#include <Ethernet.h>
// Network settings
byte mac[] = { XXXXXXXXXXXXXXXXXXXXXX}; // Modify with your Ethernet shield's MAC address
IPAddress ip(XXXXXXXXXX); // IP address for the Arduino (modify according to your network settings)
// PushSafer private or alias key
String privateKey = "XXXXXXXXXXXXXXXXX";
String deviceID = "XXXX"; // Device ID for targeting a specific device
// Ethernet client
EthernetClient client;
void setup() {
// Initialize serial communication
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect.
}
// Initialize Ethernet connection
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// Try to configure using IP address instead of DHCP:
Ethernet.begin(mac, ip);
}
delay(1000); // Give the Ethernet shield a second to initialize
}
void sendPushSaferMessage(String message) {
if (client.connect("www.pushsafer.com", 80)) {
Serial.println("Connected to PushSafer");
// Make a HTTP request:
client.println("POST /api HTTP/1.1");
client.println("Host: www.pushsafer.com");
client.println("Content-Type: application/x-www-form-urlencoded");
String postData = "k=" + privateKey + "&d=" + deviceID + "&m=" + message;
client.print("Content-Length: ");
client.println(postData.length());
client.println();
client.print(postData);
Serial.println("Message sent");
} else {
Serial.println("Connection failed");
}
// Give the web server time to respond, then disconnect
delay(500);
if (client.connected()) {
client.stop();
}
}
void loop() {
// Send a test message
sendPushSaferMessage("Hello from Arduino!");
delay(60000); // Wait a minute before sending the next message
}
Second Part
Alarm_System.ino
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
#include <Wire.h>
#define alarmPin A1
#define pirPin 11
#define greenLED 12 // Green LED pin
#define redLED 13 // Red LED pin
int offMsg = 0;
String passwd = "1234";
String inpswd;
bool activated = false;
bool activateAlarm = false;
bool activeAlarm = false;
bool passwdEntered;
const byte rows = 4;
const byte cols = 4;
char keypress;
char keys[rows][cols] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[rows] = {10, 9, 8, 7};
byte colPins[cols] = {3,2,1,0};
Keypad kp = Keypad(makeKeymap(keys), rowPins, colPins, rows, cols);
// Initialize the LCD. The I2C address is 0x27 and it has 16 columns and 2 rows.
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
lcd.init(); // Initialize the LCD
lcd.backlight(); // Turn on the backlight
pinMode(alarmPin, OUTPUT);
pinMode(pirPin, INPUT);
pinMode(greenLED, OUTPUT);
pinMode(redLED, OUTPUT);
}
void loop() {
if (activateAlarm) {
lcd.clear();
lcd.setCursor(0,0);
delay(500);
lcd.print("System Online");
digitalWrite(greenLED, HIGH);
activateAlarm = false;
activeAlarm = true;
}
if (activeAlarm == true) {
if (digitalRead(pirPin) == HIGH) {
tone(alarmPin, 1000);
digitalWrite(greenLED, LOW);
digitalWrite(redLED, HIGH);
lcd.clear();
password();
} else {
digitalWrite(redLED, LOW);
digitalWrite(greenLED, HIGH);
}
}
if (activeAlarm == false) {
digitalWrite(greenLED, LOW);
if (offMsg == 0) {
lcd.clear();
lcd.setCursor(1,0);
lcd.print("Press 'A' To");
lcd.setCursor(3,1);
lcd.print("Activate");
offMsg = 1;
}
keypress = kp.getKey();
if (keypress == 'A') {
tone(alarmPin, 1000, 200);
activateAlarm = true;
}
}
}
void password() {
int cursor = 5;
inpswd = "";
activated = true;
lcd.clear();
lcd.setCursor(1,0);
lcd.print("Enter Password");
lcd.setCursor(0,1);
while (activated) {
keypress = kp.getKey();
if (keypress != NO_KEY) {
if (keypress == '1' || keypress == '2' || keypress == '3' || keypress == '4' ||
keypress == '5' || keypress == '6' || keypress == '7' || keypress == '8' ||
keypress == '9' || keypress == '0') {
inpswd += keypress;
lcd.setCursor(cursor,1);
lcd.print(keypress);
cursor++;
}
}
if (cursor > 9 || keypress == '#') {
inpswd = "";
cursor = 5;
lcd.clear();
lcd.setCursor(1,0);
lcd.print("Enter Password");
lcd.setCursor(0,1);
}
if (keypress == '*') {
if (inpswd == passwd) {
activated = false;
activeAlarm = false;
noTone(alarmPin);
digitalWrite(redLED, LOW);
offMsg = 0;
} else {
lcd.setCursor(2,1);
lcd.print("Incorrect");
delay(1000);
lcd.clear();
lcd.setCursor(1,0);
lcd.print("Enter Password");
lcd.setCursor(0,1);
}
}
}
}
Collepals.com Plagiarism Free Papers
Are you looking for custom essay writing service or even dissertation writing services? Just request for our write my paper service, and we'll match you with the best essay writer in your subject! With an exceptional team of professional academic experts in a wide range of subjects, we can guarantee you an unrivaled quality of custom-written papers.
Get ZERO PLAGIARISM, HUMAN WRITTEN ESSAYS
Why Hire Collepals.com writers to do your paper?
Quality- We are experienced and have access to ample research materials.
We write plagiarism Free Content
Confidential- We never share or sell your personal information to third parties.
Support-Chat with us today! We are always waiting to answer all your questions.