Course 5 / Lecture 8:

Error alert using SMS

Alerts in case of unexpected events are very important in robotics. SMS alerts are often used when urgent action is needed. In this lecture you will learn how to send text message (SMS) alerts to mobile phones. You will learn about SMS messages sent by GSM modems, Android smart phones and IP SMS systems. IP SMS systems send SMS messages over the Internet and are used when large number of messages need to be sent, or when high performance is needed.

Figure 1
Figure 1 - Sending an error message using SMS

Requirements

Task #1:

Create a program to drive the robot forward if an SMS received containing the 'go' message!

Doing this task, you will be able to move your robot forward with a simple command received from your phone via SMS. You need to start the program somehow, so you should add a 'when green flag clicked' block as an entry point. After that you need a 'Get next message' block from the Ozeki category to receive the message. To compare two values with each other, you need to add an 'if [condition]' block and insert a 'From [connection] message: [text] ?' block into the condition field. In that block, select the 'My_SMS_Android_1' option for the 'connection' field and type 'go' into the textbox. So this condition will be true, if the received message coming from the Android SMS connection equals to the 'go' text. Finally, you should insert a 'Drive [motors] [direction]' block from Lego motors category into inside of the 'if' block and set its parameters like on Figure 2 to drive the robot forward if the condition is true.


Figure 2 - Program code to drive the robot forward if a 'go' command is received

Task #2:

Upgrade the code to stop the robot if it is too close to an obstacle!


You may want to stop your robot if some kind of obstacle appears in front of the robot. To implement this task, attach a 'wait until [condition]' block from Control category to the 'Drive block'. At this point, the execution of the program will wait until the condition in the 'wait until' block become true. You have to define this condition to be true if the robot can not go forward due to an obstacle. More precisely, you should check the distance measured by the Ultrasonic Sensor if it is less than 5 cm. To implement it, you need to use a green '[value] < [value]' operator block and a 'Distance in cm' one as can be seen on Figure 3. After the 'wait until' block, attach a 'Stop motor' block to stop the robot.


Figure 3 - Using the sensor

Task #3:

Send an SMS alert when the robot has encountered an obstacle!


In Ozeki 10, you can send SMS messages to every phone (from the phone device the Ozeki 10 running on) that has a valid phone number. In Snap, you can do it using the 'To [connection], address: [phone_number], message: [message]' block found in Ozeki category as well. You need to select the SMS Android connection for its connection field because this connection responsible for SMS sending as well as SMS receiving. Into the adress field, you should type the phone number you want to alert. And finally, the message field should containg the text to be sent. These steps are demonstrated in Figure 4. Now, you can try out your program!


Figure 4 - Alerting the user

Task #4:

Upgrade the program to use broadcast event to stop the robot and alert!


In the previous courses you learned how to use broadcast events. Now you are going to use one to check the distance continously while the main part of the program is waiting for the SMS messages and driving the robot. So the second part should stop the robot if it is to close too an obstacle and send an alert about it via SMS. This part also should run in parellel with the main part. At first, insert a 'when I receive [message]' block and create a new message for it called 'verify_distance' and attach a 'forever' block to it. Then, insert an 'if' block to inside of the 'forever' block. Its condition should be the one in the 'wait until' block of the main part. To inside of the 'if', you should move the blocks found under the 'wait until' block. At this point, this part verifies the distance continously and if this measured value less then 5, the program will stop the robot and alert you via SMS. But in this case, it will send the alert to you as many times as it can because of the forever block. To avoid this, you need to place a 'stop' block fround in Control category that stops the whole program. In the main part, you just need to delete the 'wait until' block and the other ones under it and insert a 'broadcast [verify_distance]' one between the 'when green flag clicked' and the 'forever' block as you can see on Figure 5.


Figure 5 - Program code uses broadcast event


Program code


Figure 6 - This program code can drive your robot forward with a simple message, and stop it if some obstacle appears

More information


Next


Copyright © 2000- |Ozeki Ltd | info@ozekirobot.com |
Page: 6289 | 18.227.0.192 | 79.99.42.43 | Login