Create a program to control the Code&Drive from your smartphone or tablet Android via Bluetooth using an app.
DIFFICULTY LEVEL: Advanced.
DURATION OF THE EXERCISE: 60 min.
- 1 USB – Micro USB cable
- Android smartphone or tablet with the App needed for the project (Arduino Bluetooth RC Car)
The Code&Drive will have to be built and connected according to the instructions manual.
How does the Build&Code board function on the Code&Drive?
For this activity you will use the digital and analog pins, DC motors connections and the Code&Drive Bluetooth communication.
- Digital Pins: They are located on the left side of the Build&Code 4in1 board. The color code is Black is (GND-ground), Red (VCC) and Yellow (Digital I/O signal). You will find 12 connectors numbered from 2 to 13. 7 of them can provide PWM output signal. These connectors are indicated with a ~ symbol besides the number.
- Analog pins: They are located on the right side of the Build&Code 4in1 board. The color code is Black is (GND ground), Red (VCC) and Blue (Analog input).
You will find 5 connectors numbered from A0 to A5.
- Data transmission from computer to Build&Code 4in1 board: Connect the board to the computer using the USB-Micro USB cable. Make sure the BLT/USB switch is on USB mode.
- Data transmission from Build&Code 4in1 to Android smartphone:Set the BLT/USB switch on BTL mode to allow the communication between the Build&Code 4in1 board and the Android device.
- Configuration of the Bluetooth communication with the Android smartphone or tablet: Feed and connect the Build&Code 4in1 board. Turn on the Bluetooth on your mobile device, search for the signal named “HC-06” and select it. If your device asks you for a password, enter 1234 or 0000.
- Powering the Build&Code 4in1 board: The Build&Code 4in1 board can be powered by the computer using a USB cable. Once you connect it, you will see it turns on automatically, and there will be power for the sensors and the Bluetooth connection, but not for the DC motors. You can also turn on the Build&Code 4in1 board with a Jack 5.5 mm input, using the external adapter connected to a 12VDC maximum electrical outlet
- Powering the DC motors: You will have to use the input of the battery holder, to which the Jack input is connected. You have to turn on the Build&Code 4in1 board manually by using the ON/OFF switch located on the top of the board.
How do the sensors of the Code&Drive function?
- Blue and green LEDs: A LED is a Light Emitting Diode. In this case, the colors are blue and green. In this exercise you will turn On/Off the front and rear lights of the Code&Drive using the App. These components can be connected to any digital pins of the Build&Code 4in1 board except for the number 4, 5, 6 and 7, which are reserved for the motors. To program the LEDs functioning, you have to configure the digital pins where they are connected to as outputs pins.
- Buzzer: It’s an electric audio signal device that makes a “buzz” sound. This component can be connected to any digital pin of the Build&Code 4in1 board except 4, 5, 6 and 7 which are reserved for the motors. To program its functioning, you have to configure the digital pins where they are connected to as outputs.
- DC motor: They are machines that transform electric energy into mechanical energy, that triggers a rotatory movement. The rotation direction will be controlled with the app cursor, and the speed will be controlled with the slide bar. In order for the motors to work correctly, you have to power the Build&Code 4in1 board with AA batteries using the batteries holder. Make sure that the DIP switch (4 white switches) is on.
To program the DC motors you will use the digital pins 4, 5, 6 and 7, but it doesn’t mean that the motors will be connected to this pins.
Pins 4 and 7 will be programmed as a digital outputs (high and low), to control the direction on which the motors will rotate.
Pins 5 and 6 will be programmed as PWM signal outputs, with values from 0 to 255.
- Connect the DC motors to the digital pins as indicated below:
- Connect the DC motors to the ports indicated below:
Control the Code&Drive with the Arduino Bluetooth RC Car App
The app we recommend to use for this exercise is Arduino Bluetooth RC CAR. You can download it from Google Play Store.
Pair your smartphone with the Code&Drive using the app. Search and pair with the HC-06 Bluetooth signal. When it is correctly paired, the red indicator will turn green. Now you can control the Code&Drive with the App.
You can do this project using the Arduino software. Below you will find the necessary code.
- Download and install the Arduino IDE program. It is available for Windows, Mac OS and Linux.
- Open the Arduino program and copy the following program in it:
- Configure and upload the code, following the indications on the Code&Drive First Steps guide.
- Check that the BTL/USB switch on the Build&Code 4in1 board is set to USB, to upload the code correctly.
RESULT OF THE EXERCISE
With this program you will control the Code&Drive with the App, using your smartphone or tablet. With the arrows you will be able to control the direction, with the slide bar you will control the speed, with the front/rear lights buttons you will control the LEDs, and with the horn button you will make the horn sound.