I am new user of arduino, I am trying to control a PWM pin with serial input code which i got from android by Bluetooth HC-06. the code is shown in Serial monitor of Arduino developer software.
Here I attached the picture of serial monitor and arduino code.
int led1 = 22;
int led2 = 23;
int led3 = 24;
int led4 = 25;
int led5 = 26;
int led6 = 27;
int led7 = 28;
int led8 = 29;
int led9 = 30;
int led10 = 31;
int led11 = 32;
int led12 = 33;
Aren't arrays great?
if (readString == "A")
{
while (Serial.available ())
{
int value =Serial.read();
analogWrite (fans,value);
readString = "";
}
}
So, one byte arrives on the serial port. It's a 'A'. So, you read all remaining data (none), and move on. No wonder nothing happens.
But, lets suppose that your f**king around with delay means that "A2" arrived. You read the 'A', so the '2' is still in the buffer. value will be 50 after the Serial.read() call, so you set pin 10 to 50. Is that what you want?
The variation in values written to the pin will be from 48 to 57, depending on which character follows the A.
You need a completely different approach to reading serial data if you expect to be able to send A250 to make the output 250. The lazy change would be to use parseInt() and get rid of the while loop.