After completing the basic functions, we’re now ready to give the Arduino robot an upgraded capability - Light and sound effects!
In this tutorial, we will teach you how to build LED module and buzzer on your robot. Same as the last ‘How to build a robot’ tutorials, an Arduino robot kit (Pirate: 4WD Arduino Mobile Robot Kit with Bluetooth 4.0 ) is used here as an example.
Lesson 1: Introduction
Lesson 2: Build a Basic Arduino Robot
Lesson 3: Build a Line Tracking Arduino Robot
Digital Buzzer Module × 1
M3*6 MM Nylon support and Nylon cable ties
STEP1: Assemble the Digital Buzzer Module
Please put the nylon columns on the buzzer just as it is shown in the photo below. Then fix them on the facade of the top plate with nuts.
Then fix the four LED lights on the back to the top plate of the car. Of course, you can also fix them on the facade of the plate if you want.
The two photos below show the facade and back of the top plate. The buzzer is fixed on the facade while the LED lights are on the back.
STEP 3: Make Cables for the LED Lights
Although we have used four LED modules , there is one signal for two LED modules on the same side. To reduce the use of IO, the simplest way is that we split the signal cables. Now let’s start making the cables.
Please take out two digital signal cables and cut them into half as it is shown in the photo below.
Take out two sensor cables with PH2.0 female heads(White) and one with 3Pin male heads(Black). Strip the insulation at one end of the sensor cable and weld the exposed wires with some tin soldering.
Now there are three bundles of sensor cables. Wield the red one (VCC) in each bundle together.
Now weld the black lines and green lines in the same way!
Once welded, please remember to wrap the welding points with insulated tape in case of a cutting-out.
Now make one more cable for the LED lights as we need two.
STEP 4: Connect the Cables
Connect the cables to the four LED lights. Please notice that the two LED lights on the same side share the same digital signal.
STEP 5: What It Looks Like When Finished
We suggest that you don’t add the plate now as the hardware circuit shall be connected next.
Now let’s connect the LED module to the car.
Connecting the hardware
As it is shown in the map below, two LED lights on the same side share the same signal port. “A” represents the two LEDs on the left side, which is connected with the digital Pin2. “B” represents the two LEDs on the right side which is connected with the digital Pin11. Digital Buzzer module connect with digital PIN3.
Note: The red cable is VCC; black one is GND; green one is signal.
Once assembled, we can add the upper plate. Ready for downloading the code…
The Light_Sound.ino code can be found in the software package. Click it and upload to the Romeo Board. Of course, don’t forget to select the Board and the Serial Port!
Once uploaded, you shall be able to turn on or turn off the four LED lights at the same time and hear the buzzing sound of the buzzer. Now let’s take a look of the coding.
At the beginning of the code is some information about the variables.
int LeftLEDPin = 11;
int RightLEDPin = 2;
int BuzzerPin = 3;
It means LED lights on the left are connected to Digital Pin9 .AND LED lights on the right are connected to Digital Pin2.The buzzer is connected to No.3 dgital pin.
Also the digital pins of LED lights and buzzer shall all be set in the OUTPUT mode.
Let’s look at the function of loop(), which included two functions: LEDState() and TurnOnBuzzer().
LEDState() is used to set the state of LEDs on the two sides. Take one case in the program for an example.
It means that LED pins on the two sides are all set as HIGH. And then, LED can be turned on at the same time.
Vice versa, the LED module on the two side can be turned off when LED pins are all set as LOW.
But if you only want to turn on the LED lights on the left and keep the ones on the right off, the code shall be written as follows.
Function for the buzzer is quite simple. Please check the fuction of TurnOnBuzzer() out.
In fact, Using the function of digitalWrite() is to give buzzer pin a HIGH level and make it start buzzing. Meanwhile, we can adjust the delay time to control the duration of the buzzing sound.
Do you know how to control the LED lights and buzzer now? Start making your robot buzz! MAKE IT SPECIAL.
Digital piranha LED Module× 4