KS0085 Keyestudio Smart Home Kit for Arduino

From Keyestudio Wiki
Revision as of 12:31, 13 April 2020 by Keyestudio (talk | contribs)
Jump to navigation Jump to search



thumb

Instruction:

The smart home kit based on Arduino is newly issued by Keyestudieo company. The concept is to make people enjoy life. You could remotely control your assorted smart systems through your phone or computer when you’re out, like turning on air conditioner and water heater on the way home; the electronic door lock and led light will automatically run when you get home. Additionally, the intelligent lighting system can be used to select preset lighting scenes to create a comfortable and quiet atmosphere, which contributes to make your brain completely relaxed. You just need a remote control to finish all the process. What surprises you is that the smart system can save electricity as well. As Bill Gates puts it, in the future, homes without smart home systems will be as unfashionable as homes without internet access today. Let’s know more about smart home kit!


Kit List


thumb

thumb

thumb

thumb

thumb

thumb


Keyestudio PLUS Control Board

Description
thumb

thumb

Serial communication interface: D0 is RX, D1 is TX PWM interface (pulse width modulation): D3 D5 D6 D9 D10 D11 External interrupt interface: D2 (interrupt 0) and D3 (interrupt 1) SPI communication interface: D10 is SS, D11 is MOSI, D12 is MISO, D13 is SCK IIC communication port: A4 is SDA, A5 is SCL


Introduction: Install Arduino with the exe. Installation package you have downloaded well.
Get the latest version from the download page. You can choose between the Installer (.exe) and the Zip packages. We suggest you use the first one that installs directly everything you need to use the Arduino Software (IDE), including the drivers. With the Zip package you need to install the drivers manually. The Zip file is also useful if you want to create a portable installation.

Frist,Click “I Agree”.
thumb

When the download finishes, proceed with the installation and please allow the driver installation process when you get a warning from the operating system.

Then, click “Next”
thumb

Next, click “Install”.
thumb

thumb

When the following interface appears, click Install to finish the installation.
thumb

Finally, click “Close” after completing the installation.
thumb

=

Installing Driver ===

Finish the download, now, let’s install the driver of keyestudio PLUS control board. Its chip is CP2102 serial chip.

(1)If download the Arduino1.8.x development software, the driver file is included in it.


thumb

thumb

Double click thumb, click to next step,as shown below:


Arduino IDE Setting

Keyestudio Sensor Shield V5.2

Description

In the experiments, you might often use ARDUINO control board and several sensor modules. If the interfaces of power output is not enough, you may need to add a breadboard and use many connection wires. Is it really troublesome?
But now, with this keyestudio sensor shield, you can easily solve that problem. This shield is fully compatible with keyestudio PLUS Control Board, so you can easily stack it onto PLUS Control Board.
This keyestudio sensor shield has extended the digital and analog ports out as 3PIN interface (G,V, S), which can directly connect 3PIN sensor modules.
It also breaks out some communication pins of 2.54mm pitch, like serial, IIC, and SPI communication.
The shield comes with a reset button and 2 signal indicators as well.
Additionally, you can supply the voltage needed to the sensor modules through blue terminal blocks on the shield. Because some sensor modules is not used with 5V or 3.3V but with special voltage.

Parameter:

  • Extends an Arduino Reset button
  • Comes with 1 electrolytic capacitor and 1 ceramic capacitor
  • Comes with a built-in power indicator and a D13 indicator
  • Breakout all the digital and analog ports of keyestudio PLUS Control Board as 3PIN headers
  • A serial communication interface
  • A I2C communication interface
  • A SPI communication interface
  • Comes with a URF interface
  • Comes with an APC220 interface
  • You can supply the voltage needed for sensor modules via terminal blocks


Pins Description:
thumb

When SE is connected with jumper cap, and input DC 7V to VCC /GND terminal block, so the voltage of V, V1 and + pins are 7V. When SE is connected with jumper cap, and VCC /GND terminal block without voltage input, shield is powered via UNO R3, so the voltage of V, V1 and + pins are 5V. When SE is disconnected, input DC 7V to VCC /GND terminal block, so the voltage of V pin is 7V, the voltage of V1 and + pins are 0V. When SE is disconnected, and VCC /GND terminal block without voltage input, shield is powered via UNO R3, so the voltage of V pin is 0V, the voltage of V1 and + pins are 5V.

Example Use Stack the Keyestudio Sensor Shield V5 on the Keyestudio PLUS Control Board, and build the circuit on the shield, as shown below.
thumb


Projects When you get this kit, there are 14 sensors/modules inside like keyestudio PLUS control board, sensor shield and dupont Lines.
We firstly stack Keyestudio Sensor Shield V5.2 on the keyestudio PLUS control board and connect 14 sensors to sensor shield via dupont lines, upload the test code and check the result.


Note: In this course, the interface of each sensor / module marked with (G,-, GND) indicates the negative pole, and G and GND are connected to Arduino board or the sensor shield; V, +, and VCC stands for positive pole, they are linked with V, VCC and 5V of Arduino board or sensor shield.


Project 1: LED Blink

Description: In this kit, there are white and yellow LED modules. Their operating method is same. In this lesson, we directly connect the white LED module to the sensor shield with three female-to-female DuPont cables. After wiring, we can upload code on the keyestudio PLUS control board to control white LED to display different colors. After GND and VCC are powered on, the LED lights up when the signal terminal S is HIGH, and the LED turns off when signal end S is LOW.

Specifications:

  • Control interface: digital port
  • Working voltage: DC 3.3-5V
  • Pin pitch: 2.54mm
  • LED display color: white
  • Size: 30 * 20mm
  • Weight: 3g

Equipment:

  • White LED module * 1
  • Keyestudio PLUS Control Board * 1
  • Sensor shield * 1
  • 3pin female to female Dupont lines
  • USB cable * 1

Connection Diagram:
thumb
Note: The G, V, and S ports of the white LED module are separately connected to G, V, and 13, then power on.

Test Code:

void setup()
{
  pinMode(13, OUTPUT);//set digital 13 to output}

void loop()
{
  digitalWrite(13,HIGH);//set digital 13 to HIGH level,LED lights up
  delay(1000);	//delay in 1000ms
  digitalWrite(13,LOW);//set digital13 to LOW level,LED lights off
  delay(1000);         //delay in 1000ms
}

Test Result: Upload the test code successfully. After power on, the white LED starts blinking, light up for 1,000ms, turn off for 1000ms,and alternately.


Project 2: LED Breathe

Description

In this project, we will control the red LED brightness via PWM.
In the previous course, we introduced how to control the yellow LED on and off by code. Similarly, you can change the step length and delay in the code to set the red LED to achieve different breathing effects.

PWM is a means of controlling the analog output via digital means. Digital control is used to generate square waves with different duty cycles (a signal that constantly switches between high and low levels) to control the analog output.In general, the input voltage of port are 0V and 5V. What if the 3V is required? Or what if switch among 1V,3V and 3.5V? We can’t change resistor constantly. For this situation, we need to control by PWM.
For the Arduino digital port voltage output, there are only LOW and HIGH, which correspond to the voltage output of 0V and 5V. You can define LOW as 0 and HIGH as 1, and let the Arduino output 500 0 or 1 signals within 1 second.

The output port is 2.5V, which is like showing movie. The movie we watch are not completely continuous. It actually outputs 25 pictures per second. In this case, the human can’t tell it. So does PWM. If want different voltage, need to control the ratio of 0 and 1. The more 0,1 signals output per unit time, the more accurate the control.

In the following figure, the green line represents a period, and its value is the reciprocal of the PWM frequency. In other words, if the frequency of the Arduino PWM is 500 Hz, then the period between the two green lines is 2 ms. The range that can be manipulated in the analogWrite () command is 0-255, analogWrite (255) means 100% duty cycle (normally open), and analogWrite (127) duty cycle is about 50% (half the time).


thumb


Specifications: Control interface: digital port Working voltage: DC 3.3-5V Pin pitch: 2.54mm LED display color: yellow Size: 30 * 20mm Weight: 3g


Equipment: Yellow LED module * 1 Keyestudio PLUS Control Board * 1 Sensor shield * 1 3pin female to female DuPont lines USB cable * 1


Connection Diagram:


thumb

Note: The G, V, and S ports of the yellow LED module are separately connected to G, V, and 13, then power on.

On the sensor expansion board, the G, V, and S pins of the yellow LED module are connected to G, V, and 5 respectively, and the power supply is connected.


Test Code:

 void setup(){
  analogWrite(5,0);//set the PWM value of digital5 to 0
}

void loop(){
  for (int i = 0; i <= 255; i = i + (51)) 
// variable i increases from 0 to 255, add 51 each time
{
    analogWrite(5,i);//set variable i to the PWM value of digital5 
    delay(500);//delay in 500ms
  }
  for (int i = 255; i >= 0; i = i + (-51))
//variable i reduces from 255 to 0,plus -51 each time
 {
    analogWrite(5,i);//set variable i to the PWM value of digital5 
    delay(500);//delay in 500ms
  }} 

Test Result: Upload test code successfully and power on, yellow LED gradually become brighter and darker to simulate the human breath.


Project 3: Passive Buzzer

Description There are many interactive works that can be completed with Arduino. The most common element is buzzer and speaker. Buzzer is easy to use. And buzzer concludes in active buzzer and passive buzzer. In this project, we use passive buzzer. In this experiment, we make the buzzer sound and play music by test code.


Specifications: Control Port: digital Working Voltage: DC 3.3-5V


Equipment Keyestudio PLUS Control Board * 1 Sensor shield * 1 Passive buzzer module * 1 USB cable * 1 3pin female to female Dupont cable * 1

Connection Diagram:


thumb

Note: The G, V, and S port of the passive buzzer module are separately connected to G, V, and 3 on the shield, power up.

Test Code:

 void setup(){
  pinMode(3, OUTPUT);//set digital3 to output
}

void loop(){
  tone(3,262);//digital3 outputs the sound of 262Hz
  delay(250);//delay in 250ms
  tone(3,294);;//digital3 outputs the sound of 294HZ
  delay(250);//delay in 250ms
  tone(3,330);
  delay(250);
  tone(3,349);
  delay(250);
  tone(3,392);
  delay(250);
  tone(3,440);
  delay(250);
  tone(3,494);
  delay(250);
  tone(3,532);
  delay(250);
  noTone(3);//digital3 turns off sound output
  delay(1000);
}

Test Result: Upload test code on keyestudio PLUS Control Board, wire according to connection diagram, passive buzzer sounds “do re mi fa so la si do”.


Project 4:Controlling LED By Button Module

Description: In this project, we will control LED to light on and off via button module. When the button is pressed, the signal end outputs low level (0); when released, the signal end of sensor keeps high level(1).


Specifications: Working voltage: DC 3.3-5V Control signal: digital signal Size: 34 * 22 * 15mm Weight: 3.8g


Equipment Keyestudio REV4 development board * 1 Sensor shield * 1 Yellow LED module * 1 Button module * 1 USB cable * 1 3pin female to female DuPont Lines *2

Connection Diagram:


thumb

Note: The G, V, and S pins of button sensor module are separately connected to G, V, and 4 on the shield, and the G, V, and S pins of the yellow LED module are connected to G, V, and 5 on the shield.

Test Code:

void setup(){
  Serial.begin(9600);//set baud rate to 9600
  pinMode(4, INPUT);//set digital4 to input
  pinMode(5, OUTPUT);//set digital5 to output
}

void loop(){
  Serial.println(digitalRead(4));//wrap word and read the value of digital4
  delay(500);//delay in 500ms
  if (digitalRead(4) == 0)
//when read the value of digital4 to 0
 {
    digitalWrite(5,HIGH);//set digital5 to HIGH level, LED lights up
  } 
else
//otherwise(when the value of digital4 is 1)
 {
    digitalWrite(5,LOW);//set digital5 to LOW level, LED lights off
}}


Test Result: Upload test code, wire according to connection diagram, when the button is pressed, serial monitor displays 0 (low level ), yellow LED is on; when released, serial monitor displays 1 (high level), yellow LED is off.


Project 5:1-channel Relay Module

Description

This module is an arduino dedicated module, and compatible with arduino sensor expansion board. It has a control system (also called an input loop) and a controlled system (also called an output loop). Commonly used in automatic control circuits, it is an "automatic switch" for high voltage which control a larger current and a lower voltage with a smaller current and a lower voltage.

Therefore, it plays the role of automatic adjustment, safety protection and conversion circuit in the circuit. It allows Arduino to drive loads below 3A, such as LED light strips, DC motors, miniature water pumps, solenoid valve pluggable interface.

大号文字

The main internal components of the electromagnetic relay are electromagnet A, armature B, spring C, moving contact D, static contact (normally open contact) E, and static contact (normally closed contact) F, (as shown in the figure ).

As long as a certain voltage is applied to both ends of the coil, a certain current will flow through the coil to generate electromagnetic effects, and the armature will attract the iron core against the pulling force of the return spring under the action of electromagnetic force attraction, thereby driving the moving contact and the static contact (normally open contact) to attract. When the coil is disconnected, the electromagnetic suction will also disappear, and the armature will return to the original position under the reaction force of the spring, releasing the moving contact and the original static contact (normally closed contact). This pulls in and releases, thus achieving the purpose of turning on and off in the circuit. The "normally open, normally closed" contacts of the relay can be distinguished in this way: the static contacts on off state when the relay coil is not energized are called "normally open contacts"; the static contacts on state are called "normally closed contact". The module comes with 2 positioning holes for you to fix the module to other equipment.


Specifications: Working voltage: 5V (DC) Interface: G, V, S interface Input signal: digital signal (high level 1, low level 0) Contacts: static contacts (normally open contacts, normally closed contacts) and moving contacts Rated current: 10A (NO) 5A (NC)  Maximum switching voltage: 150 V (AC) 24 V (DC)  Electric shock current: less than 3A  Weight: 15g  Contact action time: 10ms


Equipment: keyestudio PLUS Control Board*1 Sensor expansion board * 1 1-channel relay module * 1 White LED * 1 female to female Dupont line * 2 Male to female Dupont line * 2 3pin female to female Dupont cable * 1 USB cable * 1


Connection Diagram:


thumb

Note: On the shield, the G, V, and S pins of 1-channel relay module are connected to G, V, and 12 respectively. The NO is connected to V; the G, V, and S pins of white LED are respectively connected to G, V, and the NO of relay module.


Test Code:

void setup(){
  pinMode(12, OUTPUT);//set digital12 to output}

void loop(){
  digitalWrite(12,HIGH);//set digital12 to HIGH level, COM and NO are connected,LED is on
  delay(500);//delay in 500ms
  digitalWrite(12,LOW);//set digital12 to LOW level, COM and NO are disconnected,LED is off
  delay(500);//delay in 500ms
}


Test Result: Wire, power up and upload the code. The relay is connected(“NO” is on , NC is off) for 0.5s, then disconnected for 0.5s (NC is on, NO is off), and alternately. When the relay is connected, the white LED is on, otherwise, the white LED is off.


Project 6:Photocell Sensor

Description

The photocell sensor (photoresistor) is a resistor made by the photoelectric effect of a semiconductor. It is very sensitive to ambient light, thus its resistance value vary with different light intensity. We use its features to design a circuit and generate a photoresistor sensor module. The signal end of the module is connected to the analog port of the microcontroller. When the light intensity increases, the resistance decreases, and the voltage of the analog port rises, that is, the analog value of the microcontroller also goes up. Otherwise, when the light intensity decreases, the resistance increases, and the voltage of the analog port declines. That is, the analog value of the microcontroller becomes smaller. Therefore, we can use the photoresistor sensor module to read the corresponding analog value and sense the light intensity in the environment. It is commonly applied to light measurement, control and conversion, light control circuit as well.


Specifications: Working voltage: 3.3V-5V (DC) Interface: 3PIN interface Output signal: analog signal Weight: 2.3g


Equipment: keyestudio PLUS Control Board*1 Sensor expansion board * 1 Photocell sensor module * 1 Passive buzzer module * 1 Yellow LED module * 1 3pin female to female Dupont cable * 3 USB cable * 1


Connection Diagram:


Note: On the expansion board, the G, V, and S pins of the photocell sensor module are connected to G, V, and A1; the G, V, and S pins of the passive buzzer module are linked with G, V, and 3 respectively; the G, V, and S pins of the yellow LED module are connected to G, V, and 5 separately.


Test Code:

void setup(){
  Serial.begin(9600);//set baud rate to 9600
  pinMode(A1, INPUT);//set A1 to input
  pinMode(3, OUTPUT);//set digital3 to output
  pinMode(5, OUTPUT);//set digital5 to output

}

void loop(){
  Serial.println(analogRead(A1));//wrap word and read the analog value of A1  delay(500);//delay in 500ms
  if (analogRead(A1) <= 600)
//if the analog value of A1 is less than or equal to 600
 {
    tone(3,262);//digital3 outputs the sound of 262Hz
    delay(250);//delay in 250ms
    digitalWrite(5,HIGH);//set digital5 to HIGH level,LED is on
    delay(500);//delay in 500ms
    tone(3,294);//digital3 outputs the sound of 294Hz
    delay(250);//delay in 250ms
digitalWrite(5,LOW);//set digital5 to low level,LED is off
delay(500);//delay in 500ms
    tone(3,330);
    delay(250);
    digitalWrite(5,HIGH);
    delay(500);
    tone(3,349);
    delay(250);
    digitalWrite(5,LOW);
    delay(500);
    tone(3,392);
    delay(250);
    digitalWrite(5,HIGH);
    delay(500);
    tone(3,440);
    delay(250);
    digitalWrite(5,LOW);
    delay(500);

  } 
else
//otherwise(if the analog value of A1 is greater than 600)
 {
digitalWrite(5,LOW);//set digital5 to low level,LED is off
    noTone(3);//digital3 stops sounding
 }}


Test Result: Wire according to connection diagram, burn the code, and set the baud rate to 9600 after powering on with USB cable. When the value displayed on serial monitor is less than or equal to 600, the yellow LED flashes and the passive buzzer sensor plays music; otherwise, the yellow LED is off, and the passive buzzer sensor stops playing.

Project 7:Adjusting Motor Servo Angle

Description

When we make this kit, we often control doors and windows with servos. In this course, we’ll introduce its principle and how to use servo motors. Servo motor is a position control rotary actuator. It mainly consists of housing, circuit board, core-less motor, gear and position sensor. Its working principle is that the servo receives the signal sent by MCU or receiver and produces a reference signal with a period of 20ms and width of 1.5ms, then compares the acquired DC bias voltage to the voltage of the potentiometer and outputs a voltage difference.

Servo motor comes with many specifications. But all of them have three connection wires, distinguished by brown, red, orange colors (different brand may have different color). Brown one is for GND, red one for power positive, orange one for signal line.

The rotation angle of servo motor is controlled by regulating the duty cycle of PWM (Pulse-Width Modulation) signal. The standard cycle of PWM signal is 20ms (50Hz). Theoretically, the width is distributed between 1ms-2ms, but in fact, it's between 0.5ms-2.5ms. The width corresponds the rotation angle from 0° to 180°. But note that for different brand motor, the same signal may have different rotation angle. 


There are two ways to control a servomotor with Arduino. One is to use a common digital sensor port of Arduino to produce square wave with different duty cycle to simulate PWM signal and use that signal to control the positioning of the motor. Another way is to directly use the Servo function of the Arduino to control the motor. In this way, the program will be easier but it can only control two-contact motor because for the servo function, only digital pin 9 and 10 can be used. The Arduino drive capacity is limited. So if you need to control more than one motor, you will need external power.


Specifications: Working voltage: DC 4.8V ~ 6V Operating angle range: about 180 ° (at 500 → 2500 μsec) Pulse width range: 500 → 2500 μsec No-load speed: 0.12 ± 0.01 sec / 60 (DC 4.8V) 0.1 ± 0.01 sec / 60 (DC 6V) No-load current: 200 ± 20mA (DC 4.8V) 220 ± 20mA (DC 6V) Stopping torque: 1.3 ± 0.01kg · cm (DC 4.8V) 1.5 ± 0.1kg · cm (DC 6V) Stop current: ≦ 850mA (DC 4.8V) ≦ 1000mA (DC 6V) Standby current: 3 ± 1mA (DC 4.8V) 4 ± 1mA (DC 6V) Lead length: 250 ± 5 mm Appearance size: 22.9 * 12.2 * 30mm Weight: 9 ± 1 g (without servo horn) Storage temperature: -20 ℃ ~ 60 ℃ Operating temperature: -10 ℃ ~ 50 ℃

Connection Diagram:

Note: The servo is connected to G (GND), V (VCC), 9. The brown wire of the servo is connected to Gnd (G), the red wire is connected to 5v (V), and the orange wire is connected to digital pin 9.


Test Code:

volatile int pulsewidth;//set variable pulsewidth
//Set a subroutine to control the servo angle
void procedure(int servopin, int myangle) {
  for (int i = 0; i <= 50; i = i + (1)) {
    pulsewidth = myangle * 11 + 500;
pinMode(servopin, OUTPUT);
//varaible servopin(means signal end of servo,set to output)
    digitalWrite(servopin,HIGH);
delayMicroseconds(pulsewidth);//delay time is ms, the value is variable pulsewidth 
    pinMode(servopin, OUTPUT);
    digitalWrite(servopin,LOW);
    delay((20 - pulsewidth / 1000));
  }
}

void setup(){
  pulsewidth = 0;//set variable pulsewidth to 0
}
void loop(){
  procedure(9, 90);//set signal end of servo to digital9,the angle of servo is set to 90°
}

Test Result: Upload code, wire according to connection diagram, and power on. The DIP switch is dialed to right side, the servo rotates to 90°.


Project 8:Fan Module

Description The L9110 motor control chip is applied on Keyestudio L9110 motor control module. It can control the rotation direction and speed of the motor so as to control the fan. The module is compatible with servo motor control. This module is efficient with good fan, commonly applied to fire robot.


Specifications: Fan diameter: 75mm Working voltage: 5V


Equipment: keyestudio PLUS Control Board*1 Sensor shield* 1 Small fan module * 1 USB cable * 1 Female to female DuPont Lines


Connection Diagram:

Note: On the shield, the GND, VCC, INA, and INB pins of the fan module are respectively connected to G, V, 7, 6.


Test Code:

void setup(){
  pinMode(7, OUTPUT);//set digital7 to output
  pinMode(6, OUTPUT);//set digital6 to output
}

void loop(){
//set fan to rotate counterclockwise for 3000ms
  digitalWrite(7,LOW);
  digitalWrite(6,HIGH);
  delay(3000);
//set fan to stop rotating for 1000ms
  digitalWrite(7,LOW);
  digitalWrite(6,LOW);
  delay(1000);
//set fan to rotate clockwise for 3000ms
  digitalWrite(7,HIGH);
  digitalWrite(6,LOW);
  delay(3000);
}


Test Result: Upload test code, wire according to connection diagram, the DIP switch is dialed to right side and power on. The fan rotates counterclockwise for 3000ms, stops for 1000ms, then rotates clockwise for 3000ms.


Project 9:Steam Sensor

Description This is a commonly used steam sensor. Its principle is to detect the amount of water by bare printed parallel lines on the circuit board. The more the water is, the more wires will be connected. As the conductive contact area increases, the output voltage will gradually rise. It can detect water vapor in the air as well. The steam sensor can be used as a rain water detector and level switch. When the humidity on the sensor surface surges, the output voltage will increase.

The sensor is compatible with various microcontroller control boards, such as Arduino series microcontrollers. When using it, we provide the instruction to operate steam sensor and Arduino control board. Connect the signal end of the sensor to the analog port of the microcontroller, sense the change of the analog value, and display the corresponding analog value on the serial monitor.

It comes with the 3pin with 2.54mm pitch. Connect it to control board with dupont lines. We particularly design the shield compatible with this sensor and keyestudio PLUS control board. You just need to stack shield to keyestudio PLUS control board and connect them together with 3pin dupont lines. Note: the connect part is not waterproof, don’t immerse it in the water please.

Specifications:

Working voltage: DC 3.3-5V Working current: <20mA Operating temperature range: -10 ℃ ~ + 70 ℃; Control signal: analog signal output Interface: 2.54mm 3pin pin interface Size: 35 * 20 * 8mm Weight: 2.2g S: signal output V (+): Power supply (VCC) G (-): Ground (GND)


Equipment: keyestudio PLUS Control Board*1 Sensor shield * 1 Water vapor sensor * 1 Photocell sensor module * 1 Servo * 1 Yellow LED * 1 3pin female to female DuPont Lines USB cable * 1


Connection Diagram: 图 Note: On the sensor shield, the pins G,V and S of steam sensor are connected to G, V and A3; the pins G, V and S of photocell sensor are connected to G, V and A1; the pins G, V and S of yellow LED are linked with G, V and 5; the brown line is linked with G, red wire to V, orange wire to 9.

Test Code:

#include <Servo.h>//use the library of Servo.h

Servo servo_9;

void setup(){
  Serial.begin(9600);//set baud rate to 9600
  pinMode(A1, INPUT);//set A1 to input
  pinMode(A3, INPUT);//set A3 to input
  pinMode(5, OUTPUT);;//set digital5 to input
  servo_9.attach(9);//set signal end of servo to digital9
}

void loop(){
  Serial.print("illumination");
  Serial.print(analogRead(A1));//serial port outputs the analog value of A1  Serial.print("       ");
  Serial.print("humidity");
  Serial.println(analogRead(A3));//wrap word and output the analog value of  A3
delay(500);//delay in 500ms
  if (analogRead(A3) >= 500 && analogRead(A1) <= 450) 
//if the analog value of A3≥500 and the analog value of ≤ 450
{
digitalWrite(5,HIGH);//set digital5 to HIGH level,LED is off
servo_9.write(0);//set servo angle to 0°
    delay(200);//delay in 200ms
  } 
else
//otherwise
 {
if (analogRead(A3) < 500 && analogRead(A1) > 450) 
//if the analog value of A3 is less than 500 and the analog value of A3 is greater than 450
{
      digitalWrite(5,LOW);//set digital5 to low level,LED is off
      servo_9.write(180);//set servo angle to 180°
      delay(200);//delay in 200ms
 }}}


Test Result: Upload test code successfully, wire according to connection diagram. When put a drop of water on steam sensor and cover the photocell sensor, the analog value of steam sensor will increase on serial monitor, the analog value of photocell sensor will gradually go down, the yellow LED will light on, servo will rotate to 0°. However, when wipe off the water drop and the photocell sensor is under strong light, the analog value on the serial monitor will gradually decline, the analog value of photocell sensor will gradually increase, yellow LED will be off, and servo will rotate to 180°


Project 10: PIR Motion Sensor

Description The Pyroelectric infrared motion sensor can detect infrared signals from a moving person or moving animal, and output switching signals. It can be applied to a variety of occasions to detect the movement of human body. Conventional pyroelectric infrared sensors are much more bigger, with complex circuit and lower reliability. Now we launch this new pyroelectric infrared motion sensor, specially designed for Arduino. This sensor integrates an integrated digital pyroelectric infrared sensor, and the connection pins. It features higher reliability, lower power consumption and simpler peripheral circuit.


Specifications: Input voltage: DC 3.3V ~ 18V Working current: 15uA Working temperature: -20 ~ 85 degrees Celsius Output voltage: high 3 V, low 0 V Output delay time (high level): about 2.3 to 3 seconds Detection angle: about 100 ° Detection distance: 3-4 meters Output indicator LED (high-level light) Pin limit current: 100mA


Special note: 1. The maximum distance is 3-4 meters during testing. 2. When testing, first open the white lens, you can see the rectangular sensing part. When the long line of the rectangular sensing part is parallel to the ground, the distance is the best. 3. When testing, the sensor needs to be covered with white lens, otherwise it will affect the distance. 4. The distance is best at 25℃, and the detection distance is shortened when it exceeds 30℃. 5. Done powering up and uploading the code, you need to wait 5-10 seconds then start testing, otherwise it is not sensitive.

Equipment:

  • keyestudio PLUS Control Board*1
  • Sensor expansion board * 1
  • PIR Motion sensor * 1
  • Small fan module * 1
  • White LED module * 1
  • 3pin female to female Dupont cable * 2
  • Mother to mother Dupont line * 4
  • USB cable * 1

Connection Diagram:

Note: On the shield, the G, V and S of PIR motion sensor are connected to G, V and 2; the GND, VCC, INA and INB of fan module are separately connected to G,V,7,6. The pin G, V and S of LED module are linked with G, V and 13.


Test Code:

void setup(){
  Serial.begin(9600);//set baud rate to 9600
  pinMode(2, INPUT);//set digital2 to input
  pinMode(13, OUTPUT);//set digital13 input
  pinMode(7, OUTPUT);//set digital7 input
  pinMode(6, OUTPUT);//set digital6 input}
void loop(){
  Serial.println(digitalRead(2));//wrap word and output the value of digital2
  delay(500);//delay in 500ms
  if (digitalRead(2) == 1)
//when there is person around,the value of digital2 is 1
 {
digitalWrite(13,HIGH);//set digital13 to high level,LED lights up
//set fan to rotate
digitalWrite(7,HIGH);//set digital7 to high level
analogWrite(6,150);//set the PWM value of digital6,the higher the value,the slower the fan rotates
  } else
//otherwise(when nobody is around, the value of digital2 is 0)
 {
digitalWrite(13,LOW);//set digital13 to low level,LED lights on
//fan stops rotating
    digitalWrite(7,LOW);
    analogWrite(6,0);
  }}


Test Result: Upload test code, open serial monitor, and set baud rate to 9600. If PIR motion sensor detects the people around, the serial monitor displays “1”, the D13 and white LED light on at same time, fan rotates. If there is no person around, the serial monitor shows “0”, the D13 indicator and white LED stops rotating.

Project 11: Analog(MQ-2)Sensor