Arduinos are a very easy, beginner way of getting into computerizing electronic gadgets. The Arduino used in the robot is a normal "Arduino Nano" which you can buy separately for a few dollars. It is plugged into a bigger circuit board that has the extra stuff to play sounds (MP3 files from the microSD card), measure distance (using the ultrasonic rangefinder that is the "eyes" of the robot), run on a rechargeable battery, use the two infrared optical sensors at the front corners, receive commands via bluetooth, and of course provide power to the four servos that move the legs.
By the standards of Arduino projects, this bot is quite an advanced one.
1. The top servos bolt onto the baseplate, but you don't put the nuts on right away. The nuts go on top of the circuit board. The proper assembly sequence is to put the servos into the holes, run their cables through the holes in the circuit board, place the circuit board on top (sandwiching the servos) and then put the four screws in and put the nuts on from the top.
2. I got the legs backwards the first time! The output shafts of the servos must point to the front of the robot. I had them pointing to the back. The robot worked, but it "walked" really strangely, and it fell over during the dance routines. This is what looked like
3. They show putting the legs together first, then putting in the screws to fasten them to the top servos. This just doesn't work. What I did was first assemble the "feet" but not yet attach them to the legs (U-brackets), then go through the coarse trim routine - power it up, let it center the servos - then attach the U-bracket "legs" and screw them on, then attach the feet, go through the powerup thing again to be sure, then screw them on.
You can power it up right away to do the coarse trim by just plugging it into a charger, no need to wait for the battery to charge up. The fine trim is done later through the app.
Beware that these servos are not super heavy duty. If the robot falls off the table, for example, they will probably break. The manual also cautions against trying to force them to move while they are powered. They can be moved when the robot is turned off.
Under "Download Options" click on "Windows Win 7 and newer"
On the donations page that follows, click on "Just Download"
When it's finished downloading, run it and let it install, with defaults for everything including all the "Would you like to install..." prompts.
When it's done, you have an Arduino icon. The first time I ran it on my Windows 10 setup, it asked for another permission ("Windows Defender has blocked..."). If it asks, give it this permission.
Next, download the robot software. Start at elegoo.com
Go to "Download -> Arduino Kits Files Download"
On the left side, click on "Robot Kits -> Elegoo Penguin Bot V1.0/V2.0"
Click on the "+" to expand the options.
Under "1. Manual Book, Tutorial and Code" click on "Elegoo Penguin Bot V2.0"
When the big .zip file is downloaded, open it, and drag the folder inside to to your desktop, in order to unpack it.
In the folder, there are these signifcant subfolders:
Default Music Files: Initial contents of the microSD card, in case you need to restore them.
Penguin Bot Function Introduction: Snippets of tutorial and code for learning how to program the bot
PenguinBot: The source code for what's running on the bot
Go into the copied folder, and double click on the file with the Arduino icon.
What should happen is that the Arduino environment opens up, with a bunch of tabs for the files in the folder. At the top left is a checkmark. Click it. It should successfully compile the code.
Now let's make an experimental change. In the leftmost tab, the "PenguinBot" one, use Edit->Find to find the "setup" function and add the code shown in bold here (you can use copy/paste).
void setup()
{
Serial.begin(9600);
mp3Serial.begin(9600);
pinMode(ECHO_PIN, INPUT);
pinMode(TRIG_PIN, OUTPUT);
pinMode(INDICATOR_LED_PIN, OUTPUT);
pinMode(VOLTAGE_MEASURE_PIN, INPUT);
for(int i=0;i<5;i=i+1) {
digitalWrite(INDICATOR_LED_PIN,1);
delay(500);
digitalWrite(INDICATOR_LED_PIN,0);
delay(500);
}
analogWrite(INDICATOR_LED_PIN, LED_value);
mp3.init();
MsTimer2::set(50, getCommand);
MsTimer2::start();
servoInit();
servoAttach();
homes(200);
servoDetach();
delays(2000);
start();
}
Can you guess what this new snippet of code will do? Let's see, does it compile? Click the checkmark. Did it compile successfully?Now take the bot, turn it on, and move the small slide switch at the back from "Bluetooth" to "Upload" and then connect it to the computer using the socket above the switch (not the one you use for charging). Let the computer do the driver installation dance, and when it's finished, in the Arduino software, under Tools->Board select "Arduino Nano", and under Tools->Port find the right port. On my test setup, the bot came up as "COM3", if in doubt, unplug it and plug it back in to see which port it is.
Whenever the bot is turned on, and plugged into the computer, and the switch is in the "Upload" position you can just upload to it whenever you want, regardless what it is currently doing. After the upload is done it will run the program you uploaded right away.
Let's try it. Click the right arrow button next to the checkmark and wait. With any luck, after some time it will say "Done Uploading". You now have customized software on there. Unplug the cable, turn the bot off and on and see what happens.
From here, the sky is the limit. You can explore how the software works, and change it. To restore the bot to its original function, just compile the code in an unmodified "PenguinBot" folder and upload that.
Now let's make another change to the setup function to play it:
void setup()
{
Serial.begin(9600);
mp3Serial.begin(9600);
pinMode(ECHO_PIN, INPUT);
pinMode(TRIG_PIN, OUTPUT);
pinMode(INDICATOR_LED_PIN, OUTPUT);
pinMode(VOLTAGE_MEASURE_PIN, INPUT);
mp3.init(); // Had to move this up here from down below
delay(50);
mp3.stopPlay(); // Copied from the "start" function. Probably
delay(10); // works around a hardware bug. Without this
mp3.stopPlay(); // the initial audio clip won't play after a power cycle
delay(10);
mp3.stopPlay();
delay(10);
mp3.playSong(8, mp3.volume); // Play the new audio clip
for(int i=0;i<5;i=i+1) {
digitalWrite(INDICATOR_LED_PIN,1);
delay(500);
digitalWrite(INDICATOR_LED_PIN,0);
delay(500);
}
analogWrite(INDICATOR_LED_PIN, LED_value);
MsTimer2::set(50, getCommand);
MsTimer2::start();
servoInit();
servoAttach();
homes(200);
servoDetach();
delays(2000);
start();
}
Programming challenge. Use something like Audacity to record a 0009_whoa.mp3 (save at 128kbps rate or it may not play). Test that it works by changing the file number in the playSong above to 9. If it plays OK, make the robot say "Whoa!" when it is in obstacle avoidance mode and sees an obstacle. Harder challenge: Is it possible to make it take a bow of sorts? You can experiment by manually rotating the servos while it's off. Can you make it take a bow (or some other custom gesture) while it speaks the "hello, nice to meet you" message?
// Hand Tour APP Control Interface Left Domain Key #define BTN_UP 'f' #define BTN_DOWN 'b' #define BTN_LEFT 'l' #define BTN_RIGHT 'i' #define BTN_IDLE 's' // Right Domain Key of Hand-Tour APP Control Interface #define BTN_MUSIC '1' #define BTN_DANCE '2' #define BTN_OBSTACLE '3' #define BTN_VOL_ADD '4' #define BTN_VOL_SUB '5' #define BTN_FOLLOW '6'With the bot plugged into the computer and in "Upload" mode, go Tools->Serial Monitor, wait for the bot to do its powerup song/dance, then type "2" and press Enter. What happens? It starts the dance routine and then immediately stops. That's because the code for "Enter" immediately followed the "2" and the bot didn't know what to do with it. We can fix that, by selecting "No Line Ending" in the menu at the bottom just to the left of the baud rate. Now you can type a code, press Enter, and the robot will act on it. Try making it walk forward and stop again (BTN_UP, BTN_IDLE).
Note that the bot is reset every time the serial monitor is opened, i.e. it goes through its whole startup routine again.
The advantage of controlling it this way, is that the bot can talk back to you. As an example, find this snippet of code and add the bold line:
switch (irValue)
{
case BTN_UP:
Serial.println("I'm walking forward!");
mp3.stopPlay();
mode = BLUETOOTH;
BTmode = FORWARD;
break;
Upload that, open the serial monitor, make it walk forward ("f") and see the message. This really helps for debugging code. And it doesn't seem to hurt in bluetooth mode; at least the app on the phone doesn't care about the message.Or how about, whenever the bot measures distance using the ultrasonic rangefinder (the "eyes"), print the distance. Modify the getDistance function like this:
int getDistance()
{
digitalWrite(TRIG_PIN, LOW);
delayMicroseconds(2);
digitalWrite(TRIG_PIN, HIGH);
delayMicroseconds(10);
digitalWrite(TRIG_PIN, LOW);
int p = pulseIn(ECHO_PIN, HIGH) / 58;
Serial.print(p);
Serial.println("cm");
return p;
}
Go into the serial monitor and make it go into follow or obstacle avoidance mode. See how often it measures the distance and what results it gets. Exercise: Why the division by 58? What units does "pulseIn" return (google!) and what is the speed of sound? Still off by a factor of 2? The sound has to be sent to the target, and come back from the target. By the way there's a module that you can get, pretty cheap too, that does the same thing with light! It sends out a laser pulse and counts off how long it takes for the reflection to arrive. Accurate to a centimeter or so. Link for thatWith enough print statements you can trace how the software works. When does it call a given function? What arguments does the function get, what does it return? Just print it.
There are very reasonably priced parts kits that let you try lots experiments with Arduinos. Note how most of them include the ultrasonic rangefinder and one of the servos used in the bot.