Skip to content

Instantly share code, notes, and snippets.

@lonelybinary
lonelybinary / buildin_led.ino
Last active October 12, 2023 05:18
ESP-01S Build-in LED
/*
Written by Lonely Binary
Build-in LED On, Off and Toggle
The ESP-01S module features an onboard Blue LED that is intricately connected to GPIO2.
When GPIO2 is set to a logic LOW state, it closes the circuit, causing the LED to illuminate.
Conversely, when GPIO2 is set to a logic HIGH state, it opens the circuit, resulting in the LED being turned off.
ESP-01S Collection:
https://lonelybinary.com/collections/ESP-01S
@lonelybinary
lonelybinary / ntp.ino
Created June 18, 2023 23:09
Arduino ESP32-S3 Sync Internal RTC with NTP Server
#include <WiFi.h>
#include "time.h"
const char *ssid = "YOUR_WIFI_SSID";
const char *password = "YOUR_WIFI_PASSWORD";
const char *ntpServer = "ntp.lonelybinary.com";
const long gmtOffset_sec = 3600L * 10;
const int daylightOffset_sec = 0;
@lonelybinary
lonelybinary / esp32_rtc.ino
Created June 18, 2023 08:15
Arduino ESP32 RTC Configuration
#include <Arduino.h>
/*
Get Current unix time stamp from https://www.unixtimestamp.com/
TZ_INFO is "Australia/Sydney"
*/
#define UNIX_TIMESTAMP 1687072944
#define TZ_INFO "CST-10"
void set_time(time_t unix_time_t)
@lonelybinary
lonelybinary / preferences.cpp
Last active June 18, 2023 05:36
Arduino ESP32 Leveraging Preferences for Permanent Data Retention
/*
In the following example, we will use preferences to record the ESP32 boot times.
*/
#include <Preferences.h>
Preferences preferences;
String str_key_type(int key_type);
void setup() {
@lonelybinary
lonelybinary / softap.ino
Created June 18, 2023 00:51
Arduino ESP32 WIFI - Soft Access Point
// Soft AP DHCP Server is enabled by default.
#include <WiFi.h>
#include <WiFiAP.h>
/*
Please provide the definition for the Soft AP SSID and Password.
The password should consist of at least 8 characters.
Alternatively, if no password is specified, the network will be open.
@lonelybinary
lonelybinary / wifi_sta.ino
Last active June 17, 2023 22:40
Arduino ESP32 WIFI - STA
#include <WiFi.h>
//To switch to DHCP instead, simply modify to #define STATIC_IP 1
#define STATIC_IP 0
const char *ssid = "YOUR_WIFI_SSID";
const char *password = "YOUR_WIFI_PASSWORD";
#if defined(STATIC_IP) && STATIC_IP == 1
IPAddress local_IP(192, 168, 31, 115);
@lonelybinary
lonelybinary / wifi_multi.ino
Last active June 17, 2023 22:40
Arduino ESP32 WIFI - Multiple Wireless Networks
#include <WiFi.h>
#include <WiFiMulti.h>
WiFiMulti wifiMulti;
void setup()
{
Serial.begin(115200);
Serial.println("Lonely Binary ESP32 Multi Wifi Example");
@lonelybinary
lonelybinary / wifi_scan.ino
Last active June 17, 2023 20:09
Arduino ESP32 WIFI - WIFI Scan
#include "Arduino.h"
#include "WiFi.h"
void setup()
{
Serial.begin(115200);
Serial.println("Lonely Binary Wifi Scan Demo");
/*