Programming a Sphero BOLT True/ False Quiz

Ashleigh Bartlett-Needham
5 min readJun 13, 2019

--

Sphero Bolt is ready to test your knowledge!

Everyone loves a good quiz night. Especially me. Honestly, I have a real competitive side, and this blends well with my love of robotics, AI and programming too. For example, I really enjoy the quizzes and games offered by Google Assistant and Alexa, and it got me thinking about Sphero BOLT. Sphero BOLT is a fully programmable robotic ball. Complete with a range of sensors and a fully programmable 8x8 LED matrix, Sphero BOLT can also be programmed to say words and phrases, through whichever device is running your program. By combining this feature, with the data from one of the many sensors built in to BOLT, I figured it would be pretty easy to create a true/false quiz. So that Sphero BOLT can be the perfect companion for any trivia fan, just like me! And I could have the perfect portable tool to test my friends and family.

Deciding on a topic

The first thing to think about was the topic, or area, the quiz would be covering. General knowledge is always popular, but among my friends, there is one topic that will always stand out…Harry Potter. I thought this would be the perfect way to put their knowledge to the test, and show off my robot friend! So, I compiled a comprehensive list of statements related to the Harry Potter universe, some true, some false, and some really tough ones to give my friends a challenge. After all, the crown for biggest Harry Potter nerd is still up for grabs…

Sphero BOLT and Harry Potter- the perfect combination!

The topic of the quiz doesn’t really matter though, as this format can be used to create a quiz about anything, at any level. From learning multiplication tables at 8 years old, to testing your rocket science, if you have the knowledge you need to set the questions, you’re good to go.

It’s absolutely crucial though, that the statements are just true/false or yes/no, because you can’t verbally tell Sphero an answer, so a binary option is best suited to this quiz.

Here’s how I got started with the Sphero BOLT block coding. You’ll see I have added a question mark animation to be displayed on the LED matrix, and an opening statement explaining how to play. I’ve also only included 3 statements to keep the screenshot a reasonable size.

Using Sphero BOLT’s sensors

The next thing I needed to decide on was which sensors to use. Sphero BOLT is equipped with:

  • light sensors
  • a gyroscope
  • an accelerometer
  • a magnetometer

I chose the accelerometer as its probably the easiest option. With this sensor data, all you have to do is just give Sphero BOLT a vigorous shake when the answer is true, and hold it still when the answer is false. BOLT can then decide whether the answer entered by the user was correct, or incorrect, by using the sensor data.

Here’s how the code progressed after adding the sensor data evaluation, to determine whether the answer is wrong or right.

Scoring points

So a quiz wouldn’t be a quiz if there wasn’t a tally of points at the end! This can be added into the program fairly easily, when Sphero BOLT makes the decision about whether the submitted answer is right or wrong. By creating an integer variable (I called mine score), you can start the quiz with this set to 0, and add 1 to this variable after each correct answer. At the end of the quiz, BOLT can then either speak the score (through the device), or show the score using the LED matrix. I opted for Sphero BOLT to speak the score in this example.

The pink blocks show how the variable controlling the score fit into the overall code.

Tidying up the code by adding functions

At this point, I had a fully functioning true/false quiz program. But with only ten questions, the code was looking just a little bit too messy for me to handle. So I decided to clean it up with 2 functions. These functions simply take the evaluation part out of the main script, and are called at the right point. I needed to make two different functions, one of when the answer is true, and one for when the answer is false.

Adding the functions in makes the code look so much neater as you can tell. The functions are headed by the lime green block, and then these are called at the right part of the program, in the main section.

Finishing touches

To fully complete the Sphero BOLT true/false quiz, I created a final score evaluation that would determine Sphero Bolt’s reaction to the score. This addition made the final code look like this:

At the end of the main part of the program, I added an if/else evaluation to determine what Sphero BOLT’s reaction would be to the score achieved.

And this is what the Javascript version looks like:

Expanding the quiz

If you need to expand the quiz, and randomize the quiz questions to give yourself, or your friends more of an intellectual workout, all you need to do is create more functions.

Using the existing Harry Potter example above, I added three new functions, titled Question1, Question2 and Question3. Inside this function, a new variable called question (very imaginative I know!) is used to provide a random number. This random number then determines which question from the list will be asked. This means that even the person who wrote the quiz cant be sure which questions will be asked, and it means that your friends won’t be asked the same question each time you play. The more questions you add to each function, the more chance you have of experiencing original questions.

And if three questions just isn’t enough, you could always add more functions (Question4, Qestion5 and Question6 for example). This will pick a random question from each function, so you’ll have more questions.

Here is what the code looks like with this expansion:

As you can see, this is difficult to read so I stuck to just three questions in each function. If you want to add more questions, be sure to change your question variable in each function to a random integer, up to the number of questions you have. In this example the random integer will be between 0 and 2 (in programming 0 is the first number). For ten questions you would need a random integer between 0 and 9.

For education purposes

If you are an educator using Sphero BOLT’s in the classroom, programming a true/false quiz can be a great way to use the BOLT, across the curriculum. Why not use Sphero for your flash quiz? Or better yet, get your class to code their own, and test their friends! Anything from multiplication tables to grammar, food chains to history, can be used as an effective topic!

Sphero BOLT multiplication quiz

Simply by changing the questions used in this Harry Potter example, I created a multiplication quiz:

Test your students knowledge with a multiplication quiz. Or better yet, help them create their own, to test each other.

--

--