Connect the Arduino Uno to PC with proper USB cable.
[Arduino Uno] -> 🔌 -> 💻
Open Arduino IDE program and open program with:
Files ⌥ Examples ⌥ 01. Basics ⌥ Blink.ino
Make sure that you will set the proper settings (follow the visual instructions). From the menu choose: Tools⌥
Board: Arduino/Genuino Uno
Port: COM3
To upload the code you can click the icon Upload.
If the uploading was successful you will be prompted with the text like:
Done uploading.
Sketch uses 970 bytes (3%) of program storage space. Maximum is 32256 bytes.
Global variables use 9 bytes (0%) of dynamic memory, leaving 2039 bytes for local variables. Maximum is 2048 bytes.
Basic testing in Ardublockly
Connect the Arduino Uno to PC with proper USB cable.
[Arduino Uno] -> 🔌 -> 💻
Run Ardublockly program. Which will be running as localhost and you will be using internet browser as IDE. The addres will be: http://localhost:8000/ardublockly/index.html
In the left corner of the program you can find [=] menu icon. From where you can choose (Slide 2 and 3) [] Settings:
Finaly you can press button PLAY
And if uploading was successful you will be prompted with the text (Slide 4):
Successfully Uploaded Sketch
WARNING: Error loading hardware folder /home/david/Arduino/hardware/WAV8F
No valid hardware definitions found in folder WAV8F.
Sketch uses 444 bytes (1%) of program storage space. Maximum is 32256 bytes.
Global variables use 9 bytes (0%) of dynamic memory, leaving 2039 bytes for local variables. Maximum is 2048 bytes.
🎓 Summary:
<++>
💣 Issues:
Ardublockly returns the Error id 55: Serial port Serial Port unavailable.
Try to reconect the Arduino board. Wait a moment, check the settings and choose the COM port again then try again.
How hard is to stop the shaft of the reductor in comparison to shaft of the motor.
How fast the shaft of the reductor is spinning in comparison to the shaft of the motor?
Are you able to freely rotate the shaft of the reductor by hand?
What happened with the produced mechanical power?
Try to calculate the geared ratio of the reductor.
🎓 Summary:
Gead ratio
The gear ratio describing the ratio between the angular velocity of input gear G1 and angular velocity of output gear G2.
$$ { i=\frac{\omega_1}{\omega_2} } $$
Because each gear moves tooth per tooth and if two touching gears have different numbers of teeths their's angular velocity will be different. In fact the anguar velocity will be inversely proportional.
$$ {\frac{\omega_1}{\omega_2}=\frac{N_2}{N_1}=i} $$
💣 Issues:
The reductor's shaft is not spinning although the DC motor is working properly.
Check if the reductor is all the way connected on the motor. Check if the worm gear of the motor is in contact with first gear of the roductor.
Now you can write the program to control both motors in order to move the robot FORWARD for 3 second and STOP.
Next you can write the program which will move the robot in several different directions:
forward
backward
turn left
turn right
Questions:
How many digital outputs you have to set in order to control the robot for specific move?
How many different moves your robot can make?
🎓 Summary:
Controlling the robot in two degrees of freedom
To controlling the robot in two degrees of freedom we need to control two motors. Since we have to set two digital outputs for each motor we have to set four digital outputs for each move.
💣 Issues:
When I change the direction of the robot the robot does not move as expected.
Probably you did not set all of the outputs correctly. Remember taht some outputs may have remained set in previous output state from taken action in previous task.
In sake to detect the obstacles we have to equip robot with the "touch sensor". This sensor is basically a switch or key, which toggles it's output between GND and +5 V voltage potentials.
Follow video instructions to construct bumper in front of the robot.
Questions:
Do you hear "clicking" sound when you push the bumper?
Name the mechanical mechanism where smaller force on one end can cause greater force on the other end of the mechanism.
Tasks:
The key has three connecting terminals. Each of one is marked with the number 1, 2 or 3. Connect them in right order. Connect the key terminals in order that are specified in presentation and listed as:
connect to RobDuino C0 terminal.
connect to RobDuino voltage terminal GND.
connect to RobDuino voltage terminal +5V.
<++>
Questions:
What is the output voltage of the sensor when the robot is (or is NOT) touching the obstacle?
How many different states are presented with such sensor?
Name several more examples where digital sensor can take place.
🎓 Summary:
Digital sensors
The output of a digital sensor can be just in two states:
logical "0" - presented in voltage as 0 V.
logical "1" - presented in voltage as +5V.
💣 Issues:
Robot has no power since I connected the key as a sensor.
Probably the key or switch is connected wrong and there is short connection between the GND and +5V voltage terminals. Unconnect the key or switch and verify if the power is back.
Make a very simple program like setting the digital output bit D3 to logical state 1 or HIGH.
Send the program to Arduino controller.
Questions:
What is the difference between:
void setup()
void loop()
What is the difference between:
pinMode(3, OUTPUT);
digitalWrite(3, HIGH);
void setup() {
// put your setup code here, to run once:
pinMode(3, OUTPUT);
digitalWrite(3, HIGH);
}
void loop() {
// put your main code here, to run repeatedly:
}
🎓 Summary:
Using curly braces - {}
Using curly braces in C++ is important part of writing the programming code. Imagine that you want to merge several members of programing code to a single pile. As we would separate pencils into one pile and markers to another - to be more organized. In real life we would do by elastic bundle or rope. If you have to choose single character from the keyboard to indicate that several members are combined to the same pile - which character would you choose? Probably curly braces {} are the best choice.
Function Declaration
void loop() {
}
Function Call
digitalWrite(3, HIGH);
Function Name
Function name should be stucked together from 2 - 5 short words that unicly describing the functionalaty of the function. The first word shoul start with lower case and all the others words following should start with upper case. Some examples should be:
badname();
goodFunctionName();
💣 Issues:
Error: expected ';' before 'something'
Probably you forgot to put ; (semicolon) at the end of the command. Find the row starting with "something" and look the row above... probably missing ";".
What kind of values do you getting from the reading of the distance sensor?
Find the reasonable value vhere you shuld stop the robot.
🎓 Summary:
Analog to digital converter - ADC
ADC is an electronic sistem that converts analog signal (voltage) to a digitalized values. In our particular case the range of an analog voltage from 0V to 5V is converted to range of numbers from 0 to 1023.
What is the value of the sensor when the robot is over white/black area?
Calculate the average between those two values.
🎓 Summary:
Sensors
Sensors are electronic devices which convert physical quantity into electrical quantity (usually voltage). In simplest setup, sensor can be constructed as voltage divider with two resistors - R₁ and R₂. One of the resistors is resistor with fixed resistance value (eg. R₁ = 10 kΩ). The second one is a bit special and it's resistance depends on some physical quantity (e.g. light, temperature, humidity...).
When combining those two resistors into such voltage divider the output of the voltage divider can be calculated as:
$$ U_{Out} = \frac{R_1}{R_1 + R_2} U_0 $$
Write the program to control the robot to follow the line ( actually above the edge between black and white area ).
Questions:
What is the program function to get the light_sensor_value?
Determine the movements of the robot if the robot is over the black area and if the robot is over the white area.
[+] void setup() {
void loop() {
if ( light_sensor_value < treshold_value ){
//do this if robot is ower the blck line
} else {
// do this if robot is ower white area
}
}
[+] void robotForward() {
[+] void robotStop() {
[+] void robotLeft() {
[+] void robotRight() {
[+] void robotBackward() {
Detecting the end of line can be done by measuring the time that robot spend over the black and white area. E.g. if the robot is driving along the line - the time spent over black and time spent over white area will be quite the same. When line ends the robot will not detect the black area soon and the time spent over white area will increase significantly - and that is the trigger for detecting the end of line.
Advanced: Make a function to align (move) the robot back to the line.
Questions:
How can we store a data to the controller's memory?
How can we measure time in programming loops?
<++>
[+] void setup() {
int time_on_black = 0;
int time_on_white = 0;
void loop() {
if ( analogRead(A1) < 400 ){
// BLACK area
robotLeft();
time_on_white = 0; // reset time on white
time_on_black++; // meas. time on black
delay(100);
} else {
// WHITE area
robotRight();
// Do similar meas.
// of time on white
delay(100);
// If time is signif.
// longer:
// robotStop();exit(0);
}
}
[+] void robotForward() {
[+] void robotStop() {
[+] void robotLeft() {
[+] void robotRight() {
[+] void robotBackward() {
🎓 Summary:
What is variable?
Variables are used in C++ where you will need to store any type of values within a program and whose value can be changed during the program execution. These variables can be declared in various ways each having different memory requirements and storing capability. Variables are the name of memory locations that are allocated by compilers, and the allocation is done based on the data type used for declaring the variable.
Variable definition and initialization in C++
A variable definition means that the programmer writes some instructions to tell the compiler to create the storage in a memory location. The syntax for defining variables is:
data_type variable_name;
Here data_type means the valid C++ data type which includes int, float, double, char, wchar_t, bool and variable list is the lists of variable names to be declared which is separated by commas.
Variables are declared in the above example, but none of them has been assigned any value. Variables can be initialized, and the initial value can be assigned along with their declaration.
The easiest way to measure time is to simply count the number of loop's executions. And if we know how long is one execution of the loop - we can easily determine the time lapsed for the whole process.
Example:
int t = 0;
while (t<10){
t++;
delay(100);
}
In the previous example the while loop is executed 10 times (t = [0 .. 9]), since each execution of the loop last 100 ms (determined by delay(100);) the whole while loop last 1 s.
Time measuring with Timers
More proper way of measuring the time is by using the timer's values. More on that can be read here.
Example:
unsigned long start_time;
unsigned long stop_time;
start_time = millis();
// time measured process goes here
// ...
stop_time = millis();
unsigned long duration = stop_time - start_time;
Module RobDuino includes two "on-board" buttons which are connected from pin A4 and A5 to GND. This two buttons can allso be used but internal pull-up resistors must be turned on.
Add manual functionality to the automated barrier gate. Add the possibility to manually lift (e.g. press A4 button) and lower (A5 button) the barrier gate.