Monitor Counting From 1-10

I know this may sound really easy to most of you, however, I am very new to this and have started this subject at my school halfway through the year and could really use some assistance.

I am simply trying to write a code that prints out on the monitor the numbers 1-10 in order using (i=i+1) or (i=++). I am not sure what these mean or where to even begin. Help would be greatly appreciated!


i += 1;
i = i + 1;
Or simply

Try not to think mathematically, because " i = i + 1" is clearly mathematically impossible.
Here, the equals sign is used as an assignment - the result of the expression on the right is assigned to the variable on the left.

So how would I get this to then print 1-10?

Put all your code in setup, and leave loop empty.
A simple for loop will do it.

This is what I did:

void setup() {
// put your setup code here, to run once:
Serial.print ("i = ++");

void loop() {
// put your main code here, to run repeatedly:


and I get an error message when compiling saying:

Arduino: 1.8.13 (Mac OS X), Board: "Arduino Uno"

Sketch uses 1356 bytes (4%) of program storage space. Maximum is 32256 bytes.
Global variables use 192 bytes (9%) of dynamic memory, leaving 1856 bytes for local variables. Maximum is 2048 bytes.
Board at /dev/cu.usbmodem14101 is not available
Board at /dev/cu.usbmodem14101 is not available

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Yes, the message is saying your code is syntactically correct (it won’t do what you want, but the compiler doesn’t know what you want - you maybe missed my hint about a for loop), but that for some reason, your Mac can’t talk to your Uno.

I don’t own a Mac, so can’t help you with that.

But surely there is a way to just make my monitor print out the numbers 1-10 without the need of talking to my Uno at all right? Because that's all I want to do, just simply have the Serial Monitor do:

Counter = 1
Counter = 2
Counter = 3

and so on until it reaches 10 and then stops.

Is there some code that you could write out for me that would do just that?

If your Mac can’t communicate with your Uno, you can’t download code to your board.
If you can’t download code, how are you going to get anything on the serial monitor?

I thought the plan was for you to write the code?

If you look under “file” in the IDE, you’ll see a whole load of worked examples.

Ok, I have my Uno talking to my Mac now, and the code compiles successfully and uploads, but when I pull up the monitor nothing shows up. Am I missing something?

void setup() {
// put your setup code here, to run once:
Serial.print ("i=++");

void loop() {
// put your main code here, to run repeatedly:


Hint Serial.begin

Ahhh, yes that works well, however, now I am running into another problem. After trying to troubleshoot it from simply printing “i = + i = ++” it now just keeps printing “i = ++” endlessly on the same line.

Also I really appreciate the help. Thanks heaps.

Btw, you can put just about anything between double quotes, but don’t try putting “i=++” anywhere where you expect it to get executed, instead of simply printed.

I don’t know why it prints endlessly - that sounds bad.


int x = 1;

in setup()

What is printed ?

Okay here is what I've got:

Here is what I have got:

void setup() {
// put your setup code here, to run once:
int x = 1;

Serial.begin (9600);
Serial.print ("x = 1");

void loop() {
// put your main code here, to run repeatedly:

and I then get:

x = 1
x = 1

and then it stops. So close to getting this!

No point in printing something before the serial interface is initialised.

Please remember to use code tags when posting code

Look up 'for loop' in the arduino reference. Here: for - Arduino Reference

Try to think about what you are doing rather than just getting to the right answer by chance.

You need to get the serial communication up and running first with serial begin. Look this up in the reference. You have the right baud rate.

Then you want to print a bunch of numbers so you need a variable to store them in. This is your int i. You can initialise this on its own as in int i = 0; or you can do so in the for loop

A for loop lets you loop over and over through a bit of code while incrementing a counter until the condition in the loop is false.
You want to use the variable i as your counter, use a condition that goes to 10 and increment by 1 each time.

The bit you seem to have missed is that if you print anything in "" quotes it prints literally those characters. It doesn't do any interpreting or calculating it just prints those EXACT characters.


It’s half four here.
Yes, we could write it.
But how does that help?

That's not really the way it tends to work here. This is not a site for doing people's homework for them. You have a very clear guide to how to achieve what you are trying to do which should take a maximum of 10 minutes to do. I have included the links that literally give you examples of what you are doing that just need tweeked. If you follow it you will understand what initialising things means, serial begin is and how a for loop functions.

Here is the syntax in the reference:

for (initialization; condition; increment) {
  // statement(s);

GOT IT! Thank you all for your help. Much appreciated!