Mechabau® Coding BlockTM (U1) Pinouts
Coding BlockTM U1
The Coding BlockTM module (U1) includes an Arduino Nano circuit board. This is a mini computer which can be programmed to perform different tasks, including monitoring things and making things happen.
Coding BlockTM does not have an on/off switch when powered using the USB cable. To turn it off, disconnect the USB cable from your computer.
U1 Coding BlockTM connections:
(+) – power
(−) – power
A0, A4, A5 – Analog inputs
D2, D3, D7, D8, D9 – Digital inputs/outputs
You can also use the Coding BlockTM for your other projects.
The USB cable is used to program and communicate with the Coding BlockTM (U1).
Notes for using the Coding BlockTM module in other applications:
Power source: Coding BlockTM should only be powered using a USB cable and the 9V battery holder included in the set. Coding BlockTM should never be used with Block Circuits® battery holders from other sets or other power sources.
Analog inputs: These can measure voltage with 10-bit accuracy (1024 levels). They can also be configured to act as additional digital inputs/outputs.
Digital inputs/outputs: When configured as inputs the voltages should be above 80% of the power source voltage to be high, or below 20% of the power source voltage to be low. When configured as outputs each can supply or receive up to 20 mA; this is enough to light an LED, but an interface transistor may be needed when controlling a motor or speaker. These (D3 and D9) can be configured to simulate analog outputs using Pulse Width Modulation (PWM).
Project 1 Circuit (Blue Light)
Project 1 Explanation (Blue Light)
Block Circuits® uses electronic blocks that connect together to build different circuits. These blocks have different colors and numbers on them so you can easily identify them.
Build the circuit shown by placing all the parts. Install the code below to your Coding BlockTM and the blue LED (L2) lights.
Project 1 Code (Blue Light)
Project 2 Circuit (Adding External Power)
Project 2 Explanation (Adding External Power)
Build the same circuit at project 1. After installing the program you do not need usb cable to powering your Coding BlockTM. Reconnect the usb cable and turn the switch on. Now use your 9V battery and connect it as shown on the circuit. Install a 9V battery into the 9V battery holder, plug it into the connector on the Coding BlockTM module (U1), and turn on the switch on the switch block (S1). Alternately you may power the circuit using the USB cable instead of the 9V battery.
Slide the switch header (S1), and the blue LED (L2) lights.
Project 2 Code (Adding External Power)
Project 3 Circuit (Blinking Light)
Project 3 Explanation (Blinking Light)
This project explains the procedure for programming the Coding BlockTM module (U1). The microcontroller can be re-programmed in any circuit that uses it, by attaching the programming cable to it. When you initiate a new program download, any program currently running in the microcontroller is interrupted. When a new program download is complete, the new program will begin running.
The USB cable is needed to download new programs to the microcontroller, and to allow some programs to transfer information to/from the computer’s display. The USB also provides power to your circuits, so the 9V battery connector is ignored while you are connected to a USB device. Coding BlockTM has been programmed, you may disconnect the USB cable and run the circuit using the 9V battery connector.
Project 3 Code (Blinking Light)
Project 4 Circuit (All Lights On)
Project 4 Explanation (All Lights On)
Build the circuit, install the program, turn on the switch (S1). The white and blue LEDs (L1 and L2) will lights.
Project 4 Code (All Lights On)
Project 5 Circuit (Switching and Flashing Lights)
Project 5 Explanation (Switching and Flashing Lights)
Build this circuit. Load sketch Switching and flashing Lights into Coding BlockTM using the programming instruction. Arduino controls the two circuits LEDs (white and blue) and alternates turning them on and off by flashing.
This sketch uses the int command (int is short for integer) to assign a constant value that will be used within the sketch. Not necessary to be used. You can change the blink rate by editing the delay value, then reloading it into Coding BlockTM. The microcontroller on the Arduino Nano board lets you control the LEDs in ways that would be difficult to do using switches or other devices.
Project 5 Code (Switching and Flashing Lights)
Project 6 Circuit (Flashing Lights and Buzzer)
Project 6 Explanation (Flashing Lights and Buzzer)
Build the project 5 and add buzzer module (BZ1) on the circuit as shown. Load sketch Flashing Lights and Buzzer into Coding BlockTM using the programming instruction. Arduino controls the three circuits LEDs (white and blue) and Buzzer. It alternates turning them on and off by flashing/beeping.
You can change the blink rate by editing the delay value, then reloading it into Coding BlockTM. The microcontroller on the Arduino Nano board lets you control the LEDs in ways that would be difficult to do using switches or other devices.
Project 6 Code (Flashing Lights and Buzzer)
Project 7 Circuit (Lighting Led with Button)
Project 7 Explanation (Lighting Led with Button)
Build this circuit. Load sketch Switching and flashing Lights into Coding BlockTM using the programming instruction. Turn on the switch (S1) and LED (L2) should be on. Now Turn off the switch (S1) and LED (L2) should be off.
You have to use the PC in this project as your power source.
Not important if a program is installed or not on the Arduino Nano board because non of signal pins of the board is used.
Project 7 Code (Lighting Led with Button)
Project 8 Circuit (Reading Data from LDR)
Project 8 Explanation (Reading Data from LDR)
Build this circuit. When open the Serial Port screen we will see numbers flowing down the screen. By changing the amount of light into the photoresistor, the value of the number will also change as the voltage we send. The 330ohm resistor gives a constantly high value since the excess electrical voltage from the Photoresistor cannot be discharged over the cable. By throwing the excess voltage to GND (ground) we get more accurate value.
You have to use the PC in this project as your power source.
Project 8 Code (Reading Data from LDR)
Project 9 Circuit (Star Wars Theme Song)
Project 9 Explanation (Star Wars Theme Song)
In this project we are gonna see how to make the Star Wars theme song (imperial march) using arduino + buzzer and some leds (optional). By changing the frequency of the signal, you can get a musical note.
You have to use the PC in this project as your power source.
Project 9 Code (Star Wars Theme Song)
Project 10 Circuit (Night Lamp)
Project 10 Explanation (Night Lamp)
Build this circuit. Load sketch Night Lamp into Coding Block using the programming instructions below. Cover the phototransistor (PR1) to turn on the red LED (L1). Once programmed, you can use the 9V battery connector to power the circuit instead of the USB cable, then take the circuit with you into a dark room. (Don’t forget, before moving the circuit replace it over a flat plate.)
You have to use the PC in this project as your power source.
You can adjust the sensitivity by changing the value 12 to be higher or lower.
Project 10 Code (Night Lamp)
Project 11 Circuit (Blink Rate)
Project 11 Explanation (Blink Rate)
Use the preceding circuit, but load sketch Blinking Light (Project 3) into Coding BlockTM. The red LED (L1) will be blinking at darkness. Insert code after value given line as shown below.
Project 11 Code (Blink Rate)
Project 12 Circuit (Night Siren)
Project 12 Explanation (Night Siren)
Build the circuit project 10. Now use buzzer instead a LED. Load sketch Night Siren into Coding Block using the programming instructions below. Cover the phototransistor (PR1) to turn on the Buzzer (BZ1). Once programmed, you can use the 9V battery connector to power the circuit instead of the USB cable, then take the circuit with you into a dark room. (Don’t forget, before moving the circuit replace it over a flat plate.)
You have to use the PC in this project as your power source.
You can adjust the sensitivity by changing the value 12 to be higher or lower.
Project 12 Code (Night Siren)
Project 13 Circuit (Flashing Siren at Night)
Project 13 Explanation (Flashing Siren at Night)
Use the preceding circuit, but load sketch Blinking Light (Project 3) into Coding BlockTM. The Buzzer (BZ1) will be blinking at darkness. Insert code after -value- given line as shown below.
Project 13 Code (Flashing Siren at Night)
Project 14 Circuit (Coding Block Test)
Project 14 Explanation (Coding Block Test)
This circuit tests the electrical connections on the Coding BlockTM module (U1), and is referenced by the Advanced Troubleshooting procedure on page A7 and A8. Build the circuit as shown, leaving one end of the red cable terminal (T) unconnected for now. Load sketch “Coding Block Test” into Coding BlockTM using the programming code below.
Connect the loose end of the red cable terminal (T) to each of the unused pins on the Coding BlockTM module (U1). One at a time; the blue LED (L2) should be blinking each time when touching it to the pins.
Remove the USB cable, then connect the 9V Battery (B3) and Switch (S1) Block and turn the switch ON; the circuit should work the same as with the USB cable.
Project 14 Code (Coding Block Test)
Project 15 Circuit (Varying LED Brightness Gradually)
Project 15 Explanation (Varying LED Brightness Gradually)
Output using PWM broadens the way the LED lights up. Now, let’s change the PWM gradually to realize the effect that the LED brightens gradually.
Write a program as shown below.
The program stores the PWM ratio in the “i” variable used in the loop() function so that it can increment the value to make the LED gradually become brighter.
The while processing increases the value in increments specified by STEP until i reaches 255. The incremented value is output by analogWrite() to change the brightness of the LED. In addition, it is directed to wait for the duration specified by WAITTIME each time the PWM output is changed.
When the PWM ratio reaches 255, it is decreased until it reaches 0 to darken the LED gradually. You can modify the blinking speed by changing the value of WAITTIME or STEP. This time we’ve learned how to control the brightness of the LED.
Project 15 Code (Varying LED Brightness Gradually)
Project 16 Circuit (Changing the Volume Gradually)
Project 16 Explanation (Changing the Volume Gradually)
Create project 15 and now replace the LED (L1) with Buzzer (BZ1). The same functionality applies to this project as well.
Project 16 Code (Changing the Volume Gradually)
Project 17 Circuit (Changing the Light Intensity and Volume Gradually)
Project 17 Explanation (Changing the Light Intensity and Volume Gradually)
Use the preceding circuits and connect LED (L1) and Buzzer (BZ1) to pin D3. Connect the USB cable to Coding BlockTM and to PC as shown. Load the program to the Coding BlockTM and see what happens. Each block works together.
Project 17 Code (Changing the Light Intensity and Volume Gradually)
Project 18 Circuit (Reading Switch States)
Project 18 Explanation (Reading Switch States)
In this project, you can learn how to use switch in your Arduino project and how it actually works. The digital output enables you to control the LED, motor and buzzer etc., switching the digital output pin between two states, HIGH (5V) and LOW (0V). You can also use the output to check the electronic components. The digital output pin can be switched to the digital input. By doing this, you can check the voltage applied to the pin with input in two ways, “LOW” and “HIGH”. These input values can be used to control other electronic components. For example, you may want to operate the LED or buzzer when the digital input is HIGH or stop it when the input is LOW.
Use the “serial monitor” when you want to check the acquired status. With Arduino, you can send the data from Arduino to a PC using the USB cable used to transfer the program from the PC. Serial communication is used to exchange the data. You can use serial communication to check the state acquired by digital input by sending it to the PC.
Specify “INPUT” in pinMode() to switch pin 7 used this time to the input mode. You can now check the pin state from the program.
The pin state specified in digitalRead() is acquired and stored in the value variable. “0” is stored if it is 0V or “1” if it is 5V.
Project 18 Code (Reading Switch States)
Project 19 Circuit (Reading Voltage)
Project 19 Explanation (Reading Voltage)
It is possible to read voltage by converting from digital to analog using the pins on the Arduino. After uploading the code to Coding BlockTM, open the serial port screen. Arduino microcontroller works with 5V voltage. This microcontroller 10-bit ADC can read voltages from 0V to 5V with an accuracy steps of 210 = 1024.
Use the red cable free end “T”, First, read the current voltage value from the serial port. Next, touch the “T” lead to the “A” point and read the values again. Finally, touch the “T” lead to the “B” point and observe the voltage differences.
Project 19 Code (Reading Voltage)
Project 20 Circuit (Flip Flop Lights)
Project 20 Explanation (Flip Flop Lights)
Flip Flop Lights; It is an application that makes two LEDs flash sequentially. While one of the LEDs is on, the other is off, and you can adjust the on-off times of the LEDs as you wish.
Build this circuit. Load sketch Flip Flop Lights into Coding BlockTM using the programming instructions below.
A program that sequentially flashes the LEDs connected to pins 2 and 3 of the Coding BlockTM, with 1 second intervals and continues in a loop.
Please Note: If you have BC-135 (SKU: 86600) Mechabau® Block Circuits® Set you can use the Press Switch (S2) instead sliding switch (S1).
Project 20 Code (Flip Flop Lights)
Project 21 Circuit (Flip Flop Lights and Sound)
Project 21 Explanation (Flip Flop Lights and Sound)
Use the preceding circuit and replace LED (L1) with buzzer (BZ1) and run the program. While the LED (L2) is on, the buzzer (BZ1) is off. While the LED (L2) is off, the buzzer (BZ1) is on. And you can adjust the on-off times of the LED and buzzer as you wish as well.
If you wish, you can operate it independently from the computer by using the battery block (B3) and switch block (S1).
Please Note: If you have BC-135 (SKU: 86600) Mechabau® Block Circuits® Set you can use the Press Switch (S2) instead sliding switch (S1).
Project 21 Code (Flip Flop Lights and Sound)
Project 22 Circuit (Increasing the Light Brightness Incremental)
Project 22 Explanation (Increasing the Light Brightness Incremental)
Build the circuit and load sketch Gradually Increasing the Light Brightness into Coding BlockTM using the programming instructions. When the switch (S1) is OFF the LED (L1) will light at maximum brightness. Turn the switch ON, the brightness of the light increases in 4 steps. It keeps repeating until you turn off the switch (S1).
The LED brightness is set using the digitalWrite() command, which uses values from 0 to 255, but incremental increases will be much more noticeable between low numbers than between high numbers. Because of this, this sketch uses an array to set the LED brightness in multiples of 2, then resets back to minimum. Incremental increases will be much more noticeable when increasing 85 point relative to last value.
Please Note: If you have BC-135 (SKU: 86600) Mechabau® Block Circuits® Set you can use the Press Switch (S2) instead sliding switch (S1).
Project 22 Code (Increasing the Light Brightness Incremental)
Project 23 Circuit (Switch Toggle LED)
Project 23 Explanation (Switch Toggle LED)
In this project we are going to learn how to toggle LED each time switch is on and off. Keep switching the switch (S1) several times and see how it works. See the change of LED’s state.
Open the serial monitor and see the messages when you turn the switch (S1) on.
Please Note: If you have BC-135 (SKU: 86600) Mechabau® Block Circuits® Set you can use the Press Switch (S2) instead sliding switch (S1).
Project 23 Code (Switch Toggle LED)
Project 24 Circuit (Switch Toggle Buzzer)
Project 24 Explanation (Switch Toggle Buzzer)
This project is same as last project, just replace LED (L1) with the buzzer (BZ1). Other ways of working are same.
Open the serial monitor and see the messages when you turn the switch (S1) on.
Please Note: If you have BC-135 (SKU: 86600) Mechabau® Block Circuits® Set you can use the Press Switch (S2) instead sliding switch (S1).
Project 24 Code (Switch Toggle Buzzer)
Project 25 Circuit (How to Detect Short Press)
Project 25 Explanation (How to Detect Short Press)
We measure the time duration between the pressed and released events. If the duration is shorter than a defined time, the short press event is detected. You can change the SHORT_PRESS_TIME = 500 value as desired. You will se no reaction at the serial monitor when the duration time longer as you set.
Please Note: If you have BC-135 (SKU: 86600) Mechabau® Block Circuits® Set you can use the Press Switch (S2) instead sliding switch (S1).
Project 25 Code (How to Detect Short Press)
Project 26 Circuit (How to Detect Long Press)
Project 26 Explanation (How to Detect Long Press)
We measure the time duration between the pressed and released events. If the duration is longer than a defined time, the long press event is detected. You can change the LONG_PRESS_TIME = 1000 value as desired. You will se no reaction at the serial monitor when the duration time shorter as you set.
Please Note: If you have BC-135 (SKU: 86600) Mechabau® Block Circuits® Set you can use the Press Switch (S2) instead sliding switch (S1).
Project 26 Code (How to Detect Long Press)
Project 27 Circuit (How to Detect Long Press and Short Press)
Project 27 Explanation (How to Detect Long Press and Short Press)
References to project 25 and 26.
Why Needs Long Press and Short Press. To save the number of buttons. A single button can keep two or more functionalities. For example, short press for changing operation mode, long press for turn off the device. Use of long press to reduce the short press by accident. For example, some kinds of devices use the button for factory reset. If the button is pressed by accident, it is dangerous. To avoid it, the device is implemented to be factory reset only when the button is long-press (e.g over 5 seconds)
See the result on Serial Monitor!
Please Note: If you have BC-135 (SKU: 86600) Mechabau® Block Circuits® Set you can use the Press Switch (S2) instead sliding switch (S1).
Project 27 Code (How to Detect Long Press and Short Press)
Project 28 Circuit (Using Arduino IDE Tabs)
Project 28 Explanation (Using Arduino IDE Tabs)
In this project make sound if switch (S1) is on. Load the sketch to the Coding BlockTM below. The melody will play till to end even you switched the circuit off.
By using Arduino IDE tabs, copy the code from the first block called: Arduino Code Melody Tab
You need an additional library to use the program called pitches.h
Then open a new tab and give it this name: pitches.h than click ok button.
The Tab looks like this.
For using Arduino IDE tabs, copy the code from the second block called: pitches.h Library Tab and load the code to Coding BlockTM. Turn the switch (S1) on to listen the melody.
Please Note: If you have BC-135 (SKU: 86600) Mechabau® Block Circuits® Set you can use the Press Switch (S2) instead sliding switch (S1).
Project 28 Code (Using Arduino IDE Tabs)/Arduino Code Melody Tab
Project 28 Code (Using Arduino IDE Tabs)/pitches.h Library Tab
Project 29 Circuit (Change the Sound Frequency According to the Light Intensity)
Project 29 Explanation (Change the Sound Frequency According to the Light Intensity)
In this project, we will learn to experiment with LDR and a buzzer. The output of this experiment is sound with different frequencies that are produced depending upon the light falling on the LDR/photoresistor. Now create the circuit and load the code below to the Coding BlockTM. Turn the switch (S1) ON and move your hand over the LDR/photoresistor (PR1). Pay attention to the change in sound frequency.
Project 29 Code (Change the Sound Frequency According to the Light Intensity)
Project 30 Circuit (Change the Beep Frequency Depending on Light)
Project 30 Explanation (Change the Beep Frequency Depending on Light)
In this experiment we are going to work with a sensor which is a resistor (R1) that depends on light like last project. But in this lesson we will change the beeping frequency of buzzer (BZ1) by starting to turn ON the switch (S1). In a dark environment, the resistor will have a very high resistance. As light land on the detector (PR1), the resistance will decrease. The more light is will have a lower resistance. By reading different values from the sensor, we can detect if is it light , dark or a value between them.
Turn the switch (S1) ON and move your phonelight etc. over the LDR/photoresistor (PR1). Pay attention to the change in beeping frequency.
Project 30 Code (Change the Beep Frequency Depending on Light)
Please contact us for any questions or project suggestions within the scope of the above Mechabau® Block Circuits® / Coding Projects.