Clear Filters
Clear Filters

Why does my serial communication with Arduino is not working ?

39 views (last 30 days)
I'm trying to implement a communication from MATLAB to an Arduino Uno using Serial port.
I tried the simplest case I could imagine to test this communication but it still doesn't work.
My arduino code is the following :
#include <Servo.h>
Servo myservo; // create servo object to control a servo
void setup() {
// put your setup code here, to run once:
void loop() {
// put your main code here, to run repeatedly:
Basically, when Serial recieves anything, it moves the servo to a random position. I tried it with directly sending something in the serial monitor of Arduino and it works fine.
However, when I try to send anything with MATLAB using the simple following code :
clear s;
s=serial('COM16', 'BAUD', 9600);
The program runs, terminates, but nothing happens with the servo, indicating that nothing was recieved. As this is the simplest case I can imagine to test the communication between the two softwares, I really don't see where the problem comes from.
Thank you in advance for your help with this issue.

Answers (1)

Vinayak Choyyan
Vinayak Choyyan on 11 Apr 2023
Hi Hugo,
As per my understanding, you are facing issues when trying to communicate with your Arduino Uno over serial comm. I understand that you have used the Arduino app to confirm that your board is indeed working.
Please ensure the Arduino Uno support packages have been installed. Please refer to this documentation for details steps on how to configure and setup Arduino Uno with MATLAB
Alternatively, use the Arduino Explorer App to do the above interactively. A details documentation of the same can be for here
I hope this resolves the issue you are facing.


Find more on MATLAB Support Package for Arduino Hardware in Help Center and File Exchange




Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!