Arduino Ultrasonic Protocol
This protocol controls any ultrasonic sensor connected to the microcontroller. The trigger and echo pins can be provided in the .ino file as you can see in the Arduino codes below.
How to build a test circuit with an ultrasonic sensor and an Arduino Mega?
Arduino codes are included.
I. 'Welcome' event from microcontroller
Example
c=welcome&id=knRJ67&type=OzUltraSonicSensor&pos=2&name=MyUltra_1&t=3
Parameters
Parameter | Type | Range | Functionality |
c | String | 'welcome' | Identifies the welcome message. |
id | String | 6 characters (numbers, uppercase and lowercase characters) | The ID of the device which is chosen by the microcontroller. |
type | String | 'OzUltraSonicSensor' | Determines the type of the device. |
pos | Byte | 0-255 | Determines the position of the device on the list of the ID manager of the microcontroller. Please make sure there are no other devices in the same position. |
name (optional) | String | e.g. 'MyUltra_1' | You can give default names for devices. |
t | Byte | 0-255 | Counts the number of events and responses sent combined. Counts from 0 to 255 then from 0 again. |
II. Commands to microcontroller
'getvalue' command
With this command you can get the current distance of the measured object from your sensor. The value is provided in mm.
Example
c=getvalue&id=knRJ67&t=0
Parameters
Parameter | Type | Range | Functionality |
c | String | 'getvalue' | Identifies the command. |
id | String | 6 characters (numbers, uppercase and lowercase characters) | The ID of the device which is chosen by the microcontroller. |
t | Byte | 0-255 | Counts the number of commands sent. Counts from 0 to 255 then from 0 again. |
Response
Responds the current distance in mm between the object and the ultrasonic sensor.
Example
c=getvalue_resp&value=62.23&id=knRJ67&t=3
Parameter | Type | Range | Functionality |
c | String | 'getvalue_resp' | Identifies the response |
value | Double | Measurement range of your sensor in mm. | Shows the distance from the measured object. |
id | String | 6 characters (numbers, uppercase and lowercase characters) | The ID of the device which is chosen by the microcontroller. |
t | Byte | 0-255 | Counts the number of events and responses sent combined. Counts from 0 to 255 then from 0 again. |
'repchange' command
Sets threshold compared to the last measured distance. A 'change' event is sent everytime it passes the threshold in one of the directions. If it is set to 0 it is turned off.
Example
c=repchange&value=5.00&id=knRJ67&t=1
Parameters
Parameter | Type | Range | Functionality |
c | String | 'repchange' | Identifies the command. |
value | Double | From 0.00 to the range of your ultrasonic sensor. | Sets measurement threshold value compared to the last measured value. If it is set to 0 than the 'change' event is turned off. |
id | String | 6 characters (numbers, uppercase and lowercase characters) | The ID of the device which is chosen by the microcontroller. |
t | Byte | 0-255 | Counts the number of commands sent. Counts from 0 to 255 then from 0 again. |
Response
Responds if the threshold value has been set.
Example
c=repchange_resp&value=5.00&id=knRJ67&t=4
Parameters
Parameter | Type | Range | Functionality |
c | String | 'repchange_resp' | Identifies the response. |
value | Double | From 0.00 to the range of your ultrasonic sensor. | The measurement threshold value to trigger a 'change' event has been set. If it is set to 0 than the 'change' event is turned off. |
id | String | 6 characters (numbers, uppercase and lowercase characters) | The ID of the device which is chosen by the microcontroller. |
t | Byte | 0-255 | Counts the number of events and responses sent combined. Counts from 0 to 255 then from 0 again. |
'repabove' command
Triggers an 'above' event everytime the distance passes the value you set with this command.
Example
c=repabove&value=655.00&id=knRJ67&t=2
Parameters
Parameter | Type | Range | Functionality |
c | String | 'repabove' | Identifies the command. |
value | Double | From 0.00 to the range of your ultrasonic sensor. | If the measured value of the pin crosses this value than an 'above' event is triggered. |
id | String | 6 characters (numbers, uppercase and lowercase characters) | The ID of the device which is chosen by the microcontroller. |
t | Byte | 0-255 | Counts the number of commands sent. Counts from 0 to 255 then from 0 again. |
Response
Responds if the above value has been set.
Example
c=repabove_resp&value=655.00&id=knRJ67&t=5
Parameters
Parameter | Type | Range | Functionality |
c | String | 'repabove_resp' | Identifies the response. |
value | Double | From 0.00 to the range of your ultrasonic sensor. | If the measured value of the pin crosses this value than an 'above' event is triggered. |
id | String | 6 characters (numbers, uppercase and lowercase characters) | The ID of the device which is chosen by the microcontroller. |
t | Byte | 0-255 | Counts the number of events and responses sent combined. Counts from 0 to 255 then from 0 again. |
'repbelow' command
Triggers a 'below' event everytime the measurement value passes the value you set with this command.
Example
c=repbelow&value=133.00&id=knRJ67&t=3
Parameters
Parameter | Type | Range | Functionality |
c | String | 'repbelow' | Identifies the command. |
value | Double | From 0.00 to the range of your ultrasonic sensor. | If the measured value of the pin crosses this value than a 'below' event is triggered. |
id | String | 6 characters (numbers, uppercase and lowercase characters) | The ID of the device which is chosen by the microcontroller. |
t | Byte | 0-255 | Counts the number of commands sent. Counts from 0 to 255 then from 0 again. |
Response
Responds if the below value has been set.
Example
c=repbelow_resp&value=133.00&id=knRJ67&t=6
Parameters
Parameter | Type | Range | Functionality |
c | String | 'repbelow_resp' | Identifies the response. |
value | Double | From 0.00 to the range of your ultrasonic sensor. | If the measured value of the pin crosses this value than a 'below' event is triggered. |
id | String | 6 characters (numbers, uppercase and lowercase characters) | The ID of the device which is chosen by the microcontroller. |
t | Byte | 0-255 | Counts the number of events and responses sent combined. Counts from 0 to 255 then from 0 again. |
III. Event from microcontroller
'change' event
This event is called if the measured value has changed more then the threshold set with the 'repchange' command. This event shows the current distance measured with the OzUltraSonicSensor.
Example
c=change&value=112.00&id=knRJ67&t=7
Parameters
Parameter | Type | Range | Functionality |
c | String | 'change' | Identifies the event. |
value | Double | Measurement range of your sensor in mm. | Current value of the measured distance. It is the value measured after it has passed the threshold. |
id | String | 6 characters (numbers, uppercase and lowercase characters) | The ID of the device which is chosen by the microcontroller. |
t | Byte | 0-255 | Counts the number of events and responses sent combined. Counts from 0 to 255 then from 0 again. |
'above' event
This event is called if the measured value has crossed above a preset value which you can set with the 'repabove' command.
Example
c=above&value=655.00&id=knRJ67&t=8
Parameters
Parameter | Type | Range | Functionality |
c | String | 'above' | Identifies the event. |
value | Double | Measurement range of your sensor in mm. | Current value of the measured distance. It is the value measured after it has crossed the 'above' value that has been set. |
id | String | 6 characters (numbers, uppercase and lowercase characters) | The ID of the device which is chosen by the microcontroller. |
t | Byte | 0-255 | Counts the number of events and responses sent combined. Counts from 0 to 255 then from 0 again. |
'below' event
This event is called if the measured value has crossed below a preset value which you can set with the 'repbelow' command.
Example
c=below&value=133.00&id=knRJ67&t=9
Parameters
Parameter | Type | Range | Functionality |
c | String | 'below' | Identifies the event. |
value | Double | Measurement range of your sensor in mm. | Current value of the measured distance. It is the value measured after it has crossed the 'below' value that has been set. |
id | String | 6 characters (numbers, uppercase and lowercase characters) | The ID of the device which is chosen by the microcontroller. |
t | Byte | 0-255 | Counts the number of events and responses sent combined. Counts from 0 to 255 then from 0 again. |
More information
- RF 433 MHz Transceiver serial protocol
- Analog Joystick serial protocol
- Analog Sensor serial protocol
- Button serial protocol
- Buzzer serial protocol
- DC Motor serial protocol
- DHT Sensor serial protocol
- EEPROM serial protocol
- Keyboard serial protocol
- Gyroscope Sensor serial protocol
- ID Manager serial protocol
- IR Transceiver serial protocol
- LCD Display serial protocol
- NFC Reader serial protocol
- Optical Gate serial protocol
- Register
- RF24 Transceiver serial protocol
- RGB Led serial protocol
- RGB Sensor serial protocol
- Rotary Encoder serial protocol
- Servo Motor serial protocol
- Step Counter serial protocol
- Stepper Motor serial protocol
- Switch serial protocol
- Temperature Sensor serial protocol
- Timer serial protocol
- Ultrasonic Sensor serial protocol
- Welcome messages of the Ozeki 3D Printer