简体   繁体   中英

Arduino - Garbled serial output even at 9600 baud

I am doing a project that requires the Arduino to read data from a potentiometer. I was trying to get the potentiometer working so I used this code, which should read the potentiometer and then output it to the serial monitor.

int val = 0;

void setup(){
  Serial.begin(9600);
}

void loop(){
  val = analogRead(A1);
  Serial.println("Head " + val);
}

I used the code from https://www.arduino.cc/en/tutorial/potentiometer and changed the code from blinking an LED to outputting the value to Serial where I Am monitoring it using the Arduino IDE's Serial monitor tool and all I get is this

⸮⸮>W07⸮⸮7M⸮⸮⸮[+⸮⸮⸮⸮⸮⸮z⸮R⸮⸮⸮a~⸮⸮yo6|⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮߉⸮[⸮}⸮⸮⸮⸮⸮7⸮%
G2⸮{⸮⸮⸮⸮⸮ݪ}⸮⸮⸮>⸮⸮{⸮K⸮ݻ⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮?⸮⸮⸮:w⸮⸮⸮⸮6⸮⸮⸮⸮O⸮⸮⸮⸮?w⸮⸮07⸮⸮7M⸮⸮⸮[+⸮⸮⸮}<⸮z⸮R⸮⸮⸮a~⸮⸮yo6|⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮߉⸮[⸮}⸮⸮⸮⸮⸮7⸮%
G2⸮{⸮⸮⸮⸮⸮ݪ}⸮⸮⸮>⸮⸮{⸮K⸮ݻ⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮?⸮⸮⸮:w⸮⸮⸮⸮6⸮⸮⸮⸮O⸮⸮⸮⸮?w⸮⸮07⸮⸮7M⸮⸮⸮[+⸮⸮⸮}<⸮⸮m⸮M⸮⸮jo⸮⸮⸮⸮⸮.⸮⸮⸮⸮d⸮⸮o⸮⸮⸮⸮⸮.|⸮}⸮⸮⸮啺7|g⸮⸮⸮⸮~⸮⸮⸮:⸮N⸮?⸮{⸮n.o⸮⸮e6⸮?l⸮⸮h⸮⸮⸮⸮ϻ⸮⸮⸮⸮ԟy⸮⸮⸮o7s7⸮?u⸮⸮⸮?⸮⸮⸮⸮߰⸮⸮⸮⸮⸮~߹h⸮⸮⸮ӿw⸮⸮g⸮⸮⸮T⸮z⸮⸮|⸮t⸮⸮⸮^⸮-⸮o⸮/=⸮ݩ⸮i⸮H⸮⸮ם⸮E⸮⸮ݛ⸮筷?⸮⸮⸮⸮⸮G}⸮⸮U⸮6⸮⸮ۮ⸮2׳⸮⸮⸮⸮G}⸮⸮⸮⸮⸮⸮⸮=⸮j⸮k⸮⸮>⸮2X⸮⸮J⸮⸮⸮{⸮⸮⸮⸮⸮n⸮⸮⸮⸮i{⸮>⸮}⸮⸮{⸮⸮⸮⸮⸮⸮j⸮⸮⸮;⸮⸮un⸮⸮⸮⸮⸮⸮⸮_7⸮⸮⸮⸮y⸮/⸮/⸮⸮⸮u⸮yvN⸮F⸮շy⸮⸮⸮g⸮⸮n⸮o⸮⸮⸮⸮l⸮7⸮nw⸮⸮/⸮⸮⸮⸮⸮⸮⸮⸮{,⸮⸮⸮|⸮⸮⸮⸮⸮eſ
⸮⸮⸮⸮⸮j⸮⸮}⸮⸮⸮z⸮]٫ϛ⸮⸮⸮⸮⸮⸮⸮ݶ⸮⸮ܟ⸮⸮⸮=c⸮o⸮g⸮l^⸮⸮ƭߛ⸮?⸮[9w⸮\[⸮⸮y⸮⸮⸮⸮⸮3⸮yѷ⸮⸮⸮g⸮}⸮⸮⸮⸮⸮⸮v⸮⸮⸮]>_⸮⸮⸮ױs⸮'~⸮i;W⸮⸮⸮⸮1ֽܢ⸮⸮⸮'⸮⸮t⸮u⸮⸮]⸮_ڙͿo⸮y⸮W⸮ٗ⸮K⸮⸮_⸮⸮⸮⸮:⸮|M⸮⸮⸮⸮G⸮⸮⸮⸮⸮N⸮⸮⸮⸮⸮⸮⸮<⸮⸮⸮w^⸮⸮⸮⸮⸮⸮e⸮⸮⸮"⸮⸮Xg⸮N⸮n⸮⸮⸮⸮⸮߷⸮⸮⸮⸮⸮⸮⸮⸮c⸮⸮~⸮⸮⸮⸮⸮⸮.⸮>⸮⸮⸮⸮⸮⸮⸮n⸮⸮?7?_⸮⸮⸮'>⸮⸮k|ۉ.⸮췅⸮T⸮ϝ⸮=⸮⸮⸮⸮⸮⸮׿}⸮⸮⸮Y⸮⸮Z⸮⸮⸮⸮⸮C⸮⸮9⸮v⸮⸮~>⸮⸮⸮Z⸮z?⸮⸮⸮⸮⸮⸮^⸮Ӿ⸮Md⸮⸮⸮⸮⸮MZK⸮j⸮⸮M⸮׳⸮⸮⸮⸮⸮⸮⸮]/Wꣷ⸮?⸮;o⸮u⸮⸮9⸮⸮⸮Y˧⸮{⸮W⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮ݮYn⸮ο⸮⸮⸮⸮⸮;⸮⸮⸮7{}⸮v⸮⸮⸮⸮⸮⸮⸮v⸮⸮7⸮⸮⸮}O+Y+⸮^⸮⸮⸮⸮⸮⸮q⸮⸮z^\⸮⸮~⸮⸮⸮⸮⸮~~⸮⸮⸮⸮⸮⸮o⸮⸮⸮⸮⸮t⸮⸮⸮⸮⸮⸮⸮L⸮⸮⸮⸮⸮⸮⸮+=⸮⸮⸮C⸮⸮Ƭ⸮⸮⸮⸮⸮⸮⸮W⸮⸮⸮/⸮⸮⸮5⸮~{{⸮|.⸮;P⸮⸮p⸮⸮⸮⸮⸮⸮⸮oZ⸮⸮⸮⸮⸮⸮⸮⸮ߝ⸮⸮⸮⸮⸮⸮⸮⸮g⸮⸮⸮⸮⸮W⸮Wj⸮oY⸮;⸮⸮/?⸮⸮~⸮6⸮⸮m⸮⸮~⸮⸮⸮k⸮_O⸮߃⸮b⸮m⸮⸮kӾ?⸮l⸮⸮⸮⸮⸮⸮⸮⸮X׬>{a⸮⸮[k#⸮/⸮~ݍ⸮⸮⸮⸮_⸮⸮O_⸮9⸮⸮⸮⸮t⸮⸮g⸮⸮⸮⸮*⸮1⸮⸮⸮⸮⸮wߝ;⸮z⸮⸮⸮⸮⸮?⸮2⸮⸮⸮⸮O⸮c⸮⸮䝿⸮⸮⸮_Ŭ⸮⸮׹զޫ:⸮⸮旚⸮⸮r⸮⸮oo⸮⸮7⸮⸮⸮O,⸮G~⸮⸮.5⸮⸮⸮,⸮w⸮o⸮⸮⸮A⸮⸮⸮⸮⸮⸮uo⸮⸮⸮?o븨⸮⸮yp⸮~W⸮o⸮⸮⸮iH2⸮⸮8⸮⸮w⸮{⸮⸮C⸮F;⸮⸮!⸮?⸮⸮;⸮⸮⸮⸮⸮⸮⸮m٫⸮?o⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮ϻ⸮o.⸮⸮⸮⸮c⸮⸮⸮⸮⸮ߴ⸮q"S{⸮c⸮ٻ⸮⸮⸮H⸮~⸮⸮[⸮⸮~⸮⸮⸮}⸮w4⸮⸮⸮⸮⸮⸮⸮⸮%⸮⸮⸮⸮⸮t쟕v⸮⸮>⸮⸮⸮⸮⸮⸮oY⸮⸮⸮⸮⸮⸮~c⸮⸮a⸮⸮⸮^q⸮⸮⸮⸮⸮׍⸮⸮⸮ޟәw_⸮⸮O⸮⸮e⸮⸮⸮V⸮⸮⸮⸮⸮o⸮⸮uy⸮8⸮⸮gޟ⸮_⸮⸮w⸮⸮⸮⸮.
⸮⸮⸮⸮⸮⸮⸮r⸮R⸮?ݍ⸮⸮⸮͖⸮⸮⸮⸮:;_⸮⸮{⸮^⸮m⸮⸮E_*⸮⸮⸮[⸮⸮\wU⸮g.}⸮ۻ/?⸮⸮}j⸮⸮⸮w⸮⸮⸮⸮⸮⸮⸮⸮⸮·⸮y{>⸮⸮#}⸮⸮⸮⸮U⸮⸮⸮⸮⸮|o⸮Q⸮\⸮⸮'⸮ ⸮⸮⸮⸮iZo_⸮⸮⸮⸮⸮8⸮⸮⸮⸮⸮=⸮⸮}zݽ⸮Q⸮w⸮⸮⸮^⸮⸮t⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮|'⸮⸮T⸮⸮⸮⸮ߩ⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮   ?⸮3⸮⸮⸮⸮s}⸮⸮⸮⸮⸮߽⸮v⸮⸮⸮⸮⸮"⸮⸮>⸮⸮N?⸮ד⸮⸮_W⸮o⸮⎼⸮w⸮G|;⸮V⸮⸮⸮⸮⸮{Jg⸮⸮⸮~⸮⸮⸮⸮⸮W⸮3⸮⸮?⸮݌⸮s⸮ew⸮{⸮⸮!⸮⸮g⸮⸮⸮⸮⸮⸮⸮K⸮⸮_⸮⸮⸮⸮V7⸮j[mFԿA⸮q⸮⸮⸮lc⸮⸮⸮.⸮⸮N_ۿ⸮⸮⸮⸮fs}⸮{⸮⸮]⸮Ѷݧ⸮⸮⸮훽⸮⸮n⸮7⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮u⸮⸮⸮=⸮⸮r⸮;⸮~⸮⸮⸮⸮=⸮⸮{uߥܽ⸮⸮⸮⸮9⸮⸮⸮.ӷ⸮⸮⸮޹⸮7⸮⸮S⸮;⸮⸮⸮⸮⸮vy⸮⸮e⸮⸮⸮⸮⸮⸮s⸮n⸮⸮_<⸮⸮5Q⸮⸮⸮⸮=⸮{{⸮⸮N⸮⸮⸮sߛ⸮⸮⸮⸮⸮v⸮⸮⸮N⸮⸮#z⸮m⸮⸮⸮Q⸮⸮⸮Wq⸮⸮g⸮⸮O⸮⸮~⸮⸮⸮⸮m⸮⸮⸮⸮>W⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮p⸮⸮⸮⸮꿿⸮⸮⸮⸮^⸮⸮⸮⸮⸮E[:}⸮⸮⸮o_⸮⸮⸮⸮~⸮⸮?⸮⸮⸮⸮6⸮⸮⸮⸮⸮V⸮z⸮⸮?⸮5⸮~O⸮⸮=⸮⸮⸮⸮f⸮⸮⸮7⸮⸮⸮⸮Z]O⸮⸮ֻ⸮⸮⸮s⸮g[g⸮⸮⸮⸮?sN⸮x⸮⸮⸮⸮⸮0>⸮⸮⸮⸮⸮⸮⸮⸮_⸮⸮⸮e
v?⸮⸮j⸮o⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮߅⸮[⸮⸮t⸮3⸮⸮y⸮⸮8~⸮⸮J-4⸮v⸮?⸮⸮ֺ[⸮⸮⸮⸮N%{⸮⸮⸮⸮]⸮wxY/⸮vw⸮⸮⸮.⸮⸮e]⸮⸮{⸮⸮⸮w⸮⸮⸮⸮⸮e⸮9⸮n⸮>⸮Y!⸮⸮⸮s]⸮⸮⸮7t%⸮⸮ǿ⸮⸮⸮⸮⸮_⸮ӷ⸮⸮⸮⸮MC7⸮⸮N⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮u⸮u⸮χu⸮⸮⸮uT}⸮⸮⸮w⸮⸮⸮⸮⸮ߗ⸮o⸮⸮⸮LG⸮^^M⸮⸮n_⸮⸮t~q⸮⸮⸮~U~~`⸮l⸮-߷⸮l⸮⸮K⸮G⸮⸮⸮⸮⸮U⸮⸮⸮⸮⸮⸮ҟ='⸮⸮⸮}Ç
⸮7uO⸮⸮⸮⸮o⸮⸮⸮U_⸮⸮⸮⸮⸮;⸮⸮⸮߼_⸮⸮⸮⸮މ⸮⸮⸮y⸮{⸮W>m_⸮s⸮⸮⸮⸮-ߕȺ⸮'oN_U⸮⸮Ϳ⸮/}t⸮mo~⸮⸮sz⸮⸮⸮⸮⸮⸮~⸮_⸮⸮⸮⸮ù޿⸮&⸮⸮⸮?⸮s⸮y⸮⸮⸮7⸮⸮⸮⸮⸮⸮}⸮⸮⸮⸮⸮w⸮⸮⸮_⸮⸮⸮⸮⸮⸮⸮z⸮⸮⸮⸮L⸮⸮⸮⸮⸮⸮{⸮⸮go⸮z⸮⸮⸮⸮⸮⸮o⸮⸮⸮~⸮i⸮⸮7⸮⸮~⸮⸮M⸮⸮⸮⸮⸮⸮⸮⸮⸮v⸮⸮y⸮⸮⸮⸮޿⸮⸮⸮⸮2ߏ⸮⸮⸮⸮W⸮x⸮⸮⸮^}⸮U⸮⸮⸮J⸮w⸮⸮⸮⸮kya⸮⸮⸮N}?f⸮e⸮{⸮⸮⸮⸮k⸮⸮⸮2⸮>⸮~⸮⸮⸮⸮⸮⸮⸮⸮⸮i⸮⸮⸮⸮⸮⸮ζ⸮⸮⸮k⸮⸮w⸮⸮⸮⸮⸮⸮⸮Y⸮⸮wi⸮梲ܻ|?w⸮⸮ߥ⸮W⸮⸮⸮⸮eOӞ⸮⸮⸮z⸮⸮⸮o⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮7⸮⸮-J⸮⸮⸮⸮⸮⸮⸮+ڏ⸮⸮߿⸮j⸮}⸮9⸮?⸮⸮⸮[X_⸮⸮⸮⸮⸮⸮⸮.⸮⸮⸮⸮⸮n⸮;⸮ߝP⸮⸮⸮p⸮H⸮F[~⸮⸮⸮⸮⸮⸮⸮zL⸮⸮⸮⸮⸮⸮ݗ⸮⸮w|^⸮⸮⸮]⸮_⸮⸮⸮k⸮⸮⸮⸮U⸮o4⸮⸮mn⸮⸮>⸮⸮⸮[⸮3⸮/⸮w⸮淯⸮⸮⸮}wD⸮⸮f쿋⸮⸮z⸮⸮H⸮cP⸮YÜ5⸮y⸮?~⸮⸮⸮⸮⸮⸮⸮⸮⸮M}⸮⸮wiP#⸮⸮}⸮L⸮⸮⸮ynx|^⸮wn⸮=⸮泩⸮⸮⸮C⸮⸮⸮⸮⸮~ݳ⸮׍D⸮[⸮⸮⸮,⸮kGȯ⸮⸮⸮Q⸮⸮u⸮⸮⸮O|⸮⸮⸮⸮⸮_|?⸮⸮⸮⸮~ʖ9⸮⸮⸮⸮⸮tNW⸮⸮⸮⸮⸮⸮⸮⸮v⸮⸮e⸮⸮s⸮⸮W⸮⸮⸮⸮~⸮~⸮⸮e⸮⸮⸮⸮⸮⸮⸮q%⸮⸮⸮⸮U⸮=⸮⸮⸮?⸮⸮'⸮⸮`⸮⸮⸮⸮⸮⸮⸮⸮~⸮⸮⸮ɋ⸮⸮{⸮⸮⸮C⸮⸮'⸮Mn⸮ٷ>⸮}⸮⸮⸮⸮⸮⸮⸮ߜ⸮⸮⸮]ڞ⸮   ߶_8⸮⸮⸮⸮{.⸮⸮⸮⸮S\+⸮vSǏ⸮⸮⸮⸮⸮^⸮⸮\⸮_⸮⸮⸮˫m⸮^⸮⸮=o⸮ůw_yݨ⸮⸮⸮⸮뿜9?_⸮⸮⸮⸮⸮٧⸮⸮⸮⸮⸮ǜ⸮ήo⸮⸮f>⸮~5⸮⸮~⸮v⸮v߿?Z⸮%
⸮{⸮|⸮⸮⸮⸮~ou⸮⸮⸮⸮T⸮No⸮⸮⸮⸮⸮⸮ֹi&;⸮⸮⸮⸮⸮⸮ޛ⸮⸮⸮⸮⸮;⸮⸮⸮⸮⸮⸮⸮?⸮⸮^⸮w;⸮⸮⸮⸮ÿ⸮⸮⸮7⸮⸮⸮⸮⸮ׯ}⸮⸮8⸮⸮⸮F⸮⸮⸮⸮⸮⸮⸮⸮Z⸮⸮??⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮n⸮⸮⸮⸮ _⸮⸮⸮⸮⸮⸮s{⸮⸮⸮⸮U⸮⸮wmt[o⸮7f⸮⸮⸮⸮⸮⸮R⸮⸮⸮L⸮|>⸮M0⸮⸮v⸮%v֟}⸮⸮⸮j7⸮⸮⸮⸮⸮⸮⸮e{n⸮⸮⸮⸮{⸮⸮⸮⸮⸮⸮N}}⸮⸮CsLB⸮⸮⸮j⸮⸮x輣⸮⸮⸮⸮⸮⸮#_⸮y⸮⸮⸮⸮⸮⸮P⸮⸮⸮Z⸮(6⸮_⸮[K<⸮ם⸮_⸮{⸮⸮싛⸮߼5:?k⸮⸮߿⸮~⸮ɫ⸮⸮⸮~⸮⸮⸮K⸮⸮⸮⸮⸮⸮⸮⸮⸮x񭳶⸮⸮9⸮ɖ⸮⸮⸮]⸮⸮⸮|[⸮⸮?⸮⸮>eOs⸮⸮⸮⸮Z⸮⸮⸮⸮⸮⸮A?3⸮⸮⸮⸮⸮~⸮⸮[⸮⸮⸮⸮8<⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮}69?⸮⸮⸮⸮K⸮⸮⸮Sb⸮eJ⸮⸮oO⸮⸮''⸮⸮⸮뷳⸮O⸮⸮⸮⸮G_⸮⸮⸮.⸮⸮{⸮⸮

It works fine when using the original code.

Please Note:

  1. First make sure that the baud rate used in the sketch is same as the baud rate used in the Serial Monitor
  2. Use a delay of 10 milliseconds for stability: delay(10);
  3. The val variable is int , so better to use Serial.printline with String Constructor as:
     Serial.println("Head " + String(val);

The baud rate in your code and the baud rate chosen in the Serial Monitor window are different. make sure they match and the output should then be legible.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM