Advertisement

Quick Links

1
WELCOME TO THE
KIT GUIDE
This is your map for navigating beginning embedded electronics.
This kit contains all the information you will need to build the circuit
and robot projects for the keyestudio
REV4
Board.
When you're done with this guide, you will have built five great projects
and acquired the know-how to create countless more.
Now enough talk — let's start something!
For this guide with more information for each circuit project, visit:
wiki.keyestudio.com

Advertisement

Table of Contents
loading

Summary of Contents for Keyestudio KS0436

  • Page 1 KIT GUIDE This is your map for navigating beginning embedded electronics. This kit contains all the information you will need to build the circuit and robot projects for the keyestudio REV4 Board. When you’re done with this guide, you will have built five great projects and acquired the know-how to create countless more.
  • Page 2: Table Of Contents

    Contents INTRODUCTION.................... 4 ..............4 ..............6 ................. 11 ...............8 GET STARTED WITH CIRCUIT PROJECTS!..........17 ..................16 Circuit 1: Blinking an LED..............18 Circuit 2: Light Extension..............29 Circuit 3: Potentiometer..............43 Circuit 4: Photo Resistor..............55 Circuit 5: Buzzer..................63 Circuit 6: Button..................73 Circuit 7: 74HC595 And Segment Display........86 Circuit 8: 4-Digit Segment Display............
  • Page 3 Circuit 14: Tilt Ball Switch............... 162 Circuit 15: Vibration Switch............170 Circuit 16: Sound Sensor..............176 Circuit 17: Distance Sensor..............186 Circuit 18: Driving Servo Motor............198 Circuit 19: Relay................208 Circuit 20: PIR Motion Sensor............216 GET STARTED WITH ROBOT PROJECTS!..........226 ROBOT BASEPALTE ASSEMBLY............227 Circuit 21: Motor...
  • Page 4: Introduction

    INTRODUCTION The keyestudio REV4 Board is your development platform. REV4 Board is essentially a small, portable computer, also known as a microcontroller. It is capable of taking inputs (such as the push of a button or a reading from a light sensor) and interpreting that information to control various outputs (like blinking an LED light or spinning an electric motor).
  • Page 5 connect it to a computer with a USB cable or power it via an external DC power jack (DC 7-12V) or via female headers Vin/GND(DC 7-12V) to get started. Hardware Overview:...
  • Page 6 It has 2 power rails on both sides, a standard double-strip in the middle with 30 columns and 10 rows - a total of 400 tie in points. This tiny breadboard also has a self-adhesive on the back, so you can stick it onto an Arduino protoshield or keyestudio chassis. Breadboard Use:...
  • Page 8 REV4 Board microcontroller breadboard connected without the worry of disconnecting or damaging your circuit. 1) To begin with, collect your parts: the REV4 Board, breadboard, screwdriver, keyestudio baseplate and four baseplate screws.
  • Page 9 2) Align the board with its spot on the baseplate. The text on it should face the same direction as the text on the REV4 breadboard and the baseplate. Using four screws, affix the REV4 Board to the four stand-off holes found on the baseplate.
  • Page 10 Your baseplate is now assembled!
  • Page 11 In order to get your REV4 Board up and running. you'll need to download the newest version of the Arduino software from www.arduino.cc (it's free!). This software, known as the Arduino IDE (Integrated Development Environment), will allow you to program the REV4 Board to do exactly what you want.
  • Page 12 click the Arduino icon to open.
  • Page 13 The functions of each button on the Toolbar are listed below: Check the code for errors Verify/Compile Upload the current Sketch to the Arduino Upload Create a new blank Sketch Show a list of Sketches Open Save the current Sketch Save Display the serial data being sent from the Arduino...
  • Page 14 select the Arduino REV4 , but if you are not sure which ports Select Your Board And Serial Port should choose. Go to your computer panel, and check the Port out in NOTE: the Device Manger.
  • Page 16 The Kit contains extensive electronic components. Below shows you a part of kit components:...
  • Page 17: Get Started With Circuit Projects

    GET STARTED WITH CIRCUIT PROJECTS! There are 20 circuit projects total. Each project will introduce new concepts and components, which will be described in more detail as you progress through the circuits. As you work your way through each circuit, you will learn to use new and more complicated parts to accomplish increasingly complex tasks.
  • Page 18: Circuit 1: Blinking An Led

    Circuit 1: Blinking an LED Blinking an LED is the classic starting point for learning how to About this circuit: program embedded electronic components. In this circuit, you’ll write code that makes an LED blink on and off. REV4 Baseplate What You Need: Red LED x 1 ...
  • Page 19 positive (+) leg and a negative (-) leg, and they will only let electricity flow through them in one direction. LEDs can also burn out if too much electricity flows through them, so you should always use a resistor to limit the current when you wire an LED into a circuit.
  • Page 20 You can use them to protect sensitive components like LEDs. The strength of a resistor (measured in ohms) is marked on the body of the resistor using small colored bands. Each color stands for a number, which you can look up using a resistor chart.
  • Page 21 Check out the schematics and wiring diagram below to see how Wiring Diagram: everything is connected. Schematics:...
  • Page 23 With the 220Ω resistor in place, the LED should be quite bright. If you swap out the 220Ω resistor for the 1kΩ resistor, then the LED will appear a little dimmer. At the moment, you have Digital pin 10 going to one leg of the resistor, the other leg of the resistor going to the positive side of the LED and the other side of the LED going to GND.
  • Page 24 delay(1000); // wait for a second. digitalWrite(ledPin, LOW); // set the LED off. delay(1000); // wait for a second  Single line comments start with and everything up until the end Code Explanation: of that line is considered a comment. Comments are a great way to leave notes in your code explaining why you wrote it the way you did.
  • Page 25 states tells the Arduino board that we are going to use the LED pin as an output. void loop() It is also mandatory for a sketch to have a “loop” function. Unlike the 'setup' function that only runs once, after a reset, the 'loop' function will, after it has finished running its commands, immediately start again.
  • Page 26 This delay period is in milliseconds, so if you want the LED to blink twice as fast, change the value, try 500 or 2000. Upload the sketch again and you should see the LED start to blink more quickly or slowly. What You Will See:...
  • Page 27 After downloading this program, in the experiment, you will see the LED flashing on for one second, then off for one second. The blinking LED experiment is now completed. Thank you!
  • Page 28 Troubleshooting: Make sure you have assembled the circuit correctly and verified and  Upload failed? uploaded the code to your board. Check out the Board and Serial Port.
  • Page 29: Circuit 2: Light Extension

    Circuit 2: Light Extension After mastering LED Blinking, let’s move on to how to control lots of About this circuit: LEDs. The principle is almost the same. In this circuit, you’ll write code that makes six LEDs blink on and off one by one.
  • Page 30 Check out the wiring below to see how everything is connected. Schematics:...
  • Page 32 1) Connect the REV4 Board to a USB port on your computer. Upload Code: 2) Open the program in the code folder- Circuit 2 Light, or directly copy and paste the code below on the Ardunio IDE. 3) Select UPLOAD to program the sketch on the UNO Board. int BASE = 2 ;...
  • Page 33 one by one. delay(200); // delay for (int i = BASE; i < BASE + NUM; i ++) digitalWrite(i, HIGH); // set I/O pins as“high” , turn on LEDs one by one delay(200); // delay  Single line comments start with and everything up until the end Code Explanation: of that line is considered a comment.
  • Page 34 What You Will See:...
  • Page 35 You can see the six LEDs blink on and off one by one. It seems like light chasing. If it doesn’t, make sure you have assembled the circuit correctly and verified and uploaded the code to your board. Check out the Board and Serial Port.
  • Page 36 Make sure you connect the LED correctly or try other LEDs.  LED Not Lighting Up?
  • Page 37 How to make a traffic light? REV4 Baseplate What You Need: Red LED x 1   Yellow LED x 1  Green LED x 1  220Ω Resistor x 3  Jumper wires x 4  USB cable x 1 ...
  • Page 40 Source Code: int redled =10; // initialize digital pin 8. int yellowled =7; // initialize digital pin 7. int greenled =4; // initialize digital pin 4. void setup() pinMode(redled, OUTPUT);// set the pin with red LED as “output” pinMode(yellowled, OUTPUT); // set the pin with yellow LED as pinMode(greenled, OUTPUT);...
  • Page 41 delay(500);// wait 0.5 second digitalWrite(yellowled, LOW);// turn off yellow LED delay(500);// wait 0.5 second digitalWrite(redled, HIGH);// turn on red LED delay(5000);// wait 5 second digitalWrite(redled, LOW);// turn off red LED...
  • Page 42 Done uploading the code, you can see your own designed traffic light. This circuit design is very similar with the one in LED chase effect. The green light will turn on for 5 seconds, and then off, followed by the yellow light blinking for 3 times, and then red light turns on for 5 seconds, circularly and repeatedly.
  • Page 43: Circuit 3: Potentiometer

    Circuit 3: Potentiometer In the previous project, you have learned how to turn on or off an LED. About this circuit: In this circuit, you’ll use a potentiometer as an input device to control the speed at which your LED blinks. Here may involves a new concept PWM to control the brightness of an LED.
  • Page 44 Component Introduction: Potentiometers (also known POTENTIOMETER: “trimpots”or“knobs”) are one of the basic inputs for electronic devices. A potentiometer is a 3-pin variable resistor. When powered with 5V, the middle pin outputs a voltage between 0V and 5V, By tracking the position of the knob with your REV4 Board, you can depending on the position of the knob on the potentiometer.
  • Page 45 PWM Control: PWM is short for Pulse Width Modulation. 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.
  • Page 46 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. To be simply, 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.
  • Page 47 Analog output, it needs to call the analogWrite() function of ARDUINO, and this analogWrite() function can be controlled in the range of 0-255.
  • Page 48 Hookup Guide: The input of potentiometer is analog, so we connect it to analog port, and LED to PWM pin. Different PWM signals can regulate the LED brightness.
  • Page 50 1) Connect the REV4 Board to a USB port on your computer. Upload Code: 2) Open the program in the code folder- Circuit 3 Potentiometer, or directly copy and paste the code below on the Ardunio IDE. 3) Select UPLOAD to program the sketch on the UNO Board. int potpin=0;// initialize analog pin 0 int ledpin=11;//initialize digital pin 11(PWM output)...
  • Page 51 delay(10);// wait for 0.01 second  Single line comments start with and everything up until the end Code Explanation: of that line is considered a comment. Comments are a great way to leave notes in your code explaining why you wrote it the way you did. ...
  • Page 52 We use the analogRead() function to read the value on an analog pin. Serial.println(val); This is the line that actually prints the trimpot value to the monitor.  You should see the LED brighter or dim in accordance with your What You Will See: potentiometer.
  • Page 53 You should see numeric values print out in the monitor. Turning the potentiometer changes the value.
  • Page 54 Troubleshooting: Make sure you have assembled the circuit correctly and verified and  Upload failed? uploaded the code to your board. Ensure that you are on the correct Board and Serial Port. Make sure that you have selected the correct baud rate, 9600. ...
  • Page 55: Circuit 4: Photo Resistor

    Circuit 4: Photo Resistor In the previous circuit, you have learned how to use a potentiometer as About this circuit: an input device to control the LED’s brightness. In this circuit, you’ll be using a photoresistor, which changes resistance based on how much light the sensor receives. Using this sensor you can make a simple night-light that turns on when the room gets dark and turns off when it is bright.
  • Page 56 Component Introduction: Photo resistor (Photovaristor) is a resistor Photo Resistor: whose resistance varies according to different incident light strength. It's made based on the photoelectric effect of semiconductor. If the incident light is intense, its resistance reduces; if the incident light is weak, the resistance increases.
  • Page 57 The photoresistors, like regular resistors, are not polarized and can be Hookup Guide: installed in either direction.
  • Page 59 1) Connect the REV4 Board to a USB port on your computer. Upload Code: 2) Open the program in the code folder- Circuit 4 Photoresistor, or directly copy and paste the code below on the Ardunio IDE. 3) Select UPLOAD to program the sketch on the UNO Board. After the connection, let's begin the program compiling.
  • Page 60 val= map(analogRead(potpin),0,1023,0,255); Serial.println(val);// display the value of val analogWrite(ledpin,val);// turn on the LED and set up brightness (maximum output value 255) delay(10);// wait for 0.01...
  • Page 61 You can change the light intensity around the photovaristor and see What You Will See: corresponding brightness change of the LED. See the light intensity on the serial monitor.
  • Page 63: Circuit 5: Buzzer

    Circuit 5: Buzzer In this project, you will learn how to make tones with a buzzer. About this circuit: REV4 Baseplate What You Need: Passive Buzzer x 1   Jumper wires x2  USB cable x 1  Component Introduction: Buzzers can be categorized as active and passive ones.
  • Page 64 it beep. Different frequencies produce different sounds. By the buzzer, you can even play a song. Wiring the buzzer connected to the REV4 board, the red (positive) to Hookup Guide: the pin8, black wire (negative) to the GND.
  • Page 67 1) Connect the REV4 Board to a USB port on your computer. Upload Code: 2) Open the program in the code folder- Circuit 5 Buzzer, or directly copy and paste the code below on the Ardunio IDE. 3) Select UPLOAD to program the sketch on the UNO Board. After the connection, let's begin the program compiling.
  • Page 68 delay(1);//ms delay for(i=0;i<100;i++)// output a frequency sound { digitalWrite(buzzer,HIGH);// sound digitalWrite(buzzer,LOW);//not sound delay(2);//2ms delay Done uploading the code to the board, the passive buzzer will make a Test Reult: tone.
  • Page 69 Troubleshooting: Check your wiring of the buzzer. It’s easy to misalign a pin with a  No sound is playing? jumper wire or reverse the buzzer.
  • Page 70 What about active buzzer? The use method is almost the same. Think about it and try to make an audible beep from active buzzer. Test code is showed below: int buzzer=2;// initialize digital IO pin that controls the buzzer void setup() pinMode(buzzer,OUTPUT);// set pin mode as “output”...
  • Page 71 is connected to Digital pin 2 of REV4. The short lead is connected to ground. Troubleshooting: Check your wiring of the buzzer. It’s easy to misalign a pin with a  No sound playing?
  • Page 72 jumper wire or reverse the buzzer.
  • Page 73: Circuit 6: Button

    Circuit 6: Button Buttons are all around us, from the keys on your keyboard to the About this circuit: buttons on your remote control. In this circuit, you’ll learn how to use the button to control the LED on and off using digital input. REV4 Baseplate What You Need:...
  • Page 74 Component Introduction: Also known as momentary switches, buttons only remain in their ON Push Button: state as long as they’re being actuated, or pressed. Most often momentary switches are best used for intermittent user-input cases: reset button and keypad buttons. These switches have a nice, tactile,“clicky”feedback when you press them.
  • Page 77 1) Connect the REV4 Board to a USB port on your computer. Upload Code: 2) Open the program in the code folder- Circuit 6 Button, or directly copy and paste the code below on the Ardunio IDE. 3) Select UPLOAD to program the sketch on the UNO Board. Now, let's begin the compiling.
  • Page 78 pinMode(inpin,INPUT);// set button pin as “input” void loop() val=digitalRead(inpin);// read the level value of pin 7 and assign if to if(val==LOW)// check if the button is pressed, if yes, turn on the LED { digitalWrite(ledpin,LOW);} else { digitalWrite(ledpin,HIGH);}  Single line comments start with and everything up until the end Code Explanation: of that line is considered a comment.
  • Page 79 TRUE (1) or FALSE (0) depending on the reading. What You Will See: When the button is pressed, LED is on; otherwise, LED remains off. After the above process, the button controlled LED experiment is completed. The simple principle of this experiment is widely used in a variety of circuit and electric appliances.
  • Page 80 a button leg. Second, make sure that you have declared your buttons as inputs. Think about: How to make responder effect? Create your own exciting game. You can try to use three buttons to control three LEDs, one button used as reset button to make a responder. See what will happen?
  • Page 82 Upload Code: int redled=8; // set red LED as “output” int yellowled=7; // set yellow LED as “output” int greenled=6; // set green LED as “output” int redpin=5; // initialize pin for red button int yellowpin=4; // initialize pin for yellow button int greenpin=3;...
  • Page 83 red=digitalRead(redpin); yellow=digitalRead(yellowpin); green=digitalRead(greenpin); if(red==LOW)RED_YES(); if(yellow==LOW)YELLOW_YES(); if(green==LOW)GREEN_YES(); void RED_YES()// execute the code until red light is on; end cycle when reset button is pressed while(digitalRead(restpin)==1) digitalWrite(redled,HIGH); digitalWrite(greenled,LOW); digitalWrite(yellowled,LOW); clear_led(); void YELLOW_YES()// execute the code until yellow light is on; end cycle when reset button is pressed...
  • Page 84 while(digitalRead(restpin)==1) digitalWrite(redled,LOW); digitalWrite(greenled,LOW); digitalWrite(yellowled,HIGH); clear_led(); void GREEN_YES()// execute the code until green light is on; end cycle when reset button is pressed while(digitalRead(restpin)==1) digitalWrite(redled,LOW); digitalWrite(greenled,HIGH); digitalWrite(yellowled,LOW); clear_led(); void clear_led()// all LED off digitalWrite(redled,LOW);...
  • Page 85 digitalWrite(greenled,LOW); digitalWrite(yellowled,LOW); Press the button to turn corresponding LED on and off.
  • Page 86: Circuit 7: 74Hc595 And Segment Display

    Circuit 7: 74HC595 And Segment Display In this circuit, we will use the 74HC595 shift register to control the About this circuit: segment display. The segment display will show number from 0-9. REV4 Baseplate What You Need: 1-digit 7-seg Display x 1 ...
  • Page 87 Component Introduction: LED segment display is a semiconductor Seven segment display: light-emitting device. Its basic unit is a light-emitting diode (LED). For the common anode display, connect the common anode (COM) to +5V. When the cathode level of a certain segment is low, the segment is on;...
  • Page 88 In this experiment, we use a common cathode display. Below is the seven-segment pin diagram.
  • Page 89 74HC595 IC: The shift register operates in a fairly simple way, but can be modified to become very complicated but very useful. We can control the shift of the register with clock pulses. As we raise the signal going to the clock pin to high, the clock is moved forward one step, and when we pull it low and high again it shifts another.
  • Page 90 Check out the circuit diagram and hookup table below to see how Hookup Guide: everything is connected.
  • Page 91 The following table shows the seven-segment display 74HC595 pin correspondence table: 74HC595 pin Seven shows remarkable...
  • Page 92 8(dp) control pin (stroke) 7(g) 6(f) 5(e) 4(d) 3(c) 2(b) 1(a) First, the wiring is connected to power and ground: Step one: Connect 74HC595 VCC (pin 16) and MR (pin 10) connected to 5V GND (pin 8) and OE (pin 13) to ground ...
  • Page 93 seven-segment display corresponding pin (A ~ G and DP), and then each foot in a 220 ohm resistor in series.
  • Page 95 1) Connect the REV4 Board to a USB port on your computer. Upload Code: 2) Open the program in the code folder- Circuit 7, or directly copy and paste the code below on the Ardunio IDE. 3) Select UPLOAD to program the sketch on the UNO Board. int latchPin = 4;...
  • Page 96 counting function digitalWrite(latchPin,LOW); shiftOut(dataPin,clockPin,MSBFIRST,a[x]); //display array a[x] digitalWrite(latchPin,HIGH); delay(1000);  Single line comments start with and everything up until the end Code Explanation: of that line is considered a comment. Comments are a great way to leave notes in your code explaining why you wrote it the way you did.
  • Page 97  The 'setup' function just sets the three pins we are using to be digital void setup () outputs. pinMode(latchPin,OUTPUT); pinMode(clockPin,OUTPUT); pinMode(dataPin,OUTPUT); //three pins as output What You Will See: Hookup well and upload the code to board, you can count the numbers on segment display from 0 to 9.
  • Page 98 Troubleshooting: Make sure you have assembled the circuit correctly and verified and  Upload failed? uploaded the code to your board. Ensure that you are on the correct Board and Serial Port. Check out the wiring between the 1-digit LED display and 74HC595 IC. ...
  • Page 99: Circuit 8: 4-Digit Segment Display

    Circuit 8: 4-Digit Segment Display In this lesson, you will learn how to use a 4-digit 7-segment display. We About this circuit: make the display show changing numbers among 0000-9999. REV4 Baseplate What You Need: 4--digit 7-seg Display x 1 ...
  • Page 100 Component Introduction: LED segment display is a semiconductor light-emitting device. Its basic 4-Digit Segment Display: unit is a light-emitting diode (LED). The display features one decimal point per digit. The hardware interface is twelve (two rows of six) through-hole pins, counting from 1 to 12 anticlockwise.
  • Page 102 Check out the circuit diagram and hookup table below to see how Hookup Guide: everything is connected.
  • Page 104 1) Connect the REV4 Board to a USB port on your computer. Upload Code: 2) Open the program in the code folder- Circuit 8, or directly copy and paste the code below on the Ardunio IDE. 3) Select UPLOAD to program the sketch on the UNO Board. int a = 1;...
  • Page 105 long n = 1230; int x = 100; int del = 55; // fine adjustment for clock void setup() pinMode(d1, OUTPUT); pinMode(d2, OUTPUT); pinMode(d3, OUTPUT); pinMode(d4, OUTPUT); pinMode(a, OUTPUT); pinMode(b, OUTPUT); pinMode(c, OUTPUT); pinMode(d, OUTPUT); pinMode(e, OUTPUT); pinMode(f, OUTPUT); pinMode(g, OUTPUT); pinMode(dp, OUTPUT);...
  • Page 106 int a=0; int b=0; int c=0; int d=0; unsigned long currentMillis = millis(); while(d>=0) while(millis()-currentMillis<10) Display(1,a); Display(2,b); Display(3,c); Display(4,d); currentMillis = millis(); d++; if (d>9) c++; d=0;...
  • Page 107 if (c>9) b++; c=0; if (b>9) a++; b=0; if (a>9) a=0; b=0; c=0; d=0; ////////////////////////////////////////////////////////////// void WeiXuan(unsigned char n)//...
  • Page 108 switch (n) case 1: digitalWrite(d1, LOW); digitalWrite(d2, HIGH); digitalWrite(d3, HIGH); digitalWrite(d4, HIGH); break; case 2: digitalWrite(d1, HIGH); digitalWrite(d2, LOW); digitalWrite(d3, HIGH); digitalWrite(d4, HIGH); break; case 3: digitalWrite(d1, HIGH); digitalWrite(d2, HIGH); digitalWrite(d3, LOW); digitalWrite(d4, HIGH); break; case 4:...
  • Page 109 digitalWrite(d1, HIGH); digitalWrite(d2, HIGH); digitalWrite(d3, HIGH); digitalWrite(d4, LOW); break; default : digitalWrite(d1, HIGH); digitalWrite(d2, HIGH); digitalWrite(d3, HIGH); digitalWrite(d4, HIGH); break; void Num_0() digitalWrite(a, HIGH); digitalWrite(b, HIGH); digitalWrite(c, HIGH); digitalWrite(d, HIGH); digitalWrite(e, HIGH); digitalWrite(f, HIGH); digitalWrite(g, LOW);...
  • Page 110 digitalWrite(dp, LOW); void Num_1() digitalWrite(a, LOW); digitalWrite(b, HIGH); digitalWrite(c, HIGH); digitalWrite(d, LOW); digitalWrite(e, LOW); digitalWrite(f, LOW); digitalWrite(g, LOW); digitalWrite(dp, LOW); void Num_2() digitalWrite(a, HIGH); digitalWrite(b, HIGH); digitalWrite(c, LOW); digitalWrite(d, HIGH); digitalWrite(e, HIGH); digitalWrite(f, LOW); digitalWrite(g, HIGH);...
  • Page 111 digitalWrite(dp, LOW); void Num_3() digitalWrite(a, HIGH); digitalWrite(b, HIGH); digitalWrite(c, HIGH); digitalWrite(d, HIGH); digitalWrite(e, LOW); digitalWrite(f, LOW); digitalWrite(g, HIGH); digitalWrite(dp, LOW); void Num_4() digitalWrite(a, LOW); digitalWrite(b, HIGH); digitalWrite(c, HIGH); digitalWrite(d, LOW); digitalWrite(e, LOW); digitalWrite(f, HIGH); digitalWrite(g, HIGH);...
  • Page 112 digitalWrite(dp, LOW); void Num_5() digitalWrite(a, HIGH); digitalWrite(b, LOW); digitalWrite(c, HIGH); digitalWrite(d, HIGH); digitalWrite(e, LOW); digitalWrite(f, HIGH); digitalWrite(g, HIGH); digitalWrite(dp, LOW); void Num_6() digitalWrite(a, HIGH); digitalWrite(b, LOW); digitalWrite(c, HIGH); digitalWrite(d, HIGH); digitalWrite(e, HIGH); digitalWrite(f, HIGH); digitalWrite(g, HIGH);...
  • Page 113 digitalWrite(dp, LOW); void Num_7() digitalWrite(a, HIGH); digitalWrite(b, HIGH); digitalWrite(c, HIGH); digitalWrite(d, LOW); digitalWrite(e, LOW); digitalWrite(f, LOW); digitalWrite(g, LOW); digitalWrite(dp, LOW); void Num_8() digitalWrite(a, HIGH); digitalWrite(b, HIGH); digitalWrite(c, HIGH); digitalWrite(d, HIGH); digitalWrite(e, HIGH); digitalWrite(f, HIGH); digitalWrite(g, HIGH);...
  • Page 114 digitalWrite(dp, LOW); void Num_9() digitalWrite(a, HIGH); digitalWrite(b, HIGH); digitalWrite(c, HIGH); digitalWrite(d, HIGH); digitalWrite(e, LOW); digitalWrite(f, HIGH); digitalWrite(g, HIGH); digitalWrite(dp, LOW); void Clear() // clear the screen digitalWrite(a, LOW); digitalWrite(b, LOW); digitalWrite(c, LOW); digitalWrite(d, LOW); digitalWrite(e, LOW); digitalWrite(f, LOW); digitalWrite(g, LOW);...
  • Page 115 digitalWrite(dp, LOW); void pickNumber(unsigned char n)// select number switch (n) case 0: Num_0(); break; case 1: Num_1(); break; case 2: Num_2(); break; case 3: Num_3(); break; case 4: Num_4(); break; case 5: Num_5(); break; case 6: Num_6(); break; case 7: Num_7();...
  • Page 116 break; case 8: Num_8(); break; case 9: Num_9(); break; default: Clear(); break; void Display(unsigned char x, unsigned char Number)// take x as coordinate and display number WeiXuan(x); pickNumber(Number); delay(1); Clear() ; // clear the screen Hookup well and upload the code to board, the 4-digit LED display will What You Will See: show the jumping number among 0000-9999.
  • Page 117 Troubleshooting: Check out the wiring between the 1-digit LED display and REV4.  No number jumping on 4-digit Segment ?
  • Page 118: Circuit 9: Led Matrix Display

    Circuit 9: LED Matrix Display In this circuit, you will learn how to control the LED matrix showing the About this circuit: number. REV4 Baseplate What You Need: LED matrix display x 1   220Ω Resistor x 8  Jumper wires x 16 ...
  • Page 119 Component Introduction: Now, we are going to learn 8*8 dot matrix. It consists of 64 LEDs, LED Matrix display: located in every crossing of each row and column. Welding pins on the 8*8 dot matrix: When a row is at level 1, and a column at level 0 simultaneously, LED lights up that is between high and low level.
  • Page 120 Check out the circuit diagram and hookup table below to see how Hookup Guide: everything is connected.
  • Page 122 1) Connect the REV4 Board to a USB port on your computer. Upload Code: 2) Open the program in the code folder- Circuit 9, or directly copy and paste the code below on the Ardunio IDE. 3) Select UPLOAD to program the sketch on the UNO Board. //define an array to store “0”...
  • Page 123 for(j=0;j<8;j++) if(data & 0x01)Draw_point(j,i); data>>=1; void setup(){ int i = 0 ; for(i=2;i<18;i++) pinMode(i, OUTPUT); clear_(); void loop() show_num(); void clear_(void)//clear screen for(int i=2;i<10;i++)
  • Page 124 digitalWrite(i, LOW); for(int i=0;i<8;i++) digitalWrite(i+10, HIGH); What You Will See: Hookup well and upload the code to board, the LED matrix is displaying the “0”.
  • Page 125 Troubleshooting: Check out the wiring between the 8*8 LED matrix display and REV4.  No number displaying on 8*8 LED matrix ?
  • Page 126: Circuit 10: Lcd "Hello, World

    Circuit 10: LCD “Hello, World!” Printing “Hello, world!” is usually the first thing that programming About this circuit: tutorials will have you do in a new language. Now we’re going to print out real text using a Liquid Crystal Display (LCD).
  • Page 127 Component Introduction: 1602 LCD display: Designed to show a grid of letters, numbers and other special characters, LCDs are great for printing data and showing values. Adding an LCD to your project will make it super portable and allow you to integrate up to 32 characters (16x2) of information. On the back of LCD display there is a blue potentiometer.
  • Page 128 VCC: A pin that connects to a +5V power supply SDA: A pin that connects to analog port A4 for IIC communication SCL: A pin that connects to analog port A5 for IIC communication Check out the circuit diagram and hookup table below to see how Hookup Guide: everything is connected.
  • Page 130 Note: Before you can run this, make sure that you have installed the Upload Code: < LiquidCrystal > library or re-install it, if necessary. Otherwise, your code won't work. 2) Connect the REV4 Board to a USB port on your computer.
  • Page 131 LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27 for a 16 chars and 2 line display void setup() lcd.init(); // initialize the lcd lcd.init(); // Print a message to the LCD. lcd.backlight(); lcd.setCursor(3,0); lcd.print("Hello, world!"); lcd.setCursor(2,1); lcd.print("keyestudio!"); void loop()
  • Page 132  Single line comments start with and everything up until the end Code Explanation: of that line is considered a comment. Comments are a great way to leave notes in your code explaining why you wrote it the way you did. ...
  • Page 133 “ Hello, World!” and “keyestudio” pop up on your LCD. Remember you can adjust the contrast using the potentiometer if you can’t make out the words clearly. If you have any issues, make sure your code is correct and double-check your connections.
  • Page 135: Circuit 11: Temperature Sensor

    Circuit 11: Temperature Sensor In this circuit you can use a small, low-cost sensor like the LM35 to About this circuit: make devices that track and respond to temperature. REV4 Baseplate What You Need: LM35 temperature sensor x 1  ...
  • Page 136 Component Introduction: This temperature sensor has three legs. One LM35 temperature sensor: connects to 5V, one to ground, and the voltage output from the second leg varies proportionally to changes in temperature. See how everything is connected in the below figures. Hookup Guide:...
  • Page 139 1) Connect the REV4 Board to a USB port on your computer. Upload Code: 2) Open the program in the code folder- Circuit 11, or directly copy and paste the code below on the Ardunio IDE. 3) Select UPLOAD to program the sketch on the UNO Board. void setup() { Serial.begin(9600);...
  • Page 140 digitalWrite(13, HIGH); digitalWrite(12, LOW); digitalWrite(11, LOW); else if (vol>=28 && vol<=30) digitalWrite(13, LOW); digitalWrite(12, HIGH); digitalWrite(11, LOW); else if (vol>30) temperature area and LED setup digitalWrite(13, LOW); digitalWrite(12, LOW); digitalWrite(11, HIGH);...
  • Page 141 What You Will See: After uploading the code, open the serial monitor, it will show the temperature value. Corresponding LED will be turned on in accordance with corresponding temperature range. Put a bag filled with hot water close to the sensor. When the temperature is lower than 28℃, green LED turns on;...
  • Page 142 turns on; if greater than 30℃, red LED turns on.
  • Page 143: Circuit 12: Temperature And Humidity

    Circuit 12: Temperature and Humidity In this circuit you will learn how to use a DHT11 Temperature and About this circuit: Humidity Sensor. It’s accurate enough for most projects that need to keep track of humidity and temperature reading. REV4 Baseplate What You Need: DHT11 sensor x 1...
  • Page 144 Component Introduction: DHT11 Temperature and Humidity Sensor: This DHT11 Temperature and Humidity Sensor features calibrated digital signal output with the temperature and humidity sensor complex. Its technology ensures high reliability and excellent long-term stability. A high-performance 8-bit microcontroller is connected. This sensor includes a resistive element and a sense of wet NTC temperature measuring devices.
  • Page 145 distance make it a wide applied application and even the most demanding one. Convenient connection, special packages can be provided according to users need. Check out the circuit diagram and hookup table below to see how Hookup Guide: everything is connected.
  • Page 147 Note: Before you can run this, make sure that you have installed the Upload Code: < dht11> library or re-install it, if necessary. Otherwise, your code won't work. 2) Connect the REV4 Board to a USB port on your computer. 3) Open the program in the code folder- Circuit 12, or directly copy and paste the code below on the Ardunio IDE.
  • Page 148 void loop(){ int chk; Serial.print("DHT11, \t"); chk = DHT.read(DHT11_PIN);// READ DATA switch (chk){ case DHTLIB_OK: Serial.print("OK,\t"); break; case DHTLIB_ERROR_CHECKSUM: Serial.print("Checksum error,\t"); break; case DHTLIB_ERROR_TIMEOUT: Serial.print("Time out error,\t"); break; default: Serial.print("Unknown error,\t"); break; // DISPLAT DATA Serial.print(DHT.humidity,1); Serial.print(",\t");...
  • Page 149 Serial.println(DHT.temperature,1); delay(1000); What You Will See:...
  • Page 150 After uploading the code, open the serial monitor, it will show the temperature and humidity value of current environment.
  • Page 151 Troubleshooting:  No Data Display? Double-check that you have plugged the DTH11 sensor in correctly. Make Note that here use a 10KΩ Resistor. sure the wiring is no wrong.
  • Page 152: Circuit 13: Flame Sensor

    Circuit 13: Flame Sensor In this circuit you will learn how to use a flame sensor to trigger a About this circuit: buzzer making an alarm when detecting the fire. REV4 Baseplate What You Need: Flame sensor x 1  ...
  • Page 153 Component Introduction: Flame sensor (Infrared receiving triode) is specially used on robots to Flame Sensor: find the fire source. This sensor is of high sensitivity to flame. Below is a photo of it. Flame sensor is made based on the principle that infrared ray is highly Working Principle sensitive to flame.
  • Page 154 analog pin. As shown below:...
  • Page 155 Check out the circuit diagram and hookup table below to see how Hookup Guide: everything is connected.
  • Page 157 1) Connect the REV4 Board to a USB port on your computer. Upload Code: 2) Open the program in the code folder- Circuit 13, or directly copy and paste the code below on the Ardunio IDE. 3) Select UPLOAD to program the sketch on the UNO Board. When it's approaching a fire, the voltage value read from the analog port differs.
  • Page 158 void setup() pinMode(Beep,OUTPUT);// set LED pin as “output” pinMode(flame,INPUT);// set buzzer pin as “input” Serial.begin(9600);// set baud rate at “9600” void loop() val=analogRead(flame);// read the analog value of the sensor Serial.println(val);// output and display the analog value if(val>=600)// when the analog value is larger than 600, the buzzer will buzz digitalWrite(Beep,HIGH);...
  • Page 159 What You Will See: After uploading the code, once the sensor detects the flame, the buzzer will immediately make a sound. If no fire, everything is normal.
  • Page 160 Troubleshooting:  Buzzer Not Sound? Double-check that you have plugged them in correctly. The longer lead of the buzzer is positive end. So does the flame sensor.
  • Page 161 Note that here use a 10KΩ Resistor.
  • Page 162: Circuit 14: Tilt Ball Switch

    Circuit 14: Tilt Ball Switch In this circuit you will learn how to use two tilt ball switches to control About this circuit: two LED lights on and off. REV4 Baseplate What You Need: Tilt ball switch x 2  ...
  • Page 163 Component Introduction: Tilt sensors (tilt ball switch) allow you to detect orientation or Tilt ball switch: inclination. They are small, inexpensive, low-power and easy-to-use. If used properly, they will not wear out. The tilt-switch twig is the equivalent of a button, and is used as a digital input.
  • Page 164 Check out the circuit diagram and hookup table below to see how Hookup Guide: everything is connected.
  • Page 166 1) Connect the REV4 Board to a USB port on your computer. Upload Code: 2) Open the program in the code folder- Circuit 14, or directly copy and paste the code below on the Ardunio IDE. 3) Select UPLOAD to program the sketch on the UNO Board. int LedPinA = 5;...
  • Page 167 void loop() buttonStateA = digitalRead(ButtonPinA); if (buttonStateA == HIGH && brightnessA != 255) brightnessA ++; if (buttonStateA == LOW && brightnessA != 0) brightnessA --; analogWrite(LedPinB, brightnessA); Serial.print(brightnessA); Serial.print(" "); buttonStateB = digitalRead(ButtonPinB); if (buttonStateB == HIGH && brightnessB != 0) brightnessB --;...
  • Page 168 brightnessB++; analogWrite(LedPinA, brightnessB); Serial.println(brightnessB); delay(5); Tilt the circuit to one side, one LED gradually turns on and another LED What You Will See: turns off.
  • Page 169 Troubleshooting:  LED Not Lighting? Double-check that you have plugged them in correctly. Make sure the connection no wrong.
  • Page 170: Circuit 15: Vibration Switch

    Circuit 15: Vibration Switch In this circuit you will learn how to test the vibration switch. About this circuit: REV4 Baseplate What You Need: Vibration switch x 1   10KΩ Resistor x 1  Jumper wires x 3  USB cable x 1 ...
  • Page 171 Component Introduction: It is a electronic switch that can sense the intensity of vibration and Vibration switch : transfer the result to the circuit device, and activate the circuit to start working. Check out the circuit diagram and hookup table below to see how Hookup Guide: everything is connected.
  • Page 174 1) Connect the REV4 Board to a USB port on your computer. Upload Code: 2) Open the program in the code folder- Circuit 15, or directly copy and paste the code below on the Ardunio IDE. 3) Select UPLOAD to program the sketch on the UNO Board. #define SensorLED #define SensorINPUT unsigned char state = 0;...
  • Page 175 digitalWrite(SensorLED,HIGH); delay(3000); state = 0; else digitalWrite(SensorLED,LOW); void blink()// digital input of the sensor falling, triggering interruption function state++; Done uploading the code, vibrate the desk where the sensor placed; What You Will See: once the sensor detects vibration, the D13 led on the UNO board turns on for 3 seconds then off.
  • Page 176: Circuit 16: Sound Sensor

    Circuit 16: Sound Sensor In this circuit you will learn how to use a microphone sound sensor to About this circuit: turn an LED on and off. REV4 Baseplate What You Need: Sound sensor x 1   Red LED x 1 ...
  • Page 177 Component Introduction: Transducers are devices which convert energy from one form to other. Sound sensor: A microphone is a transducer which converts sound energy to electrical signals. It works opposite to a speaker. These microphones are widely used in electronic circuits to detect minor sounds or air vibrations which in turn are converted to electrical signals for further use.
  • Page 178 acts as a filter for the dust particles. The sound signals/air vibrations passes through the porous material and falls on the diaphragm through the hole shown in the image above. Check out the circuit diagram and hookup table below to see how Hookup Guide: everything is connected.
  • Page 181 1) Connect theREV4 Board to a USB port on your computer. Upload Code: 2) Open the program in the code folder- Circuit 16, or directly copy and paste the code below on the Ardunio IDE. 3) Select UPLOAD to program the sketch on the UNO Board. int LEDpin = 7;...
  • Page 182 else{ digitalWrite(LEDpin,LOW); // turn off the LED It has no processing of the signal from the MIC, so signal is weak and insensitive. Instead of sound signal, we blow air to the MIC. Note: By rotating the potentiometer, the analog value of A0 changes; After adjusting the potentiometer, blow air into the MIC, and observe the data in the serial monitor.
  • Page 183 What You Will See: Turn the potentiometer to adjust the sensitivity of led light. Do uploading the code, open the serial monitor and set the baud rate to 9600. Clapping your hands, you should see the LED turn on for 5 seconds then off.
  • Page 185 Troubleshooting:  LED Not Lighting? Double-check that you have plugged them in correctly. The longer lead is Make sure the sound sensor and potentiometer are assembled correctly. the positive end.
  • Page 186: Circuit 17: Distance Sensor

    Circuit 17: Distance Sensor Distance sensors are amazing tools with all kinds of uses. They can About this circuit: sense the presence of an object, they can be used in experiments to calculate speed and acceleration, and they can be used in robotics to avoid obstacles.
  • Page 187 Component Introduction: Ultrasonic sensor module HC-SR04 provides 2cm-400cm non-contact Ultrasonic sensor: measurement function, the ranging accuracy can reach to 3mm. The modules includes ultrasonic transmitters, receiver and control circuit. Distance sensors work by sending pulses of light or sound out from a transmitter, then timing how long it takes for the signals to bounce off an object and return to a receiver (just like sonar).
  • Page 188  Operating Voltage: 5V(DC) TECH SPECS:  Operating Current: 15mA  Operating Frequency: 40khz  Maximum Detection Distance: 3-5m  Minimum Detection Distance: 3-4cm  Sensing Angle: less than 15 degrees PINS:...
  • Page 189 Check out the circuit diagram and hookup table below to see how Hookup Guide: everything is connected.
  • Page 190 Note: Before you can run this, make sure that you have installed the Upload Code: LCD library or re-install it, if necessary. Otherwise, your code won't work. 2) Connect the REV4 Board to a USB port on your computer. 3) Open the program in the code folder- Circuit 17, or directly copy and...
  • Page 191 paste the code below on the Ardunio IDE. 4) Select UPLOAD to program the sketch on the UNO Board. #include <Wire.h> #include <LiquidCrystal_I2C.h> LiquidCrystal_I2C lcd(0x27,16,2); #define echoPin 7 // Echo Pin #define trigPin 8 // Trigger Pin #define LEDPin 13 // Onboard LED int maximumRange = 200;...
  • Page 192 pinMode(echoPin, INPUT); pinMode(LEDPin, OUTPUT); // Use LED indicator (if required) void loop() { /* The following trigPin/echoPin cycle is used to determine the distance of the nearest object by bouncing soundwaves off of it. */ digitalWrite(trigPin, LOW); delayMicroseconds(2); digitalWrite(trigPin, HIGH); delayMicroseconds(10);...
  • Page 193 lcd.setCursor(3,1); lcd.print("-1 "); digitalWrite(LEDPin, HIGH); else { /* turn LED OFF to indicate successful reading. */ lcd.setCursor(3,1); lcd.print(distance); digitalWrite(LEDPin, LOW); if(distance<10) lcd.setCursor(4,1); lcd.print(" "); if(distance<100) lcd.setCursor(5,1); lcd.print(" "); //Delay 50ms before next reading. delay(50);...
  • Page 194 What You Will See:...
  • Page 195 Move your hand or a large, flat object closer and farther away from the distance sensor. As the object approaches, the LCD display screen will show the distance being read from the sensor.
  • Page 196 Troubleshooting:  LCD Display Not Clear? Remember you can adjust the contrast using the potentiometer if you can’t make out the words clearly.
  • Page 198: Circuit 18: Driving Servo Motor

    Circuit 18: Driving Servo Motor In this circuit, you will learn how to wire a servo and control it with About this circuit: code. Servo motors can be told to move to a specific position and stay there. Here we will turn a potentiometer to make the servo rotate in a certain angle.
  • Page 199 Component Introduction: The servo has three interfaces,distinguished by brown, red and orange Servo motor: line (different brand may have different color). Brown line is for GND, red one for power 5V, orange one for signal terminal (PWM signal). Included with your servo motor you will find a variety of white motor mounts that connect to the shaft of your servo.
  • Page 200 PWM signal is fixed at 20ms (50 Hz), and the pulse width is distributed between 1ms-2ms. The pulse width corresponds to the rotation angle ( 0°~90°) of servo. Check out the circuit diagram and hookup table below to see how Hookup Guide: everything is connected.
  • Page 203 Note: Before you can run this, make sure that you have installed the Upload Code: <Servo.h> library or re-install it, if necessary. Otherwise, your code won't work. 2) Connect the REV4 Board to a USB port on your computer. 3) Open the program in the code folder- Circuit 18, or directly copy and paste the code below on the Ardunio IDE.
  • Page 204 myservo.write(servo);//set rotating angle delay(50);  Single line comments start with and everything up until the end Code Explanation: of that line is considered a comment. Comments are a great way to leave notes in your code explaining why you wrote it the way you did. ...
  • Page 205 Turning the potentiometer will cause the servo arm to turn. The servo will mimic the movement of the potentiometer, twisting in the same clockwise or counter-clockwise direction. If you’ve attached a white mount to the servo, this movement will be easier to see.
  • Page 208: Circuit 19: Relay

    Circuit 19: Relay In this circuit, you will learn how to use a relay and other tiny sensors About this circuit: to turn on an LED. REV4 Baseplate What You Need: Relay x 1   4N35 *1  4007 Diode*1 ...
  • Page 209 220Ω Resistor x 2  Jumper wires x 11  USB cable x 1  Component Introduction: A relay is basically an electrically controlled mechanical Relay: switch with isolation function. Relays are used where it is necessary to control a circuit by a low power signal (with complete electrical isolation between control and controlled circuits), or where several circuits must be controlled by one signal.
  • Page 210 used to drive silicon phototransistors. Used to protect the circuit 4007 Diode: Used as a switch NPN 8050 Transistor: Check out the circuit diagram and hookup table below to see how Hookup Guide: everything is connected.
  • Page 212 (pay attention to using the NPN 8050 transistor; the plug direction of 4N35, relay and diode ) Upload Code:...
  • Page 213 1) Connect theREV4 Board to a USB port on your computer. 2) Open the program in the code folder- Circuit 19, or directly copy and paste the code below on the Ardunio IDE. 3) Select UPLOAD to program the sketch on the UNO Board. int relay = 3;...
  • Page 214 What You Will See: Here, when S is in high level, relay switches to the ON end. LED will be turned on. In the test result, you should be able to hear the relay contacts click, and see the LED turning on and off at 1-second intervals.
  • Page 215 Troubleshooting:  LED Not Lighting? Double-check that you have plugged them in correctly. The longer lead is the positive end.  No Clicking Sound? Check the transistor you use is NPN8050, whether plug in the right way.
  • Page 216: Circuit 20: Pir Motion Sensor

    Circuit 20: PIR Motion Sensor In this lesson we will create an alarm system to detect motion, About this circuit: combining usage of PIR sensor, 1602 LCD and LED. REV4 Baseplate What You Need: PIR motion sensor x 1  ...
  • Page 217 Component Introduction: The Pyroelectric infrared motion sensor can detect infrared signals PIR motion sensor: from a moving person or moving animal, and output switching signals. It can be applied to a variety of occasions to detect the movement of human body. Input Voltage: DC 3.3V ~ 18V Parameters: Working Current: 15uA...
  • Page 218 Check out the circuit diagram and hookup table below to see how Hookup Guide: everything is connected.
  • Page 220 Note: Before you can run this, make sure that you have installed the Upload Code: LCD library or re-install it, if necessary. Otherwise, your code won't work. 2) Connect the REV4 Board to a USB port on your computer. 3) Open the program in the code folder- Circuit 20, or directly copy and...
  • Page 221 paste the code below on the Ardunio IDE. 4) Select UPLOAD to program the sketch on the UNO Board. #include <Wire.h> #include <LiquidCrystal_I2C.h> LiquidCrystal_I2C lcd(0x27,16,2); byte sensorPin = 6; byte indicator = 10; void setup() lcd.init(); // initialize the lcd lcd.init();...
  • Page 222 digitalWrite(indicator,state); if(state == 1) lcd.setCursor(2,0); lcd.print("Somebody is"); lcd.setCursor(2,1); lcd.print("in this area!"); else if(state == 0) lcd.setCursor(2,0); lcd.print("No one! "); lcd.setCursor(2,1); lcd.print("No one! "); delay(500);...
  • Page 223 Move your hand or a large, flat object closer and farther away from the What You Will See:...
  • Page 224 PIR sensor. If the LCD shows ”Somebody is in this area!” and LED lights up, it is reminding of you that somebody is here. Otherwise, it will tell you by displaying “No one!”on LCD and LED off. Troubleshooting:  LED Not Lighting? Double-check that you have plugged them in correctly.
  • Page 225  LCD Display Not Clear? Remember you can adjust the contrast using the potentiometer if you can’t make out the words clearly.
  • Page 226: Get Started With Robot Projects

    GET STARTED WITH ROBOT PROJECTS! In this project, you will learn all about DC motors and motor drivers by building your own robot! You’ll first learn motor control basics. By adding an IR receiver, remote control the robot to move freely. By adding an IR receiver or distance sensor, the robot can learn how to avoid obstacles.
  • Page 227: Robot Basepalte Assembly

    ROBOT BASEPALTE ASSEMBLY Before you build this circuit, you’ll need to make a few modifications to the breadboard baseplate to make it more robot-like! 1. Cut two more strips and weld the strips to the two motors. Cut and attach two short pieces of dual-lock adhesive tape to your motors. Be sure that your motors are mirror images of each other when you attach the Dual Lock tape.
  • Page 228 Make sure the Omni-directional wheel is firmly mounted on the Clear Acrylic plate with the two screws and nuts. Then cut and attach a short piece of dual-lock adhesive tape to Acrylic Stick the two motors and Omni-directional wheel on the keyestudio plate. Baseplate.
  • Page 229 3. The bottom of your baseplate should look like the image. Remember that the two motors should be mirror images of each other. 4. Attach the wheels by sliding them onto the plastic shafts on the gear motor. The shaft is flat on one side, as is the wheel coupler. Align the two, and then press to fit the wheel onto the shaft.
  • Page 231 5. The white part will act as a caster as the robot drives around. Cut two pieces of Dual Lock. Remove the adhesive backing, and attach Battery Holder Attachment: one piece to the back of the battery holder. Adhere the second piece to the bottom of the baseplate, directly in the middle.
  • Page 232 Once you’re finished, it’s time to build the circuit.
  • Page 233: Circuit 21: Motor Basics

    Circuit 21: Motor Basics In this circuit, you will learn the basic concepts behind motor control. About this circuit: You’ll use what is known as a motor controller or motor driver board to power and spin the motor accordingly. Gear Motor x 2 What You Need: ...
  • Page 234 Component Introduction: The gear motor has two main parts: a small DC Gear Motor: motor that spins quickly and a plastic gearbox that gears down the output from the hobby motor so that it is slower but stronger, allowing it to move your robot. TB6612FNG Motor Driver: The TB6612FNG Motor Driver may look complicated, but it’s easy to use.
  • Page 235 mode. Logic supply voltage (VCC) can be in the range of DC 2.7-5.5V, while the motor supply (VM) is limited to a maximum voltage of 15V DC. The output current is rated up to 1.2A per channel (or up to 3.2A for a short, single pulse).
  • Page 236 Power supply voltage: VM=15V max, VCC=2.7-5.5V Output current: Iout=1.2A(average) / 3.2A (peak)  Standby control to save power  CW/CCW/short brake/stop motor control modes  Built-in thermal shutdown circuit and low voltage detecting circuit  Filtering capacitors on both supply lines ...
  • Page 238 Circuit Diagram:...
  • Page 239 1) Connect the REV4 Board to a USB port on your computer. Upload Code: 2) Open the program in the code folder- Circuit 21, or directly copy and paste the code below on the Ardunio IDE.
  • Page 240 3) Select UPLOAD to program the sketch on the UNO Board. 4) Unplug the USB cable, then power the board with 7-12V battery pack. Code 1: int AIN1=2; int AIN2=3; int STBY=4; int BIN1=5; int BIN2=6; int PWMA=10;// enable pin 1 int PWMB=11;// enable pin 2 // D2 and D3 as a set, D5 and D6 as a set // D10 and D11 as enable pins for DC motors...
  • Page 241 void loop() // 2 DC motor rotate CW for 1S, and rotate CCW for 1S // rotate CW front(); delay(1000); Stop(); back(); delay(1000); Stop(); delay(1000); left(); delay(1000); Stop(); delay(1000); right(); delay(1000); Stop(); delay(1000); void front() { digitalWrite(STBY,HIGH);...
  • Page 242 digitalWrite(AIN1,HIGH); digitalWrite(AIN2,LOW); analogWrite(PWMA,200); digitalWrite(BIN1,HIGH); digitalWrite(BIN2,LOW); analogWrite(PWMB,200); void back() { digitalWrite(STBY,HIGH); digitalWrite(AIN1,LOW); digitalWrite(AIN2,HIGH); analogWrite(PWMA,200); digitalWrite(BIN1,LOW); digitalWrite(BIN2,HIGH); analogWrite(PWMB,200); void Stop() { digitalWrite(STBY,LOW);...
  • Page 243 void left() { digitalWrite(STBY,HIGH); digitalWrite(AIN1,HIGH); digitalWrite(AIN2,LOW); analogWrite(PWMA,200); digitalWrite(BIN1,LOW); digitalWrite(BIN2,HIGH); analogWrite(PWMB,200); void right() { digitalWrite(STBY,HIGH); digitalWrite(AIN1,LOW); digitalWrite(AIN2,HIGH); analogWrite(PWMA,200); digitalWrite(BIN1,HIGH); digitalWrite(BIN2,LOW); analogWrite(PWMB,200);...
  • Page 244 Code 2: int AIN1=2; int AIN2=3; int STBY=4; int BIN1=5; int BIN2=6; int PWMA=10;// enable pin 1 int PWMB=11;// enable pin 2 // D2 and D3 as a set, D5 and D6 as a set // D10 and D11 as enable pins for DC motors void setup() int i;...
  • Page 245 digitalWrite(STBY,HIGH); digitalWrite(AIN1,HIGH); digitalWrite(AIN2,LOW); analogWrite(PWMA,200); digitalWrite(BIN1,HIGH); digitalWrite(BIN2,LOW); analogWrite(PWMB,200); delay(1000); // pause for 1S digitalWrite(STBY,LOW); delay(1000); // rotate CCW digitalWrite(STBY,HIGH); digitalWrite(AIN1,LOW); digitalWrite(AIN2,HIGH); analogWrite(PWMA,200); digitalWrite(BIN1,LOW); digitalWrite(BIN2,HIGH); analogWrite(PWMB,200); delay(1000); // pause for 1S...
  • Page 246 digitalWrite(STBY,LOW); delay(1000); Uploaded well the code, and flip the switch. The motor will spin at the What You Will See: speed set by the motor speed variable. Here in the folder we provide two codes for the same wiring method. If upload the code 1 motor basics, the motor will rotate forward for one second then stop for one second;...
  • Page 248: Circuit 22: Light Following Robot

    Circuit 22: Light Following Robot About this circuit: Using two photo-resistors are a great way to have light control of your project. this circuit, you’ll control two motors and build your own light following robot! You can use the light source to tell the robot in what direction to move or move straight.
  • Page 249 Component Introduction: Photo resistor (Photovaristor) is a resistor whose resistance varies Photo Resistor : according to different incident light strength. It's made based on the photoelectric effect of semiconductor. If the incident light is intense, its resistance reduces; if the incident light is weak, the resistance increases.
  • Page 251 Circuit Diagram: 1) Connect the REV4 Board to a USB port on your computer. Upload Code: 2) Open the program in the code folder- Circuit 22, or directly copy and paste the code below on the Ardunio IDE. 3) Select UPLOAD to program the sketch on the UNO Board.
  • Page 252 int value1=0; int value2=0; int AIN1=2; int AIN2=3; int STBY=4; int BIN1=5; int BIN2=6; int PWMA=10;// enable pin 1 int PWMB=11;// enable pin 2 int Fspeed; int Lspeed; int Rspeed; void setup() Serial.begin(9600); int i; for (i=2;i<=6;i++) // Ardunio motor driver module pinMode(i,OUTPUT);...
  • Page 253 void loop() value1=analogRead(0); value2=analogRead(1); Serial.print(value1); Serial.print(" "); Serial.println(value2); if(value1 >900&&value2 >900) //if front distance is less than 10cm front(); if(value1 >900&&value2 <=900) //if front distance is less than 10cm left(); if(value1 <=900&&value2 >900) //if front distance is less than 10cm...
  • Page 254 right(); if(value1 <=900&&value2 <=900) //if front distance is less than 10cm stop(); void front() { digitalWrite(STBY,HIGH); digitalWrite(AIN1,HIGH); digitalWrite(AIN2,LOW); analogWrite(PWMA,200); digitalWrite(BIN1,HIGH); digitalWrite(BIN2,LOW); analogWrite(PWMB,200); void back() { digitalWrite(STBY,HIGH); digitalWrite(AIN1,LOW); digitalWrite(AIN2,HIGH);...
  • Page 255 analogWrite(PWMA,200); digitalWrite(BIN1,LOW); digitalWrite(BIN2,HIGH); analogWrite(PWMB,200); void stop() { digitalWrite(STBY,LOW); void left() { digitalWrite(STBY,HIGH); digitalWrite(AIN1,HIGH); digitalWrite(AIN2,LOW); analogWrite(PWMA,200); digitalWrite(BIN1,LOW); digitalWrite(BIN2,HIGH); analogWrite(PWMB,200); void right() {...
  • Page 256 digitalWrite(STBY,HIGH); digitalWrite(AIN1,LOW); digitalWrite(AIN2,HIGH); analogWrite(PWMA,200); digitalWrite(BIN1,HIGH); digitalWrite(BIN2,LOW); analogWrite(PWMB,200); Start by flipping the switch to the ON position. What You Will See Hook it up and upload the code success, the tank robot is walking with strong light under certain illumination. When one photoresistor senses the light source, the robot will turn round then follow the light illumination.
  • Page 257 Both two photoresistors sense the light source, the robot will go straight to follow the light illumination. Shown below.
  • Page 259: Circuit 23: Remote-Controlled Robot

    Circuit 23: Remote-Controlled Robot About this circuit: Using an IR Remote is a great way to have wireless control of your project. this circuit, you’ll control two motors and build your own remote-controlled roving robot! You can use the remote controller to tell the robot in what direction to move and how far to move.
  • Page 260 Component Introduction: IR Receiver: Infrared receiver is a component with functions of reception, amplification, and demodulation. The internal IC has already been demodulated so that can directly output digital signal. Infrared receiver has 3 pins. When you use it, connect VOUT to Analog pin, GND to GND, VCC to +5V.
  • Page 261 Below we have listed out each button value of keyestudio remote control for reference. Check out the circuit diagram and hookup table below to see how Hookup Guide: everything is connected.
  • Page 263 Circuit Diagram: Note: Before you can run this, make sure that you have installed the Upload Code: <IRremote.h> library or re-install it, if necessary. Otherwise, your code won't work. 2) Connect the REV4 Board to a USB port on your computer. 3) Open the program in the code folder- Circuit 23, or directly copy and...
  • Page 264 paste the code below on the Ardunio IDE. 4) Select UPLOAD to program the sketch on the UNO Board. #include <IRremote.h> int RECV_PIN = 8; int LED1 = 13; unsigned long on1 = 0x00FF6897; unsigned long off1 = 0x00FF9867; int AIN1=2; int AIN2=3;...
  • Page 265 void setup() int i; for (i=2;i<=6;i++) // Ardunio motor driver module pinMode(i,OUTPUT); // set digital pins 2,3,4,5,6 as output pinMode(10,OUTPUT);// set digital pins 10, 11 as output pinMode(11,OUTPUT); pinMode(LED1, OUTPUT); irrecv.enableIRIn(); // Start the receiver void loop() if (irrecv.decode(&results)) if (results.value == advance1 ) front();...
  • Page 266 if (results.value == right1 ) right(); if (results.value == on1 ) digitalWrite(LED1, HIGH); if (results.value == off1 ) digitalWrite(LED1, LOW); irrecv.resume(); // Receive the next value void front() { digitalWrite(STBY,HIGH); digitalWrite(AIN1,HIGH); digitalWrite(AIN2,LOW); analogWrite(PWMA,200); digitalWrite(BIN1,HIGH); digitalWrite(BIN2,LOW); analogWrite(PWMB,200); void back() { digitalWrite(STBY,HIGH); digitalWrite(AIN1,LOW);...
  • Page 267 digitalWrite(AIN2,HIGH); analogWrite(PWMA,200); digitalWrite(BIN1,LOW); digitalWrite(BIN2,HIGH); analogWrite(PWMB,200); void Stop() { digitalWrite(STBY,LOW); void left() { digitalWrite(STBY,HIGH); digitalWrite(AIN1,HIGH); digitalWrite(AIN2,LOW); analogWrite(PWMA,200); digitalWrite(BIN1,LOW); digitalWrite(BIN2,HIGH); analogWrite(PWMB,200);...
  • Page 268 void right() { digitalWrite(STBY,HIGH); digitalWrite(AIN1,LOW); digitalWrite(AIN2,HIGH); analogWrite(PWMA,200); digitalWrite(BIN1,HIGH); digitalWrite(BIN2,LOW); analogWrite(PWMB,200); Start by flipping the switch to the ON position. What You Will See Use remote control to make the robot move or turn.
  • Page 270: Circuit 24: Ultrasonic Ranging Robot

    Circuit 24: Ultrasonic Ranging Robot About this circuit: Gear Motor x 2 What You Need: Slide switch x 1   ultrasonic sensor x 1 TB6612FNG Motor Driver x 1   Jumper wires x 25 TB6612FN ...
  • Page 271 Check out the circuit diagram and hookup table below to see how Hookup Guide: everything is connected.
  • Page 272 Circuit Diagram:...
  • Page 273 1) Connect the REV4 Board to a USB port on your computer. Upload Code: 2) Open the program in the code folder- Circuit 24, or directly copy and paste the code below on the Ardunio IDE. 3) Select UPLOAD to program the sketch on the UNO Board. int AIN1=2;...
  • Page 274 int AIN2=3; int STBY=4; int BIN1=5; int BIN2=6; int PWMA=10;// enable pin 1 int PWMB=11;// enable pin 2 int pinTrip = 8; //define ultrasonic ting pin to D12 int pinEcho = 9; //define ultrasonic echo pin to D13 int Fspeed; int Lspeed;...
  • Page 275 void ask_pin_F() // measure the front distance digitalWrite(pinTrip, LOW); make ultrasonic emit LOW voltage 2μs delayMicroseconds(2); digitalWrite(pinTrip, HIGH); // make ultrasonic emit HIGH voltage 10μs,here at least 10μs delayMicroseconds(10); digitalWrite(pinTrip, LOW); // make ultrasonic emit LOW voltage float Fdistance = pulseIn(pinEcho, HIGH); // read the time difference Fdistance= Fdistance/5.8/10;...
  • Page 276 ask_pin_F(); // read the front distance if(Fspeed < 10) //if front distance is less than 10cm stop(); // clear the output data delay(100); back(); // backward 0.2 second delay(200); if(Fspeed < 25) //if front distance is less than25cm stop(); left(); delay(200);...
  • Page 277 if(Lspeed > Rspeed) //if left speed is greater than right speed left(); delay(400); front(); if(Lspeed <= Rspeed) //if left speed is less than or equal to right speed front(); if (Lspeed < 10 && Rspeed < 10) //if both left and right side distance are less than 10cm back();...
  • Page 278 front(); void front() { digitalWrite(STBY,HIGH); digitalWrite(AIN1,HIGH); digitalWrite(AIN2,LOW); analogWrite(PWMA,200); digitalWrite(BIN1,HIGH); digitalWrite(BIN2,LOW); analogWrite(PWMB,200); void back() { digitalWrite(STBY,HIGH); digitalWrite(AIN1,LOW); digitalWrite(AIN2,HIGH); analogWrite(PWMA,200); digitalWrite(BIN1,LOW); digitalWrite(BIN2,HIGH); analogWrite(PWMB,200);...
  • Page 279 void stop() { digitalWrite(STBY,LOW); void left() { digitalWrite(STBY,HIGH); digitalWrite(AIN1,HIGH); digitalWrite(AIN2,LOW); analogWrite(PWMA,200); digitalWrite(BIN1,LOW); digitalWrite(BIN2,HIGH); analogWrite(PWMB,200); void right() { digitalWrite(STBY,HIGH); digitalWrite(AIN1,LOW); digitalWrite(AIN2,HIGH); analogWrite(PWMA,200); digitalWrite(BIN1,HIGH);...
  • Page 280 digitalWrite(BIN2,LOW); analogWrite(PWMB,200); The robot that you will build uses a simple sensor to avoid obstacles. Keep in mind that the ultrasonic distance sensor needs a clear path to avoid unwanted interruptions in your robot’s movements. Keep the distance sensor clear of any wires from your circuit.
  • Page 281 When the switch is turned What You Will See off, the robot will sit still. When the switch is turned on, the robot will drive forward until it senses an object. When it senses an object in its path, it will reverse and then turn to avoid the obstacle.
  • Page 283: Circuit 25: Object Following Robot

    Circuit 25: Object Following Robot About this circuit: Gear Motor x 2 What You Need: Slide switch x 1   ultrasonic sensor x 1 TB6612FNG Motor Driver x 1   Jumper wires x 25 TB6612FN ...
  • Page 284 Check out the circuit diagram and hookup table below to see how Hookup Guide: everything is connected.
  • Page 286 Circuit Diagram: 1) Connect the REV4 Board to a USB port on your computer. Upload Code: 2) Open the program in the code folder- Circuit 25, or directly copy and paste the code below on the Ardunio IDE. 3) Select UPLOAD to program the sketch on the UNO Board.
  • Page 287 int AIN1=2; int AIN2=3; int STBY=4; int BIN1=5; int BIN2=6; int PWMA=10;// enable pin 1 int PWMB=11;// enable pin 2 int pinTrip = 8; //define ultrasonic ting pin to D12 int pinEcho = 9; //define ultrasonic echo pin to D13 int Fspeed;...
  • Page 288 void ask_pin_F() // measure the front distance digitalWrite(pinTrip, LOW); make ultrasonic emit LOW voltage 2μs delayMicroseconds(2); digitalWrite(pinTrip, HIGH); // make ultrasonic emit HIGH voltage 10μs,here at least 10μs delayMicroseconds(10); digitalWrite(pinTrip, LOW); // make ultrasonic emit LOW voltage float Fdistance = pulseIn(pinEcho, HIGH); // read the time difference Fdistance= Fdistance/5.8/10;...
  • Page 289 void loop() ask_pin_F(); // read the front distance if(Fspeed >0&&Fspeed <= 15) //if front distance is less than 10cm back(); if(Fspeed >15&&Fspeed <= 20) //if front distance is less than 10cm stop(); if(Fspeed >20&&Fspeed <= 40) //if front distance is less than 10cm front();...
  • Page 290 void front() { digitalWrite(STBY,HIGH); digitalWrite(AIN1,HIGH); digitalWrite(AIN2,LOW); analogWrite(PWMA,200); digitalWrite(BIN1,HIGH); digitalWrite(BIN2,LOW); analogWrite(PWMB,200); void back() { digitalWrite(STBY,HIGH); digitalWrite(AIN1,LOW); digitalWrite(AIN2,HIGH); analogWrite(PWMA,200); digitalWrite(BIN1,LOW); digitalWrite(BIN2,HIGH); analogWrite(PWMB,200); void stop() {...
  • Page 291 digitalWrite(STBY,LOW); void left() { digitalWrite(STBY,HIGH); digitalWrite(AIN1,HIGH); digitalWrite(AIN2,LOW); analogWrite(PWMA,200); digitalWrite(BIN1,LOW); digitalWrite(BIN2,HIGH); analogWrite(PWMB,200); void right() { digitalWrite(STBY,HIGH); digitalWrite(AIN1,LOW); digitalWrite(AIN2,HIGH); analogWrite(PWMA,200); digitalWrite(BIN1,HIGH); digitalWrite(BIN2,LOW); analogWrite(PWMB,200);...
  • Page 292 When the switch is turned What You Will See off, the robot will sit still. When the switch is turned on, the robot will drive forward until it senses an object. When it senses an object in its path, it will follow an object ahead to move.
  • Page 294: Get All Resources For Robot Projects

    Keyestudio is a best-selling brand owned by KEYES Corporation, our product lines range from Arduino boards, shields, sensor modules, Raspberry Pi, micro:bit extension boards and smart car to complete starter kits designed for customers of any level to learn Arduino knowledge.
  • Page 295 Welcome check more contents from our official website: http://www.keyestudio.com For more details of our products, you can check it from the links below. WIKI Website: https://wiki.keyestudio.com US Amazon storefront: http://www.amazon.com/shops/A26TCVWBQE4D9T CA Amazon storefront: http://www.amazon.ca/shops/A26TCVWBQE4D9T UK Amazon storefront: http://www.amazon.co.uk/shops/A39F7KX4U3W9JH DE Amazon storefront: http://www.amazon.de/shops/A39F7KX4U3W9JH...
  • Page 296 Thank you in advance. Fennie@keyestudio.com...

Table of Contents