Jeisson David Torrecilla ASánchez Andrés
Published © GPL3+

Car Controlled By Hands Movements Employing MATLAB

Car controlled by arms muscles movements using electrodes placed on the body. The car responds with four different commands using RF.

AdvancedFull instructions provided5 hours2,242
Car Controlled By Hands Movements Employing MATLAB

Things used in this project

Hardware components

PSoC 5LP Prototyping Kit
Cypress PSoC 5LP Prototyping Kit
×2
RF Comunication module Emitter/receptor
×1
L298N
×2
Car structure
×1
Linear Regulator (7805)
Linear Regulator (7805)
×1
Muscle Sensor
×1

Software apps and online services

MATLAB
MATLAB
PSoC Creator
Cypress PSoC Creator

Story

Read more

Schematics

Car squematic

Psoc Emitter squematic

MATLAB GUIDE

Code

Car PSOC 5

C/C++
This code is used to give the comands to move the car
#include <project.h>
char dato;
CY_ISR(InterruptRX){
    dato=UART_GetChar();
}

int main()
{
UART_Start();
LCD_Start();
LCD_Position(0,0);
LCD_PrintString("Dato:");
isrRX_StartEx(InterruptRX);
CyGlobalIntEnable; 

    for(;;)
    {        
        if (dato=='z'){
           MOT_1_1_Write(1);
           MOT_1_2_Write(0);
           MOT_2_1_Write(0);
           MOT_2_2_Write(0);
           MOT_3_1_Write(1);
           MOT_3_2_Write(0);
           MOT_4_1_Write(0);
           MOT_4_2_Write(0);
        LCD_Position(1,0);
        LCD_PrintNumber(1);
        }
        if (dato=='x'){
           MOT_1_1_Write(1);
           MOT_1_2_Write(0);
           MOT_2_1_Write(1);
           MOT_2_2_Write(0);
           MOT_3_1_Write(0);
           MOT_3_2_Write(0);
           MOT_4_1_Write(0);
           MOT_4_2_Write(0);
        LCD_Position(1,0);
        LCD_PrintNumber(2);
        }
        if (dato=='y'){
           MOT_1_1_Write(0);
           MOT_1_2_Write(0);
           MOT_2_1_Write(0);
           MOT_2_2_Write(0);
           MOT_3_1_Write(1);
           MOT_3_2_Write(0);
           MOT_4_1_Write(1);
           MOT_4_2_Write(0);
        LCD_Position(1,0);
        LCD_PrintNumber(3);
        }
        if (dato=='w'){
           MOT_1_1_Write(0);
           MOT_1_2_Write(0);
           MOT_2_1_Write(0);
           MOT_2_2_Write(0);
           MOT_3_1_Write(0);
           MOT_3_2_Write(0);
           MOT_4_1_Write(0);
           MOT_4_2_Write(0);
        LCD_Position(1,0);
        LCD_PrintNumber(4);

        }
    }
}

Psoc Emitter code

C/C++
#include <project.h>
char dato;
CY_ISR(interruptRX){
        dato=UART_GetChar();
        
}

int main()
{
    UART_Start();
    UART1_Start();
    
    CyGlobalIntEnable; 
    isr_RX_StartEx(interruptRX);


    for(;;)
    {
    UART1_PutChar(dato);
    CyDelay(100);

    }
}

MATLAB Code

MATLAB
function varargout = Flauta(varargin)
% FLAUTA MATLAB code for Flauta.fig
%      FLAUTA, by itself, creates a new FLAUTA or raises the existing
%      singleton*.
%   
%      H = FLAUTA returns the handle to a new FLAUTA or the handle to
%      the existing singleton*.
%
%      FLAUTA('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in FLAUTA.M with the given input arguments.
%
%      FLAUTA('Property','Value',...) creates a new FLAUTA or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before Flauta_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to Flauta_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help Flauta

% Last Modified by GUIDE v2.5 01-Oct-2016 18:09:59

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @Flauta_OpeningFcn, ...
                   'gui_OutputFcn',  @Flauta_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before Flauta is made visible.
function Flauta_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to Flauta (see VARARGIN)
global serial_PSoC 
serial_PSoC=serial('COM3','BaudRate',9600,'Parity','none','DataBits',8,'StopBits',1);
fopen(serial_PSoC);
% Choose default command line output for Flauta
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes Flauta wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = Flauta_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;


% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global c Fs serial_PSoC

c=1;
x=0;
while c==1
Fs=44100;
time=0.5;
recObj = audiorecorder(Fs,16,1);
disp('Start speaking.')
recordblocking(recObj, time);
disp('End of Recording.');
audio=getaudiodata(recObj);
T = 1/Fs;                     % Sample time
L = length(audio);                     % Length of signal
t = (0:L-1)*T;
NFFT = 2^nextpow2(L); % Next power of 2 from length of y
Y = fft(audio,NFFT)/L;
f = Fs/2*linspace(0,1,NFFT/2+1);
filtrada=2*abs(Y(1:NFFT/2+1));
% Plot single-sided amplitude spectrum.
[peak_value, peak_location] = findpeaks(filtrada,'minpeakheight',0.006);%0.004
set(handles.T1,'string',peak_value);
set(handles.T2,'string',peak_location);

 plot(handles.axes2,f,filtrada)
plot(handles.axes1,t,audio)
drawnow
if peak_value<0.004
   set(handles.notas,'string',' '); 
   peak_location=0;
end
if peak_value>0.004 %X
    if peak_value<0.0076
    x=1;
    end
end
if peak_value>0.0076%Y
    if peak_value<0.01
    x=2;
    end
end
if peak_value>0.01%Z
    if peak_value <0.018
    x=3;
    end
end
if peak_value>0.018%W
    if peak_value <0.05
    x=4;
    end
end
if x==0;
    set(handles.notas,'string','');
end
if x==1;
set(handles.notas,'string','');
    set(handles.notas,'string','Y');
    fprintf(serial_PSoC,'%s','y');
    x=0;
end
if x==2;
   set(handles.notas,'string','');
    set(handles.notas,'string','X');
        fprintf(serial_PSoC,'%s','x');
    x=0;
end
if x==3;
   set(handles.notas,'string','');
    set(handles.notas,'string','Z');
    fprintf(serial_PSoC,'%s','z');
    x=0;
end
if x==4;
   set(handles.notas,'string','');
    set(handles.notas,'string','W');
    fprintf(serial_PSoC,'%s','w');
    x=0;
end
if x==5;
   set(handles.notas,'string','');
    set(handles.notas,'string','O');
    fprintf(serial_PSoC,'%s','w');
    x=0 ;
end
if x==6;
   set(handles.notas,'string','');
    set(handles.notas,'string','U');
    fprintf(serial_PSoC,'%s','y');
    %idn = fscanf(s);
    
    x=0;
 
end

end

    
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global c serial_PSoC
    c=0;
   fclose(serial_PSoC);
   delete(serial_PSoC);
   clear serial_PSoC



% --- Executes during object creation, after setting all properties.
function axes1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to axes1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: place code in OpeningFcn to populate axes1


% --- Executes during object creation, after setting all properties.
function notas_CreateFcn(hObject, eventdata, handles)
% hObject    handle to notas (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

Credits

Jeisson David Torrecilla A

Jeisson David Torrecilla A

2 projects • 5 followers
Sánchez Andrés

Sánchez Andrés

2 projects • 4 followers
I'm a Control Engineering student!
Thanks to sxhxc.

Comments