how can i show the otput of the counter( which i have created as a function using ir sensor in arduino) to 16x2 lcd from MATLAB? please help!

3 views (last 30 days)
i am making my project using arduino and matlab, i have already installed the arduino support package. In my project i am counting the number of visitors which is done using ir sensor. i want to show the output on 16x2 lcd. i have used simple 'writeDigitalPin' command to glow an led for everytime i get h HIGH on ir sensor. please help me to send my data ie., the total count from matlab to lcd.

Accepted Answer

Naseeb Gill
Naseeb Gill on 13 Mar 2018
In the e-mail to me with this question link, you wrote that you have used image processing like everytime a red color object is detected, you have to start a counter in Matlab and then you have to show the output( total counts) on LCD. So I am providing codes for the same.
Matlab Code: This code will start the COM port and help to send data (counts in your case) to Arduino.
% this is used to set the port and serial
% in my case comport is 8 plz check in ur case
number = 0; % this is used in next section to count total counts
portName = 'COM8';
s = serial(portName,'BaudRate',9600,'Terminator','LF');
s.timeout = 1;
disp('Unable to open the port ');
here you said u have 'count' by image processing so paste all ur image processing code here or call function with output 'count' this section used to send code to arduino here using image processing u will get count 1 every time so in number array, each time when the red % color detected number is increased by 1
number = number + count;
this section used to close com port
disp('Unable to close the port ');
Code to display total counts in LCD using Arduino:
// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7,8,9,10,11,12);
void setup()
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
void loop() {
if (Serial.available() > 0)
int d1 = Serial.parseInt();
int d2 = Serial.parseInt(); // d2 is important here so don't remove this
lcd.setCursor(0,0); // Sets the cursor to col 0 and row 0
lcd.print("Count Value: ");
I don't have LCD right now to test the output but I think this code will work.

More Answers (1)

mohit Manchanda
mohit Manchanda on 14 Mar 2018
i want to to send the data(count) from arduino to MATLAB, for every time a red color object is detected through webcam, a counter starts and will show the count to the lcd. BUT my program is not working. please helpp:
  1 Comment
Naseeb Gill
Naseeb Gill on 14 Mar 2018
First, read the policies of this Matlab Answers. You can't paste question as an answer here. Second please learn from youtube or some other means that how to ask a question. Code should be paste in code format. Don't use "please helpp!!" etc. in your questions.

Sign in to comment.


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!