What Will You Learn?
Learn to program each of the modules of the Grove Beginner Kit for Arduino, such as the oled screen, the button, the accelerometer and many more sensors, knowing more about programming since we will use variables, arrays, functions, if and more.
Create Your Console
Download the template, and cut out each part of your console.
Assemble, with the help of your glue stick, and place your Grove Beginner Kit inside the center of your console.
A tip: We place our battery in one of the controls, leaving a space to connect it to our plate. You can leave it outside just remember to make a space for your cable, like the charging port of your console.
Open a window on your paper console, in front of your Grove plate, as well as 4 circles for each of the ends of it, then glue the controls on each side of your console.
Cut your acetate sheet, the size of your console screen (where you can see your Grove Beginner Kit) remember to attach each end of your sheet to your plate.
You’re ready! Now take your computer and start programming.
Open the zip you downloaded, press two clicks on the file “Grove_Starter_Kit.ino”, the Science Game code will open, now add the libraries found in the zip, Open the Arduino IDE, go to “Sketch” – “include Library” and click on “Add .ZIP Library” and select the 5 folders, these are the project libraries.
Analyze the Code: Define Libraries and Variables
The first section of line 1-7 you find the keyword, “#include”, this is to define each library that you are using in your code.
Below you will find the section of the sensor symbols, which will be displayed on the screen, from line 9-26, these are constant since the design will not change.
Next (in line 28 – 64) the variables of the actuators and sensors of light, sound, temperature, humidity, atmospheric pressure, accelerometer, our buttons, screen and LED are declared.
There are two versions of the board, you can identify your version, at the top of the led module, if there is the word D4 it is version 2, and if it is D5 it is version 1.
If you have version one, go to your code to line number 28, and change to version 1 (#define BoardVersion 1)
Analyze the Code: Functions
Keep analyzing the code, below is the victory song.
You define the notes on line 68 – 71, then, on the following lines, define the beats creating the melody. These are arrays or lists of data that are very useful.
From line 109 – 135, there is a function called “Checker ()”, which helps to check the led. The next section is very important for our Arduino “setup ()”
What is in this function will be executed only once, when you turn on the board, initiating the communication of the sensors and the pins that you will use in the project.
Next you have the function “loop ()”
What we define from line 168-225 is inside the section, and it will be executed as long as the board is working.
There are several “ifs”, this is a condition for example when you press the button for a long period of time you will enter the menu, then you will use the potentiometer to see the different options, then select by pressing the button, activating the chosen sensor.
Next we see the “select_mode ()” function, which will show the sensor icons on the oled screen.
The following functions are the light sensor (line 282 – 308), the atmospheric pressure (line 310 – 327) and temperature and humidity (line 329 – 355). When you select any of these sensors, it will read the value of the sensor, then it will place it on the screen, and in the “Alert ()” function it will analyze it to detect when it exceeds the limit to warn you that you won with the led and the buzzer.
On the other hand, for the sound sensor, the same process is repeated adding a filter at the beginning. The following function “Acele_show ()” receives the accelerometer values, after some conditions, it becomes a gyroscope, placing this information on the screen together with a sphere that will move at the angle in which you move your console.
And the last function “Alert ()” that receives the data from the sensors, to warn you that you won with the led and play the victory melody with the “buzz ()” function.
You have finished your code! Now download it to your board, select “tools” – “board” and press “Arduino uno”, connect your computer to the Grove Beginner Kit for Arduino. Then select “tools” – “port” and select your board.
In the upper left there are two buttons, press the arrow, wait a few minutes it will check your code and download it.
Congratulations! Science Game is already running, you can experiment with all its sensors, hold down the button and the menu will open, with the potentiometer move between the sensors, and occupy your button to select the sensor you want, finally experiment with this.
You can experiment by changing the limit of the sensors to increase the difficulty of the game.
You can take this further, creating a different type of game for example combining two or more sensors making it more complex, include a time limit to solve the complete sensor circuit, or add multiple players and scores.
Science Game Modules
Science Game modules:
- Light sensor, try to cover it with your hand or use a lamp to increase the light values and activate the alert.
Where can we find the light sensor?
This is found in photosensitive bulbs, which turn on when natural light fades at dusk.
- Sound sensor, try to make a loud sound by clapping or talking
Where can we find the sound sensor?
Smart watches have sound sensors to know if the place where you are is too noisy
- Temperature and humidity sensor,
What do you use the temperature and humidity sensor for?
In agriculture they occupy the temperature and humidity sensor to obtain data that allow the monitoring of parameters influencing the development of plants.
- Atmospheric pressure,
What do you use the atmospheric pressure sensor for?
In meteorology, atmospheric pressure is something very important to take into account when predicting and studying the behavior of the climate. Clouds, cyclones, storms, winds, etc. they are largely conditioned by changes in atmospheric pressure.
Where do we find an accelerometer and a gyroscope?
This sensor is found in drones, it measures the location angles of this, while it flies. Normally, the gyroscope is built into the same unit as the 3-axis accelerometer, in this way, the accelerometer calculates the position and the gyroscope the angle at which it is located.
Actuators: it is an inherently mechanical device whose function is to provide force to move or “act” on another mechanical device.
Sensors: it is a device that is capable of detecting external actions or stimuli and responding accordingly. These devices can transform physical or chemical quantities into electrical quantities.
Libraries: The Arduino environment can be expanded through the use of libraries, just like most programming platforms. Libraries provide additional functionality for your use of your programs, for example working with hardware or manipulating data.
array: is a finite collection of data of the same type, which is stored in consecutive memory locations and receives a common name.
function: is a section of a program that calculates a value independently from the rest of the program
void: The “void” keyword is used only in function declarations. Indicates that the function is not expected to return information to the function from which it was called.
void setup: The “setup ()” function is called when a sketch starts. Use it to initialize variables, pin modes, start using libraries, etc. The “setup ()” function will only be executed once, after each power-up or reboot of the Arduino board.
void loop: After creating a setup () function, which initializes and sets initial values, the loop () function does just what its name suggests and repeats consecutively, allowing your program to change and respond. Use it to actively control the Arduino board.
pinMode: Sets the specified pin to behave as an input or an output.
digitalWrite: Write a HIGH or LOW value to a digital pin. Its voltage will be set to the corresponding value: 5V (or 3.3V on 3.3V boards) for HIGH, 0V (ground) for LOW.
delay: Pauses the program for the time (in milliseconds) specified as a parameter. (There are 1000 milliseconds in a second.)
if: Execute the following statement or set of statements if the condition is ‘true’.