Question: Arduino Code: The code I have below is a wireless signal code from HC-12. I am sending String of numbers and this code is readying

Arduino Code:

The code I have below is a wireless signal code from HC-12. I am sending String of numbers and this code is readying it. However I just want to know how to convert the String that are getting sent over into int, so i can work with those numbers. I need to convert the data sent to the String "input" into an int type. ________________________________________________________________ #include

SoftwareSerial mySerial(2, 3); //RX, TX int ledPin = 13; void setup() { mySerial.begin(9600); Serial.begin(9600); pinMode(ledPin, OUTPUT); }

void loop() { if(mySerial.available() > 1){ String input = mySerial.readString();//read string Serial.println(input); mySerial.flush();//clear the serial buffer for unwanted inputs delay(10);//delay little for better serial communication

********** This is where i am having problem with the code. It wont accpeted it because it is a string and not an int. How do i convert string "input" into an int type?*******

if( input > 10) { digitalWrite(ledPin, HIGH) } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!