Mixly Projects

From Keyestudio Wiki
Revision as of 13:37, 28 April 2020 by Keyestudio (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search


Getting Started with Hardware Projects


Project 1: Built-in LED

When it comes to using the REV4 as core of our robot, the REV4 is the best board to get started with electronics and coding.
If this is your first experience tinkering with the platform, the REV4 is the most robust board you can start playing with.
Well, let's at first have a look at this.

Here is an explanation chart of what every element and interface of the board does:
KS0341 引脚标图.jpg

KS0001 5-1.png ICSP (In-Circuit Serial Programming) Header

In most case, ICSP is the AVR,an Arduino micro-program header consisting of MOSI, MISO, SCK, RESET, VCC, and GND. It is often called the SPI (serial peripheral interface) and can be considered an "extension" of the output. In fact, slave the output devices under the SPI bus host.
When connecting to PC, program the firmware to ATMEGA328P-PU.

KS0001 5-2.png Power LED Indicator

Powering the Arduino, LED on means that your circuit board is correctly powered on. If LED is off, connection is wrong.

KS0001 5-3.png Digital I/O

Arduino REV4 has 14 digital input/output pins (of which 6 can be used as PWM outputs). These pins can be configured as digital input pin to read the logic value (0 or 1). Or used as digital output pin to drive different modules like LED, relay, etc. The pin labeled “〜” can be used to generate PWM.

KS0001 5-4.png GND ( Ground pin headers)

Used for circuit ground

KS0001 5-5.png AREF

Reference voltage (0-5V) for analog inputs. Used with analogReference().

KS0001 5-6.png SDA

IIC communication pin

KS0001 5-7.png SCL

IIC communication pin

KS0001 5-8.png ICSP (In-Circuit Serial Programming) Header

In most case, ICSP is the AVR,an Arduino micro-program header consisting of MOSI, MISO, SCK, RESET, VCC, and GND. Connected to ATMEGA 16U2-MU. When connecting to PC, program the firmware to ATMEGA 16U2-MU.

KS0001 5-9.png RESET Button

You can reset your Arduino board, for example, start the program from the initial status. You can use the RESET button.

KS0001 5-10.png D13 LED

There is a built-in LED driven by digital pin 13. When the pin is HIGH value, the LED is on, when the pin is LOW, it's off.

KS0001 5-11.png USB Connection

Arduino board can be powered via USB connector. All you needed to do is connecting the USB port to PC using a USB cable.

KS0001 5-12.png ATMEGA 16U2-MU

USB to serial chip, can convert the USB signal into serial port signal.

KS0001 5-13.png TX LED

Onboard you can find the label: TX (transmit) When Arduino board communicates via serial port, send the message, TX led flashes.

KS0001 5-14.png RX LED

Onboard you can find the label: RX(receive ) When Arduino board communicates via serial port, receive the message, RX led flashes.

KS0001 5-15.png Crystal Oscillator

Helping Arduino deal with time problems. How does Arduino calculate time? by using a crystal oscillator.
The number printed on the top of the Arduino crystal is 16.000H9H. It tells us that the frequency is 16,000,000 Hertz or 16MHz.

KS0001 5-16.png Voltage Regulator

To control the voltage provided to the Arduino board, as well as to stabilize the DC voltage used by the processor and other components.
Convert an external input DC7-12V voltage into DC 5V, then switch DC 5V to the processor and other components.

KS0001 5-17.png DC Power Jack

Arduino board can be supplied with an external power DC7-12V from the DC power jack.

KS0001 5-18.png IOREF

Used to configure the operating voltage of microcontrollers. Use it less.

KS0001 5-19.png RESET Header

Connect an external button to reset the board. The function is the same as reset button (labeled 9)

KS0001 5-20.png Power Pin 3V3

A 3.3 volt supply generated by the on-board regulator. Maximum current draw is 50 mA.

KS0001 5-21.png Power Pin 5V

Provides 5V output voltage

KS0001 5-22.png Vin

You can supply an external power input DC7-12V through this pin to Arduino board.

KS0001 5-23.png Analog Pins

Arduino REV4 board has 6 analog inputs, labeled A0 through A5.
These pins can read the signal from analog sensors (such as humidity sensor or temperature sensor), and convert it into the digital value that can read by microcontrollers) Can also used as digital pins, A0=D14, A1=D15, A2=D16, A3=D17, A4=D18, A5=D19.

KS0001 5-24.png Microcontroller

Each Arduino board has its own microcontroller. You can regard it as the brain of your board.
The main IC (integrated circuit) on the Arduino is slightly different from the panel pair. Microcontrollers are usually from ATMEL. Before you load a new program on the Arduino IDE, you must know what IC is on your board. This information can be checked at the top of IC.



Let’s make a simple test for the REV4 built-in LED (D13).
We will work on blinking an LED. That’s right - it’s as simple as turning a light on and off!
Now enough talking - let’s get started with the LED project.

Blinking an LED
It’s pretty simple to turn a built-in led on and off. We only require REV4 control board and a USB cable to enter the wonderful programming world.
Connect your REV4 board to the computer’s USB port using a USB cable for communication.

0428图片15.png


Test Code:
Open Mixly blocks platform to get started with coding.
First, click IN/OUT, drag the “DigitalWrite PIN# (0)Stat(HIGH)” block.

0428图片16.png

This block is used to set the level HIGH or LOW of Digital pin.

  • Select HIGH is to set the HIGH level.
  • Select LOW is to set the LOW level.
  • The HIGH level is the state of high voltage, generally recorded as 1.
  • High voltage, high current, the LED lights.
  • The LOW level is the state of low voltage, generally recorded as 0.
  • Low voltage, low current, the LED Not lights.

To observe the LED blink obviously, we need to add a Delay block.
Check the test code below and upload it to your REV4 board.
0428图片17.png

What you should see:
Drag the test code to Mixly window; remember to select the proper board and COM port.
Then compile and upload the code to your control board. Upload success message will appear on the bottom bar.
The REV4 built-in LED (label “L”) will turn on for 1 second, and then turn off for 1 second, alternately and circularly.

0428图片18.png

File:File:KS0341 sy.jpg



Project 2: Light up an LED

keyestudio red LED module

In this course, we create 2 test codes. One for turning LED on and off, blinking effect; the other is to change the brightness of LED using the step and delay function in the code, simulating the breath effect.


Overview:
This is keyestudio red LED module. On the module, you will see a light emitting diode (LED), which has two states ON and OFF.
The LED module leads out three pins of 2.54mm pitch, respectively negative pin (marked -), positive pin (marked +) and signal pin (marked S).
The - pin is connected to ground, + pin is connected to VCC(3.3-5V), S pin is for signal control; you can set the High or Low level to control the LED on and off.

After programming, it will emit red light color. You can combine with other sensors to do various interactive experiments.
You can choose other LED modules to emit different light colors like blue, green, yellow and white.


Wiring Diagram:
Note: stack the motor drive shield on the REV4 board; connect red LED module to motor drive shield (pin - for GND, + for 5V, S for digital pin3 (S)). Connect the power to BAT connector.
464图片14.png


Coding:
Now write the program to make the red LED flash.
Go to “Small_Turtle_Robot” , drag out the blockP2-1.png, this block is used to set the HIGH/LOW for digital port;

Click the drop-drown triangle icon to select HIGH for digital pin, with voltage; select LOW for digital pin, with no voltage.
So what should we set the red LED pin output HIGH or LOW to turn on the LED? Through testing, set to HIGH, red LED turns on; set to LOW, red LED turns off.
Go to “Control” , drag out the blockP2-2.png;
Duplicate this piece of code string Ks0464-pro2图3.png once and set to LOW.
We turn on the red LED for one second then off for one second.


Code 1:
464图片15.png


Code 2:
The Arduino controller has 12 common digital pins (digital pin 2-13); the general digital pins can only output HIGH or LOW level.
The pin labeled “〜” is also called PWM (“Pulse-Width Modulation”) pins. The Arduino controller has totally 6 PWM outputs, which are Digital 3, 5, 6, 9, 10 and 11). The PWM pins can steadily output the HIGH and LOW level, and can continuously change HIGH or LOW in a regular time period.

The effect of LED gradually brightening and darkening is controlled by PWM. The PWM can control 0-255 "level" of voltage output.
Go to “Control” , drag out blockKs0464-pro2图4.png; here can set any random number. i is a variable. Red LED brighter is the Level variable increasing from 0 to 255. So we first set the variable i from 0 to 255 step 1.

Go to “IN/OUT” , drag the Ks0464-pro2图5.png block into the step block just made. Select pin 3 and drag a variables block Ks0464-pro2图6.png from “Variables” into the value. And add a Delay block and set to 10ms.

Ks0464-pro2图7.png

This piece of code block means the red LED is gradually brightening per 10 milliseconds with a step of 1.
What about the LED dimming? the red LED darkening is the Level variable increasing from 255 to 0.
We duplicate the above code once; set as i from 255 to 0 step -1.
Upload the complete code to see the result.


Ks0464-pro2图8.png


What you will see
Drag the test code 1 to Mixly window, compile the code and then click on the 'Upload' button.
You will see the message “Upload success” appear on the bottom bar.
Turn the slide switch to ON position.
Eventually, the LED lights up for one second, then off one second, circularly.
464图片17.png

464图片18.png


Upload Code 2 to the REV4 board; turn the slide switch to ON position.
The LED will simulate the human breath, gradually brightening and then gradually dimming, alternatively and circularly.
Ks0464-pro2图9.png



  • Little Knowledge:

1.441图15.png In the code 1, we’ve set the signal pin of LED module to D3 in the library. Or be able to randomly set the LED signal pin without library. using the block 441图16.pngalso makes sense.

2.What happens when you change the number in one or both of the delay(1000):441图17.png
This delay period is in milliseconds, so if you want the LED display as low or fast, change the value, try 2000 or 500.

3.In the code 2, we use the block 464图片23.png
The LED signal pin is connected to D3; set the PWM value to 0. The PWM value is in the range of 0-255. The greater the value set, the brighter the LED is.

4.464图片24.pngmeans the variable i increases direct from 0 to 255; each step plus 1.
464图片25.png means the variable i direct reduces direct from 255 to 0; each step minus 1.



  • Extension Practice:

1.Set the LED blink without using library; set the signal pin of LED to D11; turn on for 0.5 second, then off for 0.2 second, alternately and circularly.

Ks0464-pro2图10.png

2.Change the Code 2. Set the LED signal pin connect to D10;
When gradually brightening: PWM value increases from 0 to 255; each step plus 5; delay 30ms.
When gradually dimming: PWM value reduces from 255 to 0; each step minus 5; delay 50ms.

Ks0464-pro2图11.png


Project 3: Light up LED Matrix

464图片26.png

In the previous project, we have simply tested the LED. We now have added a new 8*8 Dot Matrix module to the turtle robot to show the moving states. Amazing display!
Do you know how is the cool advertising display made? It is exactly composed of these small LED matrix. If you want to make a similar display, this keyestudio 8*8 Dot Matrix module will meet you need.


Overview:
This tiny display has 64 LEDs packed into a 8*8 dot matrix. It integrated HT16K33 as driver chip, so with this LED matrix module, you can control it through connecting I2C communication interfaces ( A4-SDA ; A5-SCL).
It is great for displaying image/text or creating bizarre patterns, and is highly portable and convenient to use. Of course you can program it via IDE or via Mixly block. With just a few steps, you are ready to impress others!


Wiring Diagram:
Note: stack the motor drive shield on the REV4 board; connect LED matrix module to motor drive shield (pin G for GND, V for 5V, SDA for A4, SCL for A5). Connect the power to BAT connector.
464图片27.png


Coding:
Now write the program to make the LED matrix display patterns. We first set the pins then design and display the pattern.
Click “Small_Turtle_Robot” , drag out the block0464-pro3图12.png; here default SDA pin to A4, SCL pin to A5. To clear the display patterns set before, need to clear the screen.

Go to “Control” , drag out block0464-pro3图13.png, and drag the block 0464-pro3图12.png into setup block. And again drag the block 0464-pro3图15.png beneath the block just made.
Next design and display the pattern, need to call the block 0464-pro3图16.png and 0464-pro3图17.png.

For instance, tick the ledArray to show the icon you want. When tick the ledArray, it will appear the mark “√”, that is, lit the corresponding led. Here we draw a large square pattern.
Go to “Control” , drag out block441图17.png, set to delay 2000ms. And go to “Small_Turtle_Robot” , drag out the block 0464-pro3图15.png beneath the delay block. And again drag out the block0464-pro3图17.png, click the drop-down triangle to select other patterns.
0464-pro3图21.png

Then add a delay block 2000ms and a display clear block.
And duplicate the piece of code string once; click the drop-down triangle to select pattern stop2.
Upload the finished code to see the display effect!


0464-pro3-code.png


What you will see:
464图片29.png
Drag the test code to Mixly window, compile the code and then click on the 'Upload' button. You will see the message “Upload success” appear on the bottom bar.
Turn the slide switch to ON position.
You should see the keyestudio 8*8 Dot matrix show the square icon for 2 seconds, a smile face icon for 2 seconds, stop displaying for 2 seconds, alternately and circularly.
464图片30.png464图片31.png

464图片32.png



  • Little Knowledge:

1.464图片33.png In the code, we are able to set the I2C communication pin and connect to the proper pin.

2.464图片34.png Means clear the patterns shown on the dot matrix screen.

3.You can define the pattern you want to display; no need to set by yourself; just direct call the patterns in the library.
464图片35.png

4.In the code, we can also set any patterns as we like; just tick in the dot matrix, indicating that the point is lit.
464图片36.png
Set the first pattern as464图片37.png; the second pattern should be LedArray2; And so on...



  • Extension Practice:

1.Set a static icon you like and show on the dot matrix;

0464-pro3图22.png

2.Set a dynamic icon you want to show on the dot matrix.
0464-pro3图23.png

Project 4: Line Tracking Sensor


Overview:
The tracking sensor is actually an infrared sensor. The component used here is the TCRT5000 infrared tube. Its working principle is to use the different reflectivity of infrared light to the color, then convert the strength of the reflected signal into a current signal.
During the process of detection, black is active at HIGH level, but white is active at LOW. The detection height is 0-3 cm.
For keyestudio 3-channel line tracking module, we have integrated 3 sets of TCRT5000 infrared tube on a single board. It is more convenient for wiring and control.
By rotating the adjustable potentiometer on the sensor, it can adjust the detection sensitivity of the sensor.

Special note: before testing, turn the potentiometer on the sensor to adjust the detection sensitivity.
When adjust the LED front the trimpot at the threshold between ON and OFF, the sensitivity is the best.


TECH SPECS:

  • Operating Voltage: 3.3-5V (DC)
  • Interface: 5PIN
  • Output Signal: Digital signal
  • Detection Height: 0-3 cm


441图66.png


Wiring Diagram:
Note: stack the motor drive shield onto REV4 control board. connect the line tracking sensor to motor drive shield’s P1 connector (G, V, D6, D7, D8); Connect the pin (-、+、S) of red LED module to the pin G, 5V, D3(S) of motor drive shield with 3P female-to-female jumper wire; connect the power supply to BAT connector.

464图片38.png


Coding:
Now write the program to test the line tracking sensor.
Go to “Control”, drag out the “setup” block; and drag the “Serial baud rate(9600)”block from “SerialPort” into the “setup” block.

To respectively read the left, the center and the right tracking sensor on the line tracking module, we click the “SerialPort” , drag out the blockP8-1.png; drag out the blockP3-2.pngfrom “Text” into the block P8-1.png, and then duplicate the complete block six times. Change the firstP3-2.png to “left_tracking=”; drag out the block P8-5.png from library “Desktop_Car_V3” to replace the second P3-2.png; delete the third hello box, forming a blank box; change the fourth P3-2.pngto
“center_tracking=”.

Duplicate the blockP8-5.png once to replace the fifthP3-2.png and click the drop-down triangle icon to select the “center_tracking”; delete the sixth hello box, forming a blank box; change the seventh P3-2.png to “right_tracking=”.
And again go to “SerialPort”, drag out the block P8-1.png; duplicate the block P8-5.png once and drag it into P8-1.png, click the drop-down triangle icon to select the “right_tracking” And go to “Control”, drag the delay blockPro4-图片3.png; set to delay 1000ms.

P8-15.png

Complete and upload the above code to see the result. It can tell black and white.
Through testing, if line tracking sensor detects white, output LOW 0 and the built-in LED turns on red; detecting black, output HIGH 1 and the built-in LED is off.

We’ve measured what signal the line tracking sensor sends. Next the white LED is turned on when any tracking sensor detects white.
Next write the program that can turn on or off white LED module using line tracking sensor.

To judge whether the left, the center and the right tracking sensor detect black or white, here we can use the condition statement P3-13.png or P3-14.png.
But the blockP3-14.png is more efficient thanP3-13.png.

Go to “Control”, drag out the blockP3-13.png, then click the blue gear icon, appear the edit box, drag the block P3-17.png into Pro8-图片15.png block. So you can get the blockP3-14.png .

Next, go to the “Logic”, drag out the blockP3-20.png, and drag out the blockP8-5.png from the “Desktop_Car_V3” into the first input box at the left side of “=”;
drag the Pro8-图片20.png from the “Math” into the second input box at the right side of “=” ; like this:P8-26.png.
We duplicate the block twice, and respectively click the drop-down triangle icon to select “center_tracking” and “right_tracking”.P8-27.pngP8-28.png.

And again go to the “Logic”, drag out the blockP3-25.png and click the drop-down triangle to select “or”; duplicate the block P8-30.pngonce and make as P8-31.png; drag this block behind into the if statement.

Now respectively drag the blockP8-26.png,P8-27.pngandP8-28.png into the input box of blockP8-31.png.

Click the “Desktop_Car_V3”, drag out the blockP3-29.png into do statement, keep HIGH; duplicate the block once and set to LOW and drag it into else statement.

P8-37.png

Now we have written the code of tracking sensor controlling white LED module. Upload the complete to see the final result!
P8-38.png



Result:
Drag the test code to Mixly window, compile the code and then click on the 'Upload' button.
You will see the message “Upload success” appear on the bottom bar. Turn the slide switch to ON position.
When any TCRT5000 infrared pair transistor on the line tracking sensor detects white, LED module will turn on; otherwise, LED turns off.
464图片41.png



  • Little Knowledge:

1.In the code, we use the library 441图71.png to read the HIGH/LOW of the left sensor (D6); using the block 441图72.png also makes sense.
The signal pin of the middle sensor is D7; the signal pin of the right sensor is D8.

2.Ks0446图片30.png means the baud rate is set to 9600;
0428图片43.png Print the specified number, text or other value on serial monitor.
0428图片44.png Print the specified number, text or other value on newline of monitor.

3.0428图片45.pngmeans that if condition 1 is satisfied, it's going to be A, otherwise it's going to be B.
When using, you can find the if...do...statement block in the Mixly Control Block. Then click the gear icon on the block to drag out the else or else if block you need to use.
0428图片46.png

4.Pro4-图片-4.pngThis is a logical statement. It’s available as long as can satisfy any one of the three conditions.


  • Extension Practice:

1.Try to change the code without using library to make the same result.
Pro4-图片-5.png



Project 5: Ultrasonic Detecting Obstacles


Overview:
The ultrasonic module will emit the ultrasonic waves after trigger signal. When the ultrasonic waves encounter the object and are reflected back, the module outputs an echo signal, so it can determine the distance of object from the time difference between trigger signal and echo signal.
We can use the ultrasonic sensor to detect whether there is an obstacle ahead. It is commonly used to measure the distance between the front obstacle and robot.

In the process of robot DIY, we can use the measured distance by ultrasonic sensor to build functional robots, such as automatic avoiding, following, etc.
In the experiment, we use the ultrasonic sensor to measure the distance between the robot and front obstacle, controlling the LED matrix show the images.
441图47.png


TECH SPECS:

  • Operating Voltage: DC 5V
  • Operating Current: 15mA
  • Operating Frequency: 40khz
  • Maximum Range: 2-3m
  • Minimum Range: 2m
  • Sensing Angle: 15 degrees
  • Trigger Input Signal: 10µS TTL pulse


Wiring Diagram:
Note: stack the motor drive shield onto REV4 control board. Connect the ultrasonic sensor to motor drive shield’s P2 connector, VCC pin to V, Trig pin to digital 13 (S), Echo pin to digital 12 (S), G pin to GND(G);
Connect the pin G、V、SDA、SCL of dot matrix module to the pin G、5V、A4、A5 of motor drive shield with female-to-female jumper wire.
Connect the power supply to BAT connector.


464图片44.png


Coding:
The ultrasonic sensor is connected to P2 connector of motor drive shield , VCC pin to V, Trig pin to digital 13 (S), Echo pin to digital 12 (S), G pin to GND(G); Trig pin is to trigger signal and Echo pin is to receive echo signal.
Next need to write the program to get the specific distance measured by ultrasonic sensor.

Go to “Control” , drag out the “setup” block P5-1.png;
Drag out the block P5-2.png from “SerialPort” into the “setup” block.
Go to the “SerialPort” again, drag out the blockP5-3.png and P5-4.png
Go to “Text”, drag out the block P5-5.png into the block P5-3.png, and change the word “hello” to “distance=”.
Then go to “Small_Turtle_Robot”, drag and drop the ultrasonic block P5-7.png into “Serial printIn” block;
To make the value print slowly, we add a delay block.
And again go to “Control”, drag the delay blockPro4-图片3.png; set the delay time in 100ms.
Upload the code success, open the serial monitor to check the distance between ultrasonic sensor and an obstacle.

0464-pro5图9.png


In the following, try to realize another two distance situations:
When the measured distance between the ultrasonic sensor and front obstacles is smaller than 10cm, dot matrix display a smile face pattern.
When the measured distance between the ultrasonic sensor and front obstacles is greater than 10cm, clear the dot matrix display.

To judge whether the distance is smaller than 10cm or greater than 10cm, here we can use the condition statement P3-13.png or P3-14.png. But the block P3-14.png is more efficient than P3-13.png .
Go to “Control”, drag out the blockP3-13.png, then click the blue gear icon, appear the edit box, drag the P3-17.png block into Pro8-图片15.png block. So you can get the block P3-14.png.

Next, go to “Logic”, drag the block P3-20.png into the if statement, and drag out the block P5-7.png from the “Small_Turtle_Robot” into the first input box at the left side of “=”; drag the Pro8-图片20.png from the “Math” into the second input box at the right side of “=” ; change the“=” to“<” , change the value 0 to 10; like this:P5-21.png.

First set up the dot matrix display, click “Small_Turtle_Robot”, drag out the block 0464-pro3图12.png into the setup block; here default SDA pin to A4, SCL pin to A5. And again drag out the block 0464-pro3图17.png into the do statement, click the drop-down triangle to select smile pattern. The dot matrix will display a smile pattern. And drag out the block 0464-pro3图15.png into the else statement.

0464-pro5图20.png

Now we have written the test code for ultrasonic sensor. Upload the code and move an obstacle in front of ultrasonic sensor to check the result.

0464-pro5-code.png


What you will see
Upload the code success, open the monitor and set the baud rate to 9600. Turn the Slide switch ON.
When place an obstacle in front of the ultrasonic sensor, the measured distance between an obstacle and sensor is showed on the monitor. The unit is cm.
464图片46.png
When the measured distance is less than 10cm, LED matrix shows a smile image; otherwise, no image display.
464图片47.png




  • Little Knowledge:

1.In the code, we use the 441图51.png to measure the distance between ultrasonic sensor and obstacle ahead, with a unit of cm.

2.0464-pro5图22.png: print the distance value on the newline of monitor. The baud rate default by 9600.
If use the block 0464-pro5图23.png , it will not print the value on the newline; just print on the monitor. The difference between them is whether need to make line wrap.

3.What happens when you change the number in one or both of the delay(1000)
441图17.png
This delay period is in milliseconds, so if you want the LED to blink as low or fast, change the value, try 500 or 2000.

4.0428图片45.pngmeans that if condition 1 is satisfied, it's going to be A, otherwise it's going to be B.
When using, you can find the if...do...statement block in the Mixly Control Block. Then click the gear icon on the block to drag out the else or else if block you need to use.
0428图片46.png



  • Extension Practice:

1.Change the distance value measured by ultrasonic sensor to make the LED panel show different patterns.
0464-pro5图24.png



Project 6: Infrared Receiver


  • IR Remote Control:
remote control

There is no doubt that infrared remote control is commonly seen in our daily life. It's hard to imagine our world without it.
An infrared remote control can be used to control a wide range of home appliances such as television, audio, video recorders and satellite signal receivers.
Well, in the following let’s get a better understanding of the infrared remote control.

Infrared remote control is composed of infrared transmitting and infrared receiving systems. That is, consist of an infrared remote control, an infrared receiver module and a microcontroller that can decode. You can refer to the figure below.

Ks0436-201.png

The 38K infrared carrier signal transmitted by an infrared remote controller is encoded by an encoding chip inside the remote controller. It is composed of a pilot code, user code, data code, and data inversion code.
The time interval between pulses is used to distinguish whether it is a signal 0 or 1. (when the ratio of high level to low level is about 1:1, considered as signal 0.) And the encoding is just well composed of signal 0 and 1.

The user code of the same button on remote controller is unchanged. Using difference data distinguish the key pressed on the remote control.
When press down a button on the remote control, it will send out an infrared carrier signal. And when infrared receiver receives that signal, its program will decode the carrier signal, and through different data codes, thus can judge which key is pressed.
The microcontroller is decoded by an received signal 0 or 1 to determine which key is pressed by the remote control.


  • IR Receiver Module:

As for an infrared receiver module, it is mainly composed of an infrared receiving head. This device integrates with reception, amplification and demodulation. Its internal IC has been demodulated, outputting Digital signal. Suitable for IR remote control and infrared data transmission.
The infrared receiver module has only three pins (Signal, VCC, GND), very convenient to communicate with Arduino and other microcontrollers.

IR Receiver Module


Parameters of IR Receiver:

  • 1)Operating Voltage: 3.3-5V(DC)
  • 2)Interface: 3PIN
  • 3)Output Signal: Digital signal
  • 4)Receiving Angle: 90 degrees
  • 5)Frequency: 38khz
  • 6)Receiving Distance: 18m


Wiring Diagram:
Note: stack the motor drive shield on the REV4 board; connect the infrared receiver sensor to P4(G、V、A1) connector on the motor drive shield. If the digital ports are not enough, analog port can be used as digital port. Analog port A0 corresponds to digital port14; A1 corresponds to digital port15.
Connect dot matrix module to motor drive shield (pin G for GND, V for 5V, SDA for A4, SCL for A5). Connect the power to BAT connector.

464图片49.png


Coding:
Now write the program. When aligning at the IR receiver, press the key on the IR remote control, available to check the input signal change of IR receiver on the serial monitor.
Go to “Control”, drag out theP9-1.pngblock; and drag theP9-2.pngblock from “SerialPort” into the “setup” block.
Next, IR receiver will receive the infrared signal when press different keys on the IR remote control.

We first click the imported library“Small_Turtle_Robot”, drag out the blockP9-3.png; drag the blockP9-4.png from “SerialPort” into the infrared receiver block just made.
Then go to “Variables”, drag out the block P9-5.pnginto the blockP9-4.png.

So the infrared receiver can receive the infrared signal.
P9-7.png

Upload this code, open the serial monitor; aimed at the infrared receiver sensor, press the key on the IR remote control, IR receiver will receive the infrared signal, and indicator turns on red. And you can see the key encoding on the serial monitor.

P9-8.png

Next move on to realize the IR receiver controlling dot matrix displaying pattern with IR remote control.

Press the front key P9-9.png on the IR remote control, dot matrix displays a front pattern; press the key P9-10.png , dot matrix displays STOP pattern. So here we call the if statement P9-11.png from the “Control”. According to the measured result, we know the infrared encoding(string value) of front key P9-9.png is FF629D; the infrared encoding(string value) of key P9-10.png is FF02FD.
As the command key of IR remote control is hexadecimal code, the front must add 0x.

If ir_rec=0xFF629D, press the front key P9-9.png on the IR remote control,dot matrix displays a front pattern.

Go to the “Logic”, drag out the block P3-20.png into the if statement, and drag out the block P9-16.pngfrom the “Variables” into the first input box at the left side of “=”; drag the Pro8-图片20.pngfrom the “Math” into the second input box at the right side of “=” and type “0xFF629D” , like this:0464-pro6图1.png.

First set up the dot matrix display, click “Small_Turtle_Robot”, drag out the block0464-pro3图12.png into the setup block; here default SDA pin to A4, SCL pin to A5. And again drag out the block0464-pro6图3.png and 0464-pro3图17.png into the do statement, click the drop-down triangle to select front2.
0464-pro6图6.png

Next duplicate the block0464-pro6图5.png once and change “0xFF629D” to “0xFF02FD” and click the drop-down triangle to select stop2.


0464-pro6-code.png


What you will see:
Upload the code success, open the monitor and set the baud rate to 9600. Turn the Slide switch ON.
Aimed at the infrared receiver, press your remote control to send the signal, and you will see the encoding of each button on the remote control.
Note if press the control button too long, easily appear unreadable code. Shown as below figure.
464图片52.png

If receive the 464图片53.png up button value from IR remote control, LED dot matrix shows the front icon0428图片31.png ; if receive the 464图片55.pngOK key value, shows“STOP”.


464图片56.png



Below we have listed out each button value of keyestudio remote control. So you can keep it for reference.
thumb



Little Knowledge:
1.In the code, we direct use the library441图78.png; the signal pin of IR receiver module is A1; the IR receiver receives an infrared signal and outputs 16-bit encoding, printing out on serial monitor (baud rate 9600).
thumb

2.We have tested out the 16-bit encoding of each button on the infrared remote control by source code.
Or you can see the button encoding chart shown above.
In the code, we can change the different key encoding to control dot matrix display different icons.



Extension Practice:
1.Driving the 2 motors’ turning direction and speed by infrared remote control.
(refer to project 9/10 - motor driving)
Combine infrared receiver and motors driving knowledge to build an infrared remote control car.

thumb


Project 7: Bluetooth Module

keyestudio HM-10 Bluetooth-4.0 V3

Description:
Bluetooth technology is a wireless standard technology that enables short-distance data exchange between fixed devices, mobile devices, and building personal area networks (using UHF radio waves in the ISM band of 2.4 to 2.485 GHz).
The Keyestudio HM-10 Bluetooth-4.0 V3 Module is a master-slave machine. When use as the Host, it can send commands to the slave actively; when use as the Slave, it can only receive commands from the host.
The HM-10 Bluetooth module supports the Bluetooth 4.0 protocol, which not only supports Android mobile, but also supports iOS system.


Technical Details:

  • 1)Bluetooth protocol: Bluetooth Specification V4.0 BLE
  • 2)No byte limit in serial port Transceiving
  • 3)In open environment, realize 100m ultra-distance communication with iphone4s
  • 4)USB protocol: USB V2.0
  • 5)Working frequency: 2.4GHz ISM band
  • 6)Modulation method: GFSK(Gaussian Frequency Shift Keying)
  • 7)Transmission power: -23dbm, -6dbm, 0dbm, 6dbm, can be modified by AT command.
  • 8)Sensitivity: ≤-84dBm at 0.1% BER
  • 9)Transmission rate: Asynchronous: 6K bytes ; Synchronous: 6k Bytes
  • 10)Security feature: Authentication and encryption
  • 11)Supporting service: Central & Peripheral UUID FFE0, FFE1
  • 12)Power consumption: Auto sleep mode, stand by current 400uA~800uA, 8.5mA during transmission.
  • 13)Power supply: 5V DC
  • 14)Working temperature: –5 to +65 Centigrade


thumb


Pins Description:

thumb


Wiring Diagram:
connect the VCC to 5V,GND to GND, TXD to RXD, RXD to TXD.
thumb


Test Code:
When uploading the code, CANNOT connect the Bluetooth module; otherwise uploading fails!
You are supposed to upload the code to control board, then connect the Bluetooth module.


thumb


Result:
First should install the APP on the cellphone. Download the APP from the link: https://wiki.keyestudio.com/KS0455_keyestudio_HM-10_Bluetooth-4.0_V3_Compatible_with_HC-06_Pins


  • For Android APP:

APP installed well, you can see the icon thumb on your Android phone.
After wiring, upload the test code to REV4 board and then connect the Bluetooth module. Powered on, Bluetooth module’s built in LED flashes.
Open the Android APPthumb, click to scan device. As shown below.
thumb

Click Scan Device to search the Bluetooth.
thumb

Click the first device thumb to connect the Bluetooth.
Connected, built-in LED on the Bluetooth module is normally on. APP interface will show the state connected.
thumb

On the bar enter letter a, and click to send, APP will print out the character “keyestudio” and D13 indicator on the REV4 board will flash once.
Continue to send the letter a, APP prints out multiple “keyestudio” character and D13 indicator flashes.
thumb


  • For mac/iOS APP

You need to download the mac/iOS compatible APP in APP store.
First we enter the APP store, search hm10, and select the hm10 bluetooth serial lite.
thumb


Click to install the APP, as shown below.
thumb


APP installed well, a Bluetooth iconthumb will pop up on your phone. Click to enter the APP.

Upload the test code to control board successfully, then plug in the Bluetooth module.
Open the Bluetooth APP, click thumb to start searching and pairing the Bluetooth module. Click thumbto start connecting HM-10 Bluetooth module.
Connected, the built-in LED on the Bluetooth module will be from quick flash to normally on.

thumb

On the input bar enter a letter a, and click to send, APP will print out the character “keyestudio” and D13 indicator on the REV4 board will flash once.
Continue to send the letter a, APP prints out multiple “keyestudio” characters and D13 indicator flashes.
thumb