Can someone explain in detail about the function digitalWrite and how it works

digitalWrite is a simple function. Simply put, it sets the desired pin to maximum voltage(3.3 V) or 0 volt , in other words, turns it on or off.
In the digital write function, we are passing the pin number that we want to control and the value of pin number.
and in the next line var xmlhttp = new XMLHttpRequest();
we are creating an object of ajax. and after that control will go to this line"GET", base_url+api_key+"/digitalWrite?pin="+pin+"&state="+val+"&deviceName="+d_name,true);


Here ware doing the get request to the cloud the cloud. It very similar to typing the URL in the browser and pressing enter button.

And after sending the GET request to cloud the control will go to this section

xmlhttp.onreadystatechange = function() {

        if (xmlhttp.readyState == 4 && xmlhttp.status == 200 && debug == 1) {

            var obj = JSON.parse(xmlhttp.responseText);






Where the actual cloud response will be stored in xmlhttp.responseText

Do let me know in case you need further assistance.

digitalWrite is a function commonly found in Arduino programming and is used to write a digital value (HIGH or LOW) to a specified digital pin on the microcontroller.

A microcontroller has a number of pins that can be configured as digital inputs or outputs. When a pin is set as an output, the digitalWrite function can be used to set its value to either a logic high (HIGH) or a logic low (LOW) state. The state of the pin determines whether the pin is connected to the voltage supply (HIGH) or ground (LOW).

For example, consider the following code:
int ledPin = 13;

void setup() {
pinMode(ledPin, OUTPUT);

void loop() {
digitalWrite(ledPin, HIGH);
digitalWrite(ledPin, LOW);

In this code, the ledPin variable is assigned the value of 13, which represents the digital pin number on the microcontroller. In the setup function, the pinMode function is called to configure the ledPin as an output.

In the loop function, the digitalWrite function is called twice with a delay of one second between each call. The first call sets the ledPin to a logic high state, which turns on an LED connected to the pin. The second call sets the ledPin to a logic low state, which turns off the LED.

In summary, the digitalWrite function is used to set the value of a digital pin on the microcontroller to either a logic high or a logic low state. This can be used to control devices such as LEDs, relays, or motors connected to the microcontroller.