Patient Monitoring Smart Wheelchair

As part of my final year project our team chose the topic as Patient Monitoring Smart Wheelchair. We wanted to make something for the society. As a part of one of my earlier projects Improving Infrastructure for specially challenged citizens in Vashi we had conducted a survey. We found out that the existing infrastructure in Vashi(Navi Mumbai, India) is not at all disabled friendly and same is the situation in majority of India. On top of that the modern assistive technology is too expensive for the common man or aam aadmi.

proportion of diabled population

Above figure shows the percentage of disabled population to total population in India as per 2011 census. In states like Maharashtra, Andhra Pradesh etc. the percentage is very high.

type of disability

Above figure shows the proportion of disabled population by type of disability. We can see that disability in movement accounts for 20.3 % and multiple disability 7.9%. This led us to the idea of making a smart wheelchair.

rural vs urban

This shows that a major chunk of the disabled population lives in rural India. Our market analysis led us to the finding that all the modern electric wheelchairs available in the market have outrageous price tags.

market analysis

So we decided that our wheelchair would be affordable. Then depending on the analysis of disabilities we found out which all modes should be incorporated into this smart wheelchair.

The modes selected are :

  • Voice control mode
  • Gesture control mode
  • Joystick control mode

Patient monitoring was thought of as an added service. Initially the plan was to measure heart rate, body temperature and blood pressure. But due to time constraints we limited to just measuring body temperature and displaying it on a LCD.

Here is a short video of the completed project.

The bill of materials is as follows.


As you can see we achieved the cost reduction. So that is all from my side in this post. Thank you for patiently reading this and reaching till the end. If you people want a post about the technical details I will require at least 10 Word press likes Winking smile. Share with as many as you can. Maybe someone will take this idea to the next level. Thank you once again for reading this post.


P.S: I just felt like sharing this news article with you all.


Gesture control for PowerPoint presentation

Basic idea of the project

The intention of this tutorial is to learn how to control computer keyboard and mouse events using your micro-controller. For demonstration I have chosen to name the project as gesture control for PowerPoint presentation. At the end of this tutorial you will be able to control the slides using your gestures. Now in order to control the operating system you need a language like python, java, c++ etc. I find python affable and powerful so I’ll be using that for coding. You can use any language you want but the logic and algorithm will remain the same, only the syntax will differ. I won’t be teaching you python in this post that is beyond the scope of this post. If you want to learn the language there is plethora of content available online. You just need a net connection and off you go.
P.S. : If you like the posts do like and share them with others.


Python is an easy to learn high level programming language. It is a beautiful and a very powerful language. The packages that are available make it kind of limitless. Some of the places where python is used are mentioned below.

  • Google makes extensive use of Python in its web search systems.
  • The popular YouTube video sharing service is largely written in Python.
  • The Dropbox storage service codes both its server and desktop client software primarily in Python.
  • The Raspberry Pi single-board computer promotes Python as its educational language.
  • NASA, Los Alamos, Fermilab, JPL, and others use Python for scientific programming tasks.

So we know that most of the big shots use python. Now they use it for a reason and the reason being that its simply an awesome language. If you want to start learning programming you ought to start with python. Here are a list of sites and books that you may use for learning python.

  1. (This is the official page where you can learn how to install the IDE and get started.)
  2. Learning Python, 5th Edition (This is a good book if you are new to programming and otherwise as well.)

Once you get the hang of it then you can directly use the documentations for learning how to use the packages.

pySerial and PyUserInput

We will be requiring these modules in our project. The names are quite self explanatory the former is for serial communication while the latter is for the mouse and keyboard events. The links to these modules are:

Well download these and install them. I recommend you to use 32bit python 2.7 version modules as well as the language. Because most of the modules are available for 2.7 version.

Components and Software requirements

  • A microcontroller board with UART capability e.g. MSP430G2 Launchpad, Arduino Uno board etc.
  • An accelerometer e.g. ADXL335 etc..
  • Python 2.7 , pySerial & PyUserInput modules



I have used fritzing for making this. Here is the link to their home page.


We will calibrate the accelerometer and take readings for left and right position. Use the serial monitor for this. Read my tutorial titled Capacitive Accelerometer Interfacing if you don’t know what I am talking about. Next once you have those digital values you need to make the program for slide control. We know that left arrow and right arrow keys are used for navigation purpose. So in our python script the if statements will contain code for left arrow button press and right arrow button press. Note that you are reading the values that the controller is sending serially using python and taking decisions based on that value.

Energia Code

int x_pin = A0;
void setup()
  // put your setup code here, to run once:

void loop()
  // put your main code here, to run repeatedly:
  int x = analogRead(x_pin);

Python Script

__author__ = 'MANPREET'
This is a file for controlling keyboard events.
from pykeyboard import PyKeyboard
import serial
import time

comPort = raw_input("Please enter the COM port number")
baudRate = raw_input("Please enter the baud rate")
myserial = serial.Serial(comPort, baudRate)
k = PyKeyboard()
TRUE = 1;
    while (TRUE):
        if (myserial.inWaiting()):
            mydata = myserial.readline()
            x = int(mydata)
            if x > 650:
            if x < 550:
except KeyboardInterrupt:

Code Explanation

The Energia code is pretty straightforward but still just to cover that as well. We have declared A0 i.e. P1.0 pin as input and changed the ADC reference voltage to 2.5V in line 7. Next part is just getting the ADC reading and sending it serially.

The python code demands some explanation. So lets begin understanding the code .

from pykeyboard import PyKeyboard
import serial
import time

This code will import three modules PyKeyboard, serial and time. For the pykeyboard we have imported the constructor. Then you have made one object k using the same.

comPort = raw_input("Please enter the COM port number")
baudRate = raw_input("Please enter the baud rate")
myserial = serial.Serial(comPort, baudRate)
k = PyKeyboard()

myserial is an object of the serial module that you have imported. You will use this to access its functions. The raw_input() is for taking the com port and baud rate values from the user. Example COM11 and 9600.

TRUE = 1;
    while (TRUE):
        if (myserial.inWaiting()):
            mydata = myserial.readline()
            x = int(mydata)
            if x > 650:
            if x < 550:
except KeyboardInterrupt:

Well this is an infinite loop and you are checking this block for keyboard interrupt i.e. ctrl+c . This is done so that you can come out of the program properly without having to kill the program. Next we are checking if there is data in the serial buffer. If yes then we are storing it in mydata variable. Convert it into integer and store it as some variable say x. Next step is easy write two if statements and include the code and condition for left arrow button press and right arrow button press. For more details of the PyKeyboard module visit :
For running the python script install python 2.7. Copy paste the python script code into notepad and save it as any name for that matter) Then follow these steps.

  1. Open command prompt(Press windows+r, then type cmd and press enter.)
  2. opening_command_prompt

  3. Change the directory to the one containing your python script i.e. the .py file. Use cd for that.
  4. file_location

  5. Use python for running your code
  6. running the program

  7. For stopping the code press ctrl+c

Thank you for reading the post and hope that it was helpful.If you like the post do share it with others and spread the knowledge.

A taste of Image Processing

Image processing involves extracting information from images and using the information so obtained for various operations and tasks. Don’t confuse image processing image processing with image manipulation that involves adjusting the images. Photoshop and similar software are used for image manipulation.

Application areas

  • Medical Applications
  • Industrial Applications
  • Military Applications: Some of the most challenging and performance-critical scenarios for image processing solutions have been developed for military needs, ranging from detection of soldiers or vehicles to missile guidance and object recognition and reconnaissance tasks using unmanned aerial vehicles (UAVs). In addition, military applications often require the use of different imaging sensors, such as range cameras and thermo-graphic forward-looking infrared (FLIR) cameras.
  • Law Enforcement and Security: Surveillance applications have become one of the most intensely researched areas within the video processing community. Biometric techniques (e.g., fingerprint, face, iris, and hand recognition), which have been the subject of image processing research for more than a decade, have recently become commercially available.
  • Consumer Electronics
  • The World Wide Web

So as we can see image processing has wide areas of application.

That being said you need some software or programming language for making this image processing possible. There are various ways by which this can be done. You can use c, NI LabVIEW, MATLAB etc. for image processing. For this post I’ll be using MATLAB. Now we did this just so as to understand the concepts of image processing. So if you feel that its meagre you can build on this.


close all;
clear all;
video = videoinput('winvideo');%Create video variable

set(video,'FramesPerTrigger',1); % Setting frames per trigger
preview(video);%Preview the video
rgb_image = getsnapshot(video); % Storing Image in an array variable
[y x c]= size(rgb_image); % Determining the size of the captured frame.
x1 = (x/2)-(0.2*x);
x2 = (x/2)+(0.2*x);
y1 = (y/2)-(0.25*y);
y2 = (y/2)+(0.25*y);
global s;
s = serial('COM4')
image = getsnapshot(video);
fR = image(:,:,1);
fG = image(:,:,2);
fB = image(:,:,3);
I = fR>200;
for k=1:n
if x1<cbar<x2 &&  rbar<y1
    disp('Move forward');
    global s;
elseif cbar<x1 && y1<rbar<y2
    disp('Move right');
    global s;
elseif cbar>x2 && y1<rbar<y2
    disp('Move left');
    global s;
elseif x1<cbar<x2 && rbar>y2
    disp('Move back');    
    global s;
elseif x1<cbar<x2 && y1<rbar<y2
    disp('Move stop');
    global s;

Now this is the code. I am thinking I’ll just explain the logic and then you can use MATLAB help for the rest. Seriously the help provides is simply awesome. You can understand how the functions word using the help and then there is the world wide net. So I am assuming that those of you who has interest will read further.

Now let’s begin understanding the code.

video = videoinput(‘winvideo’);

This will create a video object from the available cameras. You can check the available ones by using imaqhwinfo


So for the windows winvideo is installed adapter.


Next give winvideo as the agrument to the imaqhwinfo(). Now if you have an external webcam connected to your computer you will se two device ID’s. So now suppose you want to know about the device with ID=1 all you need to do is pass device ID as second argument.


You can see the properties you the webcam.

So just use the videoinput() for creating a variable attached to the particular webcam in MATLAB. In our case video is the variable.

Next you set the frames per trigger i.e. whenever you give the capture commands how many frames will be captured every time.

Then you see a preview of the video feed so that you come to know what exactly is the camera viewing.

Next up you take a sample shot so as to determine the dimensions of the camera.

You will get a 3D matrix of the image. Extract the x and y resolution.

Now for this application what we will do is divide the webcam field into 9 quadrants and take decision depending on position of the image of the object to be detected.

Now since we wanted to learn the basic we used white light such as a torch as the source. If you have a proper webcam and good lighting conditions you can detect normal coloured balls using this program. All you need to do is some thresholding.

Now as usual open the serial port and send a particular character depending upon the quadrant in which the object lies.

So you basically take a snapshot again and again and manipulate that snap. So each image is made of 3 components red, blue and green. Since we are using white light as the object it does not matter which component you choose. But if there is a particular colour that the object has take that particular matrix. Now do the thresholding so that you get only the torch circle on the screen.

Then you remove the noise and coalesce the remaining parts to form a single body.

Then you calculate the centroid and take decision.


This is a sample of what the image will look like after thresholding. So as you can see it lies in the middle quadrant.

We had written the code such that it will transmit w,a,s,d,f depending on the quadrant. Do top middle corresponds to w and so on you can figure that yourself.

On the controller side we manipulate the data to control the bot.

I’ll be uploading the video soon. Thank you for reading. Hope this was useful.

Serial Communication

Hello!! Before I start this post I want to say that if anyone of you wants to add me to their linkedin network here is my profile link :

Often we need to communicate between two devices. This can be either parallel or serial. In parallel communication there is an individual data line for each bit, so normally there would be 8 data lines for 8 bit data. In asynchronous we require only two lines. One for transmission and the other for reception.


So the main thing in serial communication is ‘baud rate’. It is nothing but the bits sent per second. In serial asynchronous communication the baud rate of both transmitter and receiver have to be equal. If there is any mismatch there is bound to be error in sending and receiving data.

Now you might wonder what is sent serially? The answer is ASCII values of the character or symbol to be transmitted is sent serially. Now ASCII is a 7 bit hex code. There is the extended ASCII code as well. You can find all the ASCII values here.

Now let us take an example. Suppose I want to send character M serially. The ASCII value of M is 0x4D. The binary equivalent is 0b01001101. Now we send this data as pulses, changing the bits after the time 1/baud_rate.


So this is how the serial data looks like. Some of you might have this doubt that how on earth will the processor or controller come to know that the other party is transmitting data and it has to take those bits. This is a very good doubt.

The beginning of serial data is marked by a start bit and on similar grounds there is a stop bit or two. Just like one normally says ‘hello’ at the start of a conversation and ‘bye’ at the end we send the start and stop bits for the same purpose.

The other question that may arise in the mind of the curious is that what if there is noise in the system? This is a valid question as well. So there are error checking bits like parity bits which are sent along with the data serially. (Parity can be even or odd. Now if the system uses even parity, then it will make the number of ‘1’ bits in the data even by adding 1 or 0. So if the data already has even number of ones the even parity bit is 0 and if the data has odd number of ones then the even parity bit is set or is 1 so that the total number of ones in the data is even.) Well this sums up asynchronous serial communication part.

Now this is known as UART module in the microcontrollers. UART stands for universal asynchronous transmitter and receiver. Most modern microcontrollers have a dedicated hardware for asynchronous serial communication called UART. msp430 also has this facility. Now what this means that you have to just configure the peripheral and the baud rate generation, parity bits and all other factors as well as the receiving part is done by this hardware. (If you wanted to send data serially without hardware dedicated for the same you would have to make the port high and low, use delay subroutines and the rotate instructions for doing the same task. The detection will also be tedious.)

This is how the data will look when  you send it via UART module.


Well let’s begin with the USCI module that provided in the msp430 micro controllers. This provides a UART mode for asynchronous serial communication. There are few basic initialization registers like all peripherals of msp430. Note that you can use grace for initializing the UART mode. But I’ll be covering the normal method by using the command registers and configuring it to meet our needs.

Let us begin.

UART mode features include:
• 7- or 8-bit data with odd, even, or non-parity
• Independent transmit and receive shift registers
• Separate transmit and receive buffer registers
• LSB-first or MSB-first data transmit and receive
• Built-in idle-line and address-bit communication protocols for multiprocessor systems
• Receiver start-edge detection for auto-wake up from LPMx modes
• Programmable baud rate with modulation for fractional baud rate support
• Status flags for error detection and suppression
• Status flags for address detection
• Independent interrupt capability for receive and transmit

The list of all registers related to the UART mode are listed below.


Now the procedure how to initialize these registers is given in the msp430g2 user manual.


Just set those bits which you want as per the explanation given in the user guide.

Then there are the UCA0TXBUF and UCA0RXBUF via which the serial data is transmitted and received respectively. If you want to send any character just put it in the UCA0TXBUF register and it will be transmitted. Just check whether the byte has been sent or not by checking the UCA0TXIFG bit of IFG2 register. If it is set means the module is busy sending the previous byte or data and one has to wait till it is reset.

With this background you should be able to program the controller to send and receive data.

Before we shift to the program there is something that I need to tell you. For hardware UART via launchpad without having to use the rs232 cable and max232 IC. For newer launchpad versions i.e. 1.5 and above there is the position of the jumpers printed on the launchpad itself for hardware UART and software UART respectively.

Hardware UART on Launchpad 1.4

If you have a Launchpad of v1.4 (versions that have no ‘Rev x.x’ printed below the ‘MSP-EXP430G2’ label are pre 1.5) is is possible to use hardware UART by replacing the MSP430 with a newer model, such as the MSP430G2553 and then cross connecting the serial pins in header J3 i.e the TXD and RXD(use a cross jumper or female to female wires for the same.)


#include "serial.h"
#include "lcd.h"
int main(void) {
    WDTCTL = WDTPW | WDTHOLD;	// Stop watchdog timer
    IE2 |= UCA0RXIE;
    __bis_SR_register(LPM0_bits + GIE);
#pragma vector=USCIAB0RX_VECTOR
__interrupt void USCI0RX_ISR(void)
	if(UCA0RXBUF == '0')

 *  serial.h
 *  Created on   	: 01-Jan-2014 12:25:06 PM
 *  Author	  	: Manpreet Singh Minhas
 *  Website		:
 *  This is a standard header for 9600 baud rate serial communication.

#ifndef SERIAL_H_
#define SERIAL_H_

#include<msp430g2553.h>// Change this as per your micro-controller chip.
void uart_init(void);
void send_byte(int data);
void print(char *data);
void println(char *data);
void send_int(int a);
void send_intln(int a);
void uart_init()
	P1SEL  |= BIT1|BIT2; // Port for UART transmission and reception purpose.
	P1SEL2 |= BIT1|BIT2;
    UCA0CTL1 |= UCSWRST; // Software reset
    UCA0CTL1 |= UCSSEL_1;// Select ACLK
    UCA0BR0 = 3;// This is the count for getting 9600 baud rate 32768/9600 = 3.4133
    UCA0BR1 = 0;
    UCA0MCTL = UCBRS1 + UCBRS0;// Modulation bits = 0b00000011
    UCA0CTL1 &= ~UCSWRST;	// Start the UART
void send_byte(int data)
	while (!(IFG2&UCA0TXIFG));
	UCA0TXBUF = data;
void print(char *data)
void println(char *data)
void send_int(int a)
	int temp;
	int rev=0;
	int dummy =a;
	 while (dummy)
	      rev = rev * 10;
	      rev = rev + dummy%10;
	      dummy = dummy/10;
		rev /=10;
void send_intln(int a)
	int temp;
	int rev=0;
	int dummy =a;
	 while (dummy)
	      rev = rev * 10;
	      rev = rev + dummy%10;
	      dummy = dummy/10;
		rev /=10;
#endif/* SERIAL_H_ */

Well this program will send the data received serially to lcd. For sending data you will require a software like hyper terminal, putty, energia serial monitor, arduino serial monitor etc. So just configure that to 9600 baud rate with no parity bits and only one stop bit and you are all set to send data serially. If you have any problem you can comment or send me mail.


Interrupt concept and Low Power Modes (LPM)


I had  written about hardware interrupts earlier. Now I’ll write about interrupts in general. How to write program to enable interrupts and handle those. Basically there are two types of interrupts.

  • Hardware Interrupts
  • Software Interrupts

As the name suggests hardware interrupts are given on the pins of the controller. An example of this can be found in by blog post.

Software interrupts on the other hand are made by using software. And these are vectored interrupts i.e. the program counter is loaded with the contents of vector address of the interrupt that occurred. In fact all interrupts are vectored. All peripherals can generate an interrupt specific to their operation.

I’ll be taking the example of TimerA interrupt . But lets see a little theory about how to handle interrupts.

First I’ll tell you what is maskable and non-maskable interrupt.  Maskable interrupts can be disabled using software and non-maskable interrupt cannot be disabled. RST is a non-maskable interrupt. Now masking is done to avoid accidental triggering of the interrupt which can distort the program flow.

All the maskable interrupts have to be enabled. This is done by setting the GIE(General Interrupt Enable) bit of status register. So if you include the msp430.h file you can use the GIE macro defined in the header file and OR(bitwise) it with status register(SR), to enable the interrupts by setting that bit.

Now finally let’s see what happens when an interrupt occurs.


So when an interrupt occurs the PC and SR contents are pushed onto the stack after the current instruction is executed. This is known as context saving. Depending on priority the interrupt with highest priority is processed first. Thus the PC is loaded with the contents of the vector address and context switching takes place.


The image above shows how to return from an Interrupt Sub Routine (ISR). An ISR is nothing but the code you write for handling the interrupt. The address of this ISR is stored at the vector address of the interrupt you want to handle.

One has to use “RETI” instruction to return to the main program. What RETI does is it pops the PC and SR contents back from the stack. Thus original state of program is restored.

Interrupt Vector Addresses

Now these are device specific. So one has to refer datasheet of the required microcontroller for this. Since I’ll be using msp430g2553 for this I’ll post the vector address table for the device.


That is that.

Low Power Modes(LPM) of Operating modes of msp430

Now-a-days its all about reducing the power consumption. And Texas Instruments msp430 is a low power microcontroller. That means that there must be low power modes. Those are nothing but LPM. These are selected by setting or resetting the bits of SR. These modes are well explained in the user guide. I’ll post the page concerning these modes.


All the SCG1,SCG0,OSCOFF,CPUOFF are bits of the status register(SR). You can use the bits defined in the header file for setting these bits. I’ll explain more about this after the program.

Now when you enter a LPM. You can come out of it when there is an interrupt. Now we know that PC and SR are pushed onto the stack. So if you want to come out of the LPM on exit from ISR you need to change the SR contents pushed onto the stack. The process is given in the user guide.


The bic instruction is used to clear the corresponding bits of SR that are used for controlling LPM.

In LPM basically we shut the oscillators which consume the maximum power. Thus depending on your need you can shut down the ACLK,SMCLK,MCLK and DCO.


;Name             : Manpreet Singh Minhas
;Date                 : 22 Nov 2013
;Website        :
;Software        : IAR Embedded Workbench

Aim                  : To blink an LED by using TimerA interrupt and use msp430 in LPM.
#include “msp430g2553.h”     ; Include the header file
ORG 0FFFEH                                                                    ; Power On Reset Vector address
        DW MAIN                                                                    ; Here MAIN is nothing but a macro for 0C000H
                                                                                             ; memory location. You might as well write
                                                                                             ; 0C000h. We try to make the code as reader
                                                                                             ; friendly as possible, that is why MAIN macro.

ORG 0C000H                                                                 ; Starting address of FLASH MEMORY in
                                                                                          ; msp430g2553 where the program will be burnt.
MAIN:        MOV.W #WDTPW|WDTHOLD,&WDTCTL  ; Stop watchdog timer
                  MOV.W #03FFH,SP                                         ; Initialize stack pointer to top of
                  MOV.B #BIT2,&P1DIR                                             ; RAM. You’ll have to use device’s
                  MOV.W #08000H,&TA0CCR0                               ; datasheet for finding this address.
                  BIC.B #BIT2,&P1OUT                                            
                  MOV.W #TASSEL_1|ID_0|MC_1|TAIE,&TA0CTL ; Initialize timer
UP:           MOV.W #LPM3|GIE,SR                                             ; Enable interrupts and enter LPM3
                 JMP UP
TMR_ISR:    XOR.B #BIT2,&P1OUT                                         ; Toggle LED
                      BIC.W #TAIFG,&TA0CTL                                      ; Clear the interrupt flag bit
        DW TMR_ISR

The above code will make led connected P1.2 to blink after 1 sec delay. You can change the BIT2 to BIT0 or BIT6 if you don’t want to use an external LED. I’ve used TimerA in up mode. And I’m using ACLK for this part. I’ve connected a 32kHz crystal there.  So you need to connect it there by soldering. Then it’s given in the user manual that when the count goes from TA0CCR0 value to 0, the TAIFG flag is set. I’ve enabled the interrupts in SR by setting the GIE bit, also you need to enable it in the peripheral’s control register. I’ve enabled the TimerA interrupt by setting TAIE bit of TA0CTL. Now it’s vital to clear the interrupt flag of the interrupt that you are handling. In this case the TAIFG flag in TA0CTL register. So that we can acknowledge the next interrupt. Its easy to forget this so just beware. And regarding the LPM3 macro that I’ve used it just sets the corresponding bits of SR. The definition is:

#define LPM3                (SCG1+SCG0+CPUOFF)

So either you can write LPM3 or the corresponding SR bits. And instead of using mov instruction you can use bis instruction as well.


p>If any doubts feel free to ask. Thank you for reading this. Hope this was useful and informative.