Learn how to use senors for Otto
In this workshop, you will dive into the logic of robotics by learning how to program conditional statements (If/Then/Else logic) to make your Otto Bot react to its environment. Working in teams of three, you will explore how to integrate sensors such as touch, sound, or distance sensor to trigger specific movements and sounds.
This workshop assumes that you have covered Introducing Otto Hardware &
Introducing Otto Software
Material List
Overview
Conditionals
When we navigate our world we unconsciously do so with taking into consideration conditions in our everyday life. For example. If I need to exit the room ,but the door is closed, then open the door. or If it is raining outside, but I want to stay dry, grab umbrella. In these examples we have a certain outcome that we want to achieve when a certain condition is met. In our code we can define what outcomes we would like to happen when certain scenarios in our environment appear.
We do this withConditionals & Sensors for Otto -
Sensing
In order to react to our environment we need to perceive our environment. We SEE that the door is closed, we open it.
We FEEL wet, we grab an umbrella. We interact with our environment through different senses like sight, touch, hearing, smelling and, taste. To give robots a more humanoid interaction we provide sensors for our robots so that they too can interact wit their environment.
In this activity we will have the option to give our robot Conditionals & Sensors for Otto - in order to touch, hear and/or see
If-else Statements
Control
To make conditions we head to Control
Here we can see “if/ then” block and the “and” block
If/then block works by waiting for a condition to be met and if that condition is met the task is performed.
Here we see the Touch Sensor is added next to if. This is prompting the question ”Is the Touch sensor being pressed?”
If the answer to the question is yes then we continue to then.
If it is false, the then section is skipped and go to else. The condition to run this code has not been met.
“and” is added if you want two conditions to be met before the then section is run. Here we are checking to see if both Touch sensors on our robot are being touched. If so we move forward. If only one or neither are pressed then this is skipped.
You can also click on the and and replace it with “or” if you want either condition to be met before moving on.
Operations
In Operations we have the opportunity to had a range of values that our sensors provide that meet our conditions. Here we can pick blocks that allow us to check if our sensor is greater then, less then or equal to a value. We can also pick a block that allows us to pick between two values
Here we see that we can only more forward if Sound is greater then 800. If sound is greater then 800 that means it is loud.
Here we are seeing if the distance is between 0 and 100. If the distance is in this range that means that someone is too close.
lets check out some examples that use these conditionals.
Download Examples
First Download the examples folder.
Import examples into Blocky Software.
Sensors
Touch
The touch sensors allows for the our robot to sense when this component is touched or pressed.
The sensor has three pins: SIG, VCC, GND
Connect: SIG to A0 VCC to V GND to G
Open [Basic]TouchExample.bloc
In this code we are checking to see “if” Touch sensor is being touched and if so “then” the robot is happy and makes an expression and movement to reflect this.
Sight
For vision we will use of Time of Flight Sensor. This sensor send out an invisible beam of light and measures how long the light will reflect back. With this is it able to detect if there are objects in front of it.
The sensor has 6 pins but we will only use 4: VIN, GND, SCL & SDA
Connect: VIN to 5V GND to CND SCL to SCL SDA to SDA
Open [Basic]DistanceExample.bloc
In this code we are checking “if” distance is between two values. if yes “then” the robot is sad and backs away.
Serial Monitor
In both if the examples above we are using the Serial Monitor to print out and check what values our sensors are giving off. [For example distance]. This is a great debugging tool.
You view the serial monitor, click on the magnified glass next to the green go button.
One clicked. Press start to see your values being printed. Make sure that your USB Serial is set to 9600 and the Serial Monitor is also set to “9600 baud”.
