• example arduino sketches

    understanding how to use the example sketches in the arduino ide

    The example sketches below can be found in the Arduino IDE at File > Examples > ESPert

    0010 blink

    This is the most basic sketch to see if everything is set up properly. After the sketch is uploaded into the board, the on-board LED will blink every second (1000 ms)

    0012 ADC

    This sketch is use to determine the analog value at pin A0 and print it out in the serial monitor. By changing the illumination level to the light-dependent resistor (LDR) , the serial monitor will display a change in analog values.

    0020 BlinkESPert

    This is yet another 'blink' example. Instead of lengthy declaration of pin modes in void(setup) or digitalWrite functions in void(loop), a shorter function e.g. espert.led.on() is used.

    0030 BoardInfo

    This sketch is used to get information about the board displayed in the Serial monitor, e.g. board id, flash memory size, etc.

    0040 Button

    This is a simple sketch to demonstrate the effect of button push in lighting up the LED. By default, the USER button is the (momentary) switch at GPIO13.

    0050 OLED

    This sketch provides the example code to display text on the OLED screen.

    0060 DHT

    This sketch sets up the DHT22 digital humidity & temperature sensor, read and display those two values in the OLED screen as well as the Serial monitor.

    0080 WebServer

    This sketch turn the board and its sensors into a webserver.

    0090 Ajax

    This sketch will post the sensor data (temperature) from the DHT22 to an HTML page that will refreshes its value dynamically. Remember to key in the local IP address indicated in the OLED at the web browser to view the HTML page.


    Technically this is an example to illustrate the use of XMLHttpRequest to get the sensor data from the webserver (in example 0080 Webserver) side without the need to reload the page.

    0100 HttpGet

    This sketch uses the GET function to get data from a HTTP request to a webserver. A useful function for this is to extract the body of data especially when making JSON API calls.

    0110 ButtonToPushMessage

    This sketch will enable users to receive a push notification to their smartphone when the GPIO13 button is pressed. For this to work, you will need to obtain the smartphone key by creating an account at http://espert.io


    Instructions about creating the cloud account and obtaining the smartphone key is available here.

    0130 MQTT-Button

    This sketch send the button push status to the espert.io cloud server via MQTT.

    0140 MQTT-DHT

    This sketch will collect the sensor data (temperature & humidity) and send it (publish) to the cloud server e.g. espert.io via MQTT. The messages can be seen over at the MQTT websocket panel.

    0150 MQTT-LED

    This sketch allows the on-board LED to be controlled from the MQTT websocket panel. This is done by publishing the message {"cmd": x} (where x is any number from 0 to 2) to the topic using the format below:

    ESPert/xxxxxx/LED (xxxxxx is the unique board id)


    For example,

    • {"cmd":0} will turn off the LED
    • {"cmd":1} will turn on the LED
    • {"cmd":2} will toggle between turning on or off the LED

    0160 TIme-SNTP (Simple Network Time Protocol)

    This sketch will obtain a synchronised time from the network and display it on the OLED screen.