The process of choosing a network path to transfer a packet from a source to a destination node is known as routing. Successful message delivery is difficult; thus, this paper presents an algorithm for Internet of Things (IoT) devices called Optimized Routing in IoT Using Machine Learning (ORuML). This algorithm predicts the network type of the source and destination nodes using machine learning named KNN, Decision Tree, and Support Vector Machine. The unique attributes of a node, i.e., signal strength, link quality indicator, noise floor, path length (no. of hops) between the ith node and the sink node, etc., are gathered from wireless sensor network (WSN) measurements conducted in an industrial environment used to train the ML model. Using these datasets, three machine learning techniques—KNN, DT, and SVM—were employed to predict the network type of the nodes to find the best path for data transmission between source and destination. The results of the simulation show that the DT method predicts the best among the other machine learning algorithms used, outperforming KNN and SVM in terms of accuracy and AUC.