Nowadays, the smart home industry is developing rapidly. Thanks to the iterative development of the Internet of Things and artificial intelligence technology, all kinds of smart home devices have unconsciously come into our lives.
Smart homes cost a lot of money, so can we make them ourselves in very little time? The answer, of course, is yes.
Nowadays, there are endless cloud platforms of the Internet of Things, such as Huawei Cloud, Tencent cloud and Ali Cloud platform. Make the development of intelligent home becomes easier and faster.
Today, I share a remote control product for lighting, fan (exhaust fan) and humidifier (fire sprinkler) in the house, which is designed on the smart cloud platform and aims to lead beginners in the Internet of things and smart home industry to make a smart device of their own.
process
Create a product
-
Create a new product
Fill in the relevant type, you can fill in according to their own needs.
-
Adding data points
Again, you set the data points according to your own needs, each element that you control or use.
3. Generate MCU code
Download your generated code zip.
4. Integrate code
Copy and paste all of your Gizwits files except examples into two separate folders in examples.
WiFi module networking
Since it is MCU mode, we only treat the WiFi module as a module, and it itself is an independent development board. Therefore, we can connect the WiFi module through the program first, and then there is no need to connect the WiFi module again, which provides convenience for the subsequent intelligent control. #include < gizwits.h > in networkconfig. ino to #include “gizwits.h”
-
Comment out the serial port print code, part of the screenshot below.
-
Upload to the development board
Select the corresponding Arduino development board type and port number to upload.
8. Configure the network
Open the APP downloaded from the official website and hold down KEY2 to enter the configuration mode.
-
View the page of the configured APP
When the icon is on, it indicates that the configuration is successful.
Library file and header file preparation
Because we mainly use different colors of RGB lights instead of WORKING on LED lights or sprinkler heads, in fact, it is simpler to realize these functions. After defining relevant pins, the corresponding functions can be realized by outputting high or low levels. However, in order to make the experimental phenomenon more obvious, different RGB colors are used to represent LED lights and humidifiers, and pure power supply is used in the rotating part of the fan, which is more conducive to understanding.
-
#include < gizwits.h > in simpletry. ino project file to #include “gizwits.h”
-
Transplant library files we directly transplant RGB related libraries, can greatly simplify our development, if you want to understand the DEVELOPMENT of RGB lights, you can also look at the library file. In order to save time, I will put the library file here for you to download.
Function implementation
- We need to reference some library files and add RGB LED control functions
#include "Gizwits.h"
#include <Wire.h>
#include <SoftwareSerial.h>
#include <ChainableLED.h>
ChainableLED leds(A5, A4, 1);
void LED_RGB_Control(byte red, byte green, byte blue)
{
leds.setColorRGB(0, red, green, blue);
}
Copy the code
2. Define pin types
pinMode(5,OUTPUT);
pinMode(4,OUTPUT);
pinMode(SDA,OUTPUT);
pinMode(SCL,OUTPUT);
digitalWrite(5,LOW);
digitalWrite(4,LOW);
Copy the code
- By obtaining the instructions sent by the mobile APP, different operations can be carried out. Finally, the mobile phone can control the rotation of the fan and different colors of RGB LED light on and off.
bool varR_LED = 0; if(myGizwits.hasBeenSet(EVENT_LED)) { myGizwits.read(EVENT_LED,&varR_LED); If (varR_LED = = 1) {LED_RGB_Control,0,100 (0); } the else LED_RGB_Control (0, 0); } bool varR_FengShan = 0; if(myGizwits.hasBeenSet(EVENT_FengShan)) { myGizwits.read(EVENT_FengShan,&varR_FengShan); if(varR_FengShan==1) { digitalWrite(5,HIGH); } else digitalWrite(5,LOW); } bool varR_PenTou = 0; if(myGizwits.hasBeenSet(EVENT_PenTou)) { myGizwits.read(EVENT_PenTou,&varR_PenTou); //Address for storing data if(varR_PenTou==1) {LED_RGB_Control(0,100,0); } the else LED_RGB_Control (0, 0); } myGizwits.process();Copy the code
Re: WiFi remote control home device, for everyone to download.
Click on it to see you look good
Scan the QR code to obtain
More wonderful
Internet of Things knowledge
This article uses the article synchronization assistant to synchronize