# Registering a device with Microsoft Azure IoT Hub

A device must be registered with Microsoft Azure IoT Hub before this device can exchange data with Microsoft Azure IoT Hub.

You can also register the device with your Microsoft Azure IoT Hub on the Microsoft Azure IoT website.

1. Prerequisite
2. Set up an Microsoft Azure IoT Hub.
3. The device must be connected to the internet.

1. Open Node-RED.
2. Add the following nodes to the workspace and connect them to a flow:
3. inject node from the input category
4. Azure IoT Hub Registry node from the cloud category
5. debug node from the output category
6. Double-click the inject node to open the Edit node dialogue.
7. In the Payload text box, enter the desired device ID as JSON in the following format:

8. `{"deviceId":"yourDeviceId"}`

9. Enable the Inject once after 0.1 seconds check box.
10. In the Repeat list box, select none.
11. The device will be registered with the desired ID once you deploy the flow.
12. Click Done to apply your changes.
13. Double-click the Azure IoT Hub Registry node to open the Edit node dialogue.
14. In the connectionString text box, enter the IoT Hub connection string.
15. Click Done to apply your changes.
16. Click Deploy.
17. The inject node triggers the registration of the device. The device ID and its primary and secondary key are displayed in the debug tab of the sidebar.

18. If nothing is displayed in the debug tab, click the button on the left side of the inject node to trigger the registration of the device again.

19. Note down the device ID and its keys.