//Example from String to Int https://www.arduino.cc/en/Tutorial/StringToIntExample void setup() { // initialize serial: Serial.begin(4800); pinMode(13, OUTPUT); } String inString = ""; int b = 0; void loop() { if (Serial.available()>0) { int inChar = Serial.read(); if (isDigit(inChar)) { // convert the incoming byte to a char // and add it to the string: inString += (char)inChar; } // if you get a newline, print the string, // then the string's value: if (inChar == '\n') { Serial.print("Value:"); Serial.println(inString.toInt()); b = inString.toInt(); Serial.print("String: "); Serial.println(inString); // clear the string for new input: inString = ""; } } if(b>5){ Serial.println("LIGHT"); digitalWrite(13,HIGH);} else{ digitalWrite(13,LOW); } }