Page 5
Arduino project however you like. Come on! Start programing Arduino with confidence from zero to hero! If you have any questions or other interesting ideas, feel free to send an email to service@sunfounder.com. About the display language This document is available in other languages as well.
CHAPTER COMPONENTS LIST AND INTRODUCTION After opening the package, please check whether the quantity of components is compliance with product description and whether all components are in good condition. Below is the introduction to each component, which contains the operating principle of the component and the corre- sponding projects.
SunFounder 3in1 Kit 1.1 Arduino Uno R4 Minima Overview Enhanced and improved, the Arduino UNO R4 Minima is armed with a powerful 32-bit microcontroller courtesy of Renesas. Brace yourself for increased processing power, expanded memory, and a whole new level of on-board peripherals.
Page 9
SunFounder 3in1 Kit your projects by utilizing a single power source. • SWD connector: Debugging is a critical aspect of any project. Simply connect an external debugger to the UNO R4 Minima and effortlessly monitor the inner workings of your system. Stay in control and gain valuable insights.
Page 10
SunFounder 3in1 Kit • • • Chapter 1. Components List and Introduction...
SunFounder 3in1 Kit 1.2 ESP8266 Module The ESP8266 is a low-cost Wi-Fi microchip, with built-in TCP/IP networking software, and microcontroller capability, produced by Espressif Systems in Shanghai, China. The chip first came to the attention of Western makers in August 2014 with the ESP-01 module, made by a third- party manufacturer Ai-Thinker.
Page 12
SunFounder 3in1 Kit Table 1: ESP8266-01 Pins Name Description UART_TXD, sending; General Purpose Input/Outpu: GPIO1; Pull-down is not allowed when startup. CU_PD Working at high level; Power off when low level is supplied. GPIO2 It should be high level when power on, hardware pull-down is not allowed;...
Page 13
SunFounder 3in1 Kit 1.2.1 ESP8266 Adapter The ESP8266 adapter is an expansion board that allows the ESP8266 module to be used on a breadboard. It perfectly matches the pins of the ESP8266 itself, and also adds a 5V pin to receive the voltage from the Arduino board.
SunFounder 3in1 Kit • (IoT Project) IoT Projects Basic 1.3 Breadboard A breadboard is a construction base for prototyping of electronics. Originally the word referred to a literal bread board, a polished piece of wood used for slicing bread.[1] In the 1970s the solderless breadboard (a.k.a. plugboard, a terminal array board) became available and nowadays the term “breadboard”...
SunFounder 3in1 Kit 1.4 Resistor Resistor is an electronic element that can limit the branch current. A fixed resistor is a kind of resistor whose resistance cannot be changed, while that of a potentiometer or a variable resistor can be adjusted.
Page 16
SunFounder 3in1 Kit As shown in the card, each color stands for a number. Black Brown Orange Yellow Green Blue Violet Grey White Gold Silver 0.01 The 4- and 5-band resistors are frequently used, on which there are 4 and 5 chromatic bands.
Page 17
SunFounder 3in1 Kit Therefore, you can observe the gap between the two chromatic bands at one end of the resistor; if it’s larger than any other band gaps, then you can read from the opposite side. Let’s see how to read the resistance value of a 5-band resistor as shown below.
SunFounder 3in1 Kit 1.5 Capacitor Chapter 1. Components List and Introduction...
Page 19
SunFounder 3in1 Kit Capacitor, refers to the amount of charge storage under a given potential difference, denoted as C, and the international unit is farad (F). Generally speaking, electric charges move under force in an electric field. When there is a medium be- tween conductors, the movement of electric charges is hindered and the electric charges accumulate on the conductors, resulting in accumulation of electric charges.
SunFounder 3in1 Kit 1.6 Jumper Wires Wires that connect two terminals are called jumper wires. There are various kinds of jumper wires. Here we focus on those used in breadboard. Among others, they are used to transfer electrical signals from anywhere on the breadboard to the input/output pins of a microcontroller.
Page 21
SunFounder 3in1 Kit Pins of 74HC595 and their functions: • Q0-Q7: 8-bit parallel data output pins, able to control 8 LEDs or 8 pins of 7-segment display directly. • Q7’: Series output pin, connected to DS of another 74HC595 to connect multiple 74HC595s in series •...
SunFounder 3in1 Kit 1.8 LED Semiconductor light-emitting diode is a type of component which can turn electric energy into light energy via PN junctions. By wavelength, it can be categorized into laser diode, infrared light-emitting diode and visible light-emitting diode which is usually known as light-emitting diode (LED).
SunFounder 3in1 Kit 1.9 RGB LED RGB LEDs emit light in various colors. An RGB LED packages three LEDs of red, green, and blue into a transparent or semitransparent plastic shell. It can display various colors by changing the input voltage of the three pins and superimpose them, which, according to statistics, can create 16,777,216 different colors.
Page 24
SunFounder 3in1 Kit An RGB LED has 4 pins: the longest one is GND; the others are Red, Green and Blue. Touch its plastic shell and you will find a cut. The pin closest to the cut is the first pin, marked as Red, then GND, Green and Blue in turn.
SunFounder 3in1 Kit 1.10 7-segment Display A 7-segment display is an 8-shaped component which packages 7 LEDs. Each LED is called a segment - when ener- gized, one segment forms part of a numeral to be displayed. There are two types of pin connection: Common Cathode (CC) and Common Anode (CA). As the name suggests, a CC display has all the cathodes of the 7 LEDs connected when a CA display has all the anodes of the 7 segments connected.
Page 26
SunFounder 3in1 Kit Each of the LEDs in the display is given a positional segment with one of its connection pins led out from the rectangular plastic package. These LED pins are labeled from “a” through to “g” representing each individual LED. The other LED pins are connected together forming a common pin.
SunFounder 3in1 Kit 1.11 I2C LCD1602 • GND: Ground • VCC: Voltage supply, 5V. • SDA: Serial data line. Connect to VCC through a pullup resistor. • SCL: Serial clock line. Connect to VCC through a pullup resistor. As we all know, though LCD and some other displays greatly enrich the man-machine interaction, they share a common weakness.
Page 29
SunFounder 3in1 Kit Backlight/Contrast Backlight can be enabled by jumper cap, unplugg the jumper cap to disable the backlight. The blue potentiometer on the back is used to adjust the contrast (the ratio of brightness between the brightest white and the darkest black).
SunFounder 3in1 Kit Example • (Basic Project) 5.11.1 Liquid Crystal Display • (Basic Project) 5.12 Serial Read Sound 1.12 Buzzer As a type of electronic buzzer with an integrated structure, buzzers, which are supplied by DC power, are widely used in computers, printers, photocopiers, alarms, electronic toys, automotive electronic devices, telephones, timers and other electronic products or voice devices.
SunFounder 3in1 Kit Buzzer - Wikipedia Example • (Basic Project) 1.2 Beep • (Basic Project) 5.7 Tone() or noTone() • (IoT Project) 4. Cloud Music Player Driver 1.13 TT Motor This is a TT DC gearbox motor with a gear ratio of 1:48, it comes with 2 x 200mm wires with 0.1” male connectors that fit into a breadboard.
SunFounder 3in1 Kit Example • (Basic Project) 1.3 Turn the Wheel • (Car Project) 1. Move • (Car Project) 3. Speed Up • (IoT Project) 8. IoT Car 1.14 Servo A servo is generally composed of the following parts: case, shaft, gear system, potentiometer, DC motor, and embedded board.
Page 33
SunFounder 3in1 Kit It works like this: The microcontroller sends out PWM signals to the servo, and then the embedded board in the servo receives the signals through the signal pin and controls the motor inside to turn. As a result, the motor drives the gear system and then motivates the shaft after deceleration.
Page 34
SunFounder 3in1 Kit Example • (Basic Project) 5.5 Use Internal Library • (IoT Project) 7. Current Limiting Gate Chapter 1. Components List and Introduction...
SunFounder 3in1 Kit 1.15 Centrifugal Pump The centrifugal pump converts rotational kinetic energy into hydrodynamic energy to transport fluid. The rotation energy comes from the electric motor. The fluid enters the pump impeller along or near the rotating shaft, is accelerated by the impeller, flows radially outward into the diffuser or volute chamber, and then flows out from there.
SunFounder 3in1 Kit • It is a submersible pump and should be used that way. It tends to heat too much that there’s a risk of overheating if you turn it on unsubmerged. Example • (Basic Project) 1.4 Pumping •...
Page 37
SunFounder 3in1 Kit • 0A & OB(B): Output pins of Motor B. • VCC: Power input pin (2.5V-12V). • GND: Ground pin. Features • On-board 2 L9110S motor control chip • Dual-channel motor control. • Independent motor spinning direction control.
SunFounder 3in1 Kit 1.17 Button Buttons are a common component used to control electronic devices. They are usually used as switches to connect or break circuits. Although buttons come in a variety of sizes and shapes, the one used here is a 6mm mini-button as shown in the following pictures.
SunFounder 3in1 Kit Example • (Basic Project) 3.1 Reading Button Value 1.18 Reed Switch The Reed Switch is an electrical switch that operates by means of an applied magnetic field. It was invented by Walter B. Ellwood of Bell Telephone Laboratories in 1936 and patented in the United States on June 27, 1940, under patent number 2264746.
SunFounder 3in1 Kit • Reed Switch - Wikipedia Example • (Basic Project) 3.2 Feel the Magnetism • (IoT Project) 7. Current Limiting Gate 1.19 Potentiometer Potentiometer is also a resistance component with 3 terminals and its resistance value can be adjusted according to some regular variation.
Page 41
SunFounder 3in1 Kit • The resistance between the middle terminal and either one of the outer terminals varies from 0 to the maximum resistance of the pot as the knob, screw, or slider is moved. Here is the circuit symbol of potentiometer.
SunFounder 3in1 Kit 1.20 Joystick Module The basic idea of a joystick is to translate the movement of a stick into electronic information that a computer can process. In order to communicate a full range of motion to the computer, a joystick needs to measure the stick’s position on two axes –...
SunFounder 3in1 Kit Example • (Basic Project) 4.3 Toggle the Joystick 1.21 IR Receiver IR Receiver 1.21. IR Receiver...
Page 44
SunFounder 3in1 Kit • OUT: Signal output • GND: GND • VCC: power supply, 3.3v~5V An infrared-receiver is a component which receives infrared signals and can independently receive infrared rays and output signals compatible with TTL level. It is similar with a normal plastic-packaged transistor in size and is suitable for all kinds of infrared remote control and infrared transmission.
Page 45
SunFounder 3in1 Kit This is a Mini thin infrared wireless remote control with 21 function buttons and a transmitting distance of up to 8 meters, which is suitable for operating a wide range of devices in a kid’s room. • Size: 85x39x6mm •...
SunFounder 3in1 Kit 1.22 Photoresistor A photoresistor or photocell is a light-controlled variable resistor. The resistance of a photoresistor decreases with increasing incident light intensity; in other words, it exhibits photo conductivity. A photoresistor can be applied in light-sensitive detector circuits and light-activated and dark-activated switching cir- cuits acting as a resistance semiconductor.
SunFounder 3in1 Kit 1.23 Thermistor A thermistor is a type of resistor whose resistance is strongly dependent on temperature, more so than in standard resistors. The word is a combination of thermal and resistor. Thermistors are widely used as inrush current limiters, temperature sensors (negative temperature coefficient or NTC type typically), self-resetting overcurrent protectors, and self-regulating heating elements (positive temperature coefficient or PTC type typically).
SunFounder 3in1 Kit • RN is the resistance of the NTC thermistor under the rated temperature TN. Here, the numerical value of RN is 10k. • TK is a Kelvin temperature and the unit is K. Here, the numerical value of TK is 273.15 + degree Celsius.
Page 49
SunFounder 3in1 Kit Features 1. Humidity measurement range: 20 - 90%RH 2. Temperature measurement range: 0 - 60℃ 3. Output digital signals indicating temperature and humidity 4. Working voltage:DC 5V; PCB size: 2.0 x 2.0 cm 5. Humidity measurement accuracy: 5%RH 6.
SunFounder 3in1 Kit 1.25 Line Tracking Module • S: Usually low level, high level when the black line is detected. • V+: Power supply, 3.3v~5V • G: Ground This is a 1-channel Line Tracking module which, as the name suggests, tracks black lines on a white background or white lines against a black background.
SunFounder 3in1 Kit • Operating voltage: 3.3V-5V • Digital output: 0 (white) and 1 (black) • Uses wide voltage LM393 comparator. • Size: 42mmx10mm Example • (Basic Project) 3.4 Detect the Line • (Car Project) 4. Follow the line 1.26 Soil Moisture Module •...
Page 52
SunFounder 3in1 Kit There is a fixed frequency oscillator, which is built with a 555 timer IC. The generated square wave is then fed to the sensor like a capacitor. However, for the square wave signal, the capacitor has a certain reactance or, for the sake of argument, a resistor with a pure ohmic resistor (10k resistor on pin 3) to form a voltage divider.
SunFounder 3in1 Kit • (IoT Project) 6. Plant Monitor 1.27 Obstacle Avoidance Module • VCC: Power supply, 3.3 ~ 5V DC. • GND: Ground • OUT: Signal pin, usually high level, and low level when an obstacle is detected. The IR obstacle avoidance module has strong adaptability to environmental light, it has a pair of infrared transmitting and receiving tubes.
SunFounder 3in1 Kit • (Car Project) 8. Self-Driving Car • (IoT Project) 7. Current Limiting Gate 1.28 Ultrasonic Module Ultrasonic ranging module provides 2cm - 400cm non-contact measurement function, and the ranging accuracy can reach to 3mm. It can ensure that the signal is stable within 5m, and the signal is gradually weakened after 5m, till the 7m position disappears.
Page 55
SunFounder 3in1 Kit You only need to supply a short 10us pulse for the trigger input to start the ranging, and then the module will send out an 8 cycle burst of ultrasound at 40 kHz and raise its echo. You can calculate the range through the time interval between sending trigger signal and receiving echo signal.
Page 56
SunFounder 3in1 Kit Chapter 1. Components List and Introduction...
CHAPTER GET STARTED WITH ARDUINO If you have no idea about Arduino. There are several words I would like to show you: electronics, design, programming, and even Maker. Some of you may think these words are quite far away from us, but in fact, they are not far at all. Because Arduino can take us into the world of programming and help us realize the dream of being a Maker.
SunFounder 3in1 Kit 2.3 How to build an Arduino Project Follow these steps to learn how to use Arduino from zero! 2.3.1 Download and Install Arduino IDE 2.0 The Arduino IDE, known as Arduino Integrated Development Environment, provides all the software support needed to complete an Arduino project.
Page 59
SunFounder 3in1 Kit Installation Windows 1. Double click the arduino-ide_xxxx.exe file to run the downloaded file. 2. Read the License Agreement and agree it. 3. Choose installation options. 2.3. How to build an Arduino Project...
Page 60
SunFounder 3in1 Kit 4. Choose install location. It is recommended that the software be installed on a drive other than the system drive. 5. Then Finish. Chapter 2. Get Started with Arduino...
Page 61
SunFounder 3in1 Kit macOS Double click on the downloaded arduino_ide_xxxx.dmg file and follow the instructions to copy the Arduino IDE.app to the Applications folder, you will see the Arduino IDE installed successfully after a few seconds. 2.3. How to build an Arduino Project...
Page 62
SunFounder 3in1 Kit Linux For the tutorial on installing the Arduino IDE 2.0 on a Linux system, please refer to: https://docs.arduino.cc/software/ ide-v2/tutorials/getting-started/ide-v2-downloading-and-installing#linux Open the IDE 1. When you first open Arduino IDE 2.0, it automatically installs the Arduino AVR Boards, built-in libraries, and other required files.
Page 63
SunFounder 3in1 Kit 3. Now your Arduino IDE is ready! Note: In the event that some installations didn’t work due to network issues or other reasons, you can reopen the Arduino IDE and it will finish the rest of the installation. The Output window will not automatically open after all installations are complete unless you click Verify or Upload.
Page 64
SunFounder 3in1 Kit 2.3.2 Introduce of Arduino IDE 1. Verify: Compile your code. Any syntax problem will be prompted with errors. 2. Upload: Upload the code to your board. When you click the button, the RX and TX LEDs on the board will flicker fast and won’t stop until the upload is done.
Page 65
SunFounder 3in1 Kit 10. Tool: Includes some tools – the most frequently used Board (the board you use) and Port (the port your board is at). Every time you want to upload the code, you need to select or check them.
Page 66
SunFounder 3in1 Kit These sketch files have a regular temporary name, from which you can tell the date the file was created. sketch_oct14a.ino means October 14th first sketch, .ino is the file format of this sketch. 2. Now let’s try to create a new sketch. Copy the following code into the Arduino IDE to replace the original code.
Page 67
SunFounder 3in1 Kit 4. After successful saving, you will see that the name in the Arduino IDE has been updated. Please continue with the next section to learn how to upload this created sketch to your Arduino board. 2.3.4 How to upload Sketch to the Board? In this section, you will learn how to upload the sketch created previously to the Arduino board, as well as learn about some considerations.
Page 68
SunFounder 3in1 Kit If your board is already plugged in, but not recognized, check if the INSTALLED logo appears in the Arduino UNO R4 Boards section of the Boards Manager, if not, please scroll down a bit and click on INSTALL.
Page 69
SunFounder 3in1 Kit You can use it to find mistakes if you delete some characters or type a few letters by mistake. From the message bar, you can see where and what type of errors occurred. If there are no errors, you will see a message like the one below.
Page 70
SunFounder 3in1 Kit 3. Upload sketch After completing the above steps, click the Upload button to upload this sketch to the board. If successful, you will be able to see the following prompt. Chapter 2. Get Started with Arduino...
Page 71
SunFounder 3in1 Kit At the same time, the on-board LED blink. The Arduino board will automatically run the sketch after power is applied after the sketch is uploaded. The running program can be overwritten by uploading a new sketch. 2.3.5 Arduino Program Structure Let’s take a look at the new sketch file.
Page 72
SunFounder 3in1 Kit and only once. loop() is used to write the main feature, and the code inside it will run in a loop after setup() is executed. To better understand setup() and loop(), let’s use four sketches. Their purpose is to make the on-board LED of the Arduino blink.
Page 73
SunFounder 3in1 Kit void setup() { // put your setup code here, to run once: pinMode(13,OUTPUT); digitalWrite(13,HIGH); delay(1000); digitalWrite(13,LOW); delay(1000); void loop() { // put your main code here, to run repeatedly: With the help of these sketches, we can summarize several features of setup-loop.
Page 74
SunFounder 3in1 Kit (continued from previous page) void loop() { // put your main code here, to run repeatedly: digitalWrite(13,HIGH); delay(500); digitalWrite(13,LOW); delay(500); Next, let’s take a look at the following two sketches and guess if they can be correctly recognized by Arduino before running them.
Page 75
SunFounder 3in1 Kit so don’t get yourself into trouble. Curlybraces {} {} is the main component of the Arduino programming language, and they must appear in pairs. A better programming convention is to insert a structure that requires curly braces by typing the right curly brace directly after typing the left curly brace, and then moving the cursor between the curly braces to insert the statement.
Page 76
SunFounder 3in1 Kit (continued from previous page) void loop() { digitalWrite(13,HIGH); delay(200); digitalWrite(13,LOW); delay(200); Note: Use the shortcut Ctrl+/ to help you quickly comment or uncomment your code. Commment /**/ Same as // for comments. This type of comment can be more than one line long, and once the compiler reads /*, it ignores anything that follows until it encounters */.
Page 77
SunFounder 3in1 Kit (continued from previous page) void loop() { digitalWrite(ONBOARD_LED,HIGH); delay(DELAY_TIME); digitalWrite(ONBOARD_LED,LOW); delay(DELAY_TIME); To the compiler, it actually looks like this. void setup() { pinMode(13,OUTPUT); void loop() { digitalWrite(13,HIGH); delay(500); digitalWrite(13,LOW); delay(500); We can see that the identifier is replaced and does not exist inside the program. Therefore, there are several caveats when using it.
Page 78
SunFounder 3in1 Kit 2.3.7 Variable The variable is one of the most powerful and critical tools in a program. It helps us to store and call data in our programs. The following sketch file uses variables. It stores the pin numbers of the on-board LED in the variable ledPin and a number “500”...
Page 79
SunFounder 3in1 Kit Declare a variable Declaring a variable means creating a variable. To declare a variable, you need two things: the data type, and the variable name. The data type needs to be separated from the variable by a space, and the variable declaration needs to be terminated by a ;.
Page 80
SunFounder 3in1 Kit delayTime; // no value delayTime 500; // value is 500 delayTime delayTime +200; // value is 700 2.3.8 How to Build the Circuit Many of the things you use every day are powered by electricity, like the lights in your house and the computer you’re reading.
Page 81
SunFounder 3in1 Kit With electricity, you can create works with light, sound, and motion. You can light up an LED by connecting the long pin to the positive terminal and the short pin to the negative terminal. The LED will break down very quickly if you do this, so you need to add a 220* resistor inside the circuit to protect it.
Page 82
SunFounder 3in1 Kit Hello, Breadboard! A breadboard is a rectangular plastic plate with a bunch of small holes. These holes allow us to easily insert electronic components and build electronic circuits. Breadboards do not permanently fix electronic components, so we can easily repair a circuit and start over if something goes wrong.
Page 83
SunFounder 3in1 Kit 1. In this circuit, we use the 5V pin of the board to power the LED. Use a male-to-male (M2M) jumper wire to connect it to the red power bus. 2. To protect the LED, the current must pass through a 220 ohm resistor. Connect one end (either end) of the resistor to the red power bus, and the other end to the free row of the breadboard.
Page 84
SunFounder 3in1 Kit If you reverse the LED in this simple circuit that we built earlier, you will find that it no longer works. In contrast, some devices have no direction, such as the resistors in this circuit, so you can try inverting them without affecting the LEDs’...
Page 85
SunFounder 3in1 Kit By changing the wire connecting 5V to 3.3V , the LED gets dimmer. If you change the resistor from 220ohm to 1000ohm (color ring: brown, black, black, brown and brown), you will notice that the LED becomes dimmer than before.
Page 86
SunFounder 3in1 Kit Next, upload this sketch to the Arduino development board. ledPin delayTime 500; void setup() { pinMode(ledPin,OUTPUT); void loop() { digitalWrite(ledPin,HIGH); delay(delayTime); digitalWrite(ledPin,LOW); delay(delayTime); This sketch is very similar to the one we used to control the blinking of the on-board LED, the difference is that the value of ledPin has been changed to 9.
Page 87
SunFounder 3in1 Kit Now you can see the LED on the breadboard blinking. 2.3. How to build an Arduino Project...
Page 88
SunFounder 3in1 Kit Chapter 2. Get Started with Arduino...
CHAPTER THREE DOWNLOAD THE CODE Download the relevant code from the link below. • SunFounder 3 in 1 Kit for Arduino • Or check out the code at SunFounder 3 in 1 Kit for Arduino - GitHub...
Page 90
SunFounder 3in1 Kit Chapter 3. Download the Code...
CHAPTER FOUR BASIC PROJECTS This chapter is used to learn how to control electronic circuits using Arduino. Depending on the components, the basic control methods of Arduino can be divided into four types: • Write: Set the output voltage of the pin to be high or low, which can be used to turn the light on and 1.
Page 92
SunFounder 3in1 Kit Parameters – pin: the Arduino pin number. – value: HIGH or LOW. Example of Digital Write: const int void setup() { pinMode(pin, OUTPUT); // sets the digital pin as output void loop() { digitalWrite(pin, HIGH); // sets the digital pin on delay(1000);...
Page 93
SunFounder 3in1 Kit will interfere with communication, including causing the upload board to fail. • If the digital pins are used up, the analog pins (A0-A5) can also be used as digital pins. Related Components Below are the related components, you can click in to learn how to use them.
Page 94
SunFounder 3in1 Kit Code Note: • You can open the file 1.1.hello_led.ino under the path of 3in1-kit\learning_project\1.1. hello_led. • Or copy this code into Arduino IDE. After the code is uploaded successfully, you will see the LED blinking. How it works? Here, we connect the LED to the digital pin 9, so we need to declare an int variable called ledpin at the beginning of the program and assign a value of 9.
Page 95
SunFounder 3in1 Kit void setup() { pinMode(ledPin, OUTPUT); In loop(), digitalWrite() is used to provide 5V high level signal for ledpin, which will cause voltage difference between LED pins and light LED up. digitalWrite(ledPin, HIGH); If the level signal is changed to LOW, the ledPin’s signal will be returned to 0 V to turn LED off.
Page 96
SunFounder 3in1 Kit COMPONENT INTRODUCTION PURCHASE LINK Arduino Uno R4 Minima Breadboard Jumper Wires Buzzer Schematic Wiring Chapter 4. Basic Projects...
Page 97
SunFounder 3in1 Kit Code Note: • You can open the file 1.2.beep.ino under the path of 3in1-kit\learning_project\1.2.beep. • Or copy this code into Arduino IDE. After the code is uploaded successfully, you will hear a beep every second. 4.1.3 1.3 Turn the Wheel A motor is a typical digital output device, and it is used in the same way as an LED.
Page 98
SunFounder 3in1 Kit Wiring L9110S R4 Board Motor B-1B B-1A one wire of the motor one wire of the motor Code Note: • You can open the file 1.3.turn_the_wheel.ino under the path of 3in1-kit\learning_project\1.3. turn_the_wheel. • Or copy this code into Arduino IDE.
Page 99
SunFounder 3in1 Kit You can also buy them separately from the links below. COMPONENT INTRODUCTION PURCHASE LINK Arduino Uno R4 Minima Jumper Wires L9110 Motor Driver Module Centrifugal Pump Schematic Wiring L9110S R4 Board Motor B-1B B-1A one wire of the motor one wire of the motor 4.1.
SunFounder 3in1 Kit Code Note: • You can open the file 1.4.pumping.ino under the path of 3in1-kit\learning_project\1.4.pumping. • Or copy this code into Arduino IDE. Add the tubing to the pump and place it in the basin. After the code is uploaded successfully, you can see that the water in the basin is drained after a while.
Page 101
SunFounder 3in1 Kit (continued from previous page) Notes and Warnings • Looking closely at the R4 board, the pins marked with the “~” symbol have analog output function. • The PWM outputs generated on pins 5 and 6 will have higher-than-expected duty cycles. This is because of interactions with the millis() and delay() functions, which share the same internal timer used to generate those PWM outputs.
Page 103
SunFounder 3in1 Kit Code Note: • You can open the file 2.1.fading.ino under the path of 3in1-kit\learning_project\2.analogWrite\ 2.1.fading. • Or copy this code into Arduino IDE. After the code is uploaded successfully, you can see the LED breathing. 4.2. 2. Analog Write...
Page 104
SunFounder 3in1 Kit 4.2.2 2.2 Colorful Light As we know, light can be superimposed. For example, mix blue light and green light give cyan light, red light and green light give yellow light. This is called “The additive method of color mixing”.
Page 105
SunFounder 3in1 Kit The PWM pins 11, 10 and 9 control the Red, Green and Blue pins of the RGB LED respectively, and connect the common cathode pin to GND. This allows the RGB LED to display a specific color by superimposing light on these pins with different PWM values.
Page 106
SunFounder 3in1 Kit Code Here, we can choose our favorite color in drawing software (such as paint) and display it with RGB LED. Note: Chapter 4. Basic Projects...
Page 107
SunFounder 3in1 Kit • You can open the file 2.2.colorful_light.ino under the path of 3in1-kit\learning_project\2. analogWrite\2.2.colorful_light. • Or copy this code into Arduino IDE. Write the RGB value into color_set(), you will be able to see the RGB light up the colors you want.
SunFounder 3in1 Kit 4.3 3. Digital Read Sensors capture real-world information, which is then communicated to the main board via pins (some digital, some analog) so that the computer can know the reality of the situation. Therefore, the Arduino board can know the working status of digital sensors by reading the value of digital pins like buttons, IR obstacle avoidance module.
Page 109
SunFounder 3in1 Kit 2. About Pin13. All digital pins (1-13) on the R4 board can be used as digitalRead(). But digital pin 13 is more difficult to use as a digital input than other digital pins. Because it connects an LED and resistor, it is soldered on most boards.
Page 110
SunFounder 3in1 Kit 4. Here is the Serial Monitor. • 1: Option to select between automatically scroll and not scroll. • 2: Option to show timestamp prior to data displayed on Serial Monitor. Chapter 4. Basic Projects...
Page 111
SunFounder 3in1 Kit • 3: Ending selection, select the ending characters appended to data sent to Arduino. Selection includes: – No line Ending just sends what you type; – Newline is \n and will sends an ASCII new line code after what you type –...
Page 112
SunFounder 3in1 Kit One side of the button pin is connected to 5V, and the other side pin is connected to pin 2, so when the button is pressed, pin 2 will be high. However, when the button is not pressed, pin 2 is in a suspended state and may be high or low. In order to get a stable low level when the button is not pressed, pin 2 needs to be reconnected to GND through a 10K pull-down resistor.
Page 113
SunFounder 3in1 Kit Code Note: • You can open the file 3.1.read_button_value.ino under the path of 3in1-kit\learning_project\3. 4.3. 3. Digital Read...
Page 114
SunFounder 3in1 Kit 1.read_button_value. • Or copy this code into Arduino IDE. After the code is uploaded successfully, click the magnifying glass icon in the upper right corner of the Arduino IDE (Serial Monitor). When you press the button, the Serial Monitor will print “1”.
Page 115
SunFounder 3in1 Kit By default, pin 2 is low; and will go high when the magnet is near the reed switch. The purpose of the 10K resistor is to keep the pin 2 at a steady low level when no magnet is near.
Page 116
SunFounder 3in1 Kit Code Note: • You can open the file 3.2.feel_the_magnetism.ino under the path of 3in1-kit\learning_project\3. 2.feel_the_magnetism. • Or copy this code into Arduino IDE. After the code is uploaded successfully, when a magnet is near the reed switch, the serial monitor will print 1.
Page 117
SunFounder 3in1 Kit 4.3.4 3.3 Detect the Obstacle This module is commonly installed on the car and robot to judge the existence of the obstacles ahead. Also it is widely used in hand held device, water faucet and so on.
Page 118
SunFounder 3in1 Kit Code Note: • You can open the file 3.3.detect_the_obstacle.ino under the path of 3in1-kit\learning_project\ 3.3.detect_the_obstacle. • Or copy this code into Arduino IDE. When the IR obstacle avoidance module detects something blocking in front of it, [0] will appear on the serial monitor, otherwise [1] will be displayed.
Page 119
SunFounder 3in1 Kit COMPONENT INTRODUCTION PURCHASE LINK Arduino Uno R4 Minima Jumper Wires Line Tracking Module Schematic The digital pin 2 is used to read the signal of line track module. We get the VCC of the module connected to 5V, GND to GND, OUT to digital pin 2.
Page 120
SunFounder 3in1 Kit Code Note: • You can open the file 3.4.detect_the_line.ino under the path of 3in1-kit\learning_project\3.4. detect_the_line. Chapter 4. Basic Projects...
SunFounder 3in1 Kit • Or copy this code into Arduino IDE. When the line tracking module detects there is black line, there appears [1] on the Serial Monitor; otherwise, [0] is displayed. 4.4 4. Analog Read The Arduino can read the connected analog sensors through the analog pins.
Page 122
SunFounder 3in1 Kit 4.4.1 4.1 Turn the Knob Potentiometer is a resistor component with 3 terminals and its resistance value can be adjusted according to some regular variation. Required Components In this project, we need the following components. It’s definitely convenient to buy a whole kit, here’s the link:...
Page 123
SunFounder 3in1 Kit In this example, we use the analog pin (A0) to read the value of the potentiometer. By rotating the axis of the po- tentiometer, you can change the distribution of resistance among these three pins, changing the voltage on the middle pin.
Page 124
SunFounder 3in1 Kit Code Note: • You can open the file 4.1.turn_the_knob.ino under the path of 3in1-kit\learning_project\4.1. turn_the_knob. • Or copy this code into Arduino IDE. After uploading the codes to the board, you can open the serial monitor to see the reading value of the pin. When rotating the axis of the potentiometer, the serial monitor will print the value 0~1023.
Page 125
SunFounder 3in1 Kit 4.4.2 4.2 Feel the Light The photoresistor is a typical device for analog inputs and it is used in a very similar way to a potentiometer. Its resistance value depends on the intensity of the light, the stronger the irradiated light, the smaller its resistance value;...
Page 126
SunFounder 3in1 Kit In this circuit, the 10K resistor and the photoresistor are connected in series, and the current passing through them is the same. The 10K resistor acts as a protection, and the pin A0 reads the value after the voltage conversion of the photoresistor.
Page 127
SunFounder 3in1 Kit Code Note: • Open the 4.2.feel_the_light.ino file under the path of 3in1-kit\learning_project\4.2. feel_the_light. • Or copy this code into Arduino IDE. 4.4. 4. Analog Read...
Page 128
SunFounder 3in1 Kit After the code is uploaded successfully, the serial monitor prints out the photoresistor values. The stronger the current ambient brightness, the larger the value displayed on the serial monitor. 4.4.3 4.3 Toggle the Joystick The joystick should be very familiar to anyone who plays video games regularly. It is usually used to move characters or rotate the screen.
Page 129
SunFounder 3in1 Kit Note: The SW pin is connected to a 10K pull-up resistor, the reason is to be able to get a stable high level on the SW pin (Z axis) when the joystick is not pressed; otherwise the SW is in a suspended state and the output value may vary between 0/1.
Page 130
SunFounder 3in1 Kit Code Note: • Open the 4.3.toggle_the_joystick.ino file under the path of 3in1-kit\learning_project\4.3. toggle_the_joystick. • Or copy this code into Arduino IDE. Open the serial monitor after the code has been uploaded successfully to see the x,y,z values of the joystick.
Page 131
SunFounder 3in1 Kit Name ITEMS IN THIS KIT LINK 3 in 1 Starter Kit 380+ You can also buy them separately from the links below. COMPONENT INTRODUCTION PURCHASE LINK Arduino Uno R4 Minima Jumper Wires Soil Moisture Module Schematic Wiring...
Page 132
SunFounder 3in1 Kit Code Note: • Open the 4.4.measure_soil_moisture.ino file under the path of 3in1-kit\learning_project\4.4. measure_soil_moisture. • Or copy this code into Arduino IDE. Once the code is successfully uploaded, the serial monitor will print out the soil moisture value.
Page 133
SunFounder 3in1 Kit 4.4.5 4.5 Thermometer A thermometer is a device that measures temperature or a temperature gradient (the degree of hotness or coldness of an object). A thermometer has two important elements: (1) a temperature sensor (e.g. the bulb of a mercury-in-glass thermometer or the pyrometric sensor in an infrared thermometer) in which some change occurs with a change in temperature;...
Page 134
SunFounder 3in1 Kit Each thermistor has a normal resistance. Here it is 10k ohm, which is measured under 25 degree Celsius. When the temperature gets higher, the resistance of the thermistor decreases. Then the voltage data is converted to digital quantities by the A/D adapter.
Page 135
SunFounder 3in1 Kit Note: • The thermistor is black or green and marked 103. Code 4.4. 4. Analog Read...
SunFounder 3in1 Kit Note: • You can open the file 4.5_thermometer.ino under the path of euler-kit/arduino/4.5_thermometer. • Or copy this code into Arduino IDE. Don’t forget to select the Raspberry Pi Pico board and the correct port before clicking the Upload button.
Page 137
SunFounder 3in1 Kit Wiring 4.5. 5. More Syntax...
Page 139
SunFounder 3in1 Kit Note: • Open the 5.1.if_else.ino file under the path of 3in1-kit\learning_project\5.1.if_else. • Or copy this code into Arduino IDE. After the code is uploaded successfully, if you do not close the door, the LED will light up, prompting you to close the door.
Page 140
SunFounder 3in1 Kit COMPONENT INTRODUCTION PURCHASE LINK Arduino Uno R4 Minima Breadboard Jumper Wires Resistor Soil Moisture Module Schematic Wiring Chapter 4. Basic Projects...
Page 141
SunFounder 3in1 Kit Code Note: • Open the 5.2.threshold.ino file under the path of 3in1-kit\learning_project\5.2.threshold. 4.5. 5. More Syntax...
Page 142
SunFounder 3in1 Kit • Or copy this code into Arduino IDE. After the code is uploaded successfully, if your threshold is set correctly, you will see the red LED light up when the soil is dry to remind you that you need to water; after watering, the green LED will light up.
Page 143
SunFounder 3in1 Kit COMPONENT INTRODUCTION PURCHASE LINK Arduino Uno R4 Minima Breadboard Jumper Wires Resistor Button TT Motor L9110 Motor Driver Module Schematic Wiring 4.5. 5. More Syntax...
Page 144
SunFounder 3in1 Kit Code Note: • Open the 5.3.state_change_detection.ino file under the path of 3in1-kit\learning_project\5.3. state_change_detection. • Or copy this code into Arduino IDE. After the code is uploaded successfully, you press the button and the motor will turn; until you press the button again, the motor will stop.
Page 145
SunFounder 3in1 Kit 1 the next, and so on alternately. • buttonState and lastButtonState are used to record the state of the button this time and the last time, to compare whether the button was pressed or released. 2. Initialize each pin and set the baud rate of the serial monitor.
Page 146
SunFounder 3in1 Kit • When the button is pressed, its value is HIGH. Here, when the button is pressed, the value of the variable detectionState is changed, e.g., from 0 to 1 after an operation. HIGH) { (buttonState detectionState=(detectionState+1)%2; Serial.print("The detection state is: ");...
Page 147
SunFounder 3in1 Kit COMPONENT INTRODUCTION PURCHASE LINK Arduino Uno R4 Minima Breadboard Jumper Wires Resistor Button Buzzer Schematic Wiring 4.5. 5. More Syntax...
Page 149
SunFounder 3in1 Kit • Open the 5.4.interval.ino file under the path of 3in1-kit\learning_project\5.4.interval. • Or copy this code into Arduino IDE. After the code is uploaded successfully, the buzzer will play music; whenever you press the button, the LED will light up.
Page 150
SunFounder 3in1 Kit Name ITEMS IN THIS KIT LINK 3 in 1 Starter Kit 380+ You can also buy them separately from the links below. COMPONENT INTRODUCTION PURCHASE LINK Arduino Uno R4 Minima Jumper Wires Servo Schematic In this project, we use PWM pin 9 to drive the Servo, and get the orange wire of the servo connected to the PWM pin 9, the red one to 5V, and the brown one to GND.
Page 151
SunFounder 3in1 Kit Code Note: • Open the 5.5.use_internal_library.ino file under the path of 3in1-kit\learning_project\5.5. use_internal_library. • Or copy this code into Arduino IDE. Once you finish uploading the codes to the R4 board, you can see the servo arm rotating in the range 0°~180°.
Page 152
SunFounder 3in1 Kit Return 1 if the servo is currently attached. 4.5.6 5.6 Map If you observe carefully, you will notice that many values have different ranges in programming. For example, the range of values for analog inputs is (0~1023). The value range for the analog output is (0~255). The output angle of the servo is (0~180).
Page 153
SunFounder 3in1 Kit Wiring 4.5. 5. More Syntax...
Page 154
SunFounder 3in1 Kit Code Note: • Open the 5.6.map.ino file under the path of 3in1-kit\learning_project\5.6.map. • Or copy this code into Arduino IDE. After the code is uploaded successfully, you can rotate the potentiometer back and forth, and the output shaft of the servo will rotate back and forth.
Page 155
SunFounder 3in1 Kit • toHigh: the upper bound of the value’s target range. If the potentiometer controls the LED, you can also use the map to complete the task. analogRead(knob); map(x,0,1023,0,255); analogWrite(led,y); Notes and Warnings • The “lower bound” of both ranges may be larger or smaller than the “upper bound”, which means that the map() function can be used to reverse a range of numbers.
Page 156
SunFounder 3in1 Kit Connect the cathode of the Buzzer to GND, and the anode to the digital pin 9. Wiring Code Note: Chapter 4. Basic Projects...
Page 157
SunFounder 3in1 Kit • Open the 5.7.tone_notone.ino file under the path of 3in1-kit\learning_project\5.7.tone_notone. • Or copy this code into Arduino IDE. At the time when you finish uploading the codes to the R4 board, you can hear a melody containing seven notes.
Page 158
SunFounder 3in1 Kit After you open the code file, if you cannot open the pitches.h code, you can just create one manually. The steps are as follows: To make the pitches.h file, either click on the button just below the serial monitor icon and choose New Tab, or use Ctrl+Shift+N.
Page 161
SunFounder 3in1 Kit You can also buy them separately from the links below. COMPONENT INTRODUCTION PURCHASE LINK Arduino Uno R4 Minima Jumper Wires Ultrasonic Module Schematic Wiring 4.5. 5. More Syntax...
Page 162
SunFounder 3in1 Kit Code Note: • Open the 5.8.user_function.ino file under the path of 3in1-kit\learning_project\5.8. user_function. • Or copy this code into Arduino IDE. After the code is successfully uploaded, the serial monitor will print out the distance between the ultrasonic sensor and the obstacle ahead.
Page 163
SunFounder 3in1 Kit How it works? About the application of ultrasonic sensor, we can directly check the subfunction. float readSensorData(){// ...} The trigPin of the ultrasonic module transmits a 10us square wave signal every 2us digitalWrite(trigPin, LOW); delayMicroseconds(2); digitalWrite(trigPin, HIGH);...
Page 164
SunFounder 3in1 Kit COMPONENT INTRODUCTION PURCHASE LINK Arduino Uno R4 Minima Breadboard Jumper Wires Resistor 74HC595 Schematic • When MR (pin10) is high level and OE (pin13) is low level, data is input in the rising edge of SHcp and goes to the memory register through the rising edge of SHcp.
Page 165
SunFounder 3in1 Kit Wiring Code Note: • Open the 5.9.shiftout_led.ino file under the path of 3in1-kit\learning_project\5.9. shiftout_led. • Or copy this code into Arduino IDE. When you finish uploading the codes to the R4 board, you can see the LEDs turning on one after another.
Page 166
SunFounder 3in1 Kit shiftOut() is used to shift out a byte of data one bit at a time, which means to shift a byte of data in datArray[num] to the shifting register with the DS pin. MSBFIRST means to move from high bits.
Page 167
SunFounder 3in1 Kit Required Components In this project, we need the following components. It’s definitely convenient to buy a whole kit, here’s the link: Name ITEMS IN THIS KIT LINK 3 in 1 Starter Kit 380+ You can also buy them separately from the links below.
Page 168
SunFounder 3in1 Kit COMPONENT INTRODUCTION PURCHASE LINK Arduino Uno R4 Minima Breadboard Jumper Wires Resistor 7-segment Display 74HC595 Schematic Wiring Chapter 4. Basic Projects...
Page 169
SunFounder 3in1 Kit Table 1: Wiring 74HC595 LED Segment Display 4.5. 5. More Syntax...
Page 171
SunFounder 3in1 Kit Code Note: • Open the 5.10.shiftout_segment.ino file under the path of 3in1-kit\learning_project\5.10. shiftout_segment. • Or copy this code into Arduino IDE. After the code is uploaded successfully, you will be able to see the LED Segment Display display 0~9 in sequence.
Page 172
SunFounder 3in1 Kit Table 2: Glyph Code Numbers Binary Code Hex Code 00111111 0x3f 00000110 0x06 01011011 0x5b 01001111 0x4f 01100110 0x66 01101101 0x6d 01111101 0x7d 00000111 0x07 01111111 0x7f 01101111 0x6f Write these codes into shiftOut() to make the LED Segment Display display the corresponding numbers.
Page 173
SunFounder 3in1 Kit 3. The Arduino IDE will automatically download and install the library for you. Related Components Below are the related components, you can click in to learn how to use them. 5.11.1 Liquid Crystal Display An I2C LCD1602 is composed of an LCD1602 and an I2C module, LCD1602 can be used to display characters, numbers, etc., but need to take up a lot of pins of the main control, after configuring an I2C module, only 2 I/0 pins are...
Page 174
SunFounder 3in1 Kit Wiring Note: The SDA and SCL of the R4 board are the pins A4 and A5. Code Note: • Open the 5.11.liquid_crystal_display.ino file under the path of 3in1-kit\learning_project\5. 11.liquid_crystal_display. • Or copy this code into Arduino IDE.
Page 175
SunFounder 3in1 Kit After the code is uploaded successfully, you will see “SunFounder”, “Hello World” on the I2C LCD1602. Note: If the code and wiring are fine, but the LCD still does not display content, you can turn the potentiometer on the back.
Page 176
SunFounder 3in1 Kit void display() Turn the LCD display on. void nodisplay() Turn the LCD display off quickly. void clear() Clear display, set cursor position to zero. void setCursor(uint8_t col,uint8_t row) Set the cursor position to col,row. void print(data,BASE) Prints text to the LCD.
Page 177
SunFounder 3in1 Kit Wiring In this example, we wire up the left pin of IR Receiver to pin 11, the middle pin to GND, and the right pin to 5V. Code 4.5. 5. More Syntax...
Page 178
SunFounder 3in1 Kit Note: • Open the 5.11.ir_receiver.ino file under the path of 3in1-kit\learning_project\5.11. ir_receiver. • Or copy this code into Arduino IDE. • The IRremote library is used here, you can install it from the Library Manager. After uploading the codes to the R4 board, you can see that the current value of the pressed button of IR Remote Controller displays on the serial monitor.
Page 179
SunFounder 3in1 Kit void loop() { (IrReceiver.decode()) { String decodedValue decodeKeyValue(IrReceiver.decodedIRData. command); (decodedValue "ERROR" && decodedValue lastDecodedValue) { Serial.println(decodedValue); lastDecodedValue decodedValue; // Update the last decoded␣ value IrReceiver.resume(); // Enable receiving of the next value • Checks if an IR signal is received and successfully decoded.
Page 180
SunFounder 3in1 Kit The dht11, a digital temperature and humidity sensor, is provided in this kit. It uses a capacitive humidity sensor and thermistor to measure the surrounding air and outputs a digital signal on the data pin. Required Components In this project, we need the following components.
Page 181
SunFounder 3in1 Kit Wiring 4.5. 5. More Syntax...
Page 182
SunFounder 3in1 Kit Code Note: • Open the 5.11.temperature_humidity.ino file under the path of 3in1-kit\learning_project\5.11. temperature_humidity. • Or copy this code into Arduino IDE. • The DHT sensor library is used here, you can install it from the Library Manager.
Page 183
SunFounder 3in1 Kit void loop() { // Wait a few seconds between measurements. delay(2000); // Reading temperature or humidity takes about 250 milliseconds! // Sensor readings may also be up to 2 seconds 'old' (it's a very slow␣ sensor) float humidity dht.readHumidity();...
Page 184
SunFounder 3in1 Kit COMPONENT INTRODUCTION PURCHASE LINK Arduino Uno R4 Minima Jumper Wires I2C LCD1602 Schematic Wiring Code Note: • Open the 5.12.serial_read.ino file under the path of 3in1-kit\learning_project\5.12. serial_read. • Or copy this code into Arduino IDE. • The LiquidCrystal I2C library is used here, you can install it from the Library Manager.
Page 185
SunFounder 3in1 Kit After the code is uploaded successfully, you can enter text in the text box on the serial monitor, and the LCD will display the information. How it works? void loop() // when characters arrive over the serial port...
Page 186
SunFounder 3in1 Kit By the way, if you don’t use Serial.read() to get characters from the incoming stream, the characters from the in- coming stream will be stacked together. For example, if you type A followed by AB, the incoming stream will accumulate 7 characters.
Page 187
SunFounder 3in1 Kit Wiring 4.5. 5. More Syntax...
Page 188
SunFounder 3in1 Kit Code Note: • Open the 5.13.interrupt.ino file under the path of 3in1-kit\learning_project\5.13.interrupt. Chapter 4. Basic Projects...
Page 189
SunFounder 3in1 Kit • Or copy this code into Arduino IDE. After the code is successfully uploaded, turn on the Serial Monitor and you will see an auto-incrementing number printed out every second. If you press the button, the buzzer will sound. The button-controlled buzzer function and the timing function do not conflict with each other.
Page 190
SunFounder 3in1 Kit Name ITEMS IN THIS KIT LINK 3 in 1 Starter Kit 380+ You can also buy them separately from the links below. COMPONENT INTRODUCTION PURCHASE LINK Arduino Uno R4 Minima Breadboard Jumper Wires Resistor Buzzer Photoresistor Schematic...
Page 191
SunFounder 3in1 Kit Wiring 4.5. 5. More Syntax...
Page 193
SunFounder 3in1 Kit Note: • Open the 5.14.calibration.ino file under the path of 3in1-kit\learning_project\5.14. calibration. • Or copy this code into Arduino IDE. After the code is uploaded successfully, the LED will light up, and we will have 5 seconds to calibrate the detection range of the photoresistor.
Page 194
SunFounder 3in1 Kit • using millis() for timing with an interval of 5000ms. previousMillis millis(); while (millis() previousMillis <= interval) { • During these five seconds, wave a hand around the photoresistor, the maximum and minimum values of the detected light are recorded and assigned to lightHigh and lightLow respectively.
Page 195
SunFounder 3in1 Kit You can also buy them separately from the links below. COMPONENT INTRODUCTION PURCHASE LINK Arduino Uno R4 Minima Breadboard Jumper Wires Resistor Servo Button Potentiometer Schematic Wiring 4.5. 5. More Syntax...
Page 196
SunFounder 3in1 Kit Code Note: • Open the 5.15.eeproom.ino file under the path of 3in1-kit\learning_project\5.15.eeproom. • Or copy this code into Arduino IDE. To use this circuit, you simply press the button to begin recording and input the desired information through a poten- tiometer.
Page 197
SunFounder 3in1 Kit void setup() { Serial.begin(9600); //Serial.println(EEPROM.length()); To find the size of your board’s EEPROM memory, uncomment the line Serial.println(EEPROM. read(i)). This will print the size of EEPROM in the serial monitor, and you can change the value of the variable resolution accordingly.
SunFounder 3in1 Kit 4. About the EEPROM library. Here are some of its functions. • write(address,value): Write a byte to the EEPROM. – address: the location to write to, starting from 0 (int) – value: the value to write, from 0 to 255 (byte) –...
Page 199
SunFounder 3in1 Kit Name ITEMS IN THIS KIT LINK 3 in 1 Starter Kit 380+ You can also buy them separately from the links below. COMPONENT INTRODUCTION PURCHASE LINK Arduino Uno R4 Minima Breadboard Jumper Wires Resistor Photoresistor Schematic 4.6. 6. Funny Project...
Page 201
SunFounder 3in1 Kit Code Note: • Open the 6.1.light_control_led.ino file under the path of 3in1-kit\learning_project\6.1. 4.6. 6. Funny Project...
Page 202
SunFounder 3in1 Kit light_control_led. • Or copy this code into Arduino IDE. Now, shine some light on the photoresistor, and you will see several LEDs light up. Shine more light and you will see more LEDs light up. When you place it in a dark environment, all the LEDs will go out.
Page 203
SunFounder 3in1 Kit COMPONENT INTRODUCTION PURCHASE LINK Arduino Uno R4 Minima Breadboard Jumper Wires Resistor Button 74HC595 7-segment Display Schematic Wiring 4.6. 6. Funny Project...
Page 204
SunFounder 3in1 Kit Code Note: • Open the 6.2.electronic_dice.ino file under the path of 3in1-kit\learning_project\6.2. electronic_dice. • Or copy this code into Arduino IDE. Chapter 4. Basic Projects...
Page 205
SunFounder 3in1 Kit When the code is uploaded successfully, the 7-segment Display will display 0-7 in a fast scroll, and when you press the button, it will display a random number and stop scrolling. The scrolling display starts again when you press the button again.
Page 206
SunFounder 3in1 Kit 4.6.3 6.3 High Temperature Alarm Next, we will make a high temperature alarm device using thermistor, push button, potentiometer and LCD. The LCD1602 shows the temperature detected by the thermistor and the high temperature threshold value, which can be ad- justed using a potentiometer.
Page 208
SunFounder 3in1 Kit Code Note: • You can open the file 6.3.high_tem_alarm.ino under the path of 3in1-kit\learning_project\6.3. high_tem_alarm directly. • Or copy this code into Arduino IDE. • The LiquidCrystal I2C library is used here, you can install it from the Library Manager.
Page 209
SunFounder 3in1 Kit temperature threshold value, which can be adjusted using a potentiometer. The threshold value is stored on EEPROM at the same time, so if the current temperature exceeds the threshold value, the buzzer will sound. Note: If the code and wiring are fine, but the LCD still does not display content, you can turn the potentiometer on the back.
Page 210
SunFounder 3in1 Kit (continued from previous page) lcd.print("Upper Tem: "); while (1) { lcd.setCursor(11, 1); setTem map(analogRead(potPin), 0, 1023, 0, 100); lcd.print(setTem); (state EEPROM.write(0, setTem); upperTem setTem; lcd.clear(); return; • A threshold can be set with this function. When you enter this function, the LCD1602 displays the current threshold value, which can be modified using the potentiometer.
Page 211
SunFounder 3in1 Kit • The thermistor value is read and then converted to Celsius temperature by the formula and dis- played on the LCD1602. • The set threshold is also displayed on the LCD. • If the current temperature is greater than the threshold, the buzzer will sound an alarm.
Page 212
SunFounder 3in1 Kit Wiring Code Note: • You can open the file 6.4_reversingAid.ino under the path of 3in1-kit\learning_project\6. 4_reversingAid directly. • Or copy this code into Arduino IDE. Chapter 4. Basic Projects...
Page 213
SunFounder 3in1 Kit • The LiquidCrystal I2C library is used here, you can install it from the Library Manager. After the code is successfully uploaded, the current detected distance will be displayed on the LCD. Then the buzzer will change the sounding frequency according to different distances.
Page 214
SunFounder 3in1 Kit 2. Check if it’s time to beep The code calculates the difference between the current time and the previous beep time, and if the difference is greater than or equal to the interval time, it triggers the buzzer and updates the previous beep time.
Page 215
SunFounder 3in1 Kit COMPONENT INTRODUCTION PURCHASE LINK Arduino Uno R4 Minima Breadboard Jumper Wires Resistor Button Schematic Wiring 4.6. 6. Funny Project...
Page 216
SunFounder 3in1 Kit Code Note: • You can open the file 6.5_reaction_time.ino under the path of 3in1-kit\learning_project\6. 5_reversingAid directly. • Or copy this code into Arduino IDE. • Please make sure you have added the LiquidCrystal_I2C library, detailed tutorials refer to 5.11 Install External...
Page 217
SunFounder 3in1 Kit How it works? 1. Initialize the buttons and LEDs, 2 interrupt are used here to read the button status. void setup() attachInterrupt(digitalPinToInterrupt(buttonPin1), pressed1, FALLING); attachInterrupt(digitalPinToInterrupt(buttonPin2), pressed2, FALLING); 2. If the rstBtn button is pressed, the game starts again. At a random time between 2 and 5ms, make one of the LEDs light up.
Page 218
SunFounder 3in1 Kit (continued from previous page) Serial.print(currentTime timer); Serial.println(" ms"); else if (flag 1) { Serial.println("Wrong Click!"); flag This is the function that will be triggered when button 1 is pressed. When button 1 is pressed, if the flag is 0 at this time, the response time will be printed, otherwise the press error will be prompted.
Page 219
SunFounder 3in1 Kit COMPONENT INTRODUCTION PURCHASE LINK Arduino Uno R4 Minima Breadboard Jumper Wires I2C LCD1602 IR Receiver Schematic Wiring In this example, the wiring of LCD1602 and infrared receiving module is as follows. 4.6. 6. Funny Project...
Page 220
SunFounder 3in1 Kit Code Note: • You can open the file 6.6.guess_number.ino under the path of 3in1-kit\learning_project\6.6. guess_number directly. • Or copy this code into Arduino IDE. • The LiquidCrystal I2C and IRremote libraries are used here, you can install them from the Library Manager.
Page 221
SunFounder 3in1 Kit 4. If you input a single digit, you can press the CYCLE key (the key at the center of the Controller) to start the result judgment. 5. If the answer is not guessed, the new number range prompt will be displayed (if the lucky number is 51 and you enter 50, the number range prompt will change to 50~99).
CHAPTER FIVE CAR PROJECTS I believe you have seen a lot of different smart robot car, their basic functions are similar, basic movement, obstacle avoidance, line following, following and control by remote control, etc.. Here, we use the simplest structure to build a smart robot car, which can also achieve all the above functions. In addition you can control it with your cell phone, please refer to for the tutorial.
Page 224
SunFounder 3in1 Kit 2. Place the board on the table as shown in the picture, the side with the same hole as the R4 board, we call A; the back is B. This will help you avoid mistakes during assembly.
Page 225
SunFounder 3in1 Kit 4. Turn to the B side, use M3x30mm screws and M3 nuts to attach the TT Motor. 2 details here: 1 - the output shaft is facing the bat-shaped side; 2 - the motor cable is facing the inside.
Page 226
SunFounder 3in1 Kit 7. Attach the M2.5x11mm standoff to the rear of the car with M2.5x6mm screws. Chapter 5. Car Projects...
Page 227
SunFounder 3in1 Kit 8. Use M3x6mm screws to mount the universal wheel. 9. Putting on the 2 wheels and the car’s basic structure has been completed. 10. Attach the L9110 module with M2.5x6mm screws. 5.1. Assemble the Car...
Page 228
SunFounder 3in1 Kit 11. Assemble the two IR Obstacle Modules with M3x10mm screws and M3 nuts. Chapter 5. Car Projects...
Page 229
SunFounder 3in1 Kit 12. Turn to side B and attach the Line Track module with four M3x6mm screws and two M3x24mm standoffs. Note: It’s advisable to first secure the M3x24mm standoffs onto the Line Track module. One important note to keep in mind: the pins of the line sensor are slightly soft and protrude a bit towards the holes.
Page 230
SunFounder 3in1 Kit 13. Stick the velcro on the 9V battery and put on the battery clip. Stick the other section of the Velcro on the car to secure the battery. Chapter 5. Car Projects...
Page 231
SunFounder 3in1 Kit 14. Turn over to side A and mount the R4 board with M3x6mm screws. 5.1. Assemble the Car...
Page 232
SunFounder 3in1 Kit 15. Attach the breadboard to the front of the car. Thereafter, you will be able to add different components (e.g. ultrasonic module) to the breadboard as required for your project. Chapter 5. Car Projects...
Page 233
SunFounder 3in1 Kit 16. Getting the car running also requires wiring it up and writing code, which will be written in subsequent sections. Projects Here are some projects for the car, programmed in C with the Arduino IDE, if you are not particularly skilled with...
SunFounder 3in1 Kit 5.2 1. Move Before we start programming, let’s review the working principle of L9110 module. Here is the truth table of Motor B: B-1A B-1B The state of Motor B Rotate clockwise Rotate counterclockwise Brake Stop Here is the truth table of Motor A:...
Page 235
SunFounder 3in1 Kit 2. Connect B-1B and A-1A to VCC, and B-1A and A-1B to GND, then you will be able to see the car moving forward. 5.2. 1. Move...
Page 236
SunFounder 3in1 Kit If not both turn forward, but the following situations occur, you need to readjust the wiring of the two motors. • If both motors turn backward at the same time (left motor turns clockwise, right motor turns counterclockwise), swap the wiring of the left and right motors at the same time, OA(A) and OB(A) swap, OA(B) and OB(B) swap.
Page 237
SunFounder 3in1 Kit Turn Left If you want to make the car turn left, that is, make both motors turn clockwise. You need to connect B-1A and A-1A to GND, and B-1B and A-1B to VCC. 5.2. 1. Move...
Page 238
SunFounder 3in1 Kit Turn Right Conversely, if you want to turn the car to the right, that is, make both motors turn counterclockwise. You need to connect B-1A and A-1A to VCC and B-1B and A-1B to GND. Chapter 5. Car Projects...
SunFounder 3in1 Kit Stop To stop the motor, connect the inputs on the same side to 12V or GND at the same time, e.g. connect B-1A and B-1B to 12V or 5V at the same time, and the same for A-1A and A-1B.
Page 240
SunFounder 3in1 Kit You can also buy them separately from the links below. COMPONENT INTRODUCTION PURCHASE LINK Arduino Uno R4 Minima L9110 Motor Driver Module TT Motor Wiring Connect the wires between the L9110 module and the R4 board according to the diagram below.
Page 241
SunFounder 3in1 Kit Code Note: • Open the 2.move.ino file under the path of 3in1-kit\car_project\2.move. • Or copy this code into Arduino IDE. After the code is uploaded, the car will move forward, backward, left and right for two seconds respectively.
SunFounder 3in1 Kit (continued from previous page) moveBackward(); delay(2000); stopMove(); delay(500); • digitalWrite(pin, value) – pin: the Arduino pin number. – value: HIGH or LOW. Write a HIGH or a LOW value to a digital pin. If the pin has been configured as an OUTPUT with pinMode(), its voltage will be set to the corresponding value: 5V (or 3.3V on 3.3V boards) for...
SunFounder 3in1 Kit 1. Use the for() statement to give speed in steps of 5, writing values from 0 to 255 so you can see the change in the car’s forward speed. void loop() { for(int i=0;i<=255;i+=5){ moveForward(i); delay(500); for(int i=255;i>=0;i-=5){...
Page 244
SunFounder 3in1 Kit In this project, we need the following components. It’s definitely convenient to buy a whole kit, here’s the link: Name ITEMS IN THIS KIT LINK 3 in 1 Starter Kit 380+ You can also buy them separately from the links below.
Page 245
SunFounder 3in1 Kit Adjust the Module Before starting the project, you need to adjust the sensitivity of the module. Wiring according to the above diagram, then power up the R4 board (either directly into the USB cable or the 9V battery button cable), without uploading the code.
Page 246
SunFounder 3in1 Kit Code Note: • Open the 4.follow_the_line.ino file under the path of 3in1-kit\car_project\4.follow_the_line. • Or copy this code into Arduino IDE. • Or upload the code through the Arduino Web Editor. After uploading the code to the R4 board, then align the Line Tracking module under the car with the black line, and you will see the car following the line.
Page 247
SunFounder 3in1 Kit 2. Read the value of the Line Tracking module, if it is 1, then let the car go forward to the left; otherwise go forward to the right. Also you can open the serial monitor by clicking the magnifying glass icon in the upper right corner to see the change of the Line Tracking module value on the black and white line before unplugging the USB cable.
SunFounder 3in1 Kit 5.6 5. Play with Obstacle Avoidance Module Two infrared obstacle avoidance modules are mounted on the front of the car, which can be used to detect some close obstacles. In this project, the car is allowed to move forward freely, and when it encounters an obstacle it is able to avoid it and continue to move in other directions.
Page 249
SunFounder 3in1 Kit Adjust the Module Before starting the project, you need to adjust the detection distance of the module. Wiring according to the above diagram, power up the R4 board (either by plugging in the USB cable directly or by snapping the 9V battery cable), without uploading the code.
Page 250
SunFounder 3in1 Kit Code Note: • Open the 5.obstacle_avoidance_module.ino file under the path of 3in1-kit\car_project\5. obstacle_avoidance_module. • Or copy this code into Arduino IDE. • Or upload the code through the Arduino Web Editor. The car will move forward once the code has been successfully uploaded. When the left infrared module detects an obstacle, it will go backwards to the left;...
Page 251
SunFounder 3in1 Kit (continued from previous page) void setup() { //IR obstacle pinMode(leftIR, INPUT); pinMode(rightIR, INPUT); 2. Read the values of the left and right infrared modules and let the car to make the corresponding action. void loop() { left digitalRead(leftIR);...
SunFounder 3in1 Kit (continued from previous page) analogWrite(A_1A, 0); analogWrite(B_1B, 0); analogWrite(B_1A, speed); • &&: Logical AND results in true only if both operands are true. • !: Logical NOT results in a true if the operand is false and vice versa.
Page 253
SunFounder 3in1 Kit Code Note: • Open file under path 6.ultrasonic_module.ino 3in1-kit\car_project\6. ultrasonic_module. • Or copy this code into Arduino IDE. • Or upload the code through the Arduino Web Editor. After the code is successfully uploaded, turn the car towards the wall. If the distance is too far, it will move forward; if it is too close, it will move backward;...
Page 254
SunFounder 3in1 Kit (continued from previous page) void setup() { //ultrasonic pinMode(echoPin, INPUT); pinMode(trigPin, OUTPUT); 2. First read the distance value obtained from the ultrasonic module, if the distance is greater than 25, let the car move forward; if the distance is between 2-10cm, let the car move backward, otherwise (between 10~25) stop.
SunFounder 3in1 Kit 5.8 7. Follow Your Hand Think of this car as your pet here, and when you will wave to him, it comes running to you. Required Components In this project, we need the following components. It’s definitely convenient to buy a whole kit, here’s the link:...
Page 256
SunFounder 3in1 Kit Code Note: • Open the 7.follow_your_hand.ino file under the path of 3in1-kit\car_project\7.follow_your_hand. • Or copy this code into Arduino IDE. • Or upload the code through the Arduino Web Editor. Place the car on the ground after the code has been uploaded successfully. Place your hand close to 5*10cm in front of the car, and it will follow your hand forward.
SunFounder 3in1 Kit • If the right IR module detects your hand, turn right. • If neither the infrared module nor the ultrasonic module detects your hand, let the car stop. void loop() { float distance readSensorData(); left digitalRead(leftIR); // 0: Obstructed...
Page 258
SunFounder 3in1 Kit Connect the ultrasonic module and the 2 IR obstacle avoidance modules at the same time. Wire the ultrasonic to the R4 board as follows. Ultrasonic Module R4 Board Trig Echo The wiring of the 2 IR obstacle avoidance modules to the R4 board is as follows.
Page 259
SunFounder 3in1 Kit Code Note: • Open the 8.self_driving_car.ino file under the path of 3in1-kit\car_project\8.self_driving_car. • Or copy this code into Arduino IDE. • Or upload the code through the Arduino Web Editor. The car will drive freely once the code has been uploaded successfully. When the IR obstruction module on both sides detects an obstacle, it will move in the opposite direction for emergency evasion;...
SunFounder 3in1 Kit • Otherwise read the distance detected by the ultrasonic module. • If the distance is greater than 50cm, let the car go forward. • If the distance is between 2-10cm, let the car backward before turning. • If the distance is between 10-50cm, let the car go forward at low speed.
Page 261
SunFounder 3in1 Kit COMPONENT INTRODUCTION PURCHASE LINK Arduino Uno R4 Minima L9110 Motor Driver Module TT Motor IR Receiver Wiring Now build the circuit according to the diagram below. IR Receiver R4 Board R4 Board Anode(The longer pin) Cathode 5.10. 9. Remote Control...
Page 262
SunFounder 3in1 Kit Code Note: • Open the 9.remote_control.ino file under the path of 3in1-kit\car_project\9.remote_control. • Or copy this code into Arduino IDE. • The IRremote library is used here, you can install it from the Library Manager. Chapter 5. Car Projects...
Page 263
SunFounder 3in1 Kit After the code is uploaded successfully, press the button on the remote control, the LED will blink once to represent that the signal has been received, and the car will move according to the button you pressed. You can press the following keys to control the car.
Page 264
SunFounder 3in1 Kit (continued from previous page) void setup() { //IR remote IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK); // Start the IR␣ receiver // Start the receiver Serial.println("REMOTE CONTROL START"); //LED pinMode(ledPin, OUTPUT); 3. When you press the keys on the remote control, the LED will blink and the infrared receiver will know which key is pressed, and then the car will move according to the corresponding key value.
SunFounder 3in1 Kit When this function is called, have the LED repeat the toggle from on-off three times so that you see the LED blink 3 times. void blinkLED() { for (int 0; i < 3; i++) { digitalWrite(ledPin, HIGH);...
Page 266
SunFounder 3in1 Kit • The IRremote library is used here, you can install it from the Library Manager. After the code is uploaded successfully, the LED will flash rapidly 3 times for every signal received from the remote control by the IR receiver. You can press the following keys to operate the cart.
SunFounder 3in1 Kit 5.12 11. Speed Calibration In getting the car to move forward, you may find that the car does not travel in a straight line. This is because the two motors may not have the same speed at the factory. But we can write offset to the two motors to make their rotational speeds converge.
Page 268
SunFounder 3in1 Kit (continued from previous page) pinMode(B_1A, OUTPUT); //IR obstacle pinMode(leftIR, INPUT); pinMode(rightIR, INPUT); leftOffset EEPROM.read(0) 0.01;//read the offset of the left motor rightOffset EEPROM.read(1) 0.01;//read the offset of the right motor void loop() { left digitalRead(leftIR); // 0: Obstructed...
CHAPTER IOT PROJECTS This kit has the ESP8266 Wifi module which allows Arduino to connect to the internet for IoT experiments. Here we will guide you how to make Arduino connect to BLYNK platform with the help of ESP8266 Wifi module to do some interesting IoT projects.
SunFounder 3in1 Kit 6.1 1. Get Started with Blynk Getting the R4 board to communicate with Blynk requires some configuration when you first use Blynk. Follow the steps below, and note that you must do them in order and not skip any chapters.
Page 273
If you still can’t solve it, please to re-burn the firmware for ESP8266 module? take a screenshot of the serial monitor and send it to sevice@sunfounder.com, we will help you solve the problem as soon as possible. 4. Click on NEWLINE DROPDOWN BOX, select both NL & CR in the drop down option, enter AT, if it returns OK, it means ESP8266 has successfully established connection with your board.
Page 274
SunFounder 3in1 Kit 5. Enter AT+CWMODE=3 and the managed mode will be changed to Station and AP coexistence. 6. In order to use the software serial later, you must input AT+UART=9600,8,1,0,0 to modify the ESP8266’s baud rate to 9600. Chapter 6. IoT Projects...
Page 275
SunFounder 3in1 Kit 6.1.2 1.2 Configuring the Blynk 1. Go to the BLYNK and click START FREE. 2. Fill in your email address to register an account. 6.1. 1. Get Started with Blynk...
Page 276
SunFounder 3in1 Kit 3. Go to your email address to complete your account registration. Chapter 6. IoT Projects...
Page 277
SunFounder 3in1 Kit 4. Afterwards, Blynk Tour will appear and you can read it to learn the basic information about the Blynk. 5. Next we need to create a template and device with this Quick Start, click Let’s go. 6.1. 1. Get Started with Blynk...
Page 278
SunFounder 3in1 Kit 6. Select the hardware and connection type. 7. Here you are told which IDE you need to prepare, we recommend the Arduino IDE. Chapter 6. IoT Projects...
Page 279
SunFounder 3in1 Kit 8. Here is the library you need to add, but the recommended library here is a bit problematic, we need to add other libraries manually (we will mention it later). Click Next here, and a new template and device will be created.
Page 280
SunFounder 3in1 Kit 10. Click the Search button and you will see the new device you just created. 11. Go to this Quickstart Device and you will see TEMPLATE_ID, DEVICE_NAME and AUTH_TOKEN on the Device info page, and you will need to copy them later.
Page 281
SunFounder 3in1 Kit 6.1.3 1.3 Adding the required libraries You need to add the correct libraries for the Arduino IDE to use Blynk. 1. Click HERE, scroll down to the bottom of the page and download the first .zip file.
Page 282
SunFounder 3in1 Kit 6.1.4 1.4 Connecting the R4 board to Blynk 1. Reconnect the ESP8266 module and R4 board, here the software serial is used, so TX and RX are connected to pins 2 and 3 of R4 board respectively.
Page 283
SunFounder 3in1 Kit 2. Open the 1.connect.ino file under the path of 3in1-kit\iot_project\1.connect. Or copy this code into Arduino IDE. 3. Replace the following three lines of code that you can copy from your account’s Device info page. These three lines of code will allow your R4 board to find your blynk account.
SunFounder 3in1 Kit 5. Upload the code to the R4 board, then open the serial monitor and set the baud rate to 115200. when the R4 board communicates with Blynk successfully, the serial monitor will show the ready character. Note: If the message ESP is not responding appears when you connect, please follow these steps.
Page 285
SunFounder 3in1 Kit Name ITEMS IN THIS KIT LINK 3 in 1 Starter Kit 380+ You can also buy them separately from the links below. COMPONENT INTRODUCTION PURCHASE LINK Arduino Uno R4 Minima Breadboard ESP8266 Module Jumper Wires Resistor 1. Build the Cirduit Note: The ESP8266 module requires a high current to provide a stable operating environment, so make sure the 9V battery is plugged in.
Page 286
SunFounder 3in1 Kit 2. Datastreams allow the widgets on Blynk and the code on your board to recognize each other. To experience the complete configuration process, remove all Datastreams from the Datastreams page. 3. Please read the warning carefully and confirm it is correct before deleting the Datastreams.
Page 287
SunFounder 3in1 Kit 4. Create a Datastream of type Virtual Pin, which will be used to control the LED using Blynk’s switch. 6.2. 2. Get Data from Blynk...
Page 288
SunFounder 3in1 Kit 5. Configure the Virtual Pin. As the button and LED only need to be ON and OFF, set DATA TYPE to Integer and MIN and MAX to 0 and 1. Chapter 6. IoT Projects...
Page 289
SunFounder 3in1 Kit 6. Go to the Web Dashboard page and delete the existing widgets. 7. Drag and drop a switch widget from the Widget Box on the left. 8. Now to set it up. 6.2. 2. Get Data from Blynk...
Page 290
SunFounder 3in1 Kit 9. Select Datastream as the one you set earlier. 10. After selecting Datastream, you will see a few custom settings, then press Save. Chapter 6. IoT Projects...
Page 291
SunFounder 3in1 Kit 11. Finally, click Save And Apply. 3. Run the Code 1. Open file under path 2.get_data_from_blynk.ino 3in1-kit\iot_project\2. get_data_from_blynk, or copy this code into Arduino IDE. 2. Replace the Template ID, Device Name, and Auth Token with your own. You also need to enter the ssid and password of the WiFi you are using.
Page 292
SunFounder 3in1 Kit 4. Open the Serial monitor(set baudrate to 115200) and wait for a prompt such as a successful connection to appear. Chapter 6. IoT Projects...
Page 293
SunFounder 3in1 Kit Note: If the message ESP is not responding appears when you connect, please follow these steps. • Make sure the 9V battery is plugged in. • Reset the ESP8266 module by connecting the pin RST to GND for 1 second, then unplug it.
SunFounder 3in1 Kit 6. If you want to use Blynk on mobile devices, please refer to How to use Blynk on mobile device?. How it works? The difference between the code in this project and the code in the previous chapter 1.4 Connecting the R4 board to...
Page 295
SunFounder 3in1 Kit In this project, we need the following components. It’s definitely convenient to buy a whole kit, here’s the link: Name ITEMS IN THIS KIT LINK 3 in 1 Starter Kit 380+ You can also buy them separately from the links below.
Page 296
SunFounder 3in1 Kit 1. Create a Datastream of type Virtual Pin in the Datastream page to get the value of Reed Switch. Set the DATA TYPE to Integer and MIN and MAX to 0 and 1. 2. Drag and drop an LED widget on the Wed Dashboard page, at a value of 1, it will light up (with color), otherwise it will be white.
Page 297
SunFounder 3in1 Kit 3. In the settings page of the LED widget, select Datastream as Reed(V1), and save it. 3. Run the Code 6.3. 3. Push Data to Blynk...
Page 298
SunFounder 3in1 Kit 1. Open file under path 3.push_data_to_blynk.ino 3in1-kit\iot_project\3. push_data_to_blynk, or copy this code into Arduino IDE. 2. Replace the Template ID, Device Name, and Auth Token with your own. You also need to enter the ssid and password of the WiFi you are using. For detailed tutorials, please refer to 1.4 Connecting the R4 board to...
SunFounder 3in1 Kit BlynkTimer timer; void myTimerEvent() Blynk.virtualWrite(V1, pinValue); void setup() timer.setInterval(1000L, myTimerEvent); void loop() timer.run(); // Initiates BlynkTimer Blynk library provides a built-in timer, first we create a timer object. BlynkTimer timer; Set the timer interval in setup(), here we set to execute the myTimerEvent() function every 1000ms timer.setInterval(1000L, myTimerEvent);...
Page 300
SunFounder 3in1 Kit You can also buy them separately from the links below. COMPONENT INTRODUCTION PURCHASE LINK Arduino Uno R4 Minima Breadboard ESP8266 Module Jumper Wires Buzzer 1. Build the Cirduit Note: The ESP8266 module requires a high current to provide a stable operating environment, so make sure the 9V battery is plugged in.
Page 301
SunFounder 3in1 Kit 2. Also create another Datastream of type Virtual Pin to display the music name, and set the DATA TYPE to String. 6.4. 4. Cloud Music Player...
Page 302
SunFounder 3in1 Kit 3. Go to the Wed Dashboard page, drag a Switch widget and set Datastream to V0 (V0 is already set in 2. Get Blynk); drag a Label widget and set it to V3; drag a Slider widget and set it to V2.
Page 303
SunFounder 3in1 Kit Note: Your virtual pins may be different from mine, yours will prevail, but you need to modify the corresponding pin number in the code. 3. Run the Code 1. Open file under path 4.cloud_music_player.ino 3in1-kit\iot_project\4. cloud_music_player. 2. Replace the Template ID, Device Name, and Auth Token with your own. You also need to enter the ssid and password of the WiFi you are using.
Page 304
SunFounder 3in1 Kit 6. If you want to use Blynk on mobile devices, please refer to How to use Blynk on mobile device?. How it works? The datastream V0 is used to get the status of the Switch widget and assign it to the variable music- PlayFlag, which controls pausing and playing the music.
SunFounder 3in1 Kit void myTimerEvent() if(musicPlayFlag!=0) tone(buzzerPin,melody[scrubBar],250); scrubBar=(scrubBar+1)%(sizeof(melody)/sizeof(int)); delay(500); tone(buzzerPin,melody[scrubBar],250); scrubBar=(scrubBar+1)%(sizeof(melody)/sizeof(int)); Serial.println(scrubBar); Blynk.virtualWrite(V2, scrubBar); 6.5 5. Home Environment Monitoring In this chapter, we will use Blynk to create a home environment monitor. You can measure the temperature, humidity, and light intensity of a room using the DHT11 and photoresistor. By sending these values to Blynk, you will be able to know the environment of your home via the internet.
Page 306
SunFounder 3in1 Kit 2. Edit Dashboard 1. For recording humidity values, create a Datastream of type Virtual Pin on the Datastream page. Set the DATA TYPE to Double and MIN and MAX to 0 and 100. Also set the units to Percentage, %.
Page 307
SunFounder 3in1 Kit 2. Then create a Datastream of type Virtual Pin for recording the temperature. Set DATA TYPE to Double, MIN and MAX to -30 and 50, and units to Celsius, °C. 6.5. 5. Home Environment Monitoring...
Page 308
SunFounder 3in1 Kit 3. Also create a Datastream of type Virtual Pin to record the light intensity. Use the default data type - Integer, with MIN and MAX set to 0 and 1024. Chapter 6. IoT Projects...
Page 309
SunFounder 3in1 Kit 4. Go to the Wed Dashboard page, drag two Label widgets and set their data streams to V4 and V5 respectively, and drag a Gauge widget and set the data stream to V6. Also in the widget setting, you can enable Change color based on value and select the appropriate color to make the widget look better and more intuitive.
Page 310
SunFounder 3in1 Kit 3. Run the Code 1. Open the 5.home_environment_monitoring.ino file under the path of 3in1-kit\iot_project\5. home_environment_monitoring, or copy this code into Arduino IDE. Note: • The DHT sensor library is used here, you can install it from the Library Manager.
Page 311
SunFounder 3in1 Kit Note: If the message ESP is not responding appears when you connect, please follow these steps. • Make sure the 9V battery is plugged in. • Reset the ESP8266 module by connecting the pin RST to GND for 1 second, then unplug it.
Page 312
SunFounder 3in1 Kit 6. If you want to use Blynk on mobile devices, please refer to How to use Blynk on mobile device?. How it works? These two functions are used to get the temperature, humidity and light intensity of the room.
SunFounder 3in1 Kit (continued from previous page) humidity dht.readHumidity(); // Read temperature as Celsius (the default) temperature dht.readTemperature(); // Check if any reads failed and exit early (to try again). (isnan(humidity) isnan(temperature)) { Serial.println("Failed to read from DHT sensor!"); return false;...
Page 314
SunFounder 3in1 Kit COMPONENT INTRODUCTION PURCHASE LINK Arduino Uno R4 Minima Breadboard ESP8266 Module Jumper Wires Resistor Photoresistor DHT11 Humiture Sensor Soil Moisture Module L9110 Motor Driver Module Centrifugal Pump 1. Build the Cirduit Note: The ESP8266 module requires a high current to provide a stable operating environment, so make sure the 9V battery is plugged in.
Page 315
SunFounder 3in1 Kit 2. For recording soil moisture, create another Datastream of type Virtual Pin on the Datastream page. Set DATA TYPE to Integer and MIN and MAX to 0 and 1024. 3. Now go to the Wed Dashboard page, drag 2 Label widgets and set their data streams to V4 and V5 respectively;...
Page 316
SunFounder 3in1 Kit 3. Run the Code Open the 6.plant_monitoring.ino file under the path of 3in1-kit\iot_project\6.plant_monitoring, or copy this code into Arduino IDE. Note: • The DHT sensor library is used here, you can install it from the Library Manager.
Page 317
SunFounder 3in1 Kit 1. Replace the Template ID, Device Name, and Auth Token with your own. You also need to enter the ssid and password of the WiFi you are using. For detailed tutorials, please refer to 1.4 Connecting the R4 board to Blynk.
Page 318
SunFounder 3in1 Kit 5. If you want to use Blynk on mobile devices, please refer to How to use Blynk on mobile device?. Chapter 6. IoT Projects...
Page 319
SunFounder 3in1 Kit How it works? This BLYNK_WRITE causes Blynk’s Switch widget to start the pump when it is ON and turn it off when it is OFF. BLYNK_WRITE(V0) if(param.asInt()==1){ digitalWrite(pumpA,HIGH); }else{ digitalWrite(pumpA,LOW); These three functions are used to get the current environment temperature, humidity, light intensity and soil moisture.
SunFounder 3in1 Kit (continued from previous page) // Reading temperature or humidity takes about 250 milliseconds! // Sensor readings may also be up to 2 seconds 'old' (it's a very slow sensor) humidity dht.readHumidity(); // Read temperature as Celsius (the default) temperature dht.readTemperature();...
Page 321
SunFounder 3in1 Kit COMPONENT INTRODUCTION PURCHASE LINK Arduino Uno R4 Minima Breadboard ESP8266 Module Jumper Wires Resistor Servo Obstacle Avoidance Module 7-segment Display 74HC595 1. Build the Cirduit Note: The ESP8266 module requires a high current to provide a stable operating environment, so make sure the 9V battery is plugged in.
Page 322
SunFounder 3in1 Kit 2. Edit Dashboard 1. To record the number, create a Datastream of type Virtual Pin on the Datastream page. Set DATA TYPE to Integer and MIN and MAX to 0 and 10. Chapter 6. IoT Projects...
Page 323
SunFounder 3in1 Kit 2. Now go to the Wed Dashboard page, drag a Switch widget to set its data stream to V0 and a Label widget to set its data stream to V8. 3. Run the Code 1. Open the 7.current_limiting_gate.ino file under the path of 3in1-kit\iot_project\7.
Page 324
SunFounder 3in1 Kit Note: If the message ESP is not responding appears when you connect, please follow these steps. • Make sure the 9V battery is plugged in. • Reset the ESP8266 module by connecting the pin RST to GND for 1 second, then unplug it.
Page 325
SunFounder 3in1 Kit How it works? The function BLYNK_WRITE(V0) gets the status of the Switch widget and assigns it to the variable doorFlag, which will be used to determine if the smart gate system is enabled or not. BLYNK_WRITE(V0) doorFlag param.asInt();...
Page 326
SunFounder 3in1 Kit (continued from previous page) currentState digitalRead(irPin); // 0:obstacle 1:no-obstacle (currentState && lastState 1) { count=(count+1)%10; Blynk.virtualWrite(V8, count); showNumber(count); operateGate(true); else if ((currentState && lastState 0)) { operateGate(false); lastState currentState; The function showNumber(int num) is used to make the 7-segment display show the value.
SunFounder 3in1 Kit 6.8 8. IoT Car We used the Blynk APP on the cell phone to control the car for this project. But you need to refer to Car Projects assemble the car and to get a basic understanding of it. In the era of 5G network popularity, this mode may become one of the main production methods in many industries, so let’s experience this play in advance.
Page 328
SunFounder 3in1 Kit 2. Create a Datastream of type Virtual Pin to record the Y-axis value of the joystick. Set NAME to Yvalue, DATA TYPE to Integer, MIN and MAX to -10 and 10. Chapter 6. IoT Projects...
Page 329
SunFounder 3in1 Kit Next you need to do the following on your phone. 1. Search for “Blynk IoT” (not Blynk(legacy)) in GOOGLE Play or APP Store to download it. 2. After opening the APP, sign in, this account should be the same as the account used on the web client.
Page 330
SunFounder 3in1 Kit 4. Click Edit Icon. 5. Click on the blank area. 6. Select a Joystick widget. Chapter 6. IoT Projects...
Page 331
SunFounder 3in1 Kit 7. Now you will see a Joystick widget appear in the blank area, click on it. 8. Joystick Settings will appear, select the Xvalue and Yvalue you just set in the datastreams. 9. Go back to the Dashboard page and you can operate the Joystick when you want.
Page 332
SunFounder 3in1 Kit 3. Run the Code 1. Open the 8.iot_car.ino file under the path of 3in1-kit\iot_project\8.iot_car, or copy this code into Arduino IDE. 2. Replace the Template ID, Device Name, and Auth Token with your own. You also need to enter the ssid and password of the WiFi you are using.
Page 333
SunFounder 3in1 Kit Note: If the message ESP is not responding appears when you connect, please follow these steps. • Make sure the 9V battery is plugged in. • Reset the ESP8266 module by connecting the pin RST to GND for 1 second, then unplug it.
Page 334
SunFounder 3in1 Kit How it works? These functions are used to control the movement of the car. void moveForward(int speed) {...} void moveBackward(int speed) {...} void turnRight(int speed) {...} void turnLeft(int speed) {...} void stopMove() {...} The IoT section reads the values of the Joystick widget and assigns them to the variables Xvalue and Yvalue.
Page 335
SunFounder 3in1 Kit (continued from previous page) turnRight(150); else if (Xvalue <= -5) { turnLeft(150); else stopMove(); Also, add a network status determination to loop() to light up an LED if it is connected to Blynk Cloud. (!Blynk.connected()) { digitalWrite(ledPin, LOW);...
CHAPTER SEVEN 7.1 How to use Blynk on mobile device? Note: As datastreams can only be created in Blynk on the web, you will need to reference different projects to create datastreams on the web, then follow the tutorial below to create widgets in Blynk on your mobile device. 1.
Page 338
SunFounder 3in1 Kit 7. Now you will see a Joystick widget appear in the blank area, click on it. 8. Joystick Settings will appear, select the Xvalue and Yvalue datastreams you just set in the web page. Note that each widget corresponds to a different datastream in each project.
SunFounder 3in1 Kit 7.2 How to re-burn the firmware for ESP8266 module? 7.2.1 Re-brun the Firmware with R4 1. Build the circuit Connect ESP8266 and Arduino UNO R4 board. 2. Upload the Following Code to R4 void setup() { Serial.begin(115200);...
Page 340
SunFounder 3in1 Kit (continued from previous page) (Serial1.available()) { // If anything comes in Serial1 (pins 0 & 1) Serial.write(Serial1.read()); // read it and send it out Serial (USB) 3. Burning the firmware • Follow the steps below to burn the firmware if you are using Windows.
Page 341
SunFounder 3in1 Kit – Reopen the install.bat file. • To burn the firmware, follow these steps if you are using a Mac OS system. 1. Use the following commands to install Esptool. Esptool is a Python-based, open-source, platform- independent utility to communicate with the ROM bootloader in Espressif chips.
Page 342
SunFounder 3in1 Kit – Whether the computer has recognized your board properly, and make sure the port is not occupied. – Reopen the install.bat file. 4. Test 1. On the basis of the original wiring, connect IO1 to 3V3. 2. You will be able to see information about the ESP8266 module if you click the magnifying glass icon(Serial Monitor) in the upper right corner and set the baud rate to 115200.
Page 343
SunFounder 3in1 Kit Note: • If ready doesn’t appear, you can try to reset the ESP8266 module(connect RST to GND) and re-open the Serial Monitor. 3. Click on NEWLINE DROPDOWN BOX, select both NL & CR in the drop down option, enter AT, if it returns OK, it means ESP8266 has successfully established connection with your board.
Page 344
SunFounder 3in1 Kit 7.2.2 Re-brun the Firmware with R3 1. Build the circuit Connect ESP8266 and SunFounder R3 board. 2. Burning the firmware • Follow the steps below to burn the firmware if you are using Windows. 1. Download firmware and burn-in tool.
Page 345
SunFounder 3in1 Kit Note: If the burn-in fails, please check the following points. – Reset the ESP8266 module by inserting the RST on the ESP8266 Adapter to GND and then unplugging it. – Check if the wiring is correct. – Whether the computer has recognized your board properly, and make sure the port is not occupied.
Page 346
SunFounder 3in1 Kit – esptool.exe: This is a command-line utility for Windows. – install_r3.bat: This is the command package for Windows system. – install_r4.bat: Same as install_r3.bat, but dedicated to UNO R4 board. 5. Open a terminal and use the cd command to go into the firmware folder you just downloaded, then run the following command to erase the existing firmware and re-burn the new firmware.
Page 347
SunFounder 3in1 Kit 2. You will be able to see information about the ESP8266 module if you click the magnifying glass icon(Serial Monitor) in the upper right corner and set the baud rate to 115200. Note: • If ready doesn’t appear, you can try to reset the ESP8266 module(connect RST to GND) and re-open the Serial Monitor.
Page 348
SunFounder 3in1 Kit 3. Click on NEWLINE DROPDOWN BOX, select both NL & CR in the drop down option, enter AT, if it returns OK, it means ESP8266 has successfully established connection with R3 board. Now you can continue to follow to set the working mode and baud rate of the ESP8266 1.1 Configuring the ESP8266...
CHAPTER EIGHT THANK YOU Thanks to the evaluators who evaluated our products, the veterans who provided suggestions for the tutorial, and the users who have been following and supporting us. Your valuable suggestions to us are our motivation to provide better products! Particular Thanks •...
NINE COPYRIGHT NOTICE All contents including but not limited to texts, images, and code in this manual are owned by the SunFounder Company. You should only use it for personal study, investigation, enjoyment, or other non-commercial or nonprofit purposes, under the related regulations and copyrights laws, without infringing the legal rights of the author and relevant right holders.
Need help?
Do you have a question about the 3in1 Kit and is the answer not in the manual?
Questions and answers