Smart Sleep Environment Device Using Gizwits Gokit2.0 Development Board

Smart Sleep Environment Device Using Gizwits Gokit2.0 Development Board
Author: Ba He Yang, Source: Embedded Community【Gizwits Gokit2.0 Development Board Arduino Version】Review Activity.For more free evaluations of development boards and book previews, please scan the QR code at the end.
IntroductionThis project uses the Gizwits Gokit2.0 development board to implement a smart sleep environment device, addressing the pain point of increasing sleep requirements in bedrooms for most people. Pain Points-Environment data can be detected – Temperature and humidity can be intelligently adjusted – Lights turn on automatically when someone gets up – Switch controls indoor devices Functions-When the temperature exceeds 20°C, the fan turns on to the first gear; when the temperature exceeds 30°C, the fan turns on to the second gear. If the temperature is below 20°C, the fan turns off automatically.-Real-time detection of temperature and humidity sensors, infrared human detection sensors, and other data, and sends it through the serial port for display.-The infrared human detection sensor detects whether someone has gotten up in real-time, turning on the white light if someone is present.-Press button one to turn on the white light; press button two to turn on the fan.PreparationSoftware – Arduino IDE – Gizwits – Serial Debugging AssistantHardware – Gizwits Gokit2.0 Development BoardProject DevelopmentHardware Development
Smart Sleep Environment Device Using Gizwits Gokit2.0 Development Board
Software Development1. First declare the included header files
#include <Gizwits.h>#include <Wire.h>#include <SoftwareSerial.h>#include <DHT.h>#include <ChainableLED.h>#include <MsTimer2.h>
2. Define the pins for the temperature and humidity sensor, button 1, button 2, RGB light, infrared sensor, and motor according to the circuit diagram.
#define Infrared_PIN 2 ///< Infrared IO pin#define DHTPIN 3 ///< Temperature and humidity IO pin#define MOTOR_PINA 4 ///< Motor IO pin#define MOTOR_PINB 5 ///< Motor IO pin#define KEY1 6 ///< Button IO pin#define KEY2 7 ///< Button IO pin// Temperature and humidity function value definition#define DHTTYPE DHT11// Motor function value definition#define MOTOR_MAX 100#define MOTOR_MAX1 -100#define MOTOR_MIN 0#define MOTOR_16DHT dht(DHTPIN, DHTTYPE);ChainableLED leds(A5, A4, 1);SoftwareSerial mySerial(0, 1); // A2 -> RX, A3 -> TX
3. Write the function to read temperature and humidity
void DHT11_Read_Data(unsigned char * temperature, unsigned char * humidity){*temperature = (unsigned char)dht.readTemperature();*humidity = (unsigned char)dht.readHumidity();return;}
4. Write the motor control function program
void Motor_status(long motor_speed){unsigned char Temp_motor_speed = 0;if (motor_speed == 0) // Stop {digitalWrite(MOTOR_PINA, LOW);}if (motor_speed > 0) // Forward{Temp_motor_speed = (motor_speed - 0) * 51;if (Temp_motor_speed > 255) Temp_motor_speed = 255;digitalWrite(MOTOR_PINA, LOW);analogWrite( MOTOR_PINB, Temp_motor_speed);}if (motor_speed < 0) // Reverse{Temp_motor_speed = 255 - (0 - motor_speed) * 51; if (Temp_motor_speed > 255) Temp_motor_speed = 255;digitalWrite(MOTOR_PINA, HIGH);analogWrite( MOTOR_PINB, Temp_motor_speed );}}
5. Write the RGB light function program
void LED_RGB_Control(byte red, byte green, byte blue){leds.setColorRGB(0, red, green, blue);}
6. Declare temporary variables for temperature and humidity
unsigned char temperature_buf=0;unsigned char humidity_buf=0;
7. In the initialization program, define the serial port baud rate, initialize RGB, and define GPIO.
mySerial.begin(115200);leds.init();digitalWrite(A0, HIGH);// Enable RGB LEDpinMode(KEY1, INPUT_PULLUP); // KEY1 pull-up inputLED_RGB_Control(0,0,0);
8. In the main loop, first detect the temperature and humidity values, and display the values from the temperature and humidity sensor. When the temperature exceeds 20°C, the fan turns on to the first gear; when the temperature exceeds 30°C, the fan turns on to the second gear. If the temperature is below 20°C, the fan turns off automatically.
DHT11_Read_Data(&temperature_buf, &humidity_buf);if(temperature_buf>20) {Motor_status(1); }else if(temperature_buf>30) {Motor_status(2); }else {Motor_status(0); } mySerial.println("temperature:"); mySerial.println(temperature_buf, DEC); mySerial.println("humidity:"); mySerial.println(humidity_buf, DEC);
9. Press button one to turn on the white light; press button two to turn on the fan.
if(digitalRead(KEY1) == LOW)  {LED_RGB_Control(255,255,255);  mySerial.println("open led!");  }else if(digitalRead(KEY2) == LOW)  {Motor_status(1);  mySerial.println("open fan!");  }
10. Detect whether the infrared human detection sensor detects someone; if someone is present, turn on the white light; if no one is present, turn it off. Send the information through the serial port.
if (digitalRead(Infrared_PIN)){ mySerial.println("No one appears and disappears!");LED_RGB_Control(0,0,0);}else{LED_RGB_Control(255,255,255);mySerial.println("Someone is appearing!");}
Function Demonstration
Smart Sleep Environment Device Using Gizwits Gokit2.0 Development Board
Smart Sleep Environment Device Using Gizwits Gokit2.0 Development Board
Smart Sleep Environment Device Using Gizwits Gokit2.0 Development Board
Author: Ba He Yang, Source: Embedded Community【Gizwits Gokit2.0 Development Board Arduino Version】Review Activity.For more free evaluations of development boards and book previews, please scan the QR code below.
END
Smart Sleep Environment Device Using Gizwits Gokit2.0 Development Board
Smart Sleep Environment Device Using Gizwits Gokit2.0 Development Board
Circuit Diagram Collection

Common Analog Circuits | Operational Amplifier Circuits | Protection Circuits | EMC Standard Circuits | Power Supply Circuit Collection | Practical Control Circuits | Microcontroller Application Circuits | Waveform Generator Circuits | Car Circuit Diagram Collection | 555 Circuits | Small Appliance Circuits | 9 Basic Module Circuits | Schematic Abbreviations | Circuit Symbols

Basic Entry

Circuit Basics | Digital Circuits | Oscilloscope Basics | Multimeter Usage | Signal Integrity | Ground Knowledge | Embedded Basics | STM32 Basic Knowledge Summary | C Language Knowledge Points

Components

Resistors | Capacitors | Inductors | Diodes | Transistors | TVS | Thyristors | MOSFETs |IGBTs | Sensors | Relays | Equivalent Circuit of Components| Complete Guide to Component Selection | Component Faults

Join the Community

If you want to join the electronics industry WeChat group, you can scan to add our community operation. Please note the direction of joining the group (a brief description of the target group, e.g., embedded, market trends, etc.)

Smart Sleep Environment Device Using Gizwits Gokit2.0 Development Board

Leave a Comment

Your email address will not be published. Required fields are marked *