How to store numbers in Arduino? - c++
I have written this to an Arduino.
char incomingbytea;
char incomingbyteb;
char incomingop;
char result;
void setup()
{
Serial.begin(9600);
}
void loop(){
incomingbytea = 0;
incomingbyteb = 0;
incomingop = 0;
result = 0;
bytea:
if (Serial.available() > 0) {
incomingbytea = Serial.read();
Serial.println("1ok");
Serial.println(incomingbytea);
goto byteb;
}
goto bytea;
byteb:
if (Serial.available() > 0) {
incomingbyteb = Serial.read();
Serial.println("2ok");
Serial.println(incomingbyteb);
goto op;
}
goto byteb;
op:
if (Serial.available() > 0) {
incomingop = Serial.read();
Serial.println("opok");
Serial.println(incomingop);
goto oper;
}
goto op;
oper:
result = incomingbytea + incomingbyteb;
Serial.println(result);
Serial.println(incomingbytea);
Serial.println(incomingbyteb);
Serial.println(incomingop);
}
What I want to do is:
- connect to serial (check)
- collect 2 variables to add/subtract/multiply/divide later (check)
- collect a variable to decide what to do with them 1-add, 2-subtract, etc. (check)
- redirect the script to do the required operation (later)
- print the result to serial (check)
The problem is, when I enter 1 and 1 and 1(whatever, the third one doesn't count now) and I get 98 as a result. Any help? Maybe the variables are wrong?
First you should know the length of the number, and subtract 48 (48 is the ascii representation of 0) later multiply the number for 1, 10, 100, 1000, 10000, ... depending of the position of each number.
For example: String "233" to integer, using custom method
void setup() {
Serial.begin(9600);
}
void loop() {
String Numero1 = "40";
String Numero2 = "50";
double Suma = StringAInt(Numero1)+StringAInt(Numero2);//+ StringAInt(Numero2);
Serial.println(Suma);
}
double StringAInt(String Dato)
{
String Numero = Dato;
char Valores [Numero.length()+1];
Numero.toCharArray(Valores,Numero.length()+1);
double NumeroEnt = 0;
for(int i = 0; i<Numero.length(); i++)
{
int NumValores = Valores[i];
NumValores-=48;
double MultPor = pow(10,Numero.length()-(i+1));
NumeroEnt += (NumValores*MultPor);
//Serial.println(NumValores*MultPor);
}
return NumeroEnt;
}
Now you only need build a string with the data received from serial port, and you can do math simply.
Related
Error when asking for numbers on Arduino Uno
my name is Jan, it turns out that when I put a number like 200, it shows me 2 on the console, then a 0 and then another 0 This is my code : const int ledPin = 3 ; const int rePin = 2 ; const int puPin = 1 ; int pulso = 0; int input; void setup() { // initialize digital pin LED_BUILTIN as an output. Serial.begin(9600) ; pinMode(ledPin, OUTPUT); pinMode(rePin, OUTPUT); pinMode(puPin, INPUT) ; } // the loop function runs over and over again forever void loop() { if (Serial.available()) { char pulso = Serial.read(); //To introduce the pulse Serial.print("Numero de pulsaciones: "); Serial.print(pulso); This is the error : If I put 200 What I want is for an input to appear on the console that requests a certain number of pulses, then when I put them, the number of pulses that I have put appears on the console and then if the pulses are less than 35, for example, give a discharge and a led is activated.
here is the correct code, you just need to configure the serial monitor to send the both NL/CR. const int ledPin = 3 ; const int rePin = 2 ; const int puPin = 1 ; int pulso = 0; int input; bool mensajeRecibido = false; String mensajeCompleto; void setup() { // initialize digital pin LED_BUILTIN as an output. Serial.begin(9600) ; pinMode(ledPin, OUTPUT); pinMode(rePin, OUTPUT); pinMode(puPin, INPUT) ; mensajeCompleto.reserve(50); //Se reciben maximo hasta 50 bytes mensajeCompleto = ""; } // the loop function runs over and over again forever void loop() { if (Serial.available()) { char byteSerial = Serial.read(); //To introduce the pulse if(byteSerial == '\n'){ int pulso = mensajeCompleto.toInt(); Serial.print("Numero de pulsaciones: "); Serial.print(pulso); mensajeCompleto = ""; } else{ mensajeCompleto = mensajeCompleto + byteSerial; } } }
Arduino compiler failing with error code - invalid types 'int[int]' for array subscript
Quite a bit of untested code but the only thing really concerning me at the moment is my DISPLAY variable. I don't see how it is much different than my FONT array (which works fine) yet DISPLAY is the one that gets 'invalid types 'int[int]' for array subscript' I should be able to index an array of integers with integers (at least I have been with FONT). #include <WiFiNINA.h> #include <NTPClient.h> #include <WiFiUdp.h> #include "font.h" const int PIXEL_WIDTH = 30; const int PIXEL_HEIGHT = 5; int DISPLAY[PIXEL_HEIGHT][PIXEL_WIDTH] = {}; bool MILI_TIME = false; String FORMATTING[2] = {"LONGS","SHORTH:LONGM"}; char ssid[] = "REMOVED"; // your network SSID (name) between the " " char pass[] = "REMOVED"; // your network password between the " " int keyIndex = 0; // your network key Index number (needed only for WEP) int status = WL_IDLE_STATUS; // connection status WiFiServer server(80); // server socket WiFiClient client = server.available(); WiFiUDP ntpUDP; NTPClient timeClient(ntpUDP); int ledPin = LED_BUILTIN; void setup() { Serial.begin(9600); pinMode(ledPin, OUTPUT); while (!Serial); // dont do anything until there is a serial connection enable_WiFi(); connect_WiFi(); server.begin(); printWifiStatus(); timeClient.begin(); timeClient.setTimeOffset(-14400); } void loop() { timeClient.update(); client = server.available(); if (client) { printWEB(); } preRender(); } void preRender(){ String FILLED_FORMATTING[2] = FORMATTING; for(int i=0;i<2;i++){ FILLED_FORMATTING[i].replace("LONGH",leadWithZero(timeHours())); FILLED_FORMATTING[i].replace("LONGM",leadWithZero(timeMinutes())); FILLED_FORMATTING[i].replace("LONGS",leadWithZero(timeSeconds())); FILLED_FORMATTING[i].replace("SHORTH",timeHours()); FILLED_FORMATTING[i].replace("SHORTM",timeMinutes()); FILLED_FORMATTING[i].replace("SHORTS",timeSeconds()); } int x = 0; for(int i=0;i<FILLED_FORMATTING[0].length();i++){ int c_ID = charID(FILLED_FORMATTING[0][i]); if(c_ID < 38){ for(int j=0;j<5;j++){ DISPLAY[j][x] = FONT[c_ID][j][0]; x += 1; DISPLAY[j][x] = FONT[c_ID][j][1]; x += 1; DISPLAY[j][x] = FONT[c_ID][j][2]; x += 1; if(i != FILLED_FORMATTING[0].length()){ DISPLAY[j][x] = 0; x += 1; } } } } x = PIXEL_WIDTH-1; for(int i=FILLED_FORMATTING[1].length()-1;i>=0;i--){ int c_ID = charID(FILLED_FORMATTING[1][i]); if(c_ID < 38){ for(int j=0;j<5;j++){ DISPLAY[j][x] = FONT[c_ID][j][0]; x -= 1; DISPLAY[j][x] = FONT[c_ID][j][1]; x -= 1; DISPLAY[j][x] = FONT[c_ID][j][2]; x -= 1; if(i != 0){ DISPLAY[j][x] = 0; //<----------- compiler error here, and ofc all instances above x -= 1; } } } } } int charID(char c){ for(int i=0;i<FONT_ID.length();i++){ if(FONT_ID[i] == c){ return i; } } return 40; } String timeHours(){ if(MILI_TIME){ return String(timeClient.getHours()); } else{ return convFromMili(timeClient.getHours()); } } String timeMinutes(){ return String(timeClient.getMinutes()); } String timeSeconds(){ return String(timeClient.getSeconds()); } String leadWithZero(String t){ if(t.length() < 2){ t = "0"+t; return t; } } String convFromMili(int t){ if(t > 12){ t -= 12; }else if(t == 0){ t += 12; } String ts = String(t); return ts; } void printWifiStatus() { // print the SSID of the network you're attached to: Serial.print("SSID: "); Serial.println(WiFi.SSID()); // print your board's IP address: IPAddress ip = WiFi.localIP(); Serial.print("IP Address: "); Serial.println(ip); // print the received signal strength: long rssi = WiFi.RSSI(); Serial.print("signal strength (RSSI):"); Serial.print(rssi); Serial.println(" dBm"); Serial.print("To see this page in action, open a browser to http://"); Serial.println(ip); } void enable_WiFi() { // check for the WiFi module: if (WiFi.status() == WL_NO_MODULE) { Serial.println("Communication with WiFi module failed!"); // don't continue while (true); } String fv = WiFi.firmwareVersion(); if (fv < "1.0.0") { Serial.println("Please upgrade the firmware"); } } void connect_WiFi() { while (status != WL_CONNECTED) { Serial.print("Attempting to connect to SSID: "); Serial.println(ssid); status = WiFi.begin(ssid, pass); delay(10000); } } void printWEB() { if (client) { // if you get a client, Serial.println("new client"); // print a message out the serial port String currentLine = ""; // make a String to hold incoming data from the client while (client.connected()) { // loop while the client's connected if (client.available()) { // if there's bytes to read from the client, char c = client.read(); // read a byte, then Serial.write(c); // print it out the serial monitor if (c == '\n') { // if the byte is a newline character // if the current line is blank, you got two newline characters in a row. // that's the end of the client HTTP request, so send a response: if (currentLine.length() == 0) { // HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK) // and a content-type so the client knows what's coming, then a blank line: client.println("HTTP/1.1 200 OK"); client.println("Content-type:text/html"); client.println(); //create the buttons client.print(WiFi.getTime()); client.print("<br>"); client.print(timeClient.getEpochTime()); client.print("<br>"); client.print(timeClient.getFormattedTime()); client.print("<br>"); client.print(timeClient.getDay()); client.print("<br>"); client.print(timeClient.getHours()); client.print("<br>"); client.print(timeClient.getMinutes()); client.print("<br>"); client.print(timeClient.getSeconds()); client.print("<br>"); client.print("<div style=\"display:block;padding-left:calc(50% - 150px);margin-bottom:50px\"><div style=\"background-color:#e3e3e3;width:300px;height:120px;font-size:50px;text-align:center;padding-top:50px\">ON</div></div>"); client.print("<div style=\"display:block;padding-left:calc(50% - 150px)\"><div style=\"background-color:#e3e3e3;width:300px;height:120px;font-size:50px;text-align:center;padding-top:50px\">OFF</div></div>"); // The HTTP response ends with another blank line: client.println(); // break out of the while loop: break; } else { // if you got a newline, then clear currentLine: currentLine = ""; } } else if (c != '\r') { // if you got anything else but a carriage return character, currentLine += c; // add it to the end of the currentLine } if (currentLine.endsWith("GET /H")) { digitalWrite(ledPin, HIGH); } if (currentLine.endsWith("GET /L")) { digitalWrite(ledPin, LOW); } if (currentLine.endsWith("%VAL")) { // Trim 'GET /' and '%VAL' currentLine.remove(0,5); currentLine.remove(currentLine.indexOf("%"),4); Serial.println(currentLine); Serial.println(); } } } // close the connection: client.stop(); Serial.println("client disconnected"); } } font.h: int FONT[37][5][3] = {{{1,1,1},{1,0,1},{1,0,1},{1,0,1},{1,1,1},},{{1,1,0},{0,1,0},{0,1,0},{0,1,0},{1,1,1},},{{1,1,1},{0,0,1},{1,1,1},{1,0,0},{1,1,1},},{{1,1,1},{0,0,1},{1,1,1},{0,0,1},{1,1,1},},{{1,0,1},{1,0,1},{1,1,1},{0,0,1},{0,0,1},},{{1,1,1},{1,0,0},{1,1,1},{0,0,1},{1,1,1},},{{1,1,1},{1,0,0},{1,1,1},{1,0,1},{1,1,1},},{{1,1,1},{0,0,1},{0,0,1},{0,0,1},{0,0,1},},{{1,1,1},{1,0,1},{1,1,1},{1,0,1},{1,1,1},},{{1,1,1},{1,0,1},{1,1,1},{0,0,1},{1,1,1},},{{1,1,1},{1,0,1},{1,1,1},{1,0,1},{1,0,1},},{{1,1,0},{1,0,1},{1,1,0},{1,0,1},{1,1,0},},{{1,1,1},{1,0,0},{1,0,0},{1,0,0},{1,1,1},},{{1,1,0},{1,0,1},{1,0,1},{1,0,1},{1,1,0},},{{1,1,1},{1,0,0},{1,1,1},{1,0,0},{1,1,1},},{{1,1,1},{1,0,0},{1,1,1},{1,0,0},{1,0,0},},{{1,1,1},{1,0,0},{1,0,1},{1,0,1},{1,1,1},},{{1,0,1},{1,0,1},{1,1,1},{1,0,1},{1,0,1},},{{1,1,1},{0,1,0},{0,1,0},{0,1,0},{1,1,1},},{{0,0,1},{0,0,1},{0,0,1},{1,0,1},{1,1,1},},{{1,0,1},{1,0,1},{1,1,0},{1,0,1},{1,0,1},},{{1,0,0},{1,0,0},{1,0,0},{1,0,0},{1,1,1},},{{1,1,1},{1,1,1},{1,0,1},{1,0,1},{1,0,1},},{{1,1,0},{1,0,1},{1,0,1},{1,0,1},{1,0,1},},{{1,1,1},{1,0,1},{1,0,1},{1,0,1},{1,1,1},},{{1,1,1},{1,0,1},{1,1,1},{1,0,0},{1,0,0},},{{1,1,1},{1,0,1},{1,0,1},{1,1,0},{0,0,1},},{{1,1,1},{1,0,1},{1,1,0},{1,0,1},{1,0,1},},{{0,1,1},{1,0,0},{0,1,0},{0,0,1},{1,1,0},},{{1,1,1},{0,1,0},{0,1,0},{0,1,0},{0,1,0},},{{1,0,1},{1,0,1},{1,0,1},{1,0,1},{1,1,1},},{{1,0,1},{1,0,1},{1,0,1},{0,1,0},{0,1,0},},{{1,0,1},{1,0,1},{1,0,1},{1,1,1},{1,1,1},},{{1,0,1},{1,0,1},{0,1,0},{1,0,1},{1,0,1},},{{1,0,1},{1,0,1},{1,1,1},{0,0,1},{1,1,1},},{{1,1,1},{0,0,1},{0,1,0},{1,0,0},{1,1,1},},{{0,0,0},{0,1,0},{0,0,0},{0,1,0},{0,0,0}}}; String FONT_ID = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ:"; did check - int D[5][30]; void setup() { } void loop() { D[0][0] = 0; } and of course its fine, so I'm just wondering where I went wrong in the mess above? and yes there's a good bit of mess/debugging stuff
Simple solution... don't use DISPLAY as a variable it seems. Changing to DISPLAY_ fixed it, figured the variable was defined as a normal integer somewhere... just not in my code.
(Arduino) Can I skip multiple characters in a parseInt()?
Pretty much what the title says. From the arduino website: Syntax Serial.parseInt() Serial.parseInt(char skipChar) Parameters skipChar: used to skip the indicated char in the search. Used for example to skip thousands divider. Am I able to use a charmap or something similar to skip multiple characters?
Maybe you could read from Serial, but take digits only? And then parse string? Dirty example: val = 0; while (Serial.available() > 0) { int c = Serial.read(); if (isDigit(c)) { val = val * 10 + c; // Thanks to #Danny_ds for this } } // Print *val*
I ended up using a very different method to get it working by using char arrays and not relying on timing. So far it has worked perfectly. I was using this to get my arduino to work as a temp monitor. How it communicates the temperatures PC > OpenHardwaremonitor > WMI > Batch Script (shown below) > COM Port > Arduino > LCD This was the only way that I could get cpu temps correctly because it's so old Batch code: #echo off mode COM3: baud=9600 data=8 >nul wmic /namespace:\\root\openhardwaremonitor path sensor where "Identifier='/intelcpu/0/temperature/0' or Identifier='/nvidiagpu/0/temperature/0'" get Value /every:2|findstr [0-9]>COM3 Arduino code: #include <LiquidCrystal.h> LiquidCrystal lcd(12, 11, 5, 4, 3, 2); bool sounded = false; int cpu = 0; int gpu = 0; char invalids[3] = {10, 32, '\0'}; // line feed, space boolean newData = false; const byte numChars = 8; char charMap[numChars]; char tempChars[numChars]; void setup() { pinMode(6, OUTPUT); // character intensity pinMode(8, OUTPUT); // buzzer pinMode(10, OUTPUT); // backlight lcd.begin(16, 2); Serial.begin(9600); analogWrite(6, 100); // set intensity without POT analogWrite(10, 168); // ~3.3v analogReference(EXTERNAL); lcd.print("CPU: "); lcd.print((char)223); lcd.print("C AIR:"); lcd.setCursor(0, 1); lcd.print("GPU: "); lcd.print((char)223); lcd.print("C "); lcd.print((char)223); lcd.print("F"); } void loop() { recvWithoutWhitespace(); if (newData == true) { parseData(); lcd.setCursor(4, 0); lcd.print(cpu); lcd.setCursor(4, 1); lcd.print(gpu); int reading = analogRead(A0); float degreesF = (((reading * 3.3 / 1024 - 0.5) * 100) * 1.8) + 32.0; lcd.setCursor(11, 1); lcd.print((int)(degreesF+0.5)); if(!sounded && (cpu > 75 || gpu > 85)) { // used for buzzer alarm tone(8, 500); delay(250); noTone(8); delay(250); tone(8, 500); delay(250); noTone(8); delay(250); tone(8, 500); delay(250); noTone(8); sounded = true; } else if(sounded && (cpu <= 75 && gpu <= 85)) { sounded = false; } newData = false; } } void recvWithoutWhitespace() { static byte ndx = 0; static byte control = 0; // switch control variable char endMarker = 13; // ASCII code for carriage return char rc; char * check; while (Serial.available() > 0 && newData == false) { rc = Serial.read(); check=strchr(invalids,rc); //checks if any spaces or line feeds get in if (check==NULL){ if (rc != endMarker) { charMap[ndx] = rc; ndx++; if (ndx >= numChars) { ndx = numChars - 1; } } else { switch(control) { // expect 4 CRs in format: (num)CRCR(num)CRCR case 0: control = 1; // skip first of 2 CRs break; case 1: charMap[ndx] = 44; // put comma in place of CR between numbers as delimeter ndx++; if (ndx >= numChars) { ndx = numChars - 1; } control = 2; break; case 2: control = 3; // skip first of 2 CRs break; case 3: charMap[ndx] = '\0'; // string terminator in place of last CR ndx = 0; control = 0; newData = true; break; } } } } } void parseData() { strcpy(tempChars, charMap); //strtok is destructive so copy string temporarily char * strtokIndx; // this is used by strtok() as an index strtokIndx = strtok(tempChars, ","); cpu = atoi(strtokIndx); // convert cpu to an integer strtokIndx = strtok(NULL, ","); gpu = atoi(strtokIndx); // convert gpu to an integer }
Arduino Serial parsing
I'm working on an Arduino sketch and I'm trying to change a variable with serial. I'm using some example code that I found on arduino.cc to start with. I'm trying to modify the code with an "if statement" to update a variable timevar with integerFromPC; the problem I'm having is if I type a number higher than 4 digits like 99999 it prints out the wrong data and the variable timevar doesn't get updated correctly? I'm not sure what to do? unsigned long timevar = 1000000; const byte numChars = 32; char receivedChars[numChars]; char tempChars[numChars]; // temporary array for use when parsing // variables to hold the parsed data char messageFromPC[numChars] = {0}; int integerFromPC = 0; int ifpc = 0; float floatFromPC = 0.0; boolean newData = false; //============ void setup() { Serial.begin(9600); Serial.println("This demo expects 3 pieces of data - text, an integer and a floating point value"); Serial.println("Enter data in this style <HelloWorld, 12, 24.7> "); Serial.println(); } //============ void loop() { recvWithStartEndMarkers(); if (newData == true) { strcpy(tempChars, receivedChars); // this temporary copy is necessary to protect the original data // because strtok() used in parseData() replaces the commas with \0 parseData(); showParsedData(); newData = false; } } //============ void recvWithStartEndMarkers() { static boolean recvInProgress = false; static byte ndx = 0; char startMarker = '<'; char endMarker = '>'; char rc; while (Serial.available() > 0 && newData == false) { rc = Serial.read(); if (recvInProgress == true) { if (rc != endMarker) { receivedChars[ndx] = rc; ndx++; if (ndx >= numChars) { ndx = numChars - 1; } } else { receivedChars[ndx] = '\0'; // terminate the string recvInProgress = false; ndx = 0; newData = true; } } else if (rc == startMarker) { recvInProgress = true; } } } //============ void parseData() { // split the data into its parts char * strtokIndx; // this is used by strtok() as an index strtokIndx = strtok(tempChars,","); // get the first part - the string strcpy(messageFromPC, strtokIndx); // copy it to messageFromPC strtokIndx = strtok(NULL, ","); // this continues where the previous call left off integerFromPC = atoi(strtokIndx); strtokIndx = strtok(NULL, ","); floatFromPC = atof(strtokIndx); // convert this part to a float } //============ void showParsedData() { if (strcmp(messageFromPC, "set time") == 0) timevar = integerFromPC; Serial.print("Time Set To "); Serial.println(integerFromPC); Serial.println(timevar); } //do other stuff
You declare int integerFromPC. int on Arduino is 16 bits. 99999 doesn't fit into 16 bits, so will appear mod 2^16 as 34463. Use long instead as you do for timeVar and it will be ok for up to +/- 2^31 .
strcmp brakes Arduino sketch
For a school project, I'm using an Arduino Uno together with a Parallax RFID, a LCD screen and an esp8226-wifi module. I'm trying to compare the scanned tag with the tags in the database and send the name of the tag owner to a terminal in the Blynk app. Everything works just fine until I put in the function that compares the tags. If I do that, everything stops working, even the code in the setup() part. How can I fix this? I think the problem has somehing to do with the strcmp. /* Libraries that need to be manually installed: Blynk libraries: https://github.com/blynkkk/blynk-library/releases/download/v0.5.0/Blynk_Release_v0.5.0.zip LiquidCrystal_I2C library: https://cdn.instructables.com/ORIG/FVH/K8OQ/J8UH0B9U/FVHK8OQJ8UH0B9U.zip */ #define BLYNK_PRINT Serial #include <SoftwareSerial.h> #include <ESP8266_Lib.h> #include <BlynkSimpleShieldEsp8266.h> #include <Wire.h> #include <LiquidCrystal_I2C.h> //Setting up the Blynk wifi connection #define ESP8266_BAUD 9600 char auth[] = "87b00838cd834e4e87a0422265cc7a9e"; char ssid[] = "bbox2-56b2"; char pass[] = "91C2D797F6"; //Setting up the virtual pins WidgetTerminal terminal(V1); BLYNK_WRITE(V1){} //Setting up the RFID #define RFIDEnablePin 8 #define RFIDSerialRate 2400 String RFIDTAG=""; //Holds the RFID Code read from a tag String DisplayTAG = ""; //Holds the last displayed RFID Tag //Setting up the LCD LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); //Setting up the serial connection SoftwareSerial EspSerial(2, 3); ESP8266 wifi(&EspSerial); void setup() { //Serial communication Serial.begin(RFIDSerialRate); EspSerial.begin(ESP8266_BAUD); Serial.begin(RFIDSerialRate); delay(10); //Blynk setup Blynk.begin(auth, wifi, ssid, pass); //LCD setup lcd.begin(16,2);//16 kolommen, 2 rijen lcd.backlight(); //RFID setup pinMode(RFIDEnablePin,OUTPUT); digitalWrite(RFIDEnablePin, LOW); terminal.println("Terminal printing succesfull"); terminal.flush(); } void loop() { if(Serial.available() > 0) { ReadSerial(RFIDTAG); } if(DisplayTAG!=RFIDTAG) { DisplayTAG=RFIDTAG; // PROBLEM STARTS HERE //Tag database char tags[10][10] = {"6196", "6753", "5655", "69EC", "9FFC"}; char owners[10][30] = {"per1", "per2", "per3", "per4", "per5"}; int i = 0; int j = 0; int ownerLength = 0; char lastTag[10]; RFIDTAG.toCharArray(lastTag, 10); while (i < 10) { if (strcmp(tags[i], lastTag) == 0) { ownerLength = strlen(owners[i]); while (j < ownerLength) { terminal.print(owners[i][j]); } terminal.println("has entered the parking\n\r"); terminal.flush(); break; } i++; } i = 0; j = 0; //PROBLEM ENDS HERE lcd.clear(); lcd.setCursor(0,0); lcd.print("Last tag:"); lcd.setCursor(0,1); lcd.print(RFIDTAG); digitalWrite(RFIDEnablePin, HIGH); delay(1000); digitalWrite(RFIDEnablePin, LOW); } Blynk.run(); } //Function for reading the tag void ReadSerial(String &ReadTagString) { int bytesread = 0; int val = 0; char code[10]; String TagCode=""; if(Serial.available() > 0) { if((val = Serial.read()) == 10) { bytesread = 0; while(bytesread<10) // Reads the tag code { if( Serial.available() > 0) { val = Serial.read(); if((val == 10)||(val == 13)) // If header or stop bytes before the 10 digit reading { break; // Stop reading } code[bytesread] = val; // Add the digit bytesread++; // Ready to read next digit } } if(bytesread == 10) // If 10 digit read is complete { for(int x=6;x<10;x++) //Copy the Chars to a String { TagCode += code[x]; } ReadTagString = TagCode; //Returns the tag ID while(Serial.available() > 0) //Burn off any characters still in the buffer { Serial.read(); } } bytesread = 0; TagCode=""; } } }