# Bitcoin Price Clock

**URL:** https://community.particle.io/t/bitcoin-price-clock/26541
**Category:** Project Share
**Created:** [October 15, 2016, 12:51am UTC](https://community.particle.io/t/bitcoin-price-clock/26541 "2016-10-15T00:51:18Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![nrobinson2000](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/nrobinson2000/32/15624_2.png) [@nrobinson2000](https://community.particle.io/u/nrobinson2000)
#### Post date: [October 15, 2016, 12:51am UTC](https://community.particle.io/t/bitcoin-price-clock/26541/1 "2016-10-15T00:51:18Z")

</div>

###Today I made a Bitcoin Price Clock using a Particle Photon, my new Particle Shield Shield, and a [LCD Keypad Shield](https://www.dfrobot.com/wiki/index.php/Arduino_LCD_KeyPad_Shield_%28SKU:_DFR0009%29) that I had lying around.

## Here is a picture of the clock:

 ![](https://us1.discourse-cdn.com/flex026/uploads/particle/original/2X/5/5d947b69349cec17b8ed08168abb30181762a542.JPG)

## Here is the code for the Photon (the `LiquidCrystal` library is required):

```auto
#include "application.h"
#include "LiquidCrystal.h"

/ *******************************************************

Display the Bitcoin price in Dollars and the time on an LCD
Nathan Robinson, October 2016

******************************************************** /

// select the pins used on the LCD panel
LiquidCrystal lcd(A5, A4, D6, D0, D1, D7);

String getAskPrice(String data) // This function gets the value in the "ask:" part of the JSON.
{
    int kLocation = data.indexOf("k"); // Find where the "k" of ask appears
    int commaLocation = data.indexOf(",", kLocation); // Find where the comma after the value appears

   String value = data.substring(kLocation +4, commaLocation); // The value is from 4 characters after where "k" is and right before where the comma is.
    return value; // Return the ask price of Bitcoin
}

void bitcoinHandler(const char *event, const char *data) // This is called when the Photon recives the webhook data.
{
 Serial.println(data); // Print the data to serial for debugging
 String ask = String(getAskPrice(data)); // Get the ask price of Bitcoin
 Serial.println(ask); // Print it to serial
 lcd.setCursor(0, 1); // Set the cursor to the second line
 lcd.print("$"); // Clear the second line
 lcd.print(ask); // Print the price of bitcoin
 lcd.print(" "); // Print " " after
}

void setup()
{
 lcd.begin(16, 2); // start the library
 lcd.setCursor(0,0);
 lcd.print("Price: Time:"); // print a simple message

 Particle.publish("bitcoin"); // Trigger bitcoin webhook

Particle.subscribe("hook-response/bitcoin/0", bitcoinHandler, MY_DEVICES); // Subscribe to the webhook response
Time.zone(-4);
Serial.begin(9600);
}

void loop()
{
if (millis()/1000 % 10 == 0) // Every ten seconds
{
  Particle.publish("bitcoin"); // Trigger bitcoin webhook
}

 lcd.setCursor(8,1); // move cursor to second line "1" and 8 spaces over

 if (Time.hour() < 10)
 {
   lcd.print("0");
   lcd.print(Time.hour());
 }
 else
 {
    lcd.print(Time.hour());
 }

 lcd.print(":");

 if (Time.minute() < 10)
 {
   lcd.print("0");
   lcd.print(Time.minute());
 }
 else
 {
    lcd.print(Time.minute());
 }

 lcd.print(":");

 if (Time.second() < 10)
 {
   lcd.print("0");
   lcd.print(Time.second());
 }
 else
 {
    lcd.print(Time.second());
 }
}

```

## The Photon relies on a webhook to get data from the [Bitcoin Average API](https://api.bitcoinaverage.com/ticker/global/USD):

```auto
{
  "eventName": "bitcoin",
  "url": "https://api.bitcoinaverage.com/ticker/global/USD/",
  "requestType": "GET",
  "mydevices": true
}

```

## I hope you enjoyed my project of the day and I hope to make more random projects like this.

---

<div class="post-metadata">

### Author: ![Cloud](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/cloud/32/10622_2.png) [@Cloud](https://community.particle.io/u/Cloud)
#### Post date: [October 15, 2016, 9:34am UTC](https://community.particle.io/t/bitcoin-price-clock/26541/2 "2016-10-15T09:34:59Z")

</div>

Building this, I need a screen though, Kind of want to OLED it…BTW isn’t the shieldshield a sexy piece of kit…black solder mask, mmmmm.

---

<div class="post-metadata">

### Author: ![KyleG](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/kyleg/32/11077_2.png) [@KyleG](https://community.particle.io/u/KyleG)
#### Post date: [October 15, 2016, 6:54pm UTC](https://community.particle.io/t/bitcoin-price-clock/26541/3 "2016-10-15T18:54:41Z")

</div>

Thanks for sharing this! I look forward to what you build next @nrobinson2000!

---

<div class="post-metadata">

### Author: ![nrobinson2000](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/nrobinson2000/32/15624_2.png) [@nrobinson2000](https://community.particle.io/u/nrobinson2000)
#### Post date: [October 24, 2017, 7:36pm UTC](https://community.particle.io/t/bitcoin-price-clock/26541/4 "2017-10-24T19:36:13Z")

</div>

![](https://us1.discourse-cdn.com/flex026/uploads/particle/original/2X/e/e59fdb9746d9cdcc19b78875446b31181dfae8b2.JPG)

# UPDATE:

It’s been a year and Bitcoin is on track to increase tenfold of what it was when I first shared this.

Here is the updated webhook:

```json
{
    "event": "bitcoin",
    "url": "https://blockchain.info/ticker?cors=true",
    "requestType": "GET",
    "responseTemplate": "{{USD.last}}",
    "mydevices": true
}

```

And here is the updated code for the photon:

```cpp
#include "Particle.h"
#include "LiquidCrystal/LiquidCrystal.h"

/ *******************************************************

Display the Bitcoin price in Dollars and the time on an LCD
Nathan Robinson, October 2016

Updated in October 2017, to use new API and accommodate new price

******************************************************** /

// select the pins used on the LCD panel
LiquidCrystal lcd(A5, A4, D6, D0, D1, D7);

void initLCD() {
  lcd.begin(16, 2); // start the library
  lcd.setCursor(0,0);
  lcd.print("Price $: Time:"); // print
  Time.zone(-4);
  Serial.begin(9600);
}

STARTUP(initLCD());

void bitcoinHandler(const char *event, const char *data) { // This is called when the Photon recives the webhook data.
 Serial.println(data); // Print the data to serial for debugging
 String latest = String(data); // Get the latest price of Bitcoin
 Serial.println(latest); // Print it to serial
 lcd.setCursor(0, 1); // Set the cursor to the second line
 lcd.print(latest); // Print the price of bitcoin
 lcd.print(" "); // Print a dividing space after
}

void setup() {
  Particle.publish("bitcoin"); // Trigger bitcoin webhook
  Particle.subscribe("hook-response/bitcoin", bitcoinHandler, MY_DEVICES); // Subscribe to the webhook response
}

void loop() {
  if (millis()/1000 % 10 == 0) // Every ten seconds
  {
    Particle.publish("bitcoin"); // Trigger bitcoin webhook
  }
  // Print the time
  lcd.setCursor(8,1); // move cursor to second line "1" and 8 spaces over

  if (Time.hour() < 10) {
    lcd.print("0");
    lcd.print(Time.hour());
  }
  else {
    lcd.print(Time.hour());
  }

  lcd.print(":");

  if (Time.minute() < 10) {
    lcd.print("0");
    lcd.print(Time.minute());
  }
  else {
    lcd.print(Time.minute());
  }

  lcd.print(":");

  if (Time.second() < 10) {
    lcd.print("0");
    lcd.print(Time.second());
  }
  else {
    lcd.print(Time.second());
  }
}

```
