$USD
  • EUR€
  • £GBP
  • $USD
TUTORIALS Robotics

How To Build A Robot - Lesson 5: Build An Arduino Robot With Light And Sound Effects

DFRobot Dec 17 2016 1092

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. 


Lessons Menu:
Lesson 1: Introduction
Lesson 2:  Build a Basic Arduino Robot
Lesson 3: Build a Line Tracking Arduino Robot
Lesson 4: Build an Arduino Robot That Could Avoid Obstacles
Lesson 5: Build an Arduino Robot With Light And Sound Effects
Lesson 6: Build an Arduino Robot That Could Monitor Environment
Lesson 7: Build a Bluetooth-Controlled Arduino Robot 


Hardware Parts

Digital piranha LED Module× 4

Digital Buzzer Module × 1


M3*6 MM Nylon support and Nylon cable ties 

 

Assembly Instruction

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.


  

STEP2: Assemble the LED module

There are four LED lights to be installed. Please fix nylon columns on the LED lights with nuts. The finished ones are shown as follows.


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…



Coding

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.


Code Synopsis 

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.

 

    pinMode(LeftLEDPin,OUTPUT);

    pinMode(RightLEDPin,OUTPUT);

    pinMode(BuzzerPin, OUTPUT);


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(LeftLED,RightLED)


LEDState() is used to set the state of LEDs on the two sides. Take one case in the program for an example.


    LEDState(HIGH,HIGH);  


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.


    LEDState(LOW,LOW);


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.


    LEDState(HIGH,LOW);


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. 


Considerations

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




REVIEW