® ADVENTSKALENDER FÜR ARDUINO ADVENTSKALENDER FÜR ARDUINO® ® ER FÜR ARDUINO ER FÜR ARDUINO® ® ADVENT CALENDAR FOR ARDUINO ADVENT CALENDAR FOR ARDUINO® ® R FOR ARDUINO AR FOR ARDUINO® 24 Experimente, die Spaß machen 24 thrilling experiments
Overview of all experiments Arduino® Advent calendar 2019. . . . . . . . . . . . . . . . . . . . . . . . . 3 Day 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 Today in the Advent calendar. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Nano Board - Arduino compatible board. . . . . . . . . . . . . . . . . . . . . . .
Arduino® Advent calendar 2019 Programming microcontrollers used to be only for engineers and computer scientists. The Arduino platform offers a clear hardware and easy-to-understand software interface that allows anyone to get started with microcontroller technology. The name Arduino The Arduino originates from Italy and was named after the Italian King Arduino, who ruled Ivrea until 1005, headquarters of the Arduino manufacturer.
Software installation in a nutshell The driver installation in four steps: 1. Extract the ZIP archive with the downloaded software into any folder below your Windows user folder. 2. Extract the ZIP archive 67006-9-nano-board-Treiber.zip into a separate folder. 3. Connect the Nano via the USB cable and then start the driver installation with the file CH341SER.EXE from the Windows subfolder of the driver folder. To install, you must confirm a Windows User Account Control request.
LED flashes In mBlock 3 you do not need to type any program code when programming. The blocks are simply attached to each other using drag and drop. The block palette in the left part of the window contains the available blocks, sorted by topic. The programs for the Advent calendar The programs for the Advent calendar can be downloaded, numbered by days. Select File / Load Project from the menu to open a program. But you can also simply assemble them yourself every day using the illustrations.
Transferring the program to the Nano The right part of the mBlock screen shows the automatically generated Arduino program code. Click on Upload to Arduino in the upper left corner to automatically compile the program and transfer it to the Nano board. Click close in the Start Upload message to follow the transfer. Message at the start of transfer. In the lower part of the program window you can see the progress of the transfer. When the text Thank you appears, the transmission is complete.
Components: 1x Nano Board, 1x breadboard, 1x red LED with series resistor Make sure that the cathode (short wire) of the LED is connected to the GND pin, the anode (long wire) to the D2 pin. The pins on the Nano All pins marked D… are digital inputs or outputs, which can take the values True or False (On or Off). The pins marked A... are analogue inputs. GND pins are ground lines. Arduino-compatible boards work with different voltages and have two different plus pins as standard. Pin 3.3 has a +3.
How the program works The repeat continuous loop causes the two LEDs to endlessly flash alternately again. A variable is used instead of a fixed time between the switching operations. Variables in mBlock Variables are small memory locations where you can assign a number or anything else during a program. When the program ends, these variable memories are automatically cleared again.
How the program works Initially, the three variables are set to the pin numbers used for the LEDs. Afterwards the LEDs are set to a defined state before the start of the main loop. Only the green LED should light up. When using variables, mBlock 3 cannot recognize at the beginning which pins are to be used as outputs and initializes them only at their first use. Therefore, it is not possible to assume a clearly defined state of the LEDs at program start.
The program The program 05mblock dims the LED at pin D6 cyclically brighter and darker. Some new program blocks are used. How the program works Three variables are defined at the beginning: time determines the speed for dimming, light indicates the PWM value for the brightness of the LED and step indicates the step size for dimming. Now an endless loop begins. First, the current value of the variable bright is outputted to pin 6 as a PWM value for each iteration.
Analog inputs that are not connected do not have a defined state. The values read out there fluctuate due to the minimal electric fields on the Nano Board and nearby. In order to really evaluate an analogue value, a clearly defined voltage must be applied at all times. A variable resistor, a potentiometer or any sensor should always be connected as a voltage divider between 0 V and +5 V. The voltage of the sensor should be between 0 V and +5 V. The 06mblock program dims the LED with a potentiometer.
How the program works At the beginning, the four pins used for the LEDs are switched off once, so they can be initialized, since they are only addressed later via a variable and would otherwise not be initialized correctly as outputs. Then the endless loop starts, which sets the variable n to 4 in each pass, the number of the first LED. Each cycle of the endless loop causes a chaser light cycle of all four LEDs. An inner loop lets the four LEDs light up shortly after each other.
Day 9 9. Tag Today in the Advent calendar - 1x breadboard (SYB-46) Analog level display with LEDs Analogue values can be read off at a glance on a level display. Such displays consisting of several LEDs are used, for example, in volume or temperature controllers. The experiment of the ninth day shows the value set on the potentiometer via a series of four LEDs.
Day 10 10. Tag Today in the Advent calendar - 2x connecting cable Interactive control of Nano board via mBlock 3 mBlock 3 not only allows Arduino sketches to be generated and then loaded onto the Nano, but also provides an interactive mode in which the Nano is connected in real time to the program running on the PC. Setting up a real-time connection with the Nano Turn off the Arduino mode in the Edit menu. The window with the Arduino sketch disappears on the right.
Four LEDs show the position of the M-Panda. The stage with a stage design and the M-Panda character. The 10mblock program checks the position of the M-Panda and lets the LEDs light up. The RX and TX LEDs on the Nano are flashing constantly, because in interactive mode data is permanently sent back and forth between the Nano Board and the PC. How the program works mBlock 3 is based on the Scratch programming language and contains in interactive mode also its complete range of functions.
Now you can move the figure M-Panda with the mouse on the stage. If it touches one of the coloured surfaces, the corresponding LED lights up. An endless loop asks one after the other whether the M-Panda touches one of the four colours. “If... then...else” blocks are used. If the colour is touched, the appropriate LED is switched on, if it is not touched, the LED is switched off. Without switching off, all LEDs would eventually be switched on when the M-Panda has touched all colour areas once.
With the Circle tool you can create circles while holding down the [Shift] key. Switch to fill mode at the bottom left to draw filled circles. Select the colour on the palette at the bottom in the middle. Use the selection tool at the top to select and copy the finished circle with [Ctrl]+[C] and [Ctrl]+[V]. In this way you get four circles of the same size, which you only have to copy to the appropriate places. Finally, fill the circles with the colour bucket tool in the desired colours.
Switching traffic lights with pedestrian flashing light using pushbutton The project of the eleventh day represents a simple traffic light switch with pedestrian flashing light. During the red phase of the traffic light, the blue LED flashes. Since there are only four LEDs in the Advent calendar, the circuit does not represent a red/green pedestrian light, as it is common in Central Europe, but a simple pedestrian flashing light, as it is used in some other countries.
Components: 1x Nano Board, 2x breadboard, 1x red LED with series resistor, 1x yellow LED with series resistor, 1x green LED with series resistor, 1x blue LED with series resistor, 1x potentiometer, 2x push-button, 2x 10-kOhm resistor (brown - black - orange), 5x connection cable, 5x wire bridge The program The program 12mblock works similar to the program of the seventh day, but additionally queries the two buttons to select the direction of the chaser using an additional variable.
Day 13 13. Tag Today in the Advent calendar - 1x LCD module1x 560 Ohm resistor (green - blue - brown) Today an LCD module is part of the Advent calendar. Such display modules are installed in many electronic devices. The LCD module has a 16-pin terminal strip with which it is inserted on the breadboard. The LCD module in the Advent calendar works character-oriented. This means that you do not have to worry about controlling individual pixels.
Controlling the LCD module with mBlock 3 The functional range of mBlock 3 can be extended by various so-called extensions. Among them there is also an extension for LCD modules. Select Extensions / Manage Extensions from the menu. On the Available page, search for LCD at the top of the search box. Install the LCD extension by clicking on Download. Download and installation of the LCD Extension for mBlock 3.
Day 14 14. Tag Today in the Advent calendar - 2x connecting cable The cables are not used until a later day. The circuit design is unchanged from the 13th day. Moving text on the LCD module If you let a text run into the LCD module as a ticker, it is much more noticeable than just a static text. The program The 14mblock program shows a text that runs animated from the right into the LCD module. The unchanged circuit design. Extended program for animated two-line text on the LCD module.
calendar contains a battery box that delivers a voltage of 6 V with four AAA batteries and 4.8 V with rechargeable batteries, which is sufficient to power the Nano board. The batteries are not included. Do not connect the battery box yet, as you are still supplying power to the Nano via the PC until the new program has been transferred. The battery box is connected to the pins VIN and GND of the Nano board after disconnecting the USB cable.
The “LCD set cursor (line ... position ...)” block from the LCD extension sets the cursor to the line (0 or 1) specified in the first field and the column (0-15) specified in the second field, in this case to the beginning of the lower line. Here the word key: is written. The text 0.00 is displayed at position 7 in the upper line. Later here, when the stopwatch is running, the time appears. The word Start appears at the same position in the bottom line. The next keystroke is always displayed here.
The variable n is set to 1. It specifies the cursor position when writing. Another loop writes up to the character length of the word happy, the individual letters one after the other into the upper line of the LCD module. For this purpose a “character ... from” block is used which picks individual characters from a string. The word Christmas is then written in the same way in the bottom line of the LCD module. The cursor is then hidden again. The text stops until the user presses the key again.
How the program works At the beginning the pin numbers of the used analogue inputs are displayed on the LCD module as legend of the values. An endless loop then reads out four analogue inputs one after the other and writes the values to the corresponding positions after the displayed pin numbers. After 0.5 seconds the loop runs again. The program reads four analogue inputs and displays their values on the LCD module. Day 18 18.
of a connecting cable into a piece of plasticine and the other end into the breadboard as shown in the illustration. Since mBlock always switches on the pulldown resistors built into most Arduino-compatible boards, digital inputs are automatically pulled to 0 V and have a low level even without touching them. Arduino-compatible boards have additional analogue inputs, which are very suitable for sensor contacts. Analog inputs provide values between 0 (low level) and 1023 (high level).
Day 19 19. Tag Today in the Advent calendar - 1x button 1x 10 kOhm resistor (brown - black - orange) Guess numbers The project of the 19th day is a simple guessing game in which a player has to guess a number randomly chosen by the Nano in as few steps as possible. The numbers are displayed on the LCD module and entered via buttons.
How the program works The static text elements of the game display are displayed in the upper line of the LCD module. Instead of the three question marks, the game later shows the last tip. The bottom line indicates whether the solution number is greater or less than this tip. The “random number from ... to ...
If the button on pin D10 was pressed, the set number is given as a tip. The number of bets placed in variable n is increased by 1 and the number is displayed as a new bet in the top right corner of the LCD module. If the searched number x is equal to the given tip, the variable end is set to 1. After this run, the loop is not repeated again. The game is over.
The classic Pong with the script for the ball still without Nano. The normal ball movement is controlled by the script shown above. It first brings the ball to its starting position, sets the error counter to 0 and sets a random direction for the first move. Scratch provides its own block that ensures that an object that touches the edge of the stage bounces off and flies on in the right direction.
corresponding direction. The coordinates are used to check whether it would run out over the left or right edges, and in this case it is set directly to the edge. Click the paddle at the bottom left of the object palette to view and edit the script blocks for the paddle. The script for the paddle - still without Arduino. You can play the game as it is. Use the arrow keys on the keyboard to control it. The Nano is not needed.
Pull two “if... then” blocks into the loop. Each of these blocks inquires through a “read digital pin ... ” block from the robot block pallet for a digital pin on the Nano. If the respective pin delivers a high signal, the button is pressed. In this case, the same blocks for moving the paddle are processed as in the previous program version when an arrow key is pressed on the keyboard. Now click on the green flag to start the game. You can now control the paddle with the two buttons.
Click on the green flag, the game starts and the ball flies through the room. Every player can move his paddle upwards by tapping the sensor keys. If the sensor contact is not touched for a while, the paddle slowly falls down again. With some skill the players must try to hit the ball back again and again with their paddle so that it does not fly against the red or green wall. If the ball touches your own wall because you didn't put the paddle in its way in time, you get a minus point.
The sport theme in the figure library. The Paddles Click the Draw New Figure icon on the Object palette to draw the first paddle. In the drawing program, use the Line tool, select the black colour and set a mean line width at the bottom left. Draw the line vertically in the middle over the small cross in the middle so that the centre of the paddle is at the coordinate zero point. When the [Shift] key is pressed, the line becomes exactly vertical. The first paddle.
The two paddles. Program for the ball The ball is controlled by four scripts that all run simultaneously and are started when the user clicks on the green flag. The scripts and variables for the ball First, two variables are defined that are displayed on the stage in real time. Move out the display for the points of the right player on the stage to the right.
However, since clicking on the green flag starts three more script blocks for the ball, other movements may occur as well. Main program block for initialization and movement of the ball. The ball changes direction when it touches one of the paddles. If the ball touches one of the two paddles, the direction of movement is reversed. The ball flies down at the same angle from which it came from above. The current direction can be used as a variable via the Direction block from the Movement block palette.
Clicking on the green flag starts a similar script block for each of the two paddles. They first set the paddle to the start position. Then endless loops run. In the infinite loop an if/else construct triggers one of two possible actions each time: - If the player touches the sensor contact, the pin is set to LOW, i.e. it behaves like an unpressed button. The y-coordinate of the paddle is increased by 40 so that it moves up by 40 units. The LED lights up for 0.1 seconds.
How the program works At the beginning of each cycle of the infinite loop, a random value between 1 and 4 is again generated with the aid of an unconnected analogue input. This number is displayed in the upper line of the LCD module. Then the red LED at pin 12 is switched on and the stopwatch is reset. The stopwatch on the Nano All Arduino compatible boards have an internal clock that can be used for tasks that require specific periods of time.
Day 23 23. Tag Today in the Advent calendar - 1x phototransistor Phototransistor A phototransistor is a light-sensitive component that looks like a transparent LED at first glance. Depending on the intensity of the light incidence, different values can be achieved with the circuit shown on an analogue input of the Nano board. The brighter the light on the phototransistor, the lower the value at the analogue input. Unlike LEDs, a phototransistor connects the long terminal to ground, not the short one.
The program The 23mblock program displays the brightness falling on the photo transistor as a bar on the LCD module. Transfer the program from mBlock 3 to the Nano in Arduino mode. It can then also be supplied independently by the battery box. How the program works Depending on the brightness, the phototransistor delivers an analogue value between 0 and 1023, which is inversely proportional to the value-amount of light that falls on the phototransistor.
The program The 24mblock program plays four different Christmas carols depending on which button the user presses. The matching LED also lights up. Music machine with Christmas carols. The program for the Christmas carols. How the program works At the beginning variables for the pin numbers of the four LEDs and buttons are created and all LEDs are switched off. An infinite loop then waits for the user to press one of the keys.
Button 1 plays Silent Night. If the program detects that a key has been pressed, it waits until this key is released again. This prevents malfunctions caused by prolonged pressing. The LED is switched on and one of the songs is played. The LED is then switched off again. The Christmas carols are stored in the program. On the Sounds tab, you can import MP3 files using the “Load sound from a file” icon. Each imported sound automatically gets a name that can be changed at any time.