Advertisement

Quick Links

*About keyestudio ........................................................................................................... 2
*References and After-sales Service .......................................................................... 3
*Warning ............................................................................................................................. 3
*Copyright .......................................................................................................................... 4
1.Description: ................................................................................................................. 5
2.Features: ....................................................................................................................... 6
3.Parameters: .................................................................................................................. 7
4.Kit List: ........................................................................................................................... 7
5.Get Started with Arduino ........................................................................................ 13
(1) Install Arduino IDE ......................................................................................... 13
(2)Keyestudio UNO Development Board ...................................................... 16
(2) Install Driver ..................................................................................................... 22
(4)Arduino IDE Setting ........................................................................................ 28
(5)Start the First Program .................................................................................. 33
6.Installation of the Solar Tracking Device ........................................................... 37
7.Projects ......................................................................................................................... 84
Project 1: LED Blinks ............................................................................................ 84
Project 2: Adjust LED Brightness ..................................................................... 90
Project 3:Push Button Module ...................................................................... 98
Project 4: Passive Buzzer .................................................................................. 104
Contents
1

Advertisement

Table of Contents
loading

Summary of Contents for Eckstein komponente KS0530

  • Page 1: Table Of Contents

    Contents *About keyestudio ......................2 *References and After-sales Service ................3 *Warning ..........................3 *Copyright .......................... 4 1.Description: ......................... 5 2.Features: ........................6 3.Parameters: ........................7 4.Kit List: ........................... 7 5.Get Started with Arduino ..................13 (1) Install Arduino IDE ..................13 (2)Keyestudio UNO Development Board ............
  • Page 2: About Keyestudio

    Project 5: 1602 LCD Display Module ............111 Project 6: Ambient Light Sensor ..............116 Project 7: DHT11 Temperature and Humidity Sensor ......120 Project 8: BH1750 Digital Light Intensity Module ........125 Project 9: Servo ................ 错误!未定义书签。 Project 10: Lithium Power Module Powering by Solar Energy or Via USB Cable &...
  • Page 3: References And After-Sales Service

    You can obtain the details and the latest information through the following site:http://www.keyestudio.com *References and After-sales Service 1. Download Profile:https://fs.keyestudio.com/KS0530 2. If you find any parts missing or encounter any troubles, please feel free to contact us: service@keyestudio.com. We will update projects and products continuously according to your sincere advice.
  • Page 4: Copyright

    *Copyright The keyestudio trademark and logo are the copyright of KEYES DIY ROBOT co.,LTD. All products under keyestudio brand can’t be copied, sold and resold by anyone or any companies without authorization. If you ’re interested in our products, please contact with our sales representatives: fennie@keyestudio.com DIY Solar Tracking Kit...
  • Page 5: Description

    1.Description: The solar tracking kit launched by KEYES is based on Arduino. It consists of 4 ambient light sensors, 2 DOF servos, a solar panel and so on, aiming at converting light energy into electronic energy and charging power devices.
  • Page 6: Features

    It also boasts a charging module, a temperature and humidity sensor, a BH1750 light sensor, a buzzer, an LCD1602 display, a push button module, an LED module and others, highly enriching the tutorial and making projects more interesting. This kit can not only help kids have a better learning about programming but obtain knowledge about electronics, machinery, controlling logic and computer science.
  • Page 7: Parameters

    energy; ◆ Easy to build: insert into Lego jack to install and no need to fix with screws and nuts or solder circuit; also easy to dismantle; ◆ Novel style: adopt acrylic boards and copper pillars;sensors or modules connected to acrylic boards via Lego jacks; LCD 1602 modules and solar panels add technologies to it;...
  • Page 8 Picture Component ntity Acrylic Board*5 Wooden Board 3mm* 4 Keyestudio UNO Development Board Mounting Bracket Kit...
  • Page 9 Keyestudio Photoresistor Module in Building Block Structure 1860 Lithium Battery Holder keyestudio Temperature and Humidity Sensor in Building Block Structure keyestudio Passive Buzzer Module in Building Block Structure keyestudio Lithium Power Module Powered by Solar Energy and Via USB Cable...
  • Page 10 keyestudio Yellow LED Module keyestudio Single-channel Push Button Module Keyestudio I2C1602 Module keyestudio BH1750FVI Digital Light Intensity Module IIC Interface Solar Panel with Tape And Wires...
  • Page 11 2.0*40MM Screwdriver 3.0*40MM Screwdriver USB Cable Smart Phone Charging Module M3*8MM Flat Head Screw M3*14MM Flat Head Screw M3 Nickle-plated Nut M4 Nickle-plated Nut...
  • Page 12 M4*8MM Round Head Screw M3*45MM Double Pass Copper Pillar M3*10MM Double Pass Copper Pillar Lego Part 4265c Lego Part 43093 M3*6+6MM Single Pass Copper Pillar...
  • Page 13: Get Started With Arduino

    Servo 3P 26AWG 200mm F-F DuPont Wire 4P F-F 26AWG 350mm DuPont Wire 4P 26AWG 200mm DuPont Wire 20cm M to F DuPont Wire Plastic String Plastic Pipe 5.Get Started with Arduino (1) Install Arduino IDE...
  • Page 14 When you get control board, you need to download Arduino IDE and driver firstly. You could download Arduino IDE from the official website: https://www.arduino.cc/, click the SOFTWARE on the browse bar, click “DOWNLOADS” to enter download page, as shown below: There are various versions of IDE for Arduino.
  • Page 15 Click JUST DOWNLOAD.
  • Page 16: Keyestudio Uno Development Board

    (2)Keyestudio UNO Development Board You need to know that Keyestudio UNO development board is the core of this solar tracking device. Keyestudio UNO Development Board: This development board satisfy requirements microcontrollers. All you need to do is to connect it to a computer via a USB cable and power it by an external power supply of DC 7-12.
  • Page 17 Microcontroller ATMEGA328P-AU Operating Voltage Input Voltage DC7-12V (recommended) Digital I/O Pins 14 个 (D0-D13) 6 个 (D3,D5,D6,D9,D10, PWM Digital I/O Pins D11) Analog Input Pins 6 个(A0-A5) 32 KB (ATMEGA328P-PU) of Flash Memory which 0.5 KB used by bootloader SRAM 2 KB (ATMEGA328P-PU) EEPROM 1 KB (ATMEGA328P-PU)
  • Page 18 ICSP (In-Circuit Serial Programming) Header ICSP is the AVR, an Arduino micro-program header consisting of MOSI, MISO, SCK, RESET, VCC, and GND. It is often called the SPI (serial peripheral interface) and can be considered an "extension" of the output. In fact, slave the output devices under the SPI bus host.
  • Page 19 V Pins (VCC) Power the external sensors and modules. Select the voltage of 3.3V or 5V via a slide switch. Digital I/O It has 14 digital input/output pins, labeled D0 to D13 (of which 6 can be used as PWM outputs). These pins can be configured as digital input pin to read the logic value (0 or 1).
  • Page 20 Microcontroller Each control board has its own microcontroller. You can regard it as the brain of your board. Microcontrollers are usually from ATMEL. Before you load a new program on the Arduino IDE, you must know what IC is on your board.
  • Page 21 ATMEGA 16U2-MU USB to serial chip, can convert the USB signal into serial port signal. Slide Switch You can slide the switch to control the voltage of pin V (VCC), 3.3V or 5V. Voltage Regulator To control the voltage provided to the board, as well as to stabilize the DC voltage used by the processor and other components.
  • Page 22: Install Driver

    You can supply an external voltage input DC7-12V through this pin to the board. Analog Pins The board has 6 analog inputs, labeled A0 through A5. Can also used as digital pins, A0=D14, A1=D15, A2=D16, A3=D17, A4=D18, A5=D19. For analog port, you can connect through female headers, or through pin headers (labeled S) of 2.54mm pitch.
  • Page 23 You need to install it manually if your computer is other Windows system. We will take win7 system as example. Right-click and click Open file location to find out the drivers folder...
  • Page 24 Copy driver folder to D drive. Right click Computer----- Properties----- Device Manager. You will view Unknown Device.
  • Page 25 Click Unknown devices to select Update Device Management: Click“Browse..manually”:...
  • Page 26 Find the“drivers”file,and tap“Next”.
  • Page 27 Click“install this driver software anyway”: Then click“Close”and check the serial port:...
  • Page 28: Arduino Ide Setting

    Return to Device Manager page if the driver is installed. Then check correct port : (4)Arduino IDE Setting Click icon,and open Arduino IDE.
  • Page 29 When downloading the sketch to the board, you must select the correct name of Arduino board that matches the board connected to your computer. Click Tools→Board to choose the corresponding board as shown below:...
  • Page 30 Then select the correct COM port (you can see the corresponding COM port after the driver is successfully installed)
  • Page 31 The functions of all symbols are demonstrated below:...
  • Page 32 A- Used to verify whether there is any compiling mistakes or not. B- Used to upload the sketch to your Arduino board. C- Used to create shortcut window of a new sketch. D- Used to directly open an example sketch. E- Used to save the sketch.
  • Page 33: Start The First Program

    (5)Start the First Program We’ve known how to download and install the driver of development board , next, we will burn a code to show“Hello World!”in the monitor. void setup() { // initialize serial communication at 9600 bits per second: Serial.begin(9600);...
  • Page 34 delay(1000);// delay 1 second Then let’s make monitor show Hello World! Open Arduino IDE, and select Arduino UNO...
  • Page 35 Set COM port, as shown below: Click to start compiling the program, and check errors. Click to upload the program, upload successfully.
  • Page 36 Upload the program successfully, open serial monitor and set baud rate to 9600. Monitor will print“Hello World!”each 1s.
  • Page 37: Installation Of The Solar Tracking Device

    Congratulations!You have finished the first program. 6.Installation of the Solar Tracking Device (Peel the sticker off the Acrylic boards first) Part 1 Components Needed...
  • Page 38 Installation Diagram Prototype Part 2...
  • Page 39 Components Needed Installation Diagram...
  • Page 40 Prototype Part 3...
  • Page 41 Components Needed Installation Diagram...
  • Page 42 Prototype Part 4 Components Needed...
  • Page 43 Installation Diagram Prototype...
  • Page 44 Part 5 Components Needed Installation Diagram (mind installation direction)
  • Page 45 Prototype Part 6 Components Needed...
  • Page 46 Installation Diagram Prototype Part 7...
  • Page 47 Components Needed...
  • Page 48 Installation Diagram (mind installation direction) Prototype Part 8...
  • Page 49 Components Needed Installation Diagram...
  • Page 50 Prototype Part 9 Components Needed...
  • Page 51 Installation Diagram (mind installation direction the servo) Prototype Part 10...
  • Page 52 Components Needed Installation Diagram...
  • Page 53 Prototype Part 11 (adjust the angle of the servo before starting this step) Components Needed (adjust angle of the servo marked in red circle)
  • Page 54 #include <Servo.h> Servo ud_servo;//define the name of the servo rotating right and left Test Code int ud_angle = 10;//set the initial angle to 10 degree;keep the solar panels upright to detect the strongest light const byte ud_servopin = 10;//define servo rotating upwards and downwards and its control pin void setup() {...
  • Page 55 Installation Diagram (pay attention the angle of the servo as shown in the picture) Prototype Part 12...
  • Page 56 Components Needed Installation Diagram...
  • Page 57 Prototype Part 13 Components Needed...
  • Page 58 Installation Diagram Prototype Part 14 (adjust the angle of the servo before starting this step)
  • Page 59 Components Needed (adjust angle of the servo marked in red circle) #include <Servo.h> Servo lr_servo;//define the name of the servo rotating right and left Test Code int lr_angle = 90;//set the initial angle to 90 degreeset the initial angle to 90 degree const byte lr_servopin = 9;//define the name of the servo rotating upwards and downwards and its control pin void setup() {...
  • Page 60 void loop() {} Installation Diagram...
  • Page 61 Prototype Part 15 Components Needed...
  • Page 62 Installation Diagram Prototype Part 16...
  • Page 63 Components Needed Installation Diagram...
  • Page 64 Prototype Part 17 Components Needed...
  • Page 65 Installation Diagram Prototype Part 18...
  • Page 66 Components Needed Installation Diagram...
  • Page 67 Prototype Part 19 Components Needed...
  • Page 68 Installation Diagram...
  • Page 69 Prototype Start Wiring...
  • Page 70 battery holder aims power smart phone charging module Plug jack battery holder to the BAT end of power module.
  • Page 71 Connect the servo downward to main board.
  • Page 72 Connect the servo upward to D10 on the main board...
  • Page 73 Connect the solar panel to SOLAR...
  • Page 74 Connect the LCD module to A4 and A5, blue line to A4 and green line to A5...
  • Page 75 Connect the push button module...
  • Page 76 Connect the passive buzzer to D6.
  • Page 77 Connect the temperature and humidity sensor to D7.
  • Page 78 Connect the digital light intensity module main board, blue line to SDA green line to SCL.
  • Page 79 Keep the LED display front of you as reference , photoresistor on the left is connected to...
  • Page 80 Keep the LED display front of you as reference, photoresistor on the right is connected to A1.
  • Page 81 Keep the LED display front of you as reference, photoresistor on the back is connected to A2.
  • Page 82 Keep the LED display front of you as reference, photoresistor ahead connected to...
  • Page 83 Wire up the power module power main board, and V to VIN.
  • Page 84: Projects

    7.Projects Now with all these preparations done, let’s start our projects. We will start from those basic projects involved only one single sensor or module and then move to a more intricate one , solar tracking, combining these components together. Note: (G), marked on each sensor and module, is the negative pole and connected to“G”, “...
  • Page 85 For the starter and enthusiast, this is a fundamental program---LED Blinks. LED, the abbreviation of light emitting diodes, consist of Ga, As, P, N chemical compound and so on. It is often applied to numbers and text display as an indicator in the circuit. The LED can flash diverse color by altering the delay time in the test code.
  • Page 86 USB Cable*1 (4) Connection Diagram: The pin -, + and S of LED module are connected to the pin G, 5V and D3 port of expansion board.
  • Page 87 (5)Test Code: keyestudio sun_follower lesson 1.1 Blink http://www.keyestudio.com #define LED 3 //define the pin of LED as D3 void setup() pinMode(LED, OUTPUT);// initialize digital pin LED as an output. void loop() // the loop function runs over and over again forever digitalWrite(LED, HIGH);...
  • Page 88 //******************************************************************* (6)Test Results: After uploading the program, the LED blinks with the interval of 1s. (7) Code Explanations: pinMode(LED,OUTPUT) - This function can denote that the pin is INPUT or OUTPUT. digitalWrite(LED , HIGH) -When pin is OUTPUT, we can set it to HIGH(output 5V) or LOW(output 0V).
  • Page 89 lesson 1.2 Blink http://www.keyestudio.com #define LED 3 //define the pin of LED as D10 void setup() pinMode(LED, OUTPUT);// initialize digital pin LED as an output. void loop() // the loop function runs over and over again forever digitalWrite(LED, HIGH); // turn the LED on (HIGH is the voltage level delay(100);...
  • Page 90: Project 2: Adjust Led Brightness

    Project 2: Adjust LED Brightness (1) Description: In previous lesson, we control LED on and off and make it blink. In this project, we will control LED brightness through PWM to simulate breathing effect. Similarly, you can change the step length and delay time in the code so as to demonstrate different breathing effect.
  • Page 91 as 0 and HIGH as 1, and let the Arduino output five hundred 0 or 1 signals within 1 second. If output five hundred 1, that is 5V; if all of which is 1, that is 0V. If output 010101010101 in this way then the output port is 2.5V, which is like showing movie.
  • Page 92 (3) Connection Diagram: (4)Test Code keyestudio sun_follower lesson 2.1 http://www.keyestudio.com...
  • Page 93 #define LED 3 //define the pin of LED as D10 int value; void setup() pinMode(LED, OUTPUT);// initialize digital pin LED as an output. void loop () { for (value = 0; value < 255; value = value + 1) { analogWrite (LED, value);...
  • Page 94 (6) Code Explanation When we need to repeat some statements, we could use FOR statement. FOR statement format is shown below: FOR cyclic sequence: Round 1:1 → 2 → 3 → 4 Round 2:2 → 3 → 4 Until number 2 is not established, “for”loop is over, After knowing this order, go back to code: for (int value = 0;...
  • Page 95 We know that digital port only has two state of 0 and 1. So how to send an analog value to a digital value? Here,this function is needed. Let’s observe the Arduino board and find 6 pins marked“~”which can output PWM signals.
  • Page 96 In the above figure, the green line represents a period, and value of analogWrite() corresponds to a percentage which is called Duty Cycle as well. Duty cycle implies that high-level duration is divided by low-level duration in a cycle. From top to bottom, the duty cycle of first square wave is 0% and its corresponding value is 0.
  • Page 97 (7) Extension Practice: Let’s observe the status of LED if we change the delay value. keyestudio sun_follower lesson 2.2 http://www.keyestudio.com #define LED 3 //define the pin of LED as D10 int value; void setup() pinMode(LED, OUTPUT);// initialize digital pin LED as an output. void loop () { for (value = 0;...
  • Page 98: Project 3:Push Button Module

    for (value = 255; value > 0; value = value - 1) { analogWrite (LED, value); // LED gradually goes out delay (20); // delay 20MS //********************************************************** Upload code to development board, the LED’s blink frequency is slower, isn’t it? Project 3:Push Button Module (1)Description In this project, we intend to use the push button module to control the LED.
  • Page 99 (3)Components Needed: keyestudio Push keyestudio Yellow Keyestudio UNO*1 Button Module*1 LED Module*1 20cm 3pin F-F 26AWG DuPont USB Cable*1 Line*2 (4)Connection Diagram Please note that the pins G,V and S on the push button module should be connected with G, V and D2 on the development board respectively while the pins G,V and S on the LED module should be linked with G,V and D3 on the development board respectively.
  • Page 100 (5)Test Code:read the signal of the push button module keyestudio sun_follower lesson 3.1 button http://www.keyestudio.com #define button 2 //define the pin of the push button module as D2 volatile int buttonState; //the state of the level output by the push button module void setup()
  • Page 101 Serial.begin(9600);//set baud rate to 9600 pinMode(button, INPUT);// initialize digital pin button as an input. void loop () { buttonState = digitalRead(button); Serial.println(buttonState); //Automatically wrap and output the digital signal read from digital port 2 delay(100);//delay in 100ms} (6)Test Results: After uploading test code, powering the module up and open the serial monitor to set the baud rate to 9600, the value 1 (high level) output by the push button module is shown on the serial monitor and when the button is pushed, it changes to 0 (low level).
  • Page 102 (7)Code Explanation: Serial.begin(9600)-initialize the serial communication and set the baud rate to 9600 pinMode(pin, INPUT)-use the function pinMode() to tell Arduino whether it is an output pin or an input pin digitalRead(pin)-read the digital level of pins,be HIGHT OT LOW (8)Extension Project:control the LED by the push button module keyestudio sun_follower lesson 3.2...
  • Page 103 button http://www.keyestudio.com #define LED 3 //define the LED pin as D3 #define button 2 //define the pin of push button module as D2 volatile int buttonState; //the state of the level output by the push void setup() Serial.begin(9600); //set baud rate to 9600 pinMode(button, INPUT);...
  • Page 104: Project 4: Passive Buzzer

    else digitalWrite(LED, LOW); //the LED is off delay(100); //delay in 100ms Conclusion : when the button is pressed, the LED lights up; otherwise, it remains off. Project 4: Passive Buzzer (1)Description There are prolific interactive works completed by Arduino. The most common one is sound and light display.
  • Page 105 (2)Parameters: ◆ Control interface: digital port ◆ Working voltage: DC 3.3-5V (3)Components Needed Keyestudio 200mm 26AWG Keyestudio UNO*1 Passive Buzzer*1 3P F-F DuPont Line USB Cable*1 (4)Connection Diagram: The G, V and S pins of passive buzzer are connected to G, V and D6.
  • Page 106 (5)Test Code //*********************************************************************** keyestudio sun_follower lesson 4.1 buzzer http://www.keyestudio.com #define buzzer 6 //buzzer pin to D6 void setup() { pinMode(buzzer, OUTPUT);//set the digital pin 6 as output...
  • Page 107 void loop () { tone(buzzer, 262); //output the sound with frequency of 262Hz delay(250); //delay in 250ms tone(buzzer, 294);; //output the sound with frequency of 294Hz delay(250); //delay in 250ms tone(buzzer, 330); delay(250); tone(buzzer, 349); delay(250); tone(buzzer, 392); delay(250); tone(buzzer, 440); delay(250);...
  • Page 108 //*********************************************************************** ************** (6)Test Results: Upload code to Keyestudio development board, power amplifier module will emit“do re mi fa so la si do”. (7)Extension Practice:play music keyestudio sun_follower lesson 4.2 buzzer http://www.keyestudio.com #define buzzer 6 //buzzer pin to D6 void setup() { pinMode(buzzer, OUTPUT);//set digital 6 to OUTPUT...
  • Page 109 void loop () { birthday(); Happy Birthday ////////////////////////Set song ///////////////////////////////// void birthday() tone(buzzer, 294); //buzzer outputs a sound with 294Hz delay(250);//delay in 250ms tone(buzzer, 440); delay(250); tone(buzzer, 392); delay(250); tone(buzzer, 532); delay(250); tone(buzzer, 494); delay(500); tone(buzzer, 392); delay(250); tone(buzzer, 440);...
  • Page 110 delay(250); tone(buzzer, 392); delay(250); tone(buzzer, 587); delay(250); tone(buzzer, 532); delay(500); tone(buzzer, 392); delay(250); tone(buzzer, 784); delay(250); tone(buzzer, 659); delay(250); tone(buzzer, 532); delay(250); tone(buzzer, 494); delay(250); tone(buzzer, 440); delay(250); tone(buzzer, 698); delay(375); tone(buzzer, 659);...
  • Page 111: Project 5: 1602 Lcd Display Module

    delay(250); tone(buzzer, 532); delay(250); tone(buzzer, 587); delay(250); tone(buzzer, 532); delay(500); Project 5: 1602 LCD Display Module (1) Description: With I2C communication module, this is a display module that can show 2 lines with 16 characters per line. It shows blue background and white word and connects to I2C interface of MCU, which highly save the MCU resources.
  • Page 112 backlight. The communication address defaults to 0x27. The original 1602 LCD can start and run with 11 IO ports, but ours is built with ARDUINOIIC/I2C interface, saving 9 IO ports. Alternatively, the module comes with 4 positioning holes with a diameter of 3mm, which is convenient for you to fix on other devices.
  • Page 113 USB Cable*1 (4)Connection Diagram Note:the pin GND, VCC, SDA and SCL of 1602LCD module are connected to GND(-), 5V(+), SDA and SCL of IIC communication...
  • Page 114 (5)Test Code //*********************************************************************** keyestudio sun_follower lesson 5.1 I2C 1602 http://www.keyestudio.com #include <Wire.h> #include <LiquidCrystal_I2C.h> // includes the LiquidCrystal_I2C Library LiquidCrystal_I2C lcd(0x27, 16, 2); // set the LCD address to 0x27 for a 16 chars and 2 line display void setup() { lcd.init();...
  • Page 115 lcd.print("Hello, Keyes!"); //show "Hello, Keyes!" void loop () { //*********************************************************************** (6)Test Results: Upload code, wire up according to connection diagram and power on. 1602 LCD will display“Hello World!”at the first row and show“Hello Keyes!”at the second row. Note: wire up connection diagram, upload code and power on. You can adjust the potentiometer on the back of 1602LCD display module to display the character strings...
  • Page 116: Project 6: Ambient Light Sensor

    Project 6: Ambient Light Sensor (1)Description There are four identical modules in this kit, the ambient light sensors, with photoresistor as main component. The resistance of a photoresistor varies with the light intensity. When there is light around, its resistance ranges in 5-10KΩ; while when it is dark, the resistance is only 0.2MΩ.
  • Page 117 ◆ Interface:3PIN ◆ Output signal:analog signal ◆ Weight:2.3g (3)Components Needed: keyestudio keyestudio Yellow LED Keyestudio UNO*1 Photoresistor Module*1 Module*1 15cm 3pin F-F 26AWG DuPont USB Cable*1 Line*2 (4)Connection Diagram: Please note that the pins G,V and S on the push button module should be connected with G, V and A0 on the expansion board respectively while the pins G,V and S on the LED module should be linked with G,V and 3 respectively.
  • Page 118 (5)Test Code: //*********************************************************************** ***** keyestudio sun_follower lesson 6.1 photovaristor http://www.keyestudio.com #define photos A0 //photoresistance pin to A0...
  • Page 119 #define LED 3 //define the LED pin as D3 volatile int value = 0; void setup() { Serial.begin(9600); pinMode(LED, OUTPUT);// initialize digital pin LED as an output. void loop () { value = analogRead(photos); //read the value detected by the sensor Serial.println(value);...
  • Page 120: Project 7: Dht11 Temperature And Humidity Sensor

    (6)Test Results: After wiring up according to the connection diagram, uploading the test code, powering it up and setting the baud rate to 9600, the serial monitor prints the value detected by the ambient light sensor. And when we block the sensor from light, the valued printed gets smaller.
  • Page 121 This DHT11 temperature and humidity sensor is a composite sensor which contains a calibrated digital signal output of the temperature and humidity. DHT11 temperature and humidity sensor uses the acquisition technology of the digital module and temperature and humidity sensing technology, ensuring high reliability and excellent long-term stability.
  • Page 122 USB Cable*1 (4)Connection Diagram Please note that when we conduct this experiment we need to import the library file of DHT11 first. (5)Test Code: keyestudio sun_follower...
  • Page 123 lesson 7.1 DHT11 http://www.keyestudio.com #include <dht11.h> //include the library code: dht11 DHT; #define DHT11_PIN 7 //define the DHT11 as the digital port 7 void setup() { Serial.begin(9600); void loop() { int chk; chk = DHT.read(DHT11_PIN); // read data switch (chk) { case DHTLIB_OK: break;...
  • Page 124 break; // DISPLAT DATA Serial.print("humidity:"); Serial.print(DHT.humidity); Serial.print(" temperature:"); Serial.println(DHT.temperature); delay(200); (6)Test Results: After uploading test code, powering it up via USB cable and open the serial monitor to set the baud rate to 9600, the serial monitor displays the value of the current humidity and temperature as shown below:...
  • Page 125: Project 8: Bh1750 Digital Light Intensity Module

    Project 8: BH1750 Digital Light Intensity Module (1)Description: The main component of this sensor is chip BH1750FVI which is an integrated chip for digital light intensity. As shown in the picture below, BH1750 is composed of a photodiode, an operational amplifier, an ADC acquisition, a crystal oscillator, etc.
  • Page 126 and then converted into a 16-bit binary number through the logic circuit and stored in the internal register (Note: The stronger the light, the greater the photocurrent, and the greater the voltage, so the intensity of the light can be judged by the value of the voltage. However, it should be noted that the voltage and the light intensity are one-to-one correspondence, but not proportional.
  • Page 127 Small measurement deviation(maximum accuracy error +/-20%) ◆ GND power ground ◆ SDA I2C bus data pin ◆ SCL I2C bus clock pin ◆ VCC power supply voltage 3-5V ◆ (3)Components Needed: Keyestudio BH1750FVI IIC 350mm 4pin F-F Keyestudio UNO*1 Interface Digital 26AWG DuPont Line*1 Light Intensity Module*1...
  • Page 128 (4)Connection Diagram: (5)Test Code: keyestudio sun_follower lesson 8 BH1750 http://www.keyestudio.com #include <Wire.h> #include <BH1750.h> BH1750 lightMeter; void setup() {...
  • Page 129 Serial.begin(9600); // Initialize the I2C bus (BH1750 library doesn't do this automatically) Wire.begin(); // On esp8266 you can select SCL and SDA pins using Wire.begin(D4, D3); // For Wemos / Lolin D1 Mini Pro and the Ambient Light shield use Wire.begin(D2, D1);...
  • Page 130 (6)Test Results: After uploading test code, powering the module up via the USB cable and open the serial monitor to set the baud rate to 9600, the serial monitor prints the value of the ambient light intensity(unit:lux). And when light source gets closer, the value becomes bigger as shown below: (Note: since the I2C bus can have multiple devices with different addresses, when the digital light intensity module is used together with the I2C...
  • Page 131: Project 9: Servo

    Project 9: Servo (1)Description: 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 obtains the voltage difference output.
  • Page 132 different brand motor, the same signal may have different rotation angle. More details: (2)Parameters: ◆ Working voltage: DC 4.8V ~ 6V ◆ Operating angle range: about 180 ° (at 500 → 2500 μsec) ◆ Pulse width range: 500 → 2500 μsec...
  • Page 133 ◆ No-load speed: 0.12 ± 0.01 sec / 60 (DC 4.8V) 0.1 ± 0.01 sec / 60 (DC ◆ 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 ◆...
  • Page 134 servo is connected to Gnd (G), the red wire is linked with 5v (V), and the orange wire is connected to digital pin 9. When connecting the steering gear, an external power supply must be used. Because the current requirement for driving the steering gear is relatively large, and the current of the development board is far from enough.
  • Page 135 int servoPin = 9; //set the pin of the servo void setup() { pinMode(servoPin, OUTPUT);//set the pin of the servo as output void loop() { servopulse(servoPin, 0);//rotate to 0 degree delay(1000);//delay in 1s servopulse(servoPin, 90);//rotate to 90 degrees delay(1000); servopulse(servoPin, 180);//rotate to 180 degrees delay(1000);...
  • Page 136 delay(20 - pulsewidth / 1000); //*********************************************************************** *********** After uploading the test code, the servo rotate at 0°,90° and 180° alternatively. There is an easier way to control the servo that is use the servo library file of Arduino. The following link is for your reference: https://www.arduino.cc/en/Reference/Servo (6) Test Code2: Library file is used but the connection diagram remains the same.
  • Page 137 void setup() { myservo.attach(9); //link the servo to digital port 9 void loop () { //rotate from 0 degree to 180 degrees for (int i = 0; i < 180; i++) { myservo.write(i); delay(20); delay(1000); //wait for 1s //rotate from 180 degree to 0 degree for (int i = 180;...
  • Page 138 ********* (7)Test Results: After uploading the test code and powering it up, the servo rotates from 0 degree to 180 degrees. Please note that we usually use library file to control servo. (8)Code Explanation: #include <Servo.h> is the Servo function and sentences that come with Arduino.
  • Page 139: Cable & Smart Phone Charging Module

    Project 10: Lithium Power Module Powering by Solar Energy or Via USB Cable & Smart phone charging Module (1)Description: This module integrates a charging and discharging chip, which can be interfaced with an external rechargeable battery through the PH2.0MM interface. In the experiment,we use a single lithium battery. It has a Micro USB port and a charging port for solar panels, which can supply power for an external lithium battery.
  • Page 140 by Solar Energy or Via USB Cable (2)Parameters: Lithium Power Module Powering by Solar Energy or Via USB Cable Charging Port Micro USB, HP2.0MM port for solar panels Input Voltage of 4.4-6V ports of the solar panel constant-voltage 4.15-4.24V charging Max Charging 800mA Current...
  • Page 141 Smart Phone Charging Module Property non-isolated boost module (BOOST) Input voltage 1-5V Output voltage 5 士 0.1V Output current: Rated 1-1.5A (single cell lithium battery input), maximum 1.5A (single cell lithium battery input) Conversion Up to 96% . efficiency Switching 500KHz .
  • Page 142 (3)Schematic Diagram of Lithium Power Module Powering by Solar Energy or Via USB Cable (4)Features: Lithium Power Module Powering by Solar Energy or Via USB Cable...
  • Page 143 SOLAR4.8-6.0V, the input port of power, is connected to polar panels. The solar energy is converted into electric energy via solar panels. BAT, the output port of power, is interfaced with the lithium battery holder(rechargeable batteries) and saves the electric energy into batteries. This is the switch.
  • Page 144 You can charge the lithium battery via USB cable. Smart phone charging Module Place a lithium cell in the PH2.0 terminal. Connect the USB port and the smart phone via a USB cable to charge.
  • Page 145: Project 11: Solar Panel Device With Multiply Functions

    Project 11: Solar Panel Device with Multiply Functions (1)Description: In previous projects, we just focused on a single function of a certain sensor or module. Can we combine them together and make a device which is able to display various functions? The answer is positive. And in this lesson, we will write a set of test code to make the solar tracking device perform all functions illustrated before.
  • Page 146 Start Initialize the angle of the servo Read the light intensity value and adjust the angle of the servo Read Bh1750 light intensity value Press button Read T&H value Adjust the angle of the servo LCD shows light intensity value and T&H value (3)Connection In this experiment, the connection is almost the same.
  • Page 147 http://www.keyestudio.com #include <Wire.h> #include <LiquidCrystal_I2C.h> LiquidCrystal_I2C lcd(0x27, 16, 2); #include <BH1750.h> BH1750 lightMeter; #include <dht11.h> //include the library code: dht11 DHT; #define DHT11_PIN 7 //define the DHT11 as the digital pin 7 #include <Servo.h> Servo lr_servo;//define the name of the servo rotating right and left Servo ud_servo;//define the name of the servo rotating upwards and downwards const byte interruptPin = 2;...
  • Page 148 int ud_angle = 10;//set the initial angle to 10 degree;keep the solar panels upright to detect the strongest light int l_state = A0;//define the analog voltage input of the photoresistors int r_state = A1; int u_state = A2; int d_state = A3; const byte buzzer = 6;...
  • Page 149 void setup() { Serial.begin(9600); //define the serial baud rate // Initialize the I2C bus (BH1750 library doesn't do this automatically) Wire.begin(); lightMeter.begin(); lr_servo.attach(lr_servopin); // set the control pin of servo ud_servo.attach(ud_servopin); // set the control pin of servo pinMode(l_state, INPUT); //set the mode of pin pinMode(r_state, INPUT);...
  • Page 150 lr_servo.write(lr_angle);//return to initial angle delay(1000); ud_servo.write(ud_angle); delay(1000); void loop() { ServoAction(); //servo performs the action read_light(); //read the light intensity of bh1750 read_dht11(); //read the value of temperature and humidity LcdShowValue(); //Lcd shows values light intensity, temperature and humidity //serial monitor displays the resistance of the photoresistor and the angle of servo /*Serial.print("...
  • Page 151 Serial.print(" D "); Serial.print(D); Serial.print(" ud_angle "); Serial.print(ud_angle); Serial.print(" lr_angle "); Serial.println(lr_angle);*/ // delay(1000);//During the test, the serial port data is received too fast, and it can be adjusted by adding delay time */ /**********the function of the servo************/ void ServoAction(){ int L = analogRead(l_state);//read the analog voltage value of the sensor, 0-1023 int R = analogRead(r_state);...
  • Page 152 lr_servo.attach(lr_servopin); // connect servo if (lr_angle < 0) { //limit the rotation angle of the servo lr_angle = 0; lr_servo.write(lr_angle); //output the angle of the servooutput the angle of servo delay(m_speed); else if (abs(L - R) > error && L < R) { //Determine whether the error is within the acceptable range, otherwise adjust the steering gear lr_angle += resolution;//increase the angle lr_servo.attach(lr_servopin);...
  • Page 153 lr_servo.detach(); //release the pin of servo lr_servo.write(lr_angle); //output the angle of servo /***************system adjusting up and down**********************/ if (abs(U - D) > error && U >= D) { //Determine whether the error is within the acceptable range, otherwise adjust the steering gear ud_angle -= resolution;//reduce the angle ud_servo.attach(ud_servopin);...
  • Page 154 ud_servo.write(ud_angle); //output the angle of servo delay(m_speed); else if (abs(U - D) <= error) { //Determine whether the error is within the acceptable range. If it is, keep it stable and make no change in angle ud_servo.detach(); //release the pin of servo ud_servo.write(ud_angle);...
  • Page 155 lcd.setCursor(0, 0); lcd.print("Light:"); lcd.setCursor(6, 0); lcd.print(str1); lcd.setCursor(11, 0); lcd.print("lux"); //display the value of temperature and humidity lcd.setCursor(0, 1); lcd.print(temperature); lcd.setCursor(2, 1); lcd.print("C"); lcd.setCursor(5, 1); lcd.print(humidity); lcd.setCursor(7, 1); lcd.print("%"); //display the accuracy of rotation lcd.setCursor(11, 1); lcd.print("res:"); lcd.setCursor(15, 1); lcd.print(resolution);...
  • Page 156 /*if (light < 10) { lcd.setCursor(7, 0); lcd.print(" "); lcd.setCursor(6, 0); lcd.print(light); } else if (light < 100) { lcd.setCursor(8, 0); lcd.print(" "); lcd.setCursor(6, 0); lcd.print(light); } else if (light < 1000) { lcd.setCursor(9, 0); lcd.print(" "); lcd.setCursor(6, 0); lcd.print(light); } else if (light <...
  • Page 157 lcd.print(" "); lcd.setCursor(6, 0); lcd.print(light); void read_light(){ light = lightMeter.readLightLevel(); //read the light intensity detected by BH1750 void read_dht11(){ int chk; chk = DHT.read(DHT11_PIN); // read data switch (chk) { case DHTLIB_OK: break; case DHTLIB_ERROR_CHECKSUM: //check and return error break; case DHTLIB_ERROR_TIMEOUT: //Timeout and return error break;...
  • Page 158 break; temperature = DHT.temperature; humidity = DHT.humidity; /*********function disrupts service**************/ void adjust_resolution() { tone(buzzer, 800, 100); delay(10); //delay to eliminate vibration if (!digitalRead(interruptPin)){ if(resolution < 5){ resolution++; }else{ resolution = 1; //******************************************************************* (5)Test Results: After uploading the test code and powering it up, the servos rotate to the...
  • Page 159: Trouble Shooting

    initial angle. And when the ambient light sensor detects changes in light intensity, servos rotate to the position where the light is the strongest and LCD1602 shows the value of the light intensity and temperature and humidity detected by the BH1750 and DHT11 respectively. We could push the button on the servo to adjust the accuracy of the angle to make it rotate faster.
  • Page 160: The Servo Doesn't Rotate

    A: 1.Ensure the battery capacity fully charged or confirm whether the power button has been pressed. 2.Check the setting of the angle. If it is struck, please cut off the power immediately in case to damage it. 9.Resources: https://fs.keyestudio.com/KS0530 V1.0...

Table of Contents