I am new to Arduino. I cannot select any number greater than 9 to test components via serial monitor. And as I looked through the program, the input pins above 9 are not color coded/recognized. All the wiring was checked and double check so it seems to be my lack of experience somewhere in the programming.
Below if I select component 11 to test, the current sensor module is tested twice instead of the piezo element.
Your calibration factor is good!RTC lost power, lets set the time!
Which component would you like to test?
(1) Current Sensor Module ACS712
(2) Ultrasonic Sensor - HC-SR04
(3) Hall Effect Sensor - US1881
(4) IR Obstacle Avoidance Sensor
(5) LED - Basic Blue 5mm
(6) LED - Basic Green 5mm
(7) LED - Basic Red 5mm
(8) Basic Ultraviolet LED 5mm
(9) LED - Basic Yellow 5mm
(10) Monochrome 1.3 inch 128x64 OLED graphic display
(11) Piezo Element
(12) Momentary Push Button - Panel Mount (Red)
(13) RTC - Real Time Clock
(14) Relay Module 4-Ch #1
(15) Relay Module 4-Ch #2
(16) Standard Size - High Torque - Metal Gear Servo - MG995
(17) 12V Solenoid Valve - 3/4''
(18) This Analog Temprature Sensor can measure -40 to 150C. It is very percise and doesn't need calibration #1
(19) This Analog Temprature Sensor can measure -40 to 150C. It is very percise and doesn't need calibration #2
(menu) send anything else or press on board reset button
Please read the first post in any forum entitled how to use this forum. http://forum.arduino.cc/index.php/topic,148850.0.html .
Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
Tell us what your code is suppose to do, you started you post by the looks of it mid thought and not at the beginning of your story.
int theNumber;
void loop()
{
Serial.println("What's your number...");
while (Serial.available() == 0)
{ // Wait for User to Input Data
}
theNumber = Serial.parseInt();
Serial.print("The number is ");
Serial.println(theNumber);
} //loop
What's your number...
The number is 123
What's your number...
The number is 9999
What's your number...
Thank you for your replies. I thought I had mistakenly deleted the post.
The Serial Monitor Menu does not test components above Pin 9. The code is to eventually auto run a generator with fire and theft alarm.
If I select a component to test that has two digits it will only process them individually. Example, If I select 17 on the serial monitor menu to test a corresponding component, then it will test components 1, and 7, but not 17. How do I get Arduino to process "17" as opposed to breaking it up into "1" and "7"?
Here is the link to the wiring and code which is too large to post:
As I surmised in #3 the code linked in #4 does Serial.read() a char as a menu indicator. Makes one wonder if the author tested it for two-digit values?
First prize would be for OP to ask the supplier of that sketch to fix it for menu items over 9, since that's what it purports to accept already. But I don't see a "contact me" of any kind at the site linked.
Quick fix, OP, might be just to edit the sketch and promote the items you need into the single digits....
Here's a very stripped down version of that sketch that uses int as datatype (not char) and parseInt (not read) to take input >9 from the monitor.
// inspired by https://forum.arduino.cc/index.php?topic=628641
// 29 july
// original doesn't work for menu items >9 due to .read and char datatype
// this one works >9 with .parseInt and int datatype
// this one strips out all the libraries and stuff
// just a bare menu that tells you were it went
// menu is shortened and has only items 1, 2, 10 and 11
// define vars for testing menu
const int timeout = 20; //define very short timeout for testing the menu
//char menuOption = 0;
int menuOption = 0;
long time0;
void setup()
{
Serial.begin(9600);
Serial.println("calling the menu from setup");
menuOption = menu();
}//setup
// Main logic of your circuit. It defines the interaction between the components you selected. After setup, it runs over and over again, in an eternal loop.
void loop()
{
if (menuOption == 1)
{
Serial.println(F("testing 1"));
}
else if (menuOption == 2)
{
Serial.println(F("testing 2"));
}
else if (menuOption == 10)
{
Serial.println(F("testing 10"));
}
else if (menuOption == 11)
{
Serial.println(F("testing 11"));
}
if (millis() - time0 > timeout)
{
Serial.println("calling the menu from loop");
menuOption = menu();
}
}//loop
// Menu function for selecting the components to be tested
// Follow serial monitor for instrcutions
//char menu()
int menu()
{
Serial.println(F("\nWhich component would you like to test ? "));
Serial.println(F("(1) some component"));
Serial.println(F("(2) some other component"));
Serial.println(F("(10) yet another one"));
Serial.println(F("(11) or this one ? "));
Serial.println(F("(menu) send anything else or press on board reset button\n"));
while (!Serial.available());
// Read data from serial monitor if received
int c = Serial.parseInt();
if (c == 1)
Serial.println(F("you chose 1"));
else if (c == 2)
Serial.println(F("you chose 2"));
else if (c == 10)
Serial.println(F("you chose 10"));
else if (c == 11)
Serial.println(F("you chose 11"));
else
{
Serial.print(F("illegal input: "));
Serial.println(c);
return 0;
}
time0 = millis();
return c;
} //menu
@TomGeorge thank you! I looked at the post and I am subscribed to the YouTube channel ( It's very informative on a number of topics). I used alphabets, i.e "10" = "A", "11" = "B" and so forth and so on until I got to "J" which represent the number 19. It worked like a charm and I was able to test all the components. Thank you very much!!