Ks0353 keyestudio KEYBOT Coding Education Robot for Arduino STEM: Difference between revisions
Keyestudio (talk | contribs) |
Keyestudio (talk | contribs) |
||
Line 458: | Line 458: | ||
=====Interface Functions of Mixly===== | =====Interface Functions of Mixly===== | ||
'''System Functions''' | '''System Functions'''<br> | ||
Look at the main interface of Mixly, it includes five parts, that is, Blocks selection, code edit, text code (hidden), system function and message prompt area. Shown below. | Look at the main interface of Mixly, it includes five parts, that is, Blocks selection, code edit, text code (hidden), system function and message prompt area. Shown below. | ||
<br>[[Image:3.1-1.png|800px|frameless]]<br> | <br>[[Image:3.1-1.png|800px|frameless]]<br> | ||
Line 468: | Line 468: | ||
<br> | <br> | ||
'''''In/Out Block''''' | '''''In/Out Block'''''<br> | ||
[[Image:3.2-1.png|800px|frameless]]<br> | [[Image:3.2-1.png|800px|frameless]]<br> | ||
Line 551: | Line 551: | ||
<br> | <br> | ||
'''Control Block''' | '''Control Block'''<br> | ||
[[Image:Control.PNG|800px|frameless]]<br> | [[Image:Control.PNG|800px|frameless]]<br> | ||
Line 631: | Line 631: | ||
<br> | <br> | ||
''' Math Block''' | ''' Math Block'''<br> | ||
[[Image:3.4.png|900px|frameless]]<br> | [[Image:3.4.png|900px|frameless]]<br> | ||
Line 708: | Line 708: | ||
<br> | <br> | ||
'''Text Block''' | '''Text Block'''<br> | ||
[[Image:3.5.png|900px|frameless]]<br> | [[Image:3.5.png|900px|frameless]]<br> | ||
Line 779: | Line 779: | ||
<br> | <br> | ||
'''List Block''' | '''List Block'''<br> | ||
[[Image:3.6.png|800px|frameless]]<br> | [[Image:3.6.png|800px|frameless]]<br> | ||
Line 818: | Line 818: | ||
<br> | <br> | ||
'''Logic Block''' | '''Logic Block'''<br> | ||
[[Image:3.7.png|900px|frameless]]<br> | [[Image:3.7.png|900px|frameless]]<br> | ||
Line 869: | Line 869: | ||
'''Variable Block''' | '''Variable Block'''<br> | ||
[[Image:3.8.png|900px|frameless]]<br> | [[Image:3.8.png|900px|frameless]]<br> | ||
Line 899: | Line 899: | ||
<br> | <br> | ||
'''SerialPort Block''' | '''SerialPort Block'''<br> | ||
[[Image:3.9.png|900px|frameless]]<br> | [[Image:3.9.png|900px|frameless]]<br> | ||
Line 982: | Line 982: | ||
<br> | <br> | ||
'''Communicate Block''' | '''Communicate Block'''<br> | ||
[[Image:Communicate.PNG|900px|frameless]]<br> | [[Image:Communicate.PNG|900px|frameless]]<br> | ||
Line 1,029: | Line 1,029: | ||
<br> | <br> | ||
'''Sensor Block''' | '''Sensor Block'''<br> | ||
[[Image:Sensor.PNG|1000px|frameless]]<br> | [[Image:Sensor.PNG|1000px|frameless]]<br> | ||
Line 1,066: | Line 1,066: | ||
<br> | <br> | ||
'''Actuator Block''' | '''Actuator Block'''<br> | ||
[[Image:Actuator.PNG|1000px|frameless]]<br> | [[Image:Actuator.PNG|1000px|frameless]]<br> | ||
Line 1,109: | Line 1,109: | ||
'''Monitor Block''' | '''Monitor Block'''<br> | ||
[[Image:Monitor.PNG|900px|frameless]]<br> | [[Image:Monitor.PNG|900px|frameless]]<br> | ||
Line 1,178: | Line 1,178: | ||
<br> | <br> | ||
'''Functions Block''' | '''Functions Block'''<br> | ||
[[Image:Function.PNG|800px|frameless]]<br> | [[Image:Function.PNG|800px|frameless]]<br> | ||
Line 1,214: | Line 1,214: | ||
<br> | <br> | ||
'''''Software Resources''''' | '''''Software Resources'''''<br> | ||
You can download the Mixly package from the link:<br> | You can download the Mixly package from the link:<br> | ||
https://drive.google.com/open?id=1oQxF-AZ0Aw6OQhu_8NSvwo3L2OP0Z6cU<br> | https://drive.google.com/open?id=1oQxF-AZ0Aw6OQhu_8NSvwo3L2OP0Z6cU<br> |
Revision as of 11:14, 13 September 2018
KEYBOT Overview
In the near future, many things might no longer be done by ourselves because the robots are able to help us do many things. So what does the future robot look like? What can it do?
He may be controlled by human voice. Do not use the remote control. Just press the power button and the robot will start do something you said and never get tired.
In addition to cooking, there may be another magical feature. In the summer, the weather is very hot. At this time, you definitely want to drink a glass of juice. As long as you give orders, the robot will pick up the fruit and put it in his body. After a while, there will be juice to drink, and he can freeze the juice. The taste is more delicious. Robots also have a lot of magical features that allow you to enjoy a simple, fast lifestyle, and the future robots will become more excellent.
Now, let’s DIY the KEYBOT robot. The KEYBOT robot is based on easy-to-use and flexible open-source Arduino platform. KEYBOT control board comes with the RJ11 plug, so it is very easy to connect other sensor modules with only one cable.
The robot is designed in metal structure, solid and durable. The assembly is really simple, believing you can install well the KEYBOT within 30mins.
As for the KEYBOT coding, you will learn how to get started with Arduino programming C language and Mixly block platform. Even the beginner with no coding experience can easily understand the graphical program. Take your brain on an inspiring journey through the world of programming. Get started now!
KEYBOT Parameters
- External power supply range: 7-12V
- Current Range: minimum 800mA
- Motor Speed: 6.0V 100rpm/min
- Motor control is driven by TB6612
- Three groups of line tracking modules, to detect black-white line with higher accuracy and can be used for anti-fall control as well.
- Ultrasonic module is used to detect the obstacle distance, avoiding the front obstacle when the distance detected is less than a certain value.
- Bluetooth wireless module can be paired with Bluetooth device on mobile phone to remotely control the KEYBOT. Turn off the Bluetooth when programming.
- The shield has two servo interfaces.
- Can access the external voltage 7~12V.
Part List
You can see a pretty beautiful packaging box for the KEYBOT, and inside the KEYBOT packaging you will find all the parts and screws listed below.
No. | Component | Quantity | Picture |
---|---|---|---|
1 | KEYBOT Control Board
(Includes: 2pcs acrylic plate; 4pcsM3*15double-pass copper pillars; 8pcsM3*10 inner hex screws; 1pcs 50cm Blue USB cable) |
1 | |
2 | KEYBOT Ultrasonic Sensor | 1 | |
3 | KEYBOT Line Tracking Sensor | 1 | |
4 | Keyestudio Bluetooth Module-(HC-06) | 1 | |
5 | W420 steel universal wheel | 1 | |
6 | single shaft gear motor with 2.54-socket KF2510-2P red-black lead 200mm Right motor | 1 | |
7 | single shaft gear motor with 2.54-socket KF2510-2P red-black lead 140mm Left motor | 1 | thumb |
8 | 18650 2-cell Battery Case | 1 | |
9 | black-white 6515 robot wheel | 1 | |
10 | Single-pass M3*25+5MMhex copper pillar | 4 | |
11 | Screw M2*10MM round head | 4 | |
12 | M3*8MM flat-head screw | 4 | |
13 | M3*8 stainless steel inner hex screw | 6 | |
14 | M3*10MM stainless steel inner hex screw | 4 | |
15 | Nut M3 nickle plating | 12 | |
16 | KEYBOT body black holder | 1 | |
17 | Yellow-black handle 3*40MM Phillips Screwdriver | 1 | |
18 | 6-cell AA Battery Case | 1 | |
19 | EASY plug white Piranha LED module | 1 | |
20 | 6P6CRJ11 cable 10CM blue and eco-friendly | 1 | thumb |
21 | 6P6CRJ11 cable 20CM blue and eco-friendly | 1 | |
22 | L-type M2.5 Nickel plated Allen wrench | 1 |
Assembly Guide
Follow the assembly steps below to build your own robot, believe you will be full of delight to experience the robot DIY. If still confused, you are able to see the assembly video. (1) Begin with the KEYBOT body part. Firstly, you should prepare the components as follows:
- Keyestudio KEYBOT body holder *1
- M3*8 stainless steel inner hex screw *4
- M3*15 double-pass copper pillar *4
thumb
Then, fix the four M3*8 screws and four M3*15 copper pillars on the KEYBOT body holder.
thumb thumb
(2) Then install the motors for the robot, and prepare the components as follows:
- Gear motor *2
- M3*30MM round-head screw *4
- M3 Nickel plated nut *4
Firstly, place the KEYBOT body holder as below.
thumb
Mount the gear motor with short lead on the left of holder, and mount another motor with longer lead on the right of holder.
thumb
(3) Completed the above assembly, let's install the wheels for the KEYBOT.
- 6515 wheel *2
Mount the two 6515 wheels into the two gear motors.
thumb
thumb
(4) Now you should install the particular eye for the robot, i.e. Ultrasonic module. You should prepare the components as follows:
- M3*8 stainless steel hex screw *2
- M3 Nickel plated nut *2
- Ultrasonic Sensor *1
Mount the Ultrasonic sensor on the KEYBOT body holder using two M3*8 screws and two M3 Nuts.
thumb
thumb
(5) In the following section, assemble the line tracking sensor and W420 steel ball wheel.
- M3*10MM stainless steel hex screw *2
- M3 Nickel plated nut *2
- Line tracking sensor *1
- W420 steel universal wheel *1
Firstly mount the line tracking sensor on the bottom of KEYBOT body holder with two M3*8 screws.
thumb
Then fix the W420 wheel to the line tracking sensor with two M3 Nuts. Shown below.
thumb
(6) Fix the battery case on the KEYBOT body holder. Here you can choose the 18650 2-cell battery case or 6-cell AA battery case. The assembly method for 18650 2-cell battery case as below.
- M3*8MM flat-head screw *2
- M3 Nickel plated nut *2
- 18650 2-cell battery case *1
Mount the 2-cell battery case on the back of KEYBOT body holder with two M3*8MM flat-head screws and two M3 Nuts.
thumb
If you would like to install the 6-cell AA battery case, you can refer to below.
- M3*8MM flat-head screw *2
- M3 Nickel plated nut *2
- 6-cell AA battery case *1
(7) Completed the above assembly, then fix the KEYBOT control board on the robot body holder.
- M3*25+5MM single-pass copper pillar *4
- KEYBOT control board *1
thumb
Mount the KEYBOT control board on the top of KEYBOT body holder with four M3*25+5MM single-pass copper pillars.
thumb
(8) Next step is to install the Acrylic top panel on the control board.
- M3*10MM stainless steel hex screw *4
- Acrylic top panel *1
thumb
Mount the Acrylic top panel onto the control board with four M3*10MM screws.
thumb
(9) Till now, the robot parts are installed well. Final step is to connect the wire.
- 6P6C RJ11 cable 10CM *1
- 6P6C RJ11 cable 20CM *1
Hookup Guide:
Connect the both ultrasonic sensor and line tracking sensor to KETBOT control board.
Connect the ultrasonic sensor to the connector A0-D2 using the RJ11 cable 10cm.
Connect the line tracking sensor to the connector A1-A2-A3 using the RJ11 cable 20cm.
Connect the motor with short lead to MA, and connect another motor with longer lead to MB.
The battery case is connected to the DC-IN connector of control board.
thumb
thumb
Finally, plug the HC-06 Bluetooth module into the control board.
Congrats! You have completed the KEYBOT robot installation.
In the sections below, follow our step-by-step project instructions to perform some amazing functions.
Robot Projects
Project 1: Getting Started with ARDUINO
1) CorePart of Robot
The core is the part that really matters today. In fact, it is very easy to understand the core. In other word, the core is just like the human brain. It can receive various kinds of information every day and will send out various instructions every day. Thecore part of our robot is a control board specially designed for KEYBOT. It integrates both ARDUINO and motor driver, so the use method of this integrated board is the same as the ARDUINO controller. Well, let's first look at what every element and interface of the board does:
Installing Arduino IDE
When you get theUNO development board, first you should install the software and driver of Arduino. Here you can browse the ARDUINO website at this link, https://www.arduino.cc, pop up the following interface.
Then click the SOFTWARE on the browse bar, you will have two options ONLINE TOOLS and DOWNLOADS.
Click DOWNLOADS, it will appear the latest software version of ARDUINO 1.8.5 shown as below.
In this software page, on the right side you can see the version of development software for different operating systems. So ARDUINO has a rather powerful compatibility. You should download the software that is compatible with the operating system of your computer.
In our project, we will take WINDOWS system as an example here. There are also two options under Windows system, one is installed version, the other is non-installed version.
For simple installed version, first click Windows Installer, you will get the following page.
This way you just need to click JUST DOWNLOAD, then click the downloaded file to install it.
For non-installed version, first click Windows ZIP file, you will also get the pop-up interface as the above figure.
Click JUST DOWNLOAD, and when the ZIP file is downloaded well to your computer, you can directly unzip the file and then click the icon of ARDUINO program to start it.
Installing Arduino (Windows)
Install Arduino with the exe. Installation package
Click“I Agree”to see the following interface.
Click “Next”. Pop up the interface below.
You can press Browse… to choose an installation path or directly type in the directory you want.
Then click “Install” to initiate installation.
Wait for the installing process, if appear the interface of Window Security, just continue to click Install to finish the installation.
All right, up to now, you have completed the Arduino setup! The following icon will appear on your PC desktop.
Double-click the icon of Arduino to enter the desired development environment shown as below.
Installing Driver
Next, we will introduce the driver installation of UNO R3 development board. The driver installation may have slight differences in different computer systems. So in the following let’s move on to the driver installation in the WIN 7 system.
The Arduino folder contains both the Arduino program itself and the drivers that allow the Arduino to be connected to your computer by a USB cable. Before we launch the Arduino software, you are going to install the USB drivers.
Plug one end of your USB cable into the Arduino and the other into a USB socket on your computer.
When you connect UNO board to your computer at the first time, right click the icon of your “Computer” —>for “Properties”—> click the “Device manager”, under “Other Devices”, you should see an icon for“Unknown device” with a little yellow warning triangle next to it. This is your Arduino.
Then right-click on the device and select the top menu option (Update Driver Software...) shown as the figure below..
It will then be prompted to either “Search Automatically for updated driversoftware” or “Browse my computer for driver software”. Shown as below. In this page, select “Browse my computer for driver software”.
After that, select the option to browseand navigate to the “drivers” folder of Arduino installation.
Click “Next” and you may get a security warning, if so, allow the software to be installed. Shown as below.
Once the software has been installed, you will get a confirmation message. Installation completed, click “Close”.
Up to now, the driver is installed well. Then you can right click “Computer” —>“Properties”—>“Device manager”, you should see the device as the figure shown below.
2) Example Use of ARDUINO IDE
STEP 1: Open Arduino
In the previous, we have introduced the driver installation of UNO R3 development board. So this time let’s first have basic understanding of the development environment of ARDUINO. After master that, we are about to upload the program to Arduino board.
First of all, open the unzipped folder of ARDUINO development software and click icon of ARDUINO to open the software, as the figure shown below.
STEP 2: Build Projects
When open the Arduino software, you will have two options as below:
- Build a new project
- Open an exiting project example
If you want to build a new project, please select “File”→then click “New”, you will see the software interface as follows.
If you want to open an example project, please select File→Example→Basics→Blink. Shown below.
STEP 3: Select Arduino Board
In order to avoid any mistakes during the process of uploading the code to the board, you must first select the correct Arduino board that matches the board connected to your computer.
Or you can directly open the Control Panel of your computer, then click to open Device Manager, you can check your board and port here. Shown as below.
Then come back to the Arduino software, you should click Tools→Board , select the correct board. Here in our tutorial we should select Arduino Uno. Shown as below.
STEP 4: Select Serial Port
Next, we should select the serial device of Arduino board. You can click Tools→Serial Port. It may be COM3 or higher (COM1 and COM2 are usually reserved as hardware serial port). If you want to find out your Arduino board, you could disconnect your Arduino board, then reopen the menu, you will see the Arduino board disappear. After that reconnect the board and select the serial port.
You should select the correct Serial port that matches the port showed on the Device Manager of your computer.
The figure shown below is only for your reference.
Attach your Arduino board to your computer with the USB cable and check that the “Board Type” and “Serial Port” are set correctly.
STEP 5: Upload the Code to Your Board
Before showing you how to upload the code to your board, first of all let me introduce the function of each icon on the Tool bar of Arduino IDE. Look at the picture showed below.
3) Getting Started with Mixly
In the previous section, you have learned the ARDUINO. Next you will learn about Mixly block software.
Introduction:
Mixly is a free open-source graphical Arduino programming software, based on Google’s Blockly graphical programming framework, and developed by Mixly Team@ BNU.
It is a free open-source graphical programming tool for creative electronic development; a complete support ecosystem for creative e-education; a stage for maker educators to realize their dreams.
Although there is an Ardublock graphical programming software launched by Arduino official, Ardublock is not perfect enough, and many common functions cannot be realized.
Design Concept
(1) Usability
Mixly is designed to be completely green. Currently Mixly supports win, ubuntu, mac. Windows users can download the Mixly package directly from the Internet, and unzip it to run on Windows XP and above (download link is attached below).
(2) Simplicity
Mixly uses the Blockly graphical programming engine to replace complex text manipulation with graphical building blocks, providing a good foundation for beginners to get started quickly.
① Use the different color icons to represent different types of functional blocks, very convenient for users to classify.
② Provide default options in the composite function block to effectively reduce the number of user drags.
③ Integrate all the features of the software in the same interface.
④ Provide the reference tutorial and code examples.
(3) Functionality
It has versatile functions. Mixly can almost implement all the functions that Arduino IDE has. Support all official development boards of arduino.
(4) Continuity
The goal of the graphical programming system is definitely not to replace the original text programming method, but to better understand the programming principles and program thinking through graphical programming, and lay the foundation for future text programming.
It is also the design philosophy for Mixly. More continuous content has been added to the design of the software to protect the user's learning outcomes. To be specific, it includes the introduction of variable types, the consistency of text programming as much as possible in the design of the module, and the support of both graphical and text programming.
(5) Ecological
The most important design concept of Mixly is its ecological feature, which can distinguish it from other Arduino graphical programming.
In order to achieve sustainable development, Mixly is designed to allow manufacturers to develop their own unique modules (currently supports DfRobot, StartLab, MakeBlock, Sense, Seeed, Lubot. But users require JavaScript programming foundation to make this part of the module).
It also allows users directly use Mixly's graphical programming function to generate common modules (such as LED digital display, buzzer broadcast, etc. Users are able to make this part of the module only using Mixly).
Both of the two kinds of modules mentioned above can be imported into the Mixly system through the "Import" function, thereby realizing the user's own value in the popularity of Mixly software.
User Groups
From the above design concept, it can be seen that Mixly is suitable for primary and secondary school students to cultivate programming thinking. It is also available for quick programming when creating a work. Of course, it is good for those lovely friends who don't want to learn text programming, but want to do some small works with intelligent control.
Interface Functions of Mixly
System Functions
Look at the main interface of Mixly, it includes five parts, that is, Blocks selection, code edit, text code (hidden), system function and message prompt area. Shown below.
Some common functions:
Through this interface, you can complete the code compile、upload、save and manage. It support four remove methods: drag it left out code window, or drag to Recycle Bin, delete key, or right-click to delete block. It supports four languages: English、Español (Spanish)、中文简体(Chinese Simplified)、中文繁体(Chinese Traditional).
For example:
Connect your Arduino Uno board, then follow the steps below to light the Pin13 led on Arduino UNO.
No. | BLOCK ICON | DEFINITION |
---|---|---|
1 | Initialization (run only once) | |
2 | End the program, means the program will stop running when use this block. | |
3 | Delay function, click to select ms or us (pause the program for the amount of time (in milliseconds) specified as parameter. There are 1000 milliseconds in a second.) | |
4 | if_do function (first evaluate a value be true or false, if a value is true, then do some statement. You can click the blue gear icon to select the else if block or else block.) | |
5 | switch function. You can click the blue gear icon to select the case block or default block. (used to evaluate several programs then execute the corresponding function matched with program.) | |
6 | Equal to for statement. | |
7 | A while loop statement. | |
8 | break function, used to exit from the containing loop. | |
9 | millis() function, returns the system running time since the program started.
(The unit can be ms (milliseconds) or μs(microsecond)). | |
10 | Timer interrupt function, that is, set a trigger interrupt for the amount of time (in milliseconds) specified as parameter. | |
11 | Timer interrupt start block | |
12 | Timer interrupt stop block |
For example:
Compile and upload the program below to your Arduino board, you should see Pin13 LED on Arduino UNO continue to flash.(with an interval of 1s, equal to 1000ms)
No. | BLOCK ICON | DEFINITION |
---|---|---|
1 | A number | |
2 | Click to select the Arithmetic Operators: +(addition);
-(subtraction);
x (Multiplication); ÷(division); %(remainder);
^(bitwise xor) | |
3 | Click to select the & (bitwise end); l (bitwise or); << (bitshift left); >> (bitshift right) | |
4 | Click to select the sin; cos; tan; asin; acos; atan; ln; log10; e^; 10^; ++ (increment) ; | |
5 | Click to select the Round; Ceil; Floor; abs; sq; sqrt Round: Returns the integer part a number using around. | |
6 | If select the max, returns the larger number; if select the min, returns the smaller number. | |
7 | Initialize the random seed | |
8 | Return a random integer between the two specified limits, inclusive. | |
9 | Constrain a number to be between the specified limits (inclusive). (generally used to constrain an analog value read from sensor) | |
10 | Map a number from the first interval to the second interval. (For instance, potentiometer-controlled servo, map the range of potentiometer (0, 1023) to the angle of servo (0, 180)). |
No. | BLOCK ICON | DEFINITION |
---|---|---|
1 | Declare and initialize a variable. | |
2 | Define the data types |
For example: LED breath
You need an Arduino Uno and one LED module. Connect the control pin of LED module to Pin 3 of Uno board (or other pins with “~”,that is, those pins can output PWM signal). LED will gradually light then gradually dim, repeatedly.
For example: serial communication
Done uploading the code, open the Arduino monitor, then enter a “hello” on the top bar, and click Send, it will print out “hello,world”.
For example:
You need an Arduino Uno board, an IR receiver module and an IR remote control.
Connect the signal pin of IR receiver to Digital pin 3 of Uno board, then upload the code and open the monitor. If send a signal to an IR receiver module using an IR remote control, you should see the monitor show the corresponding signal data.
For example: ultrasonic ranging
Connect the Trig pin of ultrasonic sensor to Digital 1 of Uno, Echo pin to D2, then upload the code and open the monitor, you should see the distance value, updating once per 100ms.
For example:
Connect the signal end of servo to Digital 0 of Uno, then upload the code below, servo will rotate 90 degrees.
Note: Delay 100ms is the time required for servo to move.
For example: serial communication
Separately connect the SDA (A4) and SCL (A5) of Arduino Uno to SDA and SCL pins of IIC LCD1602, then set the address of your LCD1602 screen, the LCD address we used here is 0x27. Then upload the code, LCD screen has two lines, you should see the line 1 print HELLO, and line 2 print 123456789.
For example: ultrasonic ranging
Below is an example code for line tracking car. We use three tracking modules (left to D6, middle to D7, right to D8). of course you need a tracking car to test it. First edit the forward, backward, turn left, turn right and stop into functions block. Then compile and upload the code below.
Software Resources
You can download the Mixly package from the link:
https://drive.google.com/open?id=1oQxF-AZ0Aw6OQhu_8NSvwo3L2OP0Z6cU
Or check on this link: https://pan.baidu.com/s/1dE3Z6db#list/path=%2FMixly_Arduino
You can click the link below to see the details:
http://wiki.keyestudio.com/index.php/Getting_Started_with_Mixly
4) Light up LED
In the above sections, we have introduced the Mixly block software. Want to have a try? Great, let’s get started from a more basic program, lighting up the LED.
Here we will use our keyestudio EASY plug white Piranha LED module.
The wiring is pretty simple. You can connect the EASY plug Piranha LED module to the KETBOT control board using only an RJ11 cable.
Hookup as the above diagram, next we will show the first program to light up the LED module, making LED on for one second then off for one second, repeatedly.
Test Code 1:
When upload well the code to the board, you will see the status at the bottom show “Upload success! ”. And the LED on the module lights up for one second, then off for one second, repeatedly. Congrats! The first program is completed successfully.
5) LED Brightness Controlled by PWM
Overview: In the previous lesson, you have learned how to turn on or off the LED. Furthermore, you may be interested in changing the brightness of LED light, just like your bedside lamp. It is indeed important for you to master the knowledge of PWM. PWM is short for Pulse Width Modulation. How can it be understood in a simple way? We all know that the voltage output of Arduino Digital port only has two states, LOW and HIGH, corresponding to the voltage output of 0V and 5V. If merely make use of LOW and HIGH state, it cannot control the brightness of an LED light. However, if convert the voltage output of 0 Volts and 5 Volts into the value within 0-255, this way you can change the value within 0-255 to control the brightness of light. It is much more feasible, right? Pulse Width Modulation, or PWM, is a technique for getting analog results with digital means. Digital control is used to create a square wave of different duty cycle, a signal switched between on and off. This on-off pattern can simulate voltages in between full on (5 Volts) and off (0 Volts) by changing the portion of the time the signal spends on versus the time that the signal spends off. The Arduino UNO has totally 6 PWM outputs, which are Digital 3, 5, 6, 9, 10 and 11.
These PWM pins can be used as Digital output or Analog output. If used as Analog output, need to call the Mixly block
And this analogWrite() function can be controlled in the range of 0-255.
In the graphic below, the green lines represent a regular time period. This duration or period is the inverse of the PWM frequency. In other words, with Arduino's PWM frequency at about 500Hz, the green lines would measure 2 milliseconds each.
A call to analogWrite() is on a scale of 0-255, such that analogWrite(255) requests a 100% duty cycle (always on), and analogWrite(127) is a 50% duty cycle (on half the time) for example.
PWM can be applied to lots of applications, like dimming lamps, motor speed, sound production, etc.
In the following, you will learn how to control the light brightness?
Firstly, you can connect the EASY plug Piranha LED module to KETBOT coding control board with only a 6P6C RJ11 cable. In fact, it works on either D11 or D9-D10 connector. (If connecting the D11 to test the LED, D9-D10 cannot be used.)
Below is a wiring diagram used to control the LED brightness.
AnalogWrite(pin,value); Writes an analog value (PWM wave) to a pin 11. It has two parameters:
- PIN#: the pin to write to. Allowed data types: int.
- value: the duty cycle: between 0 (always off) and 255 (always on). Allowed data types: int
Can be used to light a LED at varying brightnesses or drive a motor at various speeds. After a call to analogWrite(), the pin will generate a steady square wave of the specified duty cycle until the next call to analogWrite() (or a call to digitalRead() or digitalWrite()) on the same pin. The frequency of the PWM signal on most pins is approximately 490 Hz.
Furthermore, in the motor driving project below, it also involves the PWM.