Upload 2 files
Browse files
22.ino
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include <ESP8266WiFi.h>
|
| 2 |
+
|
| 3 |
+
const char* ssid = "clock";
|
| 4 |
+
const char* password = "spencer79";
|
| 5 |
+
const char* host = "192.168.1.107"; // IP address of your Python server
|
| 6 |
+
|
| 7 |
+
void setup() {
|
| 8 |
+
Serial.begin(9600); // Initialize serial communication
|
| 9 |
+
delay(10);
|
| 10 |
+
|
| 11 |
+
// Connect to Wi-Fi
|
| 12 |
+
Serial.println();
|
| 13 |
+
Serial.print("Connecting to ");
|
| 14 |
+
Serial.println(ssid);
|
| 15 |
+
WiFi.begin(ssid, password);
|
| 16 |
+
|
| 17 |
+
while (WiFi.status() != WL_CONNECTED) {
|
| 18 |
+
delay(500);
|
| 19 |
+
Serial.print(".");
|
| 20 |
+
}
|
| 21 |
+
Serial.println("");
|
| 22 |
+
Serial.println("WiFi connected");
|
| 23 |
+
|
| 24 |
+
// Print the IP address
|
| 25 |
+
Serial.println(WiFi.localIP());
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
void loop() {
|
| 29 |
+
if (Serial.available()) {
|
| 30 |
+
// Read data from Arduino Uno
|
| 31 |
+
String data = Serial.readStringUntil('\n');
|
| 32 |
+
|
| 33 |
+
// Send data to Python server
|
| 34 |
+
WiFiClient client;
|
| 35 |
+
const int httpPort = 80;
|
| 36 |
+
if (!client.connect(host, httpPort)) {
|
| 37 |
+
Serial.println("Connection failed");
|
| 38 |
+
return;
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
// Create HTTP POST request
|
| 42 |
+
String url = "/receive_data"; // Adjust the URL endpoint as needed
|
| 43 |
+
String postData = "data=" + data;
|
| 44 |
+
client.print(String("POST ") + url + " HTTP/1.1\r\n" +
|
| 45 |
+
"Host: " + host + "\r\n" +
|
| 46 |
+
"Content-Type: application/x-www-form-urlencoded\r\n" +
|
| 47 |
+
"Content-Length: " + postData.length() + "\r\n" +
|
| 48 |
+
"\r\n" + postData);
|
| 49 |
+
delay(10);
|
| 50 |
+
|
| 51 |
+
Serial.println("Data sent to Python server");
|
| 52 |
+
}
|
| 53 |
+
}
|
All.ino
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
int counter = 0; // Initialize the integer value to 0
|
| 2 |
+
String str;
|
| 3 |
+
|
| 4 |
+
////////////////////////////////////////////////////////////cry
|
| 5 |
+
int t = 0;
|
| 6 |
+
////////////////////////////////////////////////////////534 cry
|
| 7 |
+
|
| 8 |
+
////////////////////////////////////////////////////////dfplayer
|
| 9 |
+
#include "SoftwareSerial.h"
|
| 10 |
+
#include "DFRobotDFPlayerMini.h"
|
| 11 |
+
|
| 12 |
+
// Use pins 2 and 3 to communicate with DFPlayer Mini
|
| 13 |
+
static const uint8_t PIN_MP3_TX = 2; // Connects to module's RX
|
| 14 |
+
static const uint8_t PIN_MP3_RX = 3; // Connects to module's TX
|
| 15 |
+
SoftwareSerial softwareSerial(PIN_MP3_RX, PIN_MP3_TX);
|
| 16 |
+
|
| 17 |
+
// Create the Player object
|
| 18 |
+
DFRobotDFPlayerMini player;
|
| 19 |
+
|
| 20 |
+
////////////////////////////////////////////////////////dfplayer
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
////////////////////////////////////////////////////////////light
|
| 24 |
+
const int analogInPin = A0;
|
| 25 |
+
////////////////////////////////////////////////////////////light
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
////////////////////////////////////////////////sdx////////////humidity
|
| 30 |
+
#include <dht11.h>
|
| 31 |
+
#define DHT11PIN 4
|
| 32 |
+
dht11 DHT11;
|
| 33 |
+
////////////////////////////////////////////////////////////humidity
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
////////////////////////////////////////////////////////wet
|
| 37 |
+
#define sensor_DO 7
|
| 38 |
+
////////////////////////////////////////////////////////wet
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
void setup() {
|
| 43 |
+
// Init USB serial port for debugging
|
| 44 |
+
Serial.begin(9600);
|
| 45 |
+
pinMode(8, OUTPUT);
|
| 46 |
+
pinMode(9, OUTPUT);
|
| 47 |
+
// Init serial port for DFPlayer Mini
|
| 48 |
+
softwareSerial.begin(9600);
|
| 49 |
+
|
| 50 |
+
// Start communication with DFPlayer Mini
|
| 51 |
+
if (player.begin(softwareSerial)) {
|
| 52 |
+
//Serial.print("OK");
|
| 53 |
+
player.volume(20);
|
| 54 |
+
} else {
|
| 55 |
+
//Serial.print("Connecting to DFPlayer Mini failed!");
|
| 56 |
+
}
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
void loop() {
|
| 60 |
+
Serial.print("755_");
|
| 61 |
+
////////////////////////////////////////////////////////wet
|
| 62 |
+
int val = digitalRead(sensor_DO);
|
| 63 |
+
////////////////////////////////////////////////////////wet
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
////////////////////////////////////////////////////////////humidity
|
| 68 |
+
int chk = DHT11.read(DHT11PIN);
|
| 69 |
+
////////////////////////////////////////////////////////////humidity
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
////////////////////////////////////////////////////////////cry
|
| 74 |
+
int sensorValue = analogRead(A1);
|
| 75 |
+
int n = sensorValue;
|
| 76 |
+
|
| 77 |
+
sensorValue = analogRead(A1);
|
| 78 |
+
//Serial.println("noise :");
|
| 79 |
+
//Serial.print(sensorValue);
|
| 80 |
+
if (abs(n - sensorValue) >= 10) {
|
| 81 |
+
t += 1;
|
| 82 |
+
}
|
| 83 |
+
//Serial.print("t :");
|
| 84 |
+
Serial.print(t);
|
| 85 |
+
Serial.print("_");
|
| 86 |
+
if (t==3) {
|
| 87 |
+
player.play(1);
|
| 88 |
+
}
|
| 89 |
+
if (t >= 3) {
|
| 90 |
+
digitalWrite(8, HIGH);
|
| 91 |
+
digitalWrite(9, LOW);
|
| 92 |
+
Serial.print("ON_");}
|
| 93 |
+
else {
|
| 94 |
+
Serial.print("OFF_");
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
////////////////////////////////////////////////////////////cry
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
////////////////////////////////////////////////////////////humidity
|
| 102 |
+
//Serial.print("Humidity (%): ");
|
| 103 |
+
Serial.print((float)DHT11.humidity, 2);
|
| 104 |
+
Serial.print("_");
|
| 105 |
+
|
| 106 |
+
//Serial.print("Temperature (C): ");
|
| 107 |
+
Serial.print((float)DHT11.temperature, 2);
|
| 108 |
+
Serial.print("_");
|
| 109 |
+
////////////////////////////////////////////////////////////humidity
|
| 110 |
+
|
| 111 |
+
////////////////////////////////////////////////////////wet
|
| 112 |
+
if (val == 1) {
|
| 113 |
+
Serial.print("Dry_");
|
| 114 |
+
} else {
|
| 115 |
+
Serial.print("Wet_");
|
| 116 |
+
}
|
| 117 |
+
////////////////////////////////////////////////////////wet
|
| 118 |
+
|
| 119 |
+
////////////////////////////////////////////////////////////light
|
| 120 |
+
//Serial.print("light : ");
|
| 121 |
+
Serial.println(analogRead(analogInPin));
|
| 122 |
+
delay(1000);
|
| 123 |
+
////////////////////////////////////////////////////////////light
|
| 124 |
+
}
|