0
\$\begingroup\$

I am trying to read an analog signal using the Analog.Read() function and output 1 or 0 depending on the value of the analog signal. While testing using a serial monitor, I always get the symbol for 'phi'instead of 0 and the 'square box with question mark'instead of 1. Please help.

    const int analogInPin = A3;
    int inputValue=0;
    int ch1=1,ch2=0;
    void setup()
   {

     pinMode(A0, INPUT);
     Serial.begin(9600);
    }

    void loop()
    {
      inputValue = analogRead(analogInPin);
      if(inputValue>240)
      Serial.print('1');
      else 
      Serial.print('0');
      delay(10);   
    }
\$\endgroup\$
1
\$\begingroup\$

If I remember well you can use either:

Serial.print(1);

or

Serial.write('1');

To display 1 in the serial monitor.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ I tried that too,but the same outcome with a different character. \$\endgroup\$ – Ajmal Mulla Abdul Shukoor Dec 3 '14 at 19:14
  • \$\begingroup\$ You might try also Serial.print("1"); \$\endgroup\$ – Roger C. Dec 3 '14 at 19:15
  • \$\begingroup\$ That doesn't work either. \$\endgroup\$ – Ajmal Mulla Abdul Shukoor Dec 3 '14 at 19:18
  • \$\begingroup\$ You may have a problem somewhere else because I'm pretty sure that this code works. You could look to the TX line on the oscilloscope, to see what does generate the microcontroller. \$\endgroup\$ – Roger C. Dec 3 '14 at 19:20
  • \$\begingroup\$ This is not related to the problem you're describing but in your code you're setting A0 as an input but reading from A3. \$\endgroup\$ – Roger C. Dec 3 '14 at 20:05
0
\$\begingroup\$

If you're trying to output 1 or 0 simply remove your single quotes and use the following:

Serial.print(1);

Or 

Serial.print(0);

Your code is printing out the ASCII value of 1 and 0...

| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.