keyestudio
Share your creative ideas with us here
By ran | 26 December 2024 | 0 Comments

Do a WiFi Experiment with ESP32!

Description

In the previous experiment, we have learned the WiFi Station mode, WiFi AP mode and WiFi AP+Station mode of the ESP32. In this project, We will use ESP32’s WiFi Station mode to control the work of multiple sensors/modules through APP connection with WiFi to achieve the effect of WiFi smart home.

Components

img

img

img

img

img

ESP32 Board*1

ESP32 Expansion Board*1

Keyestudio 130 Motor*1

Keyestudio5V Relay Module*1

Servo*1

img

img

img

img

img
img

Keyestudio XHT11Temperature and Humidity Sensor*1
(compatible DHT11)

Keyestudio HC-SR04 Ultrasonic Sensor*1

3P Dupont*2

4P Dupont*2

Smart Phone/PC*1

img

img

img

 

 

Battery Holder*1

Battery (provided by yourself)*6

Micro USB Cable*1

 

 

Wiring Diagram

Install APP

(1) Android device (mobile phone/PC) APP:

A. We provide the Android APP installation package:

B. Now transfer the keyes wifi.apk file in the Android APP installation package to the Android phone or PC, click the keyes wifi.apk file to enter the installation page, click “ALLOW” key, and then click “INSTALL” button. After installation, click “OPEN” button to enter the APP interface.

(2) IOS device (mobile phone /iPad) APP:

A. Open App Store

B. Enter keyes link in the search box and click search, the download interface appears. Click “” to download and install the APP of the keyes link. The following operations are similar to those of Android system. You can refer to the steps of Android system above for operation.

Test Code

Note: You need to change the Wifi name and default Wifi password of the experimental code to your own Wifi name and Wifi password.

//**********************************************************************************
/*  
 * Filename    : WiFi Smart Home.
 * Description : WiFi APP controls Multiple sensors/modules work to achieve the effect of WiFi smart home.
 * Auther      : http//www.keyestudio.com
*/
#include <Arduino.h>
#include <WiFi.h>
#include <ESPmDNS.h>
#include <WiFiClient.h>

#include "xht11.h"
//gpio15
xht11 xht(27);
unsigned char dht[4] = {0, 0, 0, 0};

#include <ESP32Servo.h>
Servo myservo;
int servoPin = 21;
#define Relay  4
#define IN1 2  //IN1 corresponds to IN+
#define IN2 15 //IN2 corresponds to IN-
#define trigPin  12
#define echoPin  13

int distance1;
String dis_str;
int ip_flag = 1;
int ultra_state = 1;
int temp_state = 1;
int humidity_state = 1;

String item = "0";
const char* ssid = "ChinaNet-2.4G-0DF0"; //the name of user's wifi
const char* password = "ChinaNet@233";   //the password of user's wifi
WiFiServer server(80);
String unoData = "";

void setup() {
  Serial.begin(115200);
  pinMode(Relay, OUTPUT);
  myservo.setPeriodHertz(50);   
  myservo.attach(servoPin, 500, 2500);
  pinMode(IN1, OUTPUT);
  pinMode(IN2, OUTPUT);
  
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.print("Connected to ");
  Serial.println(ssid);
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());

                

Leave a Reply

Your email address will not be published.Required fields are marked. *
Name
E-mail
Content
Verification code