PDA

View Full Version : pc controlled wireless car --this is an embedded project



niranjanjoshi_2288
04-21-2011, 09:49 PM
i have designed a “PC Controlled Wireless Car” by using VB.NET for front-end application and PIC16F676 as microcontroller the for car and RS232 serial port for communication with the hardware.
The project is divided into two parts :
SOFTWARE:
On the computer there is an GUI application program which has 7 buttons for start application ,quit, stop the car and 4 different motor directions. Also there is a button to capture live video from the camera attached to the car and a frame to view the video. When we click any button the specific code is generated for that action.
HARDWARE:
The RF based transmitter and receiver board is designed for wireless motor controlling. Transmitter connects with PC serial (RS232)port and sends command received from the software. Receiver has dual -channel motor driver to control a DC motor (Left, Right etc.). Specially designed for wireless Robot control application.

Hardware Components:
Transmitter
Microcontroller(PIC16F676)
Resistors ( 1 k, 10 k, 680 k )
Capacitors
Ceramic Resonator
GREEN LED (5 mm) and RED LED (5 mm)
RF Transmitter module (434 MHZ)
RTC (Real Time Clock :DS1307)
Relays(CS5-S-DC6V)
Transistor(L7805CV)434 MHz)
HT 12 E Data Encoder
9 V Battery
RS 232 Cable

Receiver:
Resistor ( 220 E, 47 k)
Capacitor (16 V)
GREEN LED( 5 mm)
RF Receiver module (434 MHZ)
L293 Motor Driver
HT 12D Data Decoder
8 way DIP switch
12 V Battery
RS232 Serial Port
Webcam/IP Camera
Other Components Used:
2 DC Motors 300 R/12V.
2 Wheels with rubber tires.
1 Bearing wheel.
Tin body for car.



i have also attached some images have a look:)
inspiration of this post:
http://www.roboticsindia.com/showthread.php/3862-Pc-operated-wireless-camera-car-project-for-sale%28complete-project-ready%29:p

niranjanjoshi_2288
04-21-2011, 09:53 PM
gui:
The GUI application is developed in VB.net programming language.
Communication with hardware is done using Microsoft Communications Control (COM component MSComm).
Command Buttons for each movement of the car (Forward, Reverse, Left, Right, Stop) are provided .

Data from camera is displayed in frame and using SaveFileDialog the picture is captured and saved at desired location in the PC.

niranjanjoshi_2288
04-21-2011, 09:54 PM
code for gui::
' Name: Wireless Car Controlled By Computer
Imports System.Runtime.InteropServices


Public Class Form1

Const cam As Short = &H400S

Const cam_DRIVER_CONNECT As Integer = cam + 10
Const cam_DRIVER_DISCONNECT As Integer = cam + 11
Const cam_Save As Integer = cam + 30

Const cam_SET_PREVIEW As Integer = cam + 50
Const cam_SET_PREVIEWRATE As Integer = cam + 52
Const cam_SET_SCALE As Integer = cam + 53
Const WS_CHILD As Integer = &H40000000
Const WS_VISIBLE As Integer = &H10000000
Const SWP_NOMOVE As Short = &H2S
Const SWP_NOSIZE As Short = 1
Const SWP_NOZORDER As Short = &H4S
Const HWND_BOTTOM As Short = 1

Dim iDevice As Integer = 0 ' Current device ID
Dim hHwnd As Integer ' Handle to preview window

Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, _
<MarshalAs(UnmanagedType.AsAny)> ByVal lParam As Object) As Integer

Declare Function SetWindowPos Lib "user32" Alias "SetWindowPos" (ByVal hwnd As Integer, _
ByVal hWndInsertAfter As Integer, ByVal x As Integer, ByVal y As Integer, _
ByVal cx As Integer, ByVal cy As Integer, ByVal wFlags As Integer) As Integer

Declare Function DestroyWindow Lib "user32" (ByVal hndw As Integer) As Boolean

Declare Function capCreateCaptureWindowA Lib "avicap32.dll" _
(ByVal lpszWindowName As String, ByVal dwStyle As Integer, _
ByVal x As Integer, ByVal y As Integer, ByVal nWidth As Integer, _
ByVal nHeight As Short, ByVal hWndParent As Integer, _
ByVal nID As Integer) As Integer

Declare Function capGetDriverDescriptionA Lib "avicap32.dll" (ByVal wDriver As Short, _
ByVal lpszName As String, ByVal cbName As Integer, ByVal lpszVer As String, _
ByVal cbVer As Integer) As Boolean
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Option1.Checked = True
PWR.Status = False
PWR.blink = False
Led4.Visible = False
Led5.Visible = False
Led6.Visible = False
Led7.Visible = False
Led8.Visible = False
Command4.Enabled = False
Command5.Enabled = False
Command6.Enabled = False
Command7.Enabled = False
Command8.Enabled = False
' Camera Coding
LoadDeviceList()
If lstDevices.Items.Count > 0 Then

lstDevices.SelectedIndex = 0

Else
lstDevices.Items.Add("No Capture Device")

End If


End Sub



Private Sub AxMSComm1_OnComm(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AxMSComm1.OnComm

End Sub

Private Sub QUIT_CMD_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles QUIT_CMD.Click
If AxMSComm1.PortOpen = True Then
AxMSComm1.PortOpen = False
PWR.blink = False
End If
ClosePreviewWindow()
End

End Sub

Private Sub START_CMD_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles START_CMD.Click
iDevice = lstDevices.SelectedIndex
OpenPreviewWindow()
If AxMSComm1.PortOpen = False Then
If Option1.Checked = True Then
AxMSComm1.PortOpen = True
PWR.Status = True
PWR.blink = True
End If

If Option2.Checked = True Then
AxMSComm1.PortOpen = True
PWR.Status = True
PWR.blink = True
End If
End If
Command4.Enabled = True
Command5.Enabled = True
Command6.Enabled = True
Command7.Enabled = True
Command8.Enabled = True
'btnCapture.Enabled = True

End Sub

Private Sub Led4_MouseDownEvent(ByVal sender As System.Object, ByVal e As AxPLed.__Led_MouseDownEvent) Handles Led4.MouseDownEvent

End Sub

Private Sub Command4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Command4.Click
If Led4.Visible = False Then
Led4.Visible = True
AxMSComm1.Output = "DATA" + "006" + Chr(13)
Else
Led4.Visible = False
AxMSComm1.Output = "DATA" + "006" + Chr(13)
End If

End Sub

Private Sub Command5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Command5.Click
If Led5.Visible = False Then
Led5.Visible = True
AxMSComm1.Output = "DATA" + "009" + Chr(13)
Else
Led5.Visible = False
AxMSComm1.Output = "DATA" + "009" + Chr(13)
End If

End Sub

Private Sub Command6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Command6.Click

If Led6.Visible = False Then
Led6.Visible = True
AxMSComm1.Output = "DATA" + "000" + Chr(13)
Else
Led6.Visible = False
AxMSComm1.Output = "DATA" + "000" + Chr(13)
End If
End Sub

Private Sub Command7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Command7.Click

If Led7.Visible = False Then
Led7.Visible = True
AxMSComm1.Output = "DATA" + "002" + Chr(13)
Else
Led7.Visible = False
AxMSComm1.Output = "DATA" + "002" + Chr(13)
End If
End Sub

Private Sub Command8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Command8.Click

If Led8.Visible = False Then
Led8.Visible = True
AxMSComm1.Output = "DATA" + "004" + Chr(13)
Else
Led8.Visible = False
AxMSComm1.Output = "DATA" + "004" + Chr(13)
End If

End Sub
Private Sub LoadDeviceList()
Dim strName As String = Space(100)
Dim strVer As String = Space(100)
Dim bReturn As Boolean
Dim x As Integer = 0

'
' Load name of all avialable devices into the lstDevices
'

Do
'
' Get Driver name and version
'
bReturn = capGetDriverDescriptionA(x, strName, 100, strVer, 100)

'
' If there was a device add device name to the list
'
If bReturn Then lstDevices.Items.Add(strName.Trim)
x += 1
Loop Until bReturn = False
End Sub

Private Sub OpenPreviewWindow()
Dim iHeight As Integer = picCapture.Height
Dim iWidth As Integer = picCapture.Width

'
' Open Preview window in picturebox
'
hHwnd = capCreateCaptureWindowA(iDevice, WS_VISIBLE Or WS_CHILD, 0, 0, 640, _
480, picCapture.Handle.ToInt32, 0)

'
' Connect to device
'
If SendMessage(hHwnd, cam_DRIVER_CONNECT, iDevice, 0) Then
'
'Set the preview scale
'
SendMessage(hHwnd, cam_SET_SCALE, True, 0)

'
'Set the preview rate in milliseconds
'
SendMessage(hHwnd, cam_SET_PREVIEWRATE, 66, 0)

'
'Start previewing the image from the camera
'
SendMessage(hHwnd, cam_SET_PREVIEW, True, 0)

'
' Resize window to fit in picturebox
'
SetWindowPos(hHwnd, HWND_BOTTOM, 0, 0, picCapture.Width, picCapture.Height, _
SWP_NOMOVE Or SWP_NOZORDER)

btnCapture.Enabled = True

Else
'
' Error connecting to device close window
'
DestroyWindow(hHwnd)

btnCapture.Enabled = False
End If
End Sub



Private Sub ClosePreviewWindow()
'
' Disconnect from device
'
SendMessage(hHwnd, cam_DRIVER_DISCONNECT, iDevice, 0)

'
' close window
'

DestroyWindow(hHwnd)
End Sub

Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing

If AxMSComm1.PortOpen = True Then
AxMSComm1.PortOpen = False
PWR.blink = False
End If
ClosePreviewWindow()
End
End Sub



Private Sub btnCapture_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCapture.Click
Dim data As IDataObject
Dim bmap As Image

'
' Copy image to clipboard
'
SendMessage(hHwnd, cam_Save, 0, 0)

'
' Get image from clipboard and convert it to a bitmap
'
data = Clipboard.GetDataObject()
If data.GetDataPresent(GetType(System.Drawing.Bitmap) ) Then
bmap = CType(data.GetData(GetType(System.Drawing.Bitmap)) , Image)
picCapture.Image = bmap
' ClosePreviewWindow()


If sfdImage.ShowDialog = DialogResult.OK Then
bmap.Save(sfdImage.FileName, Imaging.ImageFormat.Bmp)
End If

End If
End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

End Sub

Private Sub lstDevices_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstDevices.SelectedIndexChanged

End Sub
Private Sub picCapture_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles picCapture.Click
End Sub
End Class

niranjanjoshi_2288
04-21-2011, 09:54 PM
microcontroller:
The microcontroller coding is done using assembly language.

The input and output is done using functions like Serin and Serout respectively.

The microcontroller acts like the brain of the system.

It generates the commands which tell the car where to go and what movement to follow.

niranjanjoshi_2288
04-21-2011, 09:55 PM
code:
Include = PIC16F676.LIB

#Define RXD PORTC,5
#Define TXD PORTC,4
#Define TE PORTA,2
#Define D0 PORTC,0
#Define D1 PORTC,1
#Define D2 PORTC,2
#Define D3 PORTC,3

Bsf STATUS,5
ram_bank = 1
Clrf ANSEL
Movlw 7
Bcf STATUS,5
ram_bank = 0
Movwf CMCON
ANSEL = 0 ' DISABLE THE ANALOG INPUT
Bsf STATUS,5
ram_bank = 1
Clrf ANSEL

Movlw 7
Bcf STATUS,5
ram_bank = 0
Movwf CMCON
Bsf STATUS,5

Bsf OPTION_REG,7

Movlw 1
Bcf STATUS,5
Movwf PP1H
Movlw 244
Call dly@w

Movlw PORTC
Movwf GEN
Movlw 16
Movwf GENH
Movlw 64
Movwf PP5H
Movlw 84
Movwf PP5
Clrf GEN3H
Clrf GEN3
Movlw 32
Movwf BPFH
Movlw 37
Call Serout
Movlw 37
Call Serout
Movlw 37
Call Serout
Movlw 37
Call Serout
Movlw 37
Call Serout
Movlw 37
Call Serout
Movlw 37
Call Serout
Movlw 37
Call Serout
Movlw 37
Call Serout
Movlw 46
Call Serout
Movlw 46
Call Serout
Movlw 46
Call Serout
Movlw 46
Call Serout
Movlw 46
Call Serout
Movlw 46
Call Serout
Movlw 46
Call Serout
Movlw 46
Call Serout
Movlw 46
Call Serout
Movlw 46
Call Serout
Movlw 46
Call Serout
Movlw 46
Call Serout
Movlw 46
Call Serout
Movlw 46
Call Serout
Movlw 46
Call Serout
Movlw 10
Call Serout
Movlw 13
Call Serout
Movlw 100
Call dl@ms
MAIN
Bsf PORTA,2
Bsf PORTC,0
Bsf PORTC,1
Bsf PORTC,2
Bsf PORTC,3

Movlw PORTC
Movwf GEN
Movlw 32
Movwf GENH
Movlw 64
Movwf PP5H
Movlw 84
Movwf PP5
Pb@lb2
Call Serin
Sublw 68
Btfss STATUS,2
Goto Pb@lb2
Call Serin
Sublw 65
Btfss STATUS,2
Goto Pb@lb2
Call Serin
Sublw 84
Btfss STATUS,2
Goto Pb@lb2
Call Serin
Sublw 65
Btfss STATUS,2
Goto Pb@lb2
Movlw 5
Movwf RPFH
Movlw 3
Movwf GEN4H
Call in@dec
Movwf TEMP
Movlw 10
Call dl@ms

Bcf PORTA,2
Bcf STATUS,1
Btfsc TEMP,0
Bsf STATUS,1
Btfsc STATUS,1
Bsf PORTC,0
Btfss STATUS,1
Bcf PORTC,0

Bcf STATUS,1
Btfsc TEMP,1
Bsf STATUS,1
Btfsc STATUS,1
Bsf PORTC,1
Btfss STATUS,1
Bcf PORTC,1

Bcf STATUS,1
Btfsc TEMP,2
Bsf STATUS,1
Btfsc STATUS,1
Bsf PORTC,2
Btfss STATUS,1
Bcf PORTC,2

Bcf STATUS,1
Btfsc TEMP,3
Bsf STATUS,1
Btfsc STATUS,1
Bsf PORTC,3
Btfss STATUS,1
Bcf PORTC,3

Movlw 200
Call dl@ms
Bsf PORTA,2
Goto MAIN

LIST
END

i have also attached some images have a look:)


microcontroller:
The microcontroller coding is done using assembly language.

The input and output is done using functions like Serin and Serout respectively.

The microcontroller acts like the brain of the system.

It generates the commands which tell the car where to go and what movement to follow.

code:
Include = PIC16F676.LIB

#Define RXD PORTC,5
#Define TXD PORTC,4
#Define TE PORTA,2
#Define D0 PORTC,0
#Define D1 PORTC,1
#Define D2 PORTC,2
#Define D3 PORTC,3

Bsf STATUS,5
ram_bank = 1
Clrf ANSEL
Movlw 7
Bcf STATUS,5
ram_bank = 0
Movwf CMCON
ANSEL = 0 ' DISABLE THE ANALOG INPUT
Bsf STATUS,5
ram_bank = 1
Clrf ANSEL

Movlw 7
Bcf STATUS,5
ram_bank = 0
Movwf CMCON
Bsf STATUS,5

Bsf OPTION_REG,7

Movlw 1
Bcf STATUS,5
Movwf PP1H
Movlw 244
Call dly@w

Movlw PORTC
Movwf GEN
Movlw 16
Movwf GENH
Movlw 64
Movwf PP5H
Movlw 84
Movwf PP5
Clrf GEN3H
Clrf GEN3
Movlw 32
Movwf BPFH
Movlw 37
Call Serout
Movlw 37
Call Serout
Movlw 37
Call Serout
Movlw 37
Call Serout
Movlw 37
Call Serout
Movlw 37
Call Serout
Movlw 37
Call Serout
Movlw 37
Call Serout
Movlw 37
Call Serout
Movlw 46
Call Serout
Movlw 46
Call Serout
Movlw 46
Call Serout
Movlw 46
Call Serout
Movlw 46
Call Serout
Movlw 46
Call Serout
Movlw 46
Call Serout
Movlw 46
Call Serout
Movlw 46
Call Serout
Movlw 46
Call Serout
Movlw 46
Call Serout
Movlw 46
Call Serout
Movlw 46
Call Serout
Movlw 46
Call Serout
Movlw 46
Call Serout
Movlw 10
Call Serout
Movlw 13
Call Serout
Movlw 100
Call dl@ms
MAIN
Bsf PORTA,2
Bsf PORTC,0
Bsf PORTC,1
Bsf PORTC,2
Bsf PORTC,3

Movlw PORTC
Movwf GEN
Movlw 32
Movwf GENH
Movlw 64
Movwf PP5H
Movlw 84
Movwf PP5
Pb@lb2
Call Serin
Sublw 68
Btfss STATUS,2
Goto Pb@lb2
Call Serin
Sublw 65
Btfss STATUS,2
Goto Pb@lb2
Call Serin
Sublw 84
Btfss STATUS,2
Goto Pb@lb2
Call Serin
Sublw 65
Btfss STATUS,2
Goto Pb@lb2
Movlw 5
Movwf RPFH
Movlw 3
Movwf GEN4H
Call in@dec
Movwf TEMP
Movlw 10
Call dl@ms

Bcf PORTA,2
Bcf STATUS,1
Btfsc TEMP,0
Bsf STATUS,1
Btfsc STATUS,1
Bsf PORTC,0
Btfss STATUS,1
Bcf PORTC,0

Bcf STATUS,1
Btfsc TEMP,1
Bsf STATUS,1
Btfsc STATUS,1
Bsf PORTC,1
Btfss STATUS,1
Bcf PORTC,1

Bcf STATUS,1
Btfsc TEMP,2
Bsf STATUS,1
Btfsc STATUS,1
Bsf PORTC,2
Btfss STATUS,1
Bcf PORTC,2

Bcf STATUS,1
Btfsc TEMP,3
Bsf STATUS,1
Btfsc STATUS,1
Bsf PORTC,3
Btfss STATUS,1
Bcf PORTC,3

Movlw 200
Call dl@ms
Bsf PORTA,2
Goto MAIN

LIST
END

niranjanjoshi_2288
04-21-2011, 09:57 PM
Why a PC Controlled Wireless Car?
The project provides a simple design which can be used in various situations and areas with little additions to meet specific goals.

The areas of application of this project are as follows:

Military: to do recee operations, mine detection, patrolling in enemy territory etc.

Wild Life Research: to reach in areas like snake holes, burrows, caves and dens for studying animals in their natural environment without disturbing them.

Search & Rescue: to reach rough terrain, under debris etc to search for trapped victims.

Security: in malls, parking lots, buildings and basements for detecting bombs & other such threats.

Industries: to move materials and goods from one place to other.

At Home: as a luxury product to get things at the click of mouse buttons.

shobhitkukreti
04-21-2011, 10:42 PM
Vikas, please get this post formatted and post it under articles