Main content
Electrical engineering
Course: Electrical engineering > Unit 7
Lesson 4: Spider Bot- 6th graders learn to build a Spider robot
- Fun with Spider Bot
- Parts list for Spider
- Tools list for Spider
- Spider parts and tools
- Spider's click n' stick
- Battery and motor mounts for Spider
- Click n' stick base & batteries
- Spider's motor controller
- Spider's power switch
- Spider's bezel
- Spider's wheels
- Spider's Arduino Nano
- Motor controller connections
- Spider's LED eyes
- Spider's stabilizer bar
- Spider's romance
- Programming Spider
- Ben Eater's Spider
© 2023 Khan AcademyTerms of usePrivacy PolicyCookie Notice
Programming Spider
Teaching Spider how to dance
Now its time to teach Spider to dance
1. Go to: http://arduino.cc/en/main/software and download the Arduino software for your computer's operating system
2. Launch Arduino and then go to file new
3. Go to tools and select Arduino Nano w/ ATmega328
4.Connect the USB mini cable to your computer and the Arduino on your Spider bot
5. Select the following serial port
6. Copy the dance code shown below (select it and use control c on a pc or command c on a mac)
// DANCE CODE for Spider by Karl Wendt 1/15/13
// Define the pin outs
int Red_Eye_Left= 12; // LED connected to pin 12
int Red_Eye_Right= 4; // LED connected to pin 4
int Green_Eye_Left= 8; // LED connected to pin 8
int Green_Eye_Right= 3; // LED connected to pin 3
int Blue_Eye_Left= 7; // LED connected to pin 7
int Blue_Eye_Right= 2; // LED connected to pin 2
int Left_Reverse = 6; // Right motor control 1 connected to pin 6
int Left_Forward = 9; // Right motor control 2 connected to pin 9
int Right_Forward = 10; // Left motor control 1 connected to pin 10
int Right_Reverse = 11; // Left motor control 2 connected to pin 11
// Set the mode of the pin (output or input)
void setup() {
pinMode(Red_Eye_Left, OUTPUT); //sets the digital pin as output
pinMode(Red_Eye_Right, OUTPUT); //sets the digital pin as output
pinMode(Green_Eye_Left, OUTPUT); //sets the digital pin as output
pinMode(Green_Eye_Right, OUTPUT); //sets the digital pin as output
pinMode(Blue_Eye_Left, OUTPUT); //sets the digital pin as output
pinMode(Blue_Eye_Right, OUTPUT); //sets the digital pin as output
pinMode(Left_Forward, OUTPUT); // sets L1 the digital pin as output
pinMode(Left_Reverse, OUTPUT); // sets L2 the digital pin as output
pinMode(Right_Forward, OUTPUT); // sets L3 the digital pin as output
pinMode(Right_Reverse, OUTPUT); // sets L4 the digital pin as output
}
// Create your code loop
void loop() {
digitalWrite(Red_Eye_Left, HIGH); //turns on left eye red LED
digitalWrite(Red_Eye_Right, HIGH); //turns on right eye red LED
delay(500); //run for half a second
digitalWrite(Red_Eye_Left, LOW); //turns off left eye red LED
digitalWrite(Red_Eye_Right, LOW); //turns off right eye red LED
digitalWrite(Green_Eye_Left, HIGH); //turns on left eye green LED
delay(500); //run for half a second
digitalWrite(Green_Eye_Left, LOW); //turns off left eye green LED
digitalWrite(Blue_Eye_Left, HIGH); //turns on left eye blue LED
delay(500); //run for half a second
digitalWrite(Blue_Eye_Left, LOW); //turns on left eye blue LED
delay(500); //run for half a second
digitalWrite(Green_Eye_Right, HIGH); //turns on right eye green LED
delay(500); //run for half a second
digitalWrite(Green_Eye_Right, LOW); //turns off right eye green LED
digitalWrite(Blue_Eye_Right, HIGH); //turns on right eye blue LED
delay(500); //run for half a second
digitalWrite(Blue_Eye_Right, LOW); //turns off right eye blue LED
delay(500); //run for half a second
//Make new colors by combining LED lights
digitalWrite(Blue_Eye_Left, HIGH); //turns on left eye blue LED
digitalWrite(Blue_Eye_Right, HIGH); //turns on right eye blue LED
digitalWrite(Red_Eye_Left, HIGH); //turns on left eye red LED
digitalWrite(Red_Eye_Right, HIGH); //turns on right eye red LED
delay(1000); //run for a quarter second
digitalWrite(Blue_Eye_Left, LOW); //turns on left eye blue LED
digitalWrite(Blue_Eye_Right, LOW); //turns on right eye blue LED
digitalWrite(Green_Eye_Left, HIGH); //turns on left eye green LED
digitalWrite(Green_Eye_Right, HIGH); //turns on right eye green LED
digitalWrite(Red_Eye_Left, HIGH); //turns on left eye red LED
digitalWrite(Red_Eye_Right, LOW); //turns on right eye red LED
delay(1000); //run for a quarter second
//Turn on the motors and make Spider move
analogWrite(Left_Reverse, 90); //run left motor backwards at PWM speed 90
delay(500); //run for half a second
analogWrite(Left_Reverse, 0); //stop left motor
delay(200); //run for 2 seconds
analogWrite(Right_Reverse, 90); //run right motor backwards at PWM speed 90
delay(500); //run for half a second
analogWrite(Right_Reverse, 0); //stop right motor
analogWrite(Left_Forward, 90); //run left motor forward at PWM speed 90
delay(500); //wait for half a second
analogWrite(Left_Forward, 0); //stop left motor
analogWrite(Right_Forward, 90); //run right motor forward at PWM speed 90
delay(500); //run for half a second
analogWrite(Right_Forward, 0); //stop right motor
analogWrite(Left_Reverse, 90); //run left motor backwards at PWM speed 90
delay(500); //run for half a second
analogWrite(Left_Reverse, 0); //stop left motor
delay(200); //run for 2 seconds
analogWrite(Right_Reverse, 90); //run right motor backwards at PWM speed 90
delay(500); //run for half a second
analogWrite(Right_Reverse, 0); //stop right motor
analogWrite(Left_Forward, 90); //run left motor forward at PWM speed 90
delay(500); //wait for half a second
analogWrite(Left_Forward, 0); //stop left motor
analogWrite(Right_Forward, 90); //run right motor forward at PWM speed 90
delay(500); //run for half a second
analogWrite(Right_Forward, 0); //stop right motor
}
7. Paste the code into the new Arduino file you just created (place the cursor into your Arduino sketch and press control v or command v)
8.Upload the code to your Spider Bot by clicking on the horizontal arrow
9. Unplug the USB cable
10. Turn you spider on and watch him go!
11. You may need to increase the motor speed if your spider is not moving fast enough.
CAUTION: Be sure your Spider Bot is on a smooth flat floor (NOT A TABLE TOP) he is NOT programmed yet to avoid the edges of the table and he will fall and may break.
Want to join the conversation?
- Can you program it to a remote?(7 votes)
- You probably could, but Karl doesn't give us the information to do that here.(2 votes)
- Is this the only way to program spider?(7 votes)
- No, it's not. You aren't limited to what Karl just showed you.(1 vote)
- It says Arduino is only available in the US I don't live in the US. Does it mean the Arduino software or actual Arduino brick?
Cos that would be REALLY annoying if I can't get it(4 votes)- Hi Dan,
Arduino originated in Italy. You should be able to purchase a kit anywhere in the world. Also, there are many clones available.
Regards,
APD(2 votes)
- Is the ardino software on Windows 10?(4 votes)
- Yes, it operates on nearly every operating system including all modern version of Windows, Linux, and Mac.
Regards,
APD(1 vote)
- When I uploaded the program and turned the spider on it did not move(4 votes)
- If that occurs then it is most likely an issue either your program or wiring.(1 vote)
- Can you guys do a video on using python on the RaspberryPI3(4 votes)
- You can search on youtube for a tutorial.(0 votes)
- Can u make the bot just go stright 10 inches and then turn 180 degrees and repeat 5 seconds later?(2 votes)
- yes. you can modify to code to your needs.(1 vote)
- Здравствуйте помоги пожалуйста, мы с сыном по заданию преподавателя по предмету Информатика собрали вашего робота-паука, возникла проблема с загрузкой программного обеспечения Arduino, установлена ОС Windows 10 которая не видет данное устройство. Пришлите на эл. адрес korolevgorodiwe@yandex.ru как можно исправить данную проблему. Спасибо.(1 vote)
- What if we give - analogWrite(Right_Reverse, 30); //run right motor backwards at PWM speed 30
delay(500); //run for half a second(1 vote) - I am using an OSEPP nano, which was said to be 100% compatible with Arduino. I spent countless hours and money and effort on this robot, but when I finally got around to programing it, the only thing that works are the flashing LEDs. I have followed every single step correctly. Can someone help me?(1 vote)
- Hello Braden,
Don't worry - this is normal. Things rarely work the first time...
This is where you learn how to troubleshoot. Since you say the LEDs blink I am assuming you can communicate with and program the ATMega. It sound like you are having problems with the ATMega / driver / battery / interface.
Let's start out with a few easy questions:
1) What motor driver are you using? Manufacturer and part number please.
2) Does this driver have a status LED?
Please leave comments below.
Regards,
APD(1 vote)