Ks0436 keyestudio Ultimate Starter Kit For Little Inventor (Zero-based Arduino Learning Robot): Difference between revisions

From Keyestudio Wiki
Jump to navigation Jump to search
Line 564: Line 564:
* USB cable x 1
* USB cable x 1
[[File:Ks0436-17.png|200px]]
[[File:Ks0436-17.png|200px]]
<br>
'''Component Introduction:''' <br>
<span style="color:brown"> '''Photo Resistor:''' </span><br>
Photo resistor (Photovaristor) is a resistor whose resistance varies according to different incident light strength. 
[[File:Ks0436-17.png|200px|right]]
It's made based on the photoelectric effect of semiconductor. <br>
If the incident light is intense, its resistance reduces; if the incident light is weak, the resistance increases. <br>
Photo resistor is widely applied to various light control circuit, such as light control and adjustment, optical switches, etc.<br>
[[File:Ks0436-17.png|200px]]
Photovaristor is an element that changes its resistance as light strength changes. So we will need to read the analog values. <br>
We can refer to the PWM experiment, replacing the potentiometer with photovaristor. When there is change in light strength, there will be corresponding change on the LED.<br>
<br>
'''Hookup Guide:'''<br>
The photoresistors, like regular resistors, are not polarized and can be installed in either direction. <br>
[[File:Ks0436-17.png|200px]] [[File:Ks0436-17.png|200px]]
<br>
'''Upload Code:'''<br>
* 1)Connect the UNO Board to a USB port on your computer.
* 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. The program is similar to the one of PWM. <br>
For change details, please refer to the Sample Code below. <br>
<pre>
int potpin=0;// initialize analog pin 0, connected with photovaristor
int ledpin=11;// initialize digital pin 11, output regulating the brightness of LED
int val=0;// initialize variable val
void setup()
{
pinMode(ledpin,OUTPUT);// set digital pin 11 as“output”
Serial.begin(9600);// set baud rate at“9600”
}
void loop()
{
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
}
</pre>
<br>
[[File:Ks0436-17.png|200px]] <br>
'''What You Will See:'''<br>
You can change the light intensity around the photovaristor and see corresponding brightness change of the LED. See the light intensity on the serial monitor.
<br>[[File:Ks0436-17.png|200px]]<br>
<br>[[File:Ks0436-17.png|200px]]<br>

Revision as of 15:23, 12 July 2019

Zero-based Arduino Learning Robot


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 UNO 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!


INTRODUCTION

The UNO Board Platform

The keyestudio UNO Board is your development platform.

keyestudio UNO R3 Board Advanced

The UNO 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).
This board is capable of taking the world of electronics and relating it to the physical world in a real and tangible way.

The keyestudio UNO Board is a microcontroller board based on the ATmega328P microprocessor.
It has 14 digital input/output pins (of which 6 can be used as PWM outputs), 6 analog inputs, a 16 MHz quartz crystal, a USB connection, a power jack, 2 ICSP headers and a reset button.
It contains everything needed to support the microcontroller; simply 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:
KS0341 引脚.jpg



The Breadboard Platform

A breadboard is a circuit-building platform that allows you to connect multiple components without using a soldering iron.

400 transparent breadboard

This is a half-size transparent breadboard, good for small projects.
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:
Ks0436-2.png


The Baseplate Assembly

Before you can build circuits, you’ll want to first assemble the breadboard baseplate.

Baseplate

This keyestudio baseplate makes circuit building easier by keeping the UNO Board microcontroller and the breadboard connected without the worry of disconnecting or damaging your circuit.

1)To begin with, collect your parts: the UNO Board, breadboard, screwdriver, keyestudio baseplate and four baseplate screws.
framless


2)Align the UNO board with its spot on the baseplate.
The text on it should face the same direction as the text on the breadboard and the baseplate.
Using four screws, affix the UNO Board to the four stand-off holes found on the baseplate.
Ks0436-5.png


3)Peel the adhesive backing off the breadboard.
Ks0436-6.png


4)Carefully align the breadboard over its spot on the baseplate. The text on the breadboard should face the same direction as the text on the baseplate. Firmly press the breadboard to the baseplate to adhere it.
Ks0436-7.png

Your baseplate is now assembled!
Ks0436-8.png



The Arduino IDE

In order to get your UNO Board up and running.
you'll need to download the newest version of the Arduino software from www.arduino.cc (it's free!).
KS0313-3.png

This software, known as the Arduino IDE (Integrated Development Environment), will allow you to program the UNO Board to do exactly what you want. It’s like a word processor for coding.


With an internet-capable computer, open up your favorite browser and type the following URL into the address bar to download the software of any versions:
https://www.arduino.cc/en/Main/OldSoftwareReleases#1.5.x


Open Arduino IDE
Downloaded the software package, unzip the folder package, double click the Arduino icon to open.
Ks0313图片1.png

framless


The functions of each button on the Toolbar are listed below:
IDE.png

IDE 1.png Verify/Compile Check the code for errors
IDE 2.png Upload Upload the current Sketch to the Arduino
IDE 3.png New Create a new blank Sketch
IDE 4.png Open Show a list of Sketches
IDE 5.png Save Save the current Sketch
IDE 6.png Serial Monitor Display the serial data being sent from the Arduino



Select Your Board And Serial Port
NOTE: select the Arduino UNO, but if you are not sure which ports should choose. Go to your computer panel, and check the Port out in the Device Manger.
framless

framless



The Parts List

The Kit contains extensive electronic components. Below shows you a part of kit components:
framless



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.
The project will set the foundation for the rest and will aid in helping you understand the fundamentals of circuit building and electricity!

Ks0436-12.png


Circuit 1: Blinking an LED


About this circuit:
Blinking an LED is the classic starting point for learning how to program embedded electronic components.
In this circuit, you’ll write code that makes an LED blink on and off.


What You Need:

  • UNO Baseplate

Ks0436-14.png

  • Red LED x 1

Ks0436-13.png

  • 220Ω Resistor x 1

Ks0436-15.png

  • Jumper wires x 2

Ks0436-16.png

  • USB cable x 1

Ks0436-17.png


Component Introduction:

LIGHT-EMITTING DIODES (LEDS):
They come in different colors, brightnesses and sizes. LEDs have a positive (+) leg and a negative (-) leg, and they will only let electricity flow through them in one direction.

Ks0436-18.png

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.


RESISTORS: resist the flow of electricity.
Ks0436-19.png
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.

Ks0436-20.png Ks0436-21.png


Wiring Diagram:
Check out the schematics and wiring diagram below to see how everything is connected.

Schematics:

Ks0436-22.png Ks0436-23.png


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.


Upload Code:

  • 1)Connect the UNO Board to a USB port on your computer.
  • 2)Open the program in the code folder- Circuit 1 LED, 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 = 10; // define digital pin 10.
void setup()
{
pinMode(ledPin, OUTPUT);// define pin with LED connected as output.
}
void loop()
{
digitalWrite(ledPin, HIGH); // set the LED on.
delay(1000); // wait for a second.
digitalWrite(ledPin, LOW); // set the LED off.
delay(1000); // wait for a second
}


Code Explanation:

  • Single line comments start with // and everything up until the end 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.

  • The first line of code is:

int ledPin = 10; // define digital pin 10
As the comment above it explains, this is giving a name to the pin that the LED is connected to. You can change the connection pin here.

  • Next, we have the “setup” and “loop” function

void setup()
Every Arduino sketch must have a 'setup' function, and the place where you might want to add instructions of your own is between the { and the }. In this case, there is just one command there, which, as the comment 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.

  • Input Or Output ?:

pinMode(ledPin, OUTPUT)
Before you can use one of the digital pins, you need to tell the UNO Board whether it is an INPUT or OUTPUT.
We use a built-in “function” called pinMode() to make pin 10 a digital output.

Digital Output:
digitalWrite(ledPin, HIGH)
digitalWrite(ledPin, LOW)
When you’re using a pin as an OUTPUT, you can command it to be HIGH (output 5 volts) or LOW (output 0 volts).

  • What happens when you change the number in one or both of the delay(1000)

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:
Ks0436-24.png

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!
Ks0436-25.png



Troubleshooting:

  • Upload failed?

Make sure you have assembled the circuit correctly and verified and uploaded the code to your board. Check out the Board and Serial Port.



Circuit 2: Light Extension


About this circuit:
After mastering LED Blinking, let’s move on to how to control lots of 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.
Furthermore, you can also use three LEDs to simulate the traffic light. Now let’s start something different!


What You Need:

  • UNO Baseplate

Ks0436-14.png

  • Red LED x 6

Ks0436-13.png

  • 220Ω Resistor x 6

Ks0436-15.png

  • Jumper wires x 7

Ks0436-16.png

  • USB cable x 1

Ks0436-17.png


Wiring Diagram:
Check out the wiring below to see how everything is connected.


Schematics:
Ks0436-26.pngKs0436-27.png



Upload Code:

  • 1)Connect the UNO Board to a USB port on your computer.
  • 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 ;  // the I/O pin for the first LED
int NUM = 6;   // the number of LEDs
void setup()
{
   for (int i = BASE; i < BASE + NUM; i ++) 
   {
     pinMode(i, OUTPUT);   // set I/O pins as output
   }
}
void loop()
{
   for (int i = BASE; i < BASE + NUM; i ++) 
   {
     digitalWrite(i, LOW);    // set I/O pins as “low”, turn off LEDs 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
   }  
}


Code Explanation:

  • Single line comments start with // and everything up until the end 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.

  • int BASE = 2 ; // set the I/O pin for the first LED
  • int NUM = 6; // the number of LEDs

Ks0436-28.png


What You Will See:
Ks0436-29.png


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.
Ks0436-30.png



Troubleshooting:

  • Upload failed?

Make sure you have assembled the circuit correctly and verified and uploaded the code to your board. Check out the Board and Serial Port.

  • LED Not Lighting Up?

Make sure you connect the LED correctly or try other LEDs.



How to make a traffic light?


What You Need:

  • UNO Baseplate

Ks0436-14.png

  • Red LED x 1

Ks0436-13.png

  • Yellow LED x 1

Ks0436-31.png

  • Green LED x 1

Ks0436-32.png

  • 220Ω Resistor x 3

Ks0436-15.png

  • Jumper wires x 4

Ks0436-16.png

  • USB cable x 1

Ks0436-17.png


Hookup Guide:
Check out the hookup table below to see how everything is connected.
Schematics:
Ks0436-33.pngKs0436-34.png


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 “output”
pinMode(greenled, OUTPUT); // set the pin with green LED as “output”
}
void loop()
{
digitalWrite(greenled, HIGH);//// turn on green LED
delay(5000);// wait 5 seconds
digitalWrite(greenled, LOW); // turn off green LED
for(int i=0;i<3;i++)// blinks for 3 times
{
delay(500);// wait 0.5 second
digitalWrite(yellowled, HIGH);// turn on yellow LED
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
}


Ks0436-35.png

<br< 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. Ks0436-36.png



Circuit 3: Potentiometer


About this circuit:
In the previous project, you have learned how to turn on or off an LED.
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. Check more details below.


What You Need:

  • UNO Baseplate

Ks0436-14.png

  • Potentiometer x 1

Ks0436-37.png

  • Red LED x 1

Ks0436-13.png

  • 220Ω Resistor x 1

Ks0436-15.png

  • Jumper wires x 6

Ks0436-16.png

  • USB cable x 1

Ks0436-17.png



Component Introduction:

POTENTIOMETER:
Potentiometers (also known as“trimpots”or“knobs”) are one of the basic inputs for electronic devices.

Ks0436-37.png

A potentiometer is a 3-pin variable resistor.
When powered with 5V, the middle pin outputs a voltage between 0V and 5V, depending on the position of the knob on the potentiometer.
By tracking the position of the knob with your UNO Board, you can make volume controls, speed controls, angle sensors and a ton of other useful inputs for your projects.
Ks0436-38.png


PWM Control:
PWM is short for Pulse Width Modulation.

Ks0436-39.png

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. 
In the graphic, the green lines represent a regular time period.
KS0313(4)-1.png

This duration or period is the inverse of the PWM frequency.
In other words, with Arduino's PWM frequency at about 500Hz, the green lines would measure 2 milliseconds each.
A call to analogWrite() is on a scale of 0-255, such that analogWrite(255) requests a 100% duty cycle (always on), and analogWrite(127) is a 50% duty cycle (on half the time) for example.
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.
If merely make use of LOW and HIGH state, it cannot control the brightness of an LED light. However, if convert the voltage output of 0 Volts and 5 Volts into the value within 0-255, this way you can change the value within 0-255 to control the brightness of light.
The Arduino controller has totally 6 PWM outputs, which are Digital 3, 5, 6, 9, 10 and 11.
These pins can be used as Digital output or Analog output. If used as Analog output, it needs to call the analogWrite() function of ARDUINO, and this analogWrite() function can be controlled in the range of 0-255.
Ks0436-41.png


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.
Ks0436-42.pngKs0436-43.png


Upload Code:

  • 1)Connect the UNO Board to a USB port on your computer.
  • 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)
int val=0;// Temporarily store variables' value from the sensor
void setup()
{
pinMode(ledpin,OUTPUT);// define digital pin 11 as “output”
Serial.begin(9600);// set baud rate at 9600
// attention: for analog ports, they are automatically set up as “input”
}
void loop()
{
val=analogRead(potpin);// read the analog value from the sensor and assign it to val
Serial.println(val);// display value of val
analogWrite(ledpin,val/4);// turn on LED and set up brightness(maximum output of PWM is 255)
delay(10);// wait for 0.01 second
}


Code Explanation:

  • Single line comments start with // and everything up until the end 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.

  • The first line of code is:

int potpin=0;// initialize analog pin 0
A variable is a placeholder for values that may change in your code. You must introduce, or“declare,”variables before you use them.
Here we’re declaring a variable called potPosition of type int (integer).

  • Serial.begin(9600)

Serial commands can be used to send and receive data from your computer. Notice that the baud rate, 9600, is the same as the one we selected in the monitor. This is the speed at which the two devices communicate, and it must match on both sides.

  • val=analogRead(potpin)

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.


What You Will See:
You should see the LED brighter or dim in accordance with your potentiometer.
Ks0436-45.png

You should see numeric values print out in the monitor. Turning the potentiometer changes the value.
Ks0436-46.png



Troubleshooting:

  • Upload failed?

Make sure you have assembled the circuit correctly and verified and uploaded the code to your board. Ensure that you are on the correct Board and Serial Port.

  • No values in Serial Monitor?

Make sure that you have selected the correct baud rate, 9600.


Circuit 4: Photo Resistor


About this circuit:
In the previous circuit, you have learned how to use a potentiometer as 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.


What You Need:

  • UNO Baseplate

Ks0436-14.png

  • Potentiometer x 1

Ks0436-37.png

  • Red LED x 1

Ks0436-13.png

  • 220Ω Resistor x 1

Ks0436-15.png

  • 10KΩ Resistor x 1
  • Jumper wires x 5

Ks0436-16.png

  • USB cable x 1

Ks0436-17.png



Component Introduction:

Photo Resistor:
Photo resistor (Photovaristor) is a resistor whose resistance varies according to different incident light strength.

Ks0436-17.png

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. 
Photo resistor is widely applied to various light control circuit, such as light control and adjustment, optical switches, etc.
Ks0436-17.png

Photovaristor is an element that changes its resistance as light strength changes. So we will need to read the analog values.
We can refer to the PWM experiment, replacing the potentiometer with photovaristor. When there is change in light strength, there will be corresponding change on the LED.


Hookup Guide:
The photoresistors, like regular resistors, are not polarized and can be installed in either direction.
Ks0436-17.png Ks0436-17.png



Upload Code:

  • 1)Connect the UNO Board to a USB port on your computer.
  • 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. The program is similar to the one of PWM.
For change details, please refer to the Sample Code below. 

int potpin=0;// initialize analog pin 0, connected with photovaristor
int ledpin=11;// initialize digital pin 11, output regulating the brightness of LED
int val=0;// initialize variable val
void setup()
{
pinMode(ledpin,OUTPUT);// set digital pin 11 as“output”
Serial.begin(9600);// set baud rate at“9600”
}
void loop()
{
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 
}


Ks0436-17.png
What You Will See:
You can change the light intensity around the photovaristor and see corresponding brightness change of the LED. See the light intensity on the serial monitor.
Ks0436-17.png

Ks0436-17.png