#include <Gizwits.h>#include <Wire.h>#include <SoftwareSerial.h>#include <DHT.h>#include <ChainableLED.h>#include <MsTimer2.h>
#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
void DHT11_Read_Data(unsigned char * temperature, unsigned char * humidity){*temperature = (unsigned char)dht.readTemperature();*humidity = (unsigned char)dht.readHumidity();return;}
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 );}}
void LED_RGB_Control(byte red, byte green, byte blue){leds.setColorRGB(0, red, green, blue);}
unsigned char temperature_buf=0;unsigned char humidity_buf=0;
mySerial.begin(115200);leds.init();digitalWrite(A0, HIGH);// Enable RGB LEDpinMode(KEY1, INPUT_PULLUP); // KEY1 pull-up inputLED_RGB_Control(0,0,0);
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);
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!"); }
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!");}
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
Circuit Basics | Digital Circuits | Oscilloscope Basics | Multimeter Usage | Signal Integrity | Ground Knowledge | Embedded Basics | STM32 Basic Knowledge Summary | C Language Knowledge Points
Resistors | Capacitors | Inductors | Diodes | Transistors | TVS | Thyristors | MOSFETs |IGBTs | Sensors | Relays | Equivalent Circuit of Components| Complete Guide to Component Selection | Component Faults
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.)
Leave a Comment
Your email address will not be published. Required fields are marked *