The advantages of IoT are incontrovertible; however, significant risks and uncertainties over the protection of best practices and their related costs prevent many companies from adopting the technology. Also, users are aware of the consequences of breaches of IoT protection. Recent research indicates that 90% of consumers lack confidence in the safety of IoT devices. IoT defense has been described as one of the weakest areas. In this respect, significant efforts have been made, often through traditional cryptographic methods, to overcome security and privacy issues in IoT systems. The list of security issues (confidentiality, integrity, authentication, and availability) must be addressed to secure IoT devices from attack. IoT nodes' specific features do not adequately protect the whole security spectrum of IoT networks through existing solutions. This paper aims to provide security to the IoT devices using nature-inspired Gravitational Search-guided artificial neural key. In this paper, artificial neural synchronization is used to create a neural key exchange protocol between two IoT devices over a public channel for cryptographic purposes. This proposed technique has many benefits, such as 1) it provides an optimized design of the neural network that facilitates the development and establishment of a neural key between the two approved IoT devices. 2) It offers the sharing of the private neural key over the public channel via artificial neural synchronization 3)Three hidden layers of the neural network contribute to the deep internal design. So, it's going to be hard for the intruder to infer the internal layout. 4) The increase in the weight spectrum of the neural network raises the complexity of an effective attack exponentially, but the effort to create a neural key decreases over polynomial time. Various parametric experiments have been conducted out on the proposed methodology. The simulations of the procedure demonstrate efficacy in terms of the findings cited in the paper.