i paid some one for cod but code not work

hi
i am new here in programming so for my project i paid some one and purchase code from him , i have good knowlege of pcb schematic so no problem in conection
i am sending code here please check it in your arduino and tell me its working or not , because from my site no output in serial monitor and lcd

programmer says that u have wrong swich conection but i am 100% sure that its correct because i test swich inbuilt programm called button when i press swich led goes on

by the way experts plz check code and tell me its work on your device or not
#include <Wire.h>
#include <EEPROM.h>
#include <LiquidCrystal_I2C.h>
#define COUNTVALUE 10

LiquidCrystal_I2C lcd(0x27, 16, 2);

int buttonPin = 3;
int flag;
int buttonState;
int lastcntvalue = 0;

void setup()
{
Serial.begin(38400);
//Serial.begin(9600);
delay(1000);
lcd.begin();
lcd.backlight();
pinMode(buttonPin, INPUT);
flag = 0;
lastcntvalue = EEPROM.read(0);
}

void loop()
{
buttonState = digitalRead(buttonPin);

if ((buttonState == LOW) && (lastcntvalue < COUNTVALUE))
{
lastcntvalue++;
lcd.print("WRITING COMMANDS");
delay(1000);
Serial.write(26);
delay(1000);
Serial.println("/Ti4,1,22");
delay(1000);
Serial.println("/1N1");
delay(3000);
EEPROM.update(0, lastcntvalue);
lcd.clear();
lcd.print("WRITE IS SUCCESS");
delay(2000);
lcd.clear();
lcd.print("Count Left: ");
lcd.print(COUNTVALUE - lastcntvalue);
delay(2000);
/if ((COUNTVALUE - lastcntvalue) != -1)
{
Serial.print("Count Left: ");
Serial.println(COUNTVALUE - lastcntvalue);
}
/
}
else if (lastcntvalue == COUNTVALUE)
{
EEPROM.update(0, 0);
flag = 1;
}
else if (flag == 1)
{
while (1);
}
}

please check serial monitor output , no need to conect lcd , is any output in serial monitor???

How is your switch wired up? The code produces output when digitalRead returns LOW, so you should have a pullup resistor. I'd expect the code to have used INPUT_PULLUP instead of INPUT in the pinmode call.

That it doesn't implies that you're providing an external pullup. Are you?

i used 10k resitor and schematic provided here

https://www.arduino.cc/en/tutorial/button ( here d2 pin use , but i use d3 pin)

in my code i use d3 pin for switch

wildbill:
How is your switch wired up? The code produces output when digitalRead returns LOW, so you should have a pullup resistor. I'd expect the code to have used INPUT_PULLUP instead of INPUT in the pinmode call.

That it doesn't implies that you're providing an external pullup. Are you?

i tried INPUT_PULLUP nstead of INPUT in the pinmode call. but same nothing on serial monitor

Your contractor needs his arse kicked for the lack of comments....


cdma-india:
i tried INPUT_PULLUP nstead of INPUT in the pinmode call. but same nothing on serial monitor

If you had it wired according to the schematic you linked, did you remove the external pulldown resistor, and rewire the button so it's from pin to ground not pin to 5V?

If you have a schematic, then post it.

Add a Serial.println( "hello world" ) statement to setup() to see if you get that far.

If it gets stuck here, you'll see nothing:

while ( 1 ) ;

I am not able to test your program, and I am not sure what it should do....

But start checking the basics.

Button must be connected to pin 3. Check with a DMM the pin 3 has 0V when button is pressed, and 5V when not.

Regarding serial monitor, use same baud rate as in Serial.begin() in setup().

'lastcntvalue' is read from EEPROM at startup, and the if-condition does not handle values above 'COUNTVALUE' it will end up with 'while(1);' and do nothing.

Try change

else if (lastcntvalue == COUNTVALUE)

to

else if (lastcntvalue >= COUNTVALUE)

here schematic i use on my arduino and use pin d3 becuase code use pin 3

i also try without resitor direct conect d3 and gnd to switch

but same nothing on serial monitor

Add a serial.println() to your setup() code to see what value is read out from the EEPROM there:

  .
  .
  .  
  pinMode(buttonPin, INPUT);
  flag = 0;
  lastcntvalue = EEPROM.read(0);
  Serial.println( lastcntvalue, HEX );

}
.
.
.

All of your output is contingent on "lastcntvalue < COUNTVALUE" so it makes sense to verify the initial value there.

Also, verify that your serial monitor is set for 38400.

Hope you didn't pay much for that code.

Blackfin:
Hope you didn't pay much for that code.

The comments were thrown in for free....

A fresh eeprom has every bit filled with 1s. This :

lastcntvalue = EEPROM.read(0);

will leave lastcntvalue with a value of 255. The code will get stuck in the while( 1 ) statement .

6v6gt:
A fresh eeprom has every bit filled with 1s. This :

lastcntvalue = EEPROM.read(0);

will leave lastcntvalue with a value of 255. The code will get stuck in the while( 1 ) statement .

thanks friend you save my day

code working now

cdma-india:
working now

There was something fishy...

cod.GIF

cod.GIF

12Stepper:
There was something fishy...

cod.GIF

spell mistake friend