Dancing Robots

Learning Intention

To program a robot to dance

To modify programs and create functions

Success Criteria

I can create and call a function




Re-exam the dancing robot sheet.


Copy the code below and upload to an Arduino create a function to stop and turn left or right. When the program is uploads without errors bring laptop to front and the teacher will test on a robot.


Use the programs below on a robot to see it works. Then create and test your dancing robot code.

//Motor A 
int motorAspeed = 10; // MCU PWM Pin 10 to ENA  
int motorAforward = 9;  // MCU Digital Pin 9 to IN1  
int motorAback = 8;  // MCU Digital Pin 8 to IN2  

//Motor B 
int motorBspeed = 5;  // MCU PWM Pin 5 to ENB  
int motorBforward = 7;  // MCU Digital pin 7 to IN3  
int motorBback = 6;  // MCU Digital pin 6 to IN4  

void setup() { 
  pinMode(motorAspeed, OUTPUT); 
  pinMode(motorBspeed, OUTPUT); 
  pinMode(motorAforward, OUTPUT); 
  pinMode(motorAback, OUTPUT); 
  pinMode(motorBforward, OUTPUT); 
  pinMode(motorBback, OUTPUT);   

void loop()

void forward() {
  analogWrite(motorAspeed, 200);
  digitalWrite(motorAforward, HIGH); // Turn HIGH motor A
  digitalWrite(motorAback, LOW);
  analogWrite(motorBspeed, 200);  
  digitalWrite(motorBforward, HIGH); // turn HIGH motor B
  digitalWrite(motorBback, LOW);  

void reverse() {
  analogWrite(motorAspeed, 200);
  digitalWrite(motorAforward, LOW); // Turn HIGH motor A
  digitalWrite(motorAback, HIGH);
  analogWrite(motorBspeed, 200);
  digitalWrite(motorBforward, LOW); // turn HIGH motor B
  digitalWrite(motorBback, HIGH);  

//Create a function to stop here

//Create a function to turn left or right.


Is your robot not driving forwards and backwards in a straight line? Is it not driving at all? Click on the image below to see the wiring diagram, and double check your robot’s wiring

H-Bridge Thumb


Did you get your robot working correctly today? If not what happened and how did you try and fix it?

Print Friendly, PDF & Email