Skip to content

Instantly share code, notes, and snippets.

@elktros
elktros / ESP32-Web-Server.ino
Created March 15, 2021 17:48
Code for creating a simple Web Server using ESP32.
#include <WiFi.h>
#define gpio16LEDPin 16 /* One LED connected to GPIO16 - RX2 */
#define gpio17LEDPin 17 /* One LED connected to GPIO17 - TX2 */
const char* ssid = "ESP32-WiFi"; /* Add your router's SSID */
const char* password = "12345678"; /*Add the password */
int gpio16Value;
int gpio17Value;
@elktros
elktros / ESP32-ADC-LED-PWM-Control.ino
Created March 12, 2021 15:37
Code for controlling brightness of LED using ESP32 ADC and PWM.
#define ADCPIN A0
const int LEDPin = 16; /* GPIO16 */
uint16_t dutyCycle;
const int PWMFreq = 5000;
const int PWMChannel = 0;
const int PWMResolution = 12;
const int MAX_DUTY_CYCLE = (int)(pow(2, PWMResolution) - 1);
@elktros
elktros / ESP32-ADC-Analog-Voltage.ino
Created March 12, 2021 15:28
Code for measuring analog voltage using ESP32 ADC.
#define ADCPIN A0
int adcValue;
float voltValue;
void setup()
{
Serial.begin(115200);
}
void loop()
{
@elktros
elktros / ESP32-PWM-ADC.ino
Created March 12, 2021 15:19
ESP32 PWM ADC
const int redLEDPin = 16; /* GPIO16 */
const int greenLEDPin = 17; /* GPIO17 */
const int blueLEDPin = 4; /* GPIO4 */
uint16_t redDutyCycle;
uint16_t greenDutyCycle;
uint16_t blueDutyCycle;
const int redPWMFreq = 5000; /* 5 KHz */
const int redPWMChannel = 0;
const int redPWMResolution = 12;
@elktros
elktros / ESP32-PWM-LED_Fading.ino
Created March 12, 2021 15:12
ESP32 PWM LED Fading.
const int LEDPin = 16; /* GPIO16 */
int dutyCycle;
/* Setting PWM Properties */
const int PWMFreq = 5000; /* 5 KHz */
const int PWMChannel = 0;
const int PWMResolution = 10;
const int MAX_DUTY_CYCLE = (int)(pow(2, PWMResolution) - 1);
void setup()
{
@elktros
elktros / Raspberry-Pi-Pico-C-Blink.c
Created March 5, 2021 15:23
C Program for Blinking on-board LED of Raspberry Pi Pico.
@elktros
elktros / Arduino-RC522-RFID-Access-Control.ino
Created March 4, 2021 12:37
Code for Arduino RC522 RFID Access Control System.
#include <SPI.h>
#include <MFRC522.h>
#include <Servo.h>
#include <LiquidCrystal_I2C.h>
/*Using Hardware SPI of Arduino */
/*MOSI (11), MISO (12) and SCK (13) are fixed */
/*You can configure SS and RST Pins*/
#define SS_PIN 10 /* Slave Select Pin */
#define RST_PIN 7 /* Reset Pin */
@elktros
elktros / NodeMCU-ESP8266-Nokia-5110-LCD-Contrast.ino
Created March 3, 2021 13:40
Adjust contrast of Nokia 5110 LCD using ESP8266 NodeMCU board and a Potentiometer.
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h>
#define analogPin A0 /* ESP8266 Analog Pin ADC0 = A0 */
/* Declare LCD object for SPI
Adafruit_PCD8544(CLK,DIN,D/C,CE,RST);*/
Adafruit_PCD8544 display = Adafruit_PCD8544(14, 13, 5, 15, 4); /*D5, D7, D1, D8, D2 */
int contrastValue = 60; /* Default Contrast Value */
@elktros
elktros / NodeMCU-ESP8266-Nokia-5110-LCD-Text.ino
Created March 3, 2021 12:51
Display text on Nokia 5110 LCD using ESP8266 NodeMCU Board.
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h>
/* Declare LCD object for SPI
Adafruit_PCD8544(CLK,DIN,D/C,CE,RST);*/
Adafruit_PCD8544 display = Adafruit_PCD8544(14, 13, 5, 15, 4); /*D5, D7, D1, D8, D2 */
int contrastValue = 60; /* Default Contrast Value */
void setup()
@elktros
elktros / Arduino-RC522-Write-to-RFID.ino
Created March 3, 2021 09:18
Write data to MIFARE 1K RFID Card using RC522 RFID Module and Arduino.
#include <SPI.h>
#include <MFRC522.h>
/*Using Hardware SPI of Arduino */
/*MOSI (11), MISO (12) and SCK (13) are fixed */
/*You can configure SS and RST Pins*/
#define SS_PIN 10 /* Slave Select Pin */
#define RST_PIN 7 /* Reset Pin */
/* Create an instance of MFRC522 */