My arduino is contantly printing 0's even with no Serial.begin(number here)
, just eternal zeros. How do I fix this? I also had a magnetic speaker near my arduino. This happened since i've been using my speaker
-
Always show us a good schematic of your proposed circuit.
Show us good images of your ‘actual’ wiring.
Give links to components. -
In the Arduino IDE, use Ctrl T or CMD T to format your code then copy the complete sketch.
Use the < CODE / > icon from the ‘posting menu’ to attach the copied sketch.
this is the code:
`]int x = A1;
int y = A0;
void setup(){
pinMode(y, INPUT);
pinMode(x, INPUT);
pinMode(2, OUTPUT);
pinMode(13, OUTPUT);
Serial.begin(9600);
}
void loop(){
Serial.println(x);
Serial.print(" X val");
Serial.println(y);
Serial.print(" y val");
}
`
type or paste code here
ignore the random stuff
void loop(){
Serial.println(x);
Serial.print(" X val");
Serial.println(y);
Serial.print(" y val");
}
Test time.
- Tell us, line by line, what the above code does.
I forgot to mention it'sconnected to a joystick, Anyway it prints the x value of the joy stick, after that the string "x val" same thing for y but replaced with y instead of x
Serial.println(x);
- The above line of code prints the ASCII value of x.
int x = A1;
int y = A0;
. . .
Since x = A1; Which is 15
ASCII 15 is:
Same goes for int y = A0;
If A0 and A1 are analog inputs, you need to read these as an analog value:
Serial.println(analogRead(x) );
I didn't exactly understand that, please make it a little simpler
- If A0 and A1 are analog inputs, you need to read these as analog values,
i.e.
Serial.println(analogRead(x) );
Thanks, but why does it print 0 even with no BAUD rate ( its stil 9600 even with no begin promt or something) or no Print command?
Say what ?
void setup(){
pinMode(y, INPUT);
pinMode(x, INPUT);
pinMode(2, OUTPUT);
pinMode(13, OUTPUT);
Serial.begin(9600); <----------<<<<
}
No, I meant i removed the Serial commands, still printed 0
- Show us the actual sketch (which compiles) that you have uploaded to the Arduino.
how?
- In the Arduino IDE, use Ctrl T or CMD T to format your code then copy the complete sketch.
Use the < CODE / > icon from the ‘posting menu’ to attach the copied sketch.
Um, I thought it was printing out the pin on the Arduino that OP assigned in the globals.
int x = A1;
int y = A0;
A0 can be used as pin 14, A1 as pin 15.
You know more than I do in electronics, are we talking about the same thing? Is this a coincidental naming convention thing, or am I mistaken?
int x = A1;
int y = A0;
void setup(){
pinMode(y, INPUT);
pinMode(x, INPUT);
pinMode(2, OUTPUT);
pinMode(13, OUTPUT);
Serial.begin(9600);
}
void loop(){
Serial.println(x);
Serial.print(" X val");
Serial.println(y);
Serial.print(" y val");
}
Without Serial
commands:
int x = A1;
int y = A0;
void setup(){
pinMode(y, INPUT);
pinMode(x, INPUT);
pinMode(2, OUTPUT);
pinMode(13, OUTPUT);
}
void loop(){
}
- What is the baud rate of your serial monitor set to ?
- Nothing will get printed in this example.