Building your own programmable clock

20180120_204454Wow, it’s been quite a while since the last posting.  I thought we would start the year off with a cool project, a reboot of my Half-Byte Clock, featuring Embedded Tiny Basic. This time, I use an Arduino Nano and a nice canvas/wooden ‘case’ to house it all.

Instead of using the somewhat large Half-Byte Console board, I use the Nano so it fit inside the wooden frame. The frame is roughly one inch thick, just big enough for the Nano and all of the components to fit. On this particular iteration, the light sensor and speaker are on the back of the frame and, because of poor planning, the temperature sensor sticks out of the side. I intend to remedy that, but that will be later.  I am too busy to worry about that right now.

The Components

For the project, you will need:Samsung 6980

    • Arduino Nano or similar 328 based microcontroller board
    • HC-06 Bluetooth module
    • DHT-11 Temperature sensor
    • Light Sensor (I used the OSEP LIGHT 01 module)
    • Two or Three 8×8 LED Matrix displays, assembled with controller
    • DS3231 RTC for Arduino (Real Time Clock)
    • Small speaker (I stole this out of a toy cell phone I purchased at Dollar Tree)
    • Case/Frame/Canvas

My total cost is about twenty five dollars. The most costly part was the canvas frame-$8.95 at Target. All other parts were sourced from Hobby Town or Amazon.


The clock features programmability via Half-Byte Embedded BasiSamsung 6945c, though you can use whatever code you like. This project, though, is aimed at a reprogrammable device that can display the time/date, temperature/humidity, output sound, use the ambient light to brighten or darken the display and be programmable over Bluetooth.  You have about 1k of RAM to store your Basic code and, once saved, will remain in memory, even if you unplug it. Upon power up, if there is something in memory, it will auto start after five seconds.

Wiring it Up

I was going to get all fancy and draw a diagram, but I think the pin connections will make more sense to more people, so that’s what I am going to do.  There are also photos you can look at.  As my hands aren’t as steady as they once were, my soldering leaves a lot to be desired.

DHT 11:

  • Data line to pin 2 of Nano
  • (+) to +5v on NanoSamsung 7010
  • (-) to GND on Nano



  • SCL to A5
  • SDA to A4
  • GND to GND
  • VCC to +5v


Light Sensor:

  • Pin S to A0 on NanoSamsung 7008
  • (+) to 3.3v on Nano
  • (-) To GND on Nano


LED Array:

  • data to pin D12    DIN pin of MAX7219 module
  • load to pin D10    CS pin of MAX7219 module
  • clk to pin D11       CLK pin of MAX7219 module



  • GND to GND
  • + to Pin D8 on NanoSamsung 7014


HC-06 Bluetooth:

  • VCC to +5v
  • GND to GND
  • RX to TX on Nano
  • TX to RX on Nano

Sample Embedded Basic Startup Apps:

Example 1:

100 PRINT "Welcome to Half-Byte LED Programmable Clock"
111 SCROLL " Clock."
112 IF HOUR(0)<12 SCROLL " Good Morning! "
114 IF HOUR(0)>11 IF HOUR(0)<18 SCROLL " Good Afternoon! "
116 IF HOUR(0)>17 IF HOUR(0)<=23 SCROLL "  Good Evening!  "
120 TIME
125 IF IN(0)<>-1 GOTO 600
130 SCROLL ".   Temp is "
140 TEMP
145 SCROLL "F  "
150 SCROLL "Humidity is "
170 SCROLL "  Hello!  "
180 IF IN(0)<>-1 GOTO 600
190 IF RND(99)>50 GOTO 110
200 SCROLL "       "
205 O=MINUTE(0)
210 W=15
220 H=7
230 X=RND(W)
240 Y=RND(H)
250 P=RND(W)
260 Q=RND(H)
265 IF IN(0)<>-1 GOTO 600
290 SET X,Y,0
300 SET 16+(X),Y,1
310 SET 16+(X),H-Y,1
320 SET 16+(W-X),Y,1
330 SET 16+(W-X),H-Y,1
340 IF IN(0)<>-1 GOTO 600
350 SET 16+(P),Q,0
360 SET 16+(P),H-Q,0
370 SET 16+(W-P),Q,0
380 SET 16+(W-P),H-Q,0
390 IF IN(0)<>-1 GOTO 600
400 K=MINUTE(0)
410 IF K-O>1 GOTO 110
590 GOTO 230

Example 1 will randomly display random dot pattern for about a minute. It also analyses the time and inserts ‘Morning’, ‘afternoon’ or ‘evening’ in the greeting.  If you are connected via USB or Bluetooth, you can interrupt the app by sending a character followed by the ENTER key.


200 SCROLL "        "
210 W=15
220 H=7
230 X=RND(W)
240 Y=RND(H)
250 P=RND(W)
260 Q=RND(H)
300 SET 16+(X),Y,1
310 SET 16+(X),H-Y,1
320 SET 16+(W-X),Y,1
330 SET 16+(W-X),H-Y,1
340 IF IN(0)<>-1 GOTO 600
350 SET 16+(P),Q,0
360 SET 16+(P),H-Q,0
370 SET 16+(W-P),Q,0
380 SET 16+(W-P),H-Q,0
390 IF IN(0)<>-1 GOTO 600
590 GOTO 230

Example 2 is the kaleidoscope from Example 1


100 SCROLL " Half-Byte Clock "
110 H=HOUR(0)
120 IF H<12 SCROLL " Good Morning! "
130 IF H>11 IF H<18 SCROLL " Good Afternoon! "
140 IF H>17 IF H<=23 SCROLL "  Good Evening!  "
150 TIME
160 IF IN(0)<>-1 GOTO 600
170 SCROLL " Temp is "
180 TEMP
190 SCROLL "F  "
200 SCROLL "Humidity is "
215 SCROLL "%         "
220 SET 20,2,1
230 SET 23,2,1
240 SET 20,4,1
250 SET 23,4,1
260 SET 21,5,1
270 SET 22,5,1
280 FOR X=1 to 5
300 SCROLL"  "
320 SCROLL"  "
530 IF IN(0)<>-1 GOTO 600
540 NEXT X
580 SCROLL "       "
590 GOTO 110

Example 3 displays the date and time as well as the humidity and temp. It also shows an animated smiley face.


100 SCROLL ” Half-Byte Clock ”
110 H=HOUR(0)
120 IF H>=0 IF H<12 SCROLL ” Good Morning! ”
130 IF H>11 IF H<18 SCROLL ” Good Afternoon! ”
140 IF H>17 IF H<=23 SCROLL” Good Evening! ”
150 TIME
155 IF H=17 IF MINUTE(0)>=0 IF MINUTE<=10 SCROLL ”  TIME FOR name TO COME HOME!”: TONE 8,3000,3000
160 IF IN(0)<>-1 GOTO 600
163 SCROLL ” ”
170 SCROLL “Temp is ”
175 TEMP
177 SCROLL “F  Humidity is ”
190 SCROLL “%”
200 SCROLL ”   ”
220 SET 20,2,1: SET 23,2,1
240 SET 20,4,1: SET 23,4,1
260 SET 21,5,1: SET 22,5,1
280 FOR X=1 TO 5
281 DELAY 40
300 SCROLL ”  ”
320 SCROLL ”  ”
530 IF IN(0)<>-1 GOTO 600
560 NEXT X
580 SCROLL ”       ”
590 GOTO 110
600 SCROLL “Interrupted!”

Example 4 is an example of an ‘alarm’. It evaluates the hour and minute and displays a custom message and then generates a tone. It also features the animated smiley.

Samsung 7025With some clever coding, you could write a game, create an interesting art display, message board and more.  There are unused pins on the Nano that you can also use to wire up something to control (like a pet watering device, lights, etc.)  All of the sensors are available in Basic or, if you choose to write your own custom code, use the pin outs above to read or write to them. You are only limited by your imagination. And, well, that tiny bit of RAM that these things have. C’mon, we went to moon on less.


IT’s HERE! Half-Byte Tiny Basic 3!

randomdotsOne of the things I have really enjoyed since embarking on my Arduino journey and this blog, is seeing others take things I’ve worked on or created and expand upon it. This is especially true with Half-Byte Tiny Basic, something that started out as the work of Mike Field, who, himself used the work of another person. HB Tiny Basic is an iterative work, built on the work of others as well as myself.  For HB Tiny Basic 3, I have incorporated the work of others to make it better.  I would love to take credit for these changes, but, I cannot.  This release is strictly due to Hill Satoshi of the Hirosaki University Faculty of Education and someone named ‘Koyama’.  A Big thanks to them.

Please visit Hill Satoshi’s page. There are a lot of great ideas, basic electronics information and some code snippets…be careful, some features of the basic there were not incorporated in HB Tiny Basic, like the motor control and PLOT (which is the same as Set and Reset.)

Among the additions and changes are an auto load and auto run feature (requested by many of you) and a better eSave and eLoad feature.  In fact, I like much of what was done to the language and may incorporate more at a later date.

So, what’s new?

Two new statements have been added: NUMLED and BMP.  A new function, TREAD.  The aforementioned auto load and auto save feature.  Three new operators: %, & and |. % returns the remainder of a division, & is logical AND and | is a logical OR.

What’s changed?

The code to do a eSave or eLoad has changed and should be more reliable.  The startup code has changed a little, dynamically calculating the amount of ram that is available.  Ability to read in characters from the serial input as if it were the keyboard. This means you can connect to a serial terminal and enter and run Tiny Basic code without a PS/2 Keyboard attached. And a few minor tweaks here and there.

New Statements

The first new statement is NUMLED.  If you connect a seven segment LED directly to the device you are running HB Tiny Basic on, you can output directly to the LED.  The syntax is:

NUMLED x  where x is a digit from 0 to 9.


20 for I=0 to 9

30 numled I

40 delay 1000

50 next I

60 goto 20


BMP allows you to draw a bitmap on the screen.  It is very much like the DRAW statement in old Microsoft Basics. It feature its own mini design language for you to draw on the screen. A minimum of three parameters are required: x,y,string.  Where x and y are the start points and string is the definition.

Table of Commands for Mini Language:


(0 is black;
1 is white)


(0 is black;
1 is white)







10 cls 
20 bmp0,0,"ffffc00000007fff","ffffc00000001fff", "fffe0000000003ff","fffc0000000000ff", "fff80000000000ff","fff000000000007f", "ffe000000000003f","ff0000000000003f" 
30 bmp0,8,"ff0000000000001f","ff2f00000000000f", "ff1fc0000000000f","ff000c000000000f", "ff003f000000000f","ff0020400000000f", "fc0000fc1800000f","fc00000f7f3c000f" 
40 bmp0,16,"f80000037f7e000f","f8000000007e0003", "f01c00c0001cf7c3","f03e03c00000efcf", "f03e07c00e00000f","c03f1ff01f000003", "c03ffff03f800003","cf3ffff87fc380c3" 
50 bmp0,24,"ce3fffffffc3c0c3","c03fc03fffe7f1cf", "c03f003ffffff3c0","ff3fff3fff0fff88", "ff1ffffffc0fff1c","ff9ffffff043ff3c", "ff8fffc03ff3ff38","ff8fffc03ff3fe00" 
60 bmp0,32,"ffcfffff3ffffc01","ffc7fffffffffcff", "ffc3fffffffff8ff","fff3ff007ffff1ff", "fff1ff0c7fffc3ff","fff0ff0c7fffc7ff", "fffc7f0c7fff8fff","fffe3f807ffe1fff"
70 bmp0,40,"ffff3fc0fffe3fff","ffff07c3fff07fff", "fff023ffffe1ffff","ffe0203fff83ffff", "ff07e00000003fff","fc0fe3ffff8f0fff", "fc3fe3ffff8f0fff","f0ffe3ffff8fc1ff" 
80 shift 1,3:delay 99:goto 80


Aviary Photo_131159334768733501

The example code above produces this bitmap.

New Function:

TREAD is an alternate method for reading a temperature sensor. It does not require any additional libraries and reads the sensor directly. Usage is: Var=TREAD(pin)  where pin is A0 to A7.


100 a=TREAD(A3)

The example reads in a value between –30 and 50 degrees Celsius.

Auto Load and Auto Save

HB Tiny Basic will now load the saved program in EEPROM.  You have three seconds to press a key or the loaded program will auto run.  If you press a key in those three seconds, you will get the normal prompt as in the past.  This feature is useful if you want to use HB Tiny Basic for embedded use or simply to restart if the device loses power.  There are a lot of uses for this feature.

Other small changes have been made, but are not worth discussing as they are mostly cosmetic or code optimizations.

In reviewing my code, I see just how sloppy it has become. I am going to clean it up, but, until I do, please feel free to offer up any suggestions you may have for features or changes.  As always, the code is free and open.  I ask that you leave the regular header intact, at the top of the code. I want all involved to be recognized.

Thanks and let us know what you do with Half-Byte Tiny Basic.

Download Link: Half-Byte Tiny Basic 3