ESP32 Cryptocurrency Price Ticker with OLED Display

ESP32 Cryptocurrency Price Ticker with OLED Display

In this project, we'll build a standalone cryptocurrency price ticker using an ESP32 microcontroller and an OLED display. This device will fetch live cryptocurrency prices from the internet and display them in real-time, making it perfect for traders and crypto enthusiasts.

What You'll Build

A compact device that:

  • Connects to WiFi automatically
  • Fetches live crypto prices from CoinGecko API
  • Displays Bitcoin, Ethereum, and more on OLED screen
  • Updates every 60 seconds
  • Shows price changes and percentage gains/losses
  • Runs 24/7 with low power consumption

Required Components

  • ESP32 Development Board - Any variant (30 NodeMCU, DOIT, etc.)
  • 0.96" OLED Display - I2C interface (SSD1306 controller)
  • Micro-USB Cable - For power and programming
  • Breadboard - For connections
  • Jumper Wires - For wiring

Optional Enhancements

  • 3D printed enclosure
  • USB power adapter for continuous operation
  • Button for manual refresh
  • SD card for logging price history

Wiring Connections

OLED Display (I2C) to ESP32:
- VCC → 3.3V
- GND → GND
- SCL (Clock) → GPIO 22
- SDA (Data) → GPIO 21

Setting Up Libraries

In Arduino IDE, install these libraries:

  • Adafruit SSD1306 - OLED display driver
  • Adafruit GFX - Graphics library
  • ArduinoJSON - Parse JSON responses

Install via: Sketch → Include Library → Manage Libraries

Complete Arduino Code

#include <WiFi.h>
#include <HTTPClient.h>
#include <ArduinoJson.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

// WiFi credentials
const char* ssid = "YOUR_SSID";
const char* password = "YOUR_PASSWORD";

// OLED Display
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);

// CoinGecko API
const char* coingecko_url = "https://api.coingecko.com/api/v3/simple/price?ids=bitcoin,ethereum&vs_currencies=usd&include_24hr_change=true";

// Crypto data structure
struct CryptoData {
  char name[20];
  float price;
  float change24h;
};

CryptoData cryptos[2] = {
  {"Bitcoin", 0, 0},
  {"Ethereum", 0, 0}
};

unsigned long lastUpdate = 0;
const unsigned long updateInterval = 60000; // 60 seconds

void setup() {
  Serial.begin(115200);
  
  // Initialize OLED
  if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    Serial.println("SSD1306 allocation failed");
    while (1);
  }
  
  display.clearDisplay();
  display.setTextSize(2);
  display.setTextColor(SSD1306_WHITE);
  display.setCursor(0, 0);
  display.println("Crypto Ticker");
  display.setTextSize(1);
  display.println("Connecting...");
  display.display();
  
  // Connect to WiFi
  connectToWiFi();
}

void loop() {
  // Update prices every 60 seconds
  if (millis() - lastUpdate >= updateInterval) {
    fetchCryptoPrices();
    lastUpdate = millis();
  }
  
  displayPrices();
  delay(1000);
}

void connectToWiFi() {
  WiFi.begin(ssid, password);
  int attempts = 0;
  
  while (WiFi.status() != WL_CONNECTED && attempts < 20) {
    delay(500);
    Serial.print(".");
    attempts++;
  }
  
  if (WiFi.status() == WL_CONNECTED) {
    Serial.println("\nWiFi connected!");
    Serial.print("IP: ");
    Serial.println(WiFi.localIP());
  } else {
    Serial.println("\nFailed to connect to WiFi");
  }
}

void fetchCryptoPrices() {
  if (WiFi.status() != WL_CONNECTED) {
    connectToWiFi();
    return;
  }
  
  HTTPClient http;
  http.begin(coingecko_url);
  
  int httpCode = http.GET();
  
  if (httpCode > 0) {
    String payload = http.getString();
    
    // Parse JSON
    StaticJsonDocument<500> doc;
    DeserializationError error = deserializeJson(doc, payload);
    
    if (!error) {
      // Bitcoin
      cryptos[0].price = doc["bitcoin"]["usd"];
      cryptos[0].change24h = doc["bitcoin"]["usd_24h_change"];
      
      // Ethereum
      cryptos[1].price = doc["ethereum"]["usd"];
      cryptos[1].change24h = doc["ethereum"]["usd_24h_change"];
      
      Serial.println("Prices updated!");
    } else {
      Serial.println("JSON parse error");
    }
  } else {
    Serial.println("HTTP error");
  }
  
  http.end();
}

void displayPrices() {
  display.clearDisplay();
  display.setTextSize(1);
  display.setTextColor(SSD1306_WHITE);
  display.setCursor(0, 0);
  
  // Bitcoin
  display.print("BTC: $");
  display.println(cryptos[0].price, 0);
  display.print("24h: ");
  if (cryptos[0].change24h >= 0) {
    display.print("+");
  }
  display.print(cryptos[0].change24h, 2);
  display.println("%");
  
  // Ethereum
  display.print("ETH: $");
  display.println(cryptos[1].price, 0);
  display.print("24h: ");
  if (cryptos[1].change24h >= 0) {
    display.print("+");
  }
  display.print(cryptos[1].change24h, 2);
  display.println("%");
  
  // Update time
  display.setTextSize(1);
  display.setCursor(0, 55);
  display.print("Last: ");
  display.print(millis() / 1000);
  display.println("s");
  
  display.display();
}

Configuration

Replace these with your actual values:

const char* ssid = "YOUR_SSID";           // Your WiFi name
const char* password = "YOUR_PASSWORD";   // Your WiFi password

How It Works

  1. ESP32 connects to your WiFi network
  2. Every 60 seconds, it fetches prices from CoinGecko API
  3. The API returns JSON data with current prices and 24h changes
  4. ESP32 parses the JSON and extracts cryptocurrency data
  5. Prices are displayed on the OLED screen
  6. Color changes show if price went up (green) or down (red)

Adding More Cryptocurrencies

To add more coins, modify the CoinGecko URL:

// Add Cardano, Solana, and Litecoin
const char* coingecko_url = "https://api.coingecko.com/api/v3/simple/price?ids=bitcoin,ethereum,cardano,solana,litecoin&vs_currencies=usd&include_24hr_change=true";

Power Optimization

For battery-powered operation:

  • Use deep sleep between updates: esp_deep_sleep(60 * 1000000);
  • Reduce screen brightness
  • Use lower WiFi power mode
  • Update less frequently (every 5 minutes)

Troubleshooting

Display shows "Connecting..." forever

  • Check WiFi credentials
  • Verify WiFi signal strength
  • Restart ESP32

Prices show 0.00

  • Check internet connection
  • Verify CoinGecko API is accessible
  • Check JSON parsing in Serial Monitor

OLED Display not showing

  • Check I2C address (use I2C scanner)
  • Verify wiring connections
  • Try different I2C speed

Advanced Enhancements

Add Alert Function

if (cryptos[0].price > ALERT_PRICE) {
  digitalWrite(BUZZER_PIN, HIGH);
  delay(100);
  digitalWrite(BUZZER_PIN, LOW);
}

Log Prices to SD Card

Store historical data for analysis and charting.

Add Web Interface

Use ESP32 web server to check prices from any browser.

Next Steps

Combine this project with:

  • Koinest API - Track your full portfolio
  • Payment Integration - Add NFC for crypto payments
  • Data Logging - Store prices in database
  • Mobile App - Remote monitoring via WiFi

Conclusion

You've built a functional cryptocurrency price tracker! This project demonstrates ESP32's capabilities in connecting to the internet, parsing JSON data, and displaying real-time information.

This is just the beginning. The combination of hardware and crypto creates endless possibilities for traders, developers, and enthusiasts.

What will you build next? Try connecting it to Koinest API to track your full portfolio! 🚀

Amazon ELEGOO ESP32ELEGOO ESP32 Amazon AZDelivery 0.96 Display OLED I2C SSD1306AZDelivery 0.96 Display OLED I2C SSD1306