Walter the Sonar Bot
![7.png](/proxy/?url=https://content.instructables.com/F7O/1F65/KCNDLYLH/F7O1F65KCNDLYLH.png&filename=7.png)
We will program Walter's Sonar
This a video tutorial following the instructable steps.
Downloads
![1.png](/proxy/?url=https://content.instructables.com/FG7/9M1U/KCLYAHAC/FG79M1UKCLYAHAC.png&filename=1.png)
We will modify the Walter microbot code so we can have a working sonar.
![2.png](/proxy/?url=https://content.instructables.com/FS9/0ZAC/KCLYAJB7/FS90ZACKCLYAJB7.png&filename=2.png)
Open the inputs tab and select On Button Press command which I have highlighted.
![3.png](/proxy/?url=https://content.instructables.com/FPU/GWEA/KCLYALCG/FPUGWEAKCLYALCG.png&filename=3.png)
![4.png](/proxy/?url=https://content.instructables.com/FFF/SBJB/KCLYANN9/FFFSBJBKCLYANN9.png&filename=4.png)
![5.png](/proxy/?url=https://content.instructables.com/FKT/GWOQ/KCLYANXO/FKTGWOQKCLYANXO.png&filename=5.png)
We will need 2 of these commands, make sure to change one of the buttons to B and leave the other on A.
![6.png](/proxy/?url=https://content.instructables.com/F28/IMJ4/KCLYAUIA/F28IMJ4KCLYAUIA.png&filename=6.png)
Open the variables tab and click on make a variable
![6.png](/proxy/?url=https://content.instructables.com/F6T/KNI3/KCLYAVP5/F6TKNI3KCLYAVP5.png&filename=6.png)
![6.png](/proxy/?url=https://content.instructables.com/FZA/LJSA/KCLYAY9V/FZALJSAKCLYAY9V.png&filename=6.png)
![6.png](/proxy/?url=https://content.instructables.com/FMK/NZTQ/KCLYAYUV/FMKNZTQKCLYAYUV.png&filename=6.png)
When you click on make a variable it will ask you to name it to make things simple just name it Button and then press ok, then you should see 3 commands appear.
![6.png](/proxy/?url=https://content.instructables.com/FGZ/PFV0/KCLYB22D/FGZPFV0KCLYB22D.png&filename=6.png)
![6.png](/proxy/?url=https://content.instructables.com/FOR/DO90/KCLYB3IA/FORDO90KCLYB3IA.png&filename=6.png)
Drag the Set Button command to On Button command like I showed.
![6.png](/proxy/?url=https://content.instructables.com/FXA/WFI6/KCLYB51B/FXAWFI6KCLYB51B.png&filename=6.png)
Open the logic tab and grab the command that I highlighted.
![6.png](/proxy/?url=https://content.instructables.com/FGC/6221/KCLYB9XM/FGC6221KCLYB9XM.png&filename=6.png)
![6.png](/proxy/?url=https://content.instructables.com/FWZ/IBZ4/KCLYBAIO/FWZIBZ4KCLYBAIO.png&filename=6.png)
Replace the Button Command with the new command.
![6.png](/proxy/?url=https://content.instructables.com/FNN/9P5W/KCLYBE0K/FNN9P5WKCLYBE0K.png&filename=6.png)
![6.png](/proxy/?url=https://content.instructables.com/F4P/QSV8/KCLYBHJO/F4PQSV8KCLYBHJO.png&filename=6.png)
![6.png](/proxy/?url=https://content.instructables.com/FE2/VV3G/KCLYBI5D/FE2VV3GKCLYBI5D.png&filename=6.png)
Select the button variable and replace the first 0. It might take you a couple of tries to get it to snap to the right stop.
![6.png](/proxy/?url=https://content.instructables.com/FS1/BB8A/KCLYC10J/FS1BB8AKCLYC10J.png&filename=6.png)
![6.png](/proxy/?url=https://content.instructables.com/FT9/IYVY/KCLYC13G/FT9IYVYKCLYC13G.png&filename=6.png)
![6.png](/proxy/?url=https://content.instructables.com/FLZ/6X6T/KCLYC2D0/FLZ6X6TKCLYC2D0.png&filename=6.png)
Open the variable tab and we will be making a new variable named Sonar.
![6.png](/proxy/?url=https://content.instructables.com/FMG/N53H/KCLYC2ZA/FMGN53HKCLYC2ZA.png&filename=6.png)
![6.png](/proxy/?url=https://content.instructables.com/F7Q/ODQE/KCLYC30U/F7QODQEKCLYC30U.png&filename=6.png)
![6.png](/proxy/?url=https://content.instructables.com/F4Z/07BR/KCLYC33Q/F4Z07BRKCLYC33Q.png&filename=6.png)
Go to extensions and search for sonar and choose the one i highlighted.
![6.png](/proxy/?url=https://content.instructables.com/FYD/XOYZ/KCLYC39S/FYDXOYZKCLYC39S.png&filename=6.png)
![6.png](/proxy/?url=https://content.instructables.com/FYO/RA27/KCLYC3H4/FYORA27KCLYC3H4.png&filename=6.png)
Grab the set Sonar command and drag it under the if statement.
![6.png](/proxy/?url=https://content.instructables.com/F7D/XJLA/KCLYC3MW/F7DXJLAKCLYC3MW.png&filename=6.png)
![6.png](/proxy/?url=https://content.instructables.com/FDS/8AU3/KCLYC3NS/FDS8AU3KCLYC3NS.png&filename=6.png)
![6.png](/proxy/?url=https://content.instructables.com/FUN/9Z5N/KCLYC3OR/FUN9Z5NKCLYC3OR.png&filename=6.png)
Drag the Sonar command into the sonar variable.
![6.png](/proxy/?url=https://content.instructables.com/F7M/CCF5/KCLYC3XV/F7MCCF5KCLYC3XV.png&filename=6.png)
![6.png](/proxy/?url=https://content.instructables.com/FE6/AC73/KCLYC3Z5/FE6AC73KCLYC3Z5.png&filename=6.png)
![6.png](/proxy/?url=https://content.instructables.com/FFV/TWMG/KCLYC40W/FFVTWMGKCLYC40W.png&filename=6.png)
![6.png](/proxy/?url=https://content.instructables.com/F6F/2RZH/KCLYC41Y/F6F2RZHKCLYC41Y.png&filename=6.png)
Next we will change the variables in the sonar command.
![6.png](/proxy/?url=https://content.instructables.com/FEG/E232/KCLYC46O/FEGE232KCLYC46O.png&filename=6.png)
![6.png](/proxy/?url=https://content.instructables.com/F42/XOFH/KCLYC47P/F42XOFHKCLYC47P.png&filename=6.png)
Open logic tab and drag the if else command under the Sonar command.
![6.png](/proxy/?url=https://content.instructables.com/F8D/AH0R/KCLYC4CH/F8DAH0RKCLYC4CH.png&filename=6.png)
![6.png](/proxy/?url=https://content.instructables.com/F1M/6225/KCLYC4DU/F1M6225KCLYC4DU.png&filename=6.png)
![6.png](/proxy/?url=https://content.instructables.com/FJ0/37CS/KCLYC59W/FJ037CSKCLYC59W.png&filename=6.png)
Open logic tab and drag the <0=0> command to replace the true statement.
![6.png](/proxy/?url=https://content.instructables.com/F6D/7B4B/KCLYCAXU/F6D7B4BKCLYCAXU.png&filename=6.png)
![6.png](/proxy/?url=https://content.instructables.com/FUS/15SR/KCLYCB94/FUS15SRKCLYCB94.png&filename=6.png)
![6.png](/proxy/?url=https://content.instructables.com/FIJ/T93T/KCLYCBAC/FIJT93TKCLYCBAC.png&filename=6.png)
Drag the Sonar Variable and replace the true statment.
![6.png](/proxy/?url=https://content.instructables.com/FRV/XO88/KCLYCC0H/FRVXO88KCLYCC0H.png&filename=6.png)
![6.png](/proxy/?url=https://content.instructables.com/FOZ/F2PW/KCLYCC1P/FOZF2PWKCLYCC1P.png&filename=6.png)
Drag the continuous servo command under the second if statement.
![6.png](/proxy/?url=https://content.instructables.com/FHI/NA3B/KCLYCD0H/FHINA3BKCLYCD0H.png&filename=6.png)
![6.png](/proxy/?url=https://content.instructables.com/FAY/C072/KCLYCCJZ/FAYC072KCLYCCJZ.png&filename=6.png)
![6.png](/proxy/?url=https://content.instructables.com/F71/0EWD/KCLYCD6Z/F710EWDKCLYCD6Z.png&filename=6.png)
![6.png](/proxy/?url=https://content.instructables.com/FVP/HBQ9/KCLYCD9N/FVPHBQ9KCLYCD9N.png&filename=6.png)
Click on advanced and then open the control tab. Then drag it under the first 2 continuous servo commands.
![6.png](/proxy/?url=https://content.instructables.com/FD6/9AUK/KCLYCDIU/FD69AUKKCLYCDIU.png&filename=6.png)
![6.png](/proxy/?url=https://content.instructables.com/FPL/OZ26/KCLYCDKE/FPLOZ26KCLYCDKE.png&filename=6.png)
![6.png](/proxy/?url=https://content.instructables.com/FC9/7QNJ/KCLYCDLY/FC97QNJKCLYCDLY.png&filename=6.png)
Drag the second set of continuous command under the wait command.
![6.png](/proxy/?url=https://content.instructables.com/FCK/MH2O/KCLYCDUF/FCKMH2OKCLYCDUF.png&filename=6.png)
![6.png](/proxy/?url=https://content.instructables.com/FUW/DGIC/KCLYCDYH/FUWDGICKCLYCDYH.png&filename=6.png)
![6.png](/proxy/?url=https://content.instructables.com/FGP/41OP/KCLYCE0B/FGP41OPKCLYCE0B.png&filename=6.png)
Add a wait time under the second set of continuous servo command. Then drag the third set of continuous commands under the first else command.
![6.png](/proxy/?url=https://content.instructables.com/FKB/0UHI/KCLYCF3N/FKB0UHIKCLYCF3N.png&filename=6.png)
![6.png](/proxy/?url=https://content.instructables.com/FDT/0YXZ/KCLYCF83/FDT0YXZKCLYCF83.png&filename=6.png)
![6.png](/proxy/?url=https://content.instructables.com/FYY/IKV0/KCLYCFEM/FYYIKV0KCLYCFEM.png&filename=6.png)
![6.png](/proxy/?url=https://content.instructables.com/FSQ/G2T8/KCLYCFL4/FSQG2T8KCLYCFL4.png&filename=6.png)
Delete the other statements and leave the else if statement and the stop servo commands.
![6.png](/proxy/?url=https://content.instructables.com/F02/N3N5/KCLYCG1Y/F02N3N5KCLYCG1Y.png&filename=6.png)
Drag the stop servo command under the else if statement.
![6.png](/proxy/?url=https://content.instructables.com/FIY/8NPD/KCLYCGKG/FIY8NPDKCLYCGKG.png&filename=6.png)
![6.png](/proxy/?url=https://content.instructables.com/FJZ/NVK8/KCLYCH57/FJZNVK8KCLYCH57.png&filename=6.png)
Open the logic tab and drag a <0=0> command to the slot.
![6.png](/proxy/?url=https://content.instructables.com/F83/FQV6/KCLYCHBE/F83FQV6KCLYCHBE.png&filename=6.png)
![6.png](/proxy/?url=https://content.instructables.com/FAE/AADI/KCLYCHGM/FAEAADIKCLYCHGM.png&filename=6.png)
Drag a button variable to replace the 0
![6.png](/proxy/?url=https://content.instructables.com/FSW/GLWI/KCLYCHYY/FSWGLWIKCLYCHYY.png&filename=6.png)
![6.png](/proxy/?url=https://content.instructables.com/F2P/5MJE/KCLYCI6F/F2P5MJEKCLYCI6F.png&filename=6.png)
![6.png](/proxy/?url=https://content.instructables.com/FX4/J8EH/KCLYCIM1/FX4J8EHKCLYCIM1.png&filename=6.png)
![6.png](/proxy/?url=https://content.instructables.com/FZ1/YRCI/KCLYCIOC/FZ1YRCIKCLYCIOC.png&filename=6.png)
Now were going to change some of the variables.
![2.png](/proxy/?url=https://content.instructables.com/FE4/U7RA/KCNDM3K4/FE4U7RAKCNDM3K4.png&filename=2.png)
This is what the finished code should look like.
Step 20: Here Are Video Instructions If You Prefer That! :)
![Walter- Sonar Programming tutorial](/proxy/?url=https://content.instructables.com/FQX/PHW2/KCXDOCQ2/FQXPHW2KCXDOCQ2.jpg&filename=Walter- Sonar Programming tutorial)