Ever since I started with Arduino I wanted to create a cash register for my girl.
My requirements:
- A “scanner” that triggers a buzzer and displays a (random) value on a LCD.
- A keyboard where numbers can be pressed and calculated.
For the scanner I thought it would be a good idea to use a LDR (Photo resistor). Initially I hard coded a threshold value and when the value returned from the LDR was over that value, it triggered a buzzer. I then realized that working with the LDR depended a lot on the light – meaning it really mattered if I tested at day or at night with no daylight. I decided to add a potentiometer with which I can fine tune the threshold value later instead of uploading new code to the Arduino just to change a constant.
I also added a LED to the scanner that is on most of the time but turns off when the LDR value goes over the threshold value, ie when it is dark.
As a keypad I chose a 16 Key Membrane Switch Keypad (4×4 Matrix) which can be found cheap on ebay.
I was using my Arduino Uno during the prototype phase and decided to use the Arduino Nano for the finished project because it provides all the functionality I needed but it’s just lots smaller (and also cheaper) than the Uno. I ordered it also from ebay but I must have had the same bad luck as Wai Hung because I could not program it over USB. But instead of soldering and putting a lot of energy into solving the problem I just used my Uno as ISP like I did it in my Christmas Tree project.
I put the Nano onto a 170 tie point self adhesive breadboard.
For the “wooden hardware” I used plywood and MDF and painted it.
- Front panel
- Panel backside
- Side panels
- Side panels inside
- Side panel detail 1
- Side panel detail 2
- Side panel detail 3 before
- Side panel detail 3 after
- All parts before painting
- Scanner
- Arduino Nano on a self adhesive breadboard
- Wiring 2
- Wiring 3
- Front
- Front / Side
- Back / Inside
- Inside with battery
- Backside closed
- Side with drawer 1
- Side with drawer 2
- Front complete
- Scanner complete
The code goes here:
// include the library code: #include <LiquidCrystal.h> #include <Keypad.h> #include <stdio.h> // These constants won't change. // They're used to give names to the pins used: const int analogInPin = A3; // Analog input pin that the ldr is attached to const int thresholdPin = A5; // Analog input pin that the threshold poti is attached to const int buzzer = 13; // Analog output pin that the buzzer is attached to const int led = 18; // scanner LED int sensorValue = 0; // value read from the ldr int lightThreshold = 0; boolean hasBeeped = false; // has beeped? const int buzzerValue = 200; // frequency const int beepDuration = 250; // beeps 250ms // used for calculation of values entered by the keypad String keyPadValue; float keyValue = 0.0; float keySum = 0.0; boolean isKeypadInput = false; // keypad const byte ROWS = 4; // Four rows const byte COLS = 4; // columns // Define the Keymap char keys[ROWS][COLS] = { {'1','2','3','A'}, {'4','5','6','B'}, {'7','8','9','C'}, {'*','0','#','D'} }; // Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins. byte rowPins[ROWS] = { 12, 11, 10, 9 }; // Connect keypad COL0, COL1 and COL2 to these Arduino pins. byte colPins[COLS] = { 8, 7, 6, 5 }; // Create the Keypad Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS ); // initialize the library with the numbers of the interface pins LiquidCrystal lcd( 16, 4, 3, 2, 14, 15 ); // for the greeting message byte heart[8] = { B00000, B01010, B11111, B11111, B01110, B00100, B00000, B00000 }; void setup() { pinMode(14, OUTPUT); pinMode(15, OUTPUT); pinMode(16, OUTPUT); lcd.createChar(0, heart); // set up the LCD's number of columns and rows: lcd.begin(16, 2); // Print a greeting message to the LCD. lcd.write((uint8_t)0); lcd.print(" Hoi Laura! "); lcd.write((uint8_t)0); pinMode(led, OUTPUT); digitalWrite(led, HIGH); // initialize serial communications at 9600 bps: Serial.begin(9600); // delay it by 3sec so we are able to see the message delay(3000); lcd.clear(); lcd.setCursor(0, 1); } void loop() { char key = keypad.getKey(); if (key != NO_KEY){ beep(); int len=0; switch(key) { case '*': // treat it like a '+' keySum += keyValue; len = keyPadValue.length(); // write from right to left lcd.clear(); lcd.setCursor(16 - (len+9), 0); lcd.print("Fr. "); lcd.setCursor(16 - (len+3), 0); lcd.print(keySum); // lcd.print(printf("%00.00d", keySum )); keyPadValue = ""; keyValue = 0.0; break; case '#': keySum += keyValue; // treat it like a '=' lcd.clear(); lcd.setCursor(0, 0); lcd.print("Total:"); lcd.setCursor(0, 1); lcd.print("Fr. "); lcd.print(keySum); keyPadValue = ""; keyValue = 0.0; break; case 'A': case 'B': case 'C': case 'D': // ignore break; default: if (!isKeypadInput) { lcd.clear(); printKeySum(keySum); } isKeypadInput = true; // append new key input keyPadValue += key; len = keyPadValue.length(); // write from right to left lcd.setCursor(16 - len, 1); lcd.print(keyPadValue); // store the string into a float char buffer[100]; // didn't work wit len+1 so i took 100... keyPadValue.toCharArray(buffer, len+1); keyValue = atof(buffer); // convert char array to float } } // read the analog in value: sensorValue = analogRead(analogInPin); lightThreshold = analogRead(thresholdPin); Serial.print("sensor = "); Serial.print(sensorValue); Serial.print("\t threshold = "); Serial.println(lightThreshold); if (sensorValue > lightThreshold) { // dark digitalWrite(led, LOW); // change the analog out value: if (hasBeeped == false) { beep(); hasBeeped = true; int d1 = random(1,20); int d2 = random(0,10); int d3 = random(0,2); if (d3==1) { d3 = 5; } char buf[6]; sprintf(buf,"%d.%d%d",d1,d2,d3); // to get a string in the format of ##.#5 or ##.#0 int len=4; // write from right to left if (d1 >= 10) { len = 5; } else { lcd.clear(); } lcd.setCursor(16 - (len+4), 1); lcd.print("Fr. "); lcd.setCursor(16 - len, 1); lcd.print(buf); printKeySum(keySum); keyValue = atof(buf); keySum += keyValue; } } else { // light digitalWrite(led, HIGH); hasBeeped = false; } // wait 2 milliseconds before the next loop // for the analog-to-digital converter to settle // after the last reading: delay(2); } void printKeySum(float keySum) { if (keySum > 0) { // sum int len = 4; if (keySum >= 10 && keySum < 100) { len = 5; } else if (keySum >= 100 && keySum < 1000) { len = 6; } else if (keySum >= 1000 && keySum < 10000) { len = 7; } else if (keySum >= 10000 && keySum < 100000) { len = 8; } lcd.setCursor(16 - (len+4), 0); lcd.print("Fr. "); lcd.setCursor(16 - len, 0); lcd.print(keySum); } } void beep(){ analogWrite(buzzer, buzzerValue); // beep 250ms delay(beepDuration); analogWrite(buzzer, 0); }
Hi. Just saw your ping back. This is an amazing project, so much effort has been put into it from the electronics to the woodwork. And it’s great to know that you went through all this to make it for your daughter instead of buying something off the shelves.
Good luck in your projects 🙂
Hi Wai Hung
thank you so much for your kind words!
Pingback: Build a childrens’ cash register with Arduino « freetronicsblog
Pingback: Featured on freetronics.com! | Hacking – DIY and Coding
Hello,
I am trying to build a cash register with arduino and I was very impressed by your work, could you please message me I have a few questions I would love to ask you
Best regards
Jonathan Meguira
Hi,
this is really a great project.
I have something similar in mind for my niece.
Did you find a way to automate opening the drawer (in a child safe way)?
Thanks and Regards,
Torsten Knodt