--- title: "Activity: Balance Bot" date: "2021-06-04" categories: ["Activities", "All", "Simulator Activities"] tags: ["Iteration", "Algorithm Design", "Accelerometer", "Motors", "Maths", "Advanced"] excerpt: "Learn iteration, algorithm design, maths, and how to use the Rover’s accelerometer and motors." featuredImage: "/images/resources/balance-bot.png" --- ** | ** Challenge students to program their rover to always try and stabilise itself. When complete, the rover will always turn and drive upwards on any tilted surface. Once the surface the robot is driving on is flat, it should stop moving. This means the robot will balance on a seesaw. Students will need to use data from the accelerometer to control the motors based on the orientation of the rover. #### Relevant Coding Skills Branching --> Iteration Functions Variables --> Algorithm Design Maths #### Relevant Rover Concepts Ultrasonic --> IR --> Colour Gyroscope Accelerometer Motors LEDs --> Buzzer --> Activity Demonstration ### Setup ![](https://images.squarespace-cdn.com/content/v1/60a43bf842d7b601064a8828/1622791717500-EVGL2F387L08PUMP3JUA/balancebot-setup.png) We use a large hard cover book for this challenge as a platform. Any flat surface that can be moved and tilted will work. When the object is tilted the rover should move up the surface in an attempt to stabilize. When the surface is flat the rover has found balance and will not move. For this exercise you can also use a seesaw style balance board or a circular wobble board. We use a seesaw board build from 2 pieces of wood as pictured. ### Here’s Our Approach ![](https://images.squarespace-cdn.com/content/v1/60a43bf842d7b601064a8828/2c208513-92e1-4454-a85f-5bf189edb0af/Screenshot+2023-10-31+083156.png) Example Code (single axis balancing) #### Stage 1 Using an IF statement block, we can check if the x axis of the accelerometer is above or below zero. If its above, we can use a motor block to move forward, otherwise we can use the motor block to move backwards. #### **Stage 2** To make the rover move smoothly and make fine adjustments, we can use the scale number block to scale the X axis between -1 and 1 to -30 and 30 for the motor block. #### **Stage 3** ![](https://images.squarespace-cdn.com/content/v1/60a43bf842d7b601064a8828/1622791925793-ZR3JU9N77ENPMDUUJLFP/balance-bot-answer-2.png) Example Code (multi-axis balancing) To make the program also work for a circular board we need to also take into account the Y axis of the accelerometer. We can use the same scale number block to create a variable called rotation, which we can include in our motor block. Since our speed variable determines the speed the motors move forward or back, the rotation modifier needs a + or - sign. We need this sign because the robot rotates by making its tracks move in opposite directions. ### Related Posts Resources [ ![](https://images.squarespace-cdn.com/content/v1/60a43bf842d7b601064a8828/1639455538805-9NI7CPKR7IYG6D4RBKAN/high+quality+sumo.png) ](/resources/creating-a-sumo-unit) [All](/resources?category=All) [Creating A Sumo Unit For Your Digital Technologies Class](/resources/creating-a-sumo-unit) [All](/resources?category=All) How to run a sumo unit in your digital technologies classroom. [Read More →](/resources/creating-a-sumo-unit) [All](/resources?category=All) [ ![](https://images.squarespace-cdn.com/content/v1/60a43bf842d7b601064a8828/1637464845856-BBPD7GTIIHHOSJCFORWF/the+ultrasonic+sensor.png) ](/resources/ultrasonic-sensor) [All](/resources?category=All), [Guides](/resources?category=Guides) [The Ultrasonic Sensor](/resources/ultrasonic-sensor) [All](/resources?category=All), [Guides](/resources?category=Guides) Learn all about the ultrasonic sensor! [Read More →](/resources/ultrasonic-sensor) [All](/resources?category=All), [Guides](/resources?category=Guides) [ ![](https://images.squarespace-cdn.com/content/v1/60a43bf842d7b601064a8828/1625616494179-LZHZP5MUA0E0MQKEB7HC/cropped+image+4.png) ](/resources/year-7-digital-tech-at-st-peters) [All](/resources?category=All), [Customer Stories](/resources?category=Customer+Stories) [Case Study: Year 7 Digital Tech at St Peters Lutheran College](/resources/year-7-digital-tech-at-st-peters) [All](/resources?category=All), [Customer Stories](/resources?category=Customer+Stories) See how Meg Foley at St Peters conducted a challenge for their Year 7s using Micromelon. [Read More →](/resources/year-7-digital-tech-at-st-peters) [All](/resources?category=All), [Customer Stories](/resources?category=Customer+Stories)