I need help to write program for items billing, i want to add items and shows total bill after individual prices

#include <Arduino.h>
#include <Wire.h>
 
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20, 4);
 
 
char input[12];
int count = 0;
int count1 = 0;
int count2 = 0;
int count3 = 0;
int check = 0;
int check3 = 0;
int check2 = 0;
 
int a;
int p1 = 0, p2 = 0, p3 = 0, p4 = 0;
int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
 
double total = 0;
int count_prod = 1;
 
void setup ()
{
   lcd.init();
  lcd.backlight();
  Wire.begin();
  Serial.begin(9600);
  lcd.setCursor(0, 0);
  lcd.print(" AUTOMATIC BILL");
  delay (2000);
  lcd.setCursor(0, 1);
  lcd.print(" SHOPPING CART ");
  delay (2000);
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("WELCOME TO");
  delay (2000);
  lcd.setCursor(3, 1);
  lcd.print("SUPER MARKET");
  delay (2000);
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Plz Add iTem");
 
 
}

void loop()
{
  count = 0;
  while (Serial.available() && count < 12)
  {
    input[count] = Serial.read();
    count++;
    delay(5);
  }
  int a = digitalRead(6);
 
  if ((strncmp(input, "2C007CC3D546", 12) == 0) && (a == 1))
  {
 
    lcd.setCursor(0, 0);
    lcd.print("Butter Added       ");
    lcd.setCursor(0, 1);
    lcd.print("Price :- 10.00      ");
    p1++;
    delay(2000);
    total = total + 10.00;
    count_prod1++;
      lcd.clear();
      
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("Total Price :-");
      lcd.setCursor(0, 1);
      lcd.print(total);
  }

  if ((strncmp(input, "0400C2D7C9D8", 12) == 0) && (a == 1))
  {
    lcd.setCursor(0, 0);
    lcd.print("Milk Added       ");
    lcd.setCursor(0, 1);
    lcd.print("Price :- 20.00      ");
    p2++;
    delay(2000);
    total = total + 20.00;
    count_prod2++;
      lcd.clear();
      
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("Total Price :-");
      lcd.setCursor(0, 1);
      lcd.print(total);
  }
  if ((strncmp(input, "0400BC5B29CA", 12) == 0) && (a == 1))
  {
    lcd.setCursor(0, 0);
    lcd.print("Pencil Added       ");
    lcd.setCursor(0, 1);
    lcd.print("Price :- 5.00      ");
    p3++;
    delay(2000);
    total = total + 5.00;
    count_prod3++;
      
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("Total Price :-");
      lcd.setCursor(0, 1);
      lcd.print(total);
  }
  }

moderator edit: code tags added

This isn’t a beginner project, but either way, you’ll need a processor with enough memory, a storage / data capacity to hold all your inventory items etc,

Possibly an ESP, or more, ideally something with more storage and supporting a file system and small DB if you have a lot of data items.

If you’re intending to stay with a small processor, you could your item data in an array of structs.

what is a ?

from what it reads? is it zero ended or "\r\n" ?

Hello engrshoukat99

I made a quick and short code review and I can only recommend to study the object oriented programming for this project.

The C language standard is a null-terminated string; so I would recommend you to add an additional element to input array.

a == 1 this is used for to add item

ok...thanks bro....can you suggest me programming for mentioned problem of project

yes brother...i checked this...lcd display shows the item name and price....but serial monitor does not show anything.

dear...i didnot get your meaning....because with that programming lcd display shows the RFID card with name...only problem is that...it is not showing total price if i add second or third item....

here you are:

#include <Arduino.h>
#include <Wire.h>

#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20, 4);


char input[12];
int count = 0;
int count1 = 0;
int count2 = 0;
int count3 = 0;
int check = 0;
int check3 = 0;
int check2 = 0;

int a;
int p1 = 0, p2 = 0, p3 = 0, p4 = 0;
int c1 = 0, c2 = 0, c3 = 0, c4 = 0;

double total = 0;
int count_prod = 1;

void setup ()
{
  lcd.init();
  lcd.backlight();
  Wire.begin();
  Serial.begin(9600);
  lcd.setCursor(0, 0);
  lcd.print(" AUTOMATIC BILL");
  delay (2000);
  lcd.setCursor(0, 1);
  lcd.print(" SHOPPING CART ");
  delay (2000);
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("WELCOME TO");
  delay (2000);
  lcd.setCursor(3, 1);
  lcd.print("SUPER MARKET");
  delay (2000);
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Plz Add iTem");


}

void loop()
{
  count = 0;
  while (Serial.available() && count < 12)
  {
    input[count] = Serial.read();
    count++;
    delay(5);
  }
  int a = digitalRead(6);

  if ((strncmp(input, "2C007CC3D546", 12) == 0) && (a == 1))
  {

    lcd.setCursor(0, 0);
    lcd.print("Butter Added       ");
    lcd.setCursor(0, 1);
    lcd.print("Price :- 10.00      ");
    p1++;
    delay(2000);
    total = total + 10.00;
    count_prod1++;
    lcd.clear();

    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Total Price :-");
    lcd.setCursor(0, 1);
    lcd.print(total);
    Serial.println(total);
  }

  if ((strncmp(input, "0400C2D7C9D8", 12) == 0) && (a == 1))
  {
    lcd.setCursor(0, 0);
    lcd.print("Milk Added       ");
    lcd.setCursor(0, 1);
    lcd.print("Price :- 20.00      ");
    p2++;
    delay(2000);
    total = total + 20.00;
    count_prod2++;
    lcd.clear();

    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Total Price :-");
    lcd.setCursor(0, 1);
    lcd.print(total);
    Serial.println(total);
  }
  if ((strncmp(input, "0400BC5B29CA", 12) == 0) && (a == 1))
  {
    lcd.setCursor(0, 0);
    lcd.print("Pencil Added       ");
    lcd.setCursor(0, 1);
    lcd.print("Price :- 5.00      ");
    p3++;
    delay(2000);
    total = total + 5.00;
    count_prod3++;

    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Total Price :-");
    lcd.setCursor(0, 1);
    lcd.print(total);
    Serial.println(total);
  }
}

Now you’re catching up a bit, take another read of post #2 to combine what you picked up.
An array of structs will help your data scheme a lot.

try dtostrf() for floating point numbers

exactly serial monitor does not show...only lcd display show

mark post #12 as solution

dear still not reached at solution...it will be better for me if you send me complete program as you are suggesting...i will try.thanks

$1000 USD should do it

1 Like

Your code doesn't print a single line on Serial Monitor. What do you expecting from it?

Please answer the questions:

Where does the RFID number come from in your program?

Are you using some RFID reader connected via serial?

What kind of Arduino do you have and to what pins is the RFID module connected?

You need to do at least a 2 yr program in data processing.

iMO this is not a Arduino project . I would looking at a spreadsheet and using Macro’s /VBA etc to give the functionality you desire .