Examples | Shop
 
Intruder alert with PIR sensor and I2C LCD
 
The following example application demonstrates the versatility of the DS-SXM16S Servo Expansion Module. Not only does the DS-SXM16S enable you to very easily connect servos to a microcontroller (powering the micro and the servos from the same power supply) it also allows you to easily connect digital or analogue sensors and I2C devices.
When the PIR detects movement (within its 5 metre range) an alarm message is displayed on the attached I2C LCD screen. After a five second alarm condition the system again checks for movement. If no movement is detected the screen refreshes and displays an all-clear message.

 

'********************************************************************
'* Description: Intruder alert using DS-PRX Passive Infrared Motion
'* Sensor, LCD I2C Interface Module (2 Line by 20 Characters), Servo
'* Expansion Module DS-SXM16S Controlled by the OOPic/OOPic2
'* Micro-controllers.
'*
'* Created: 31/07/02 Revision: 1.00
'* Written by: Total Robots (Jamie Finnan)
'* TR-001
'********************************************************************

Dim LCD As New oI2c ‘Set up LCD as I2C
Dim PIR As New odio1 ‘Set up PIR as digital input/output
'********************************************************************
Sub Main()
LCD.Node = &h14 'Device address
LCD.Width = cv8bit 'Control info as 1 bit
LCD.Mode = cv10bit 'I2c mode is 1o-bit
LCD.NoInc = cvTrue 'No Increment
LCD.Location = 1 'Point to Register R1
LCD = &h01 'Clear screen command
oopic.delay = 50 'Short delay to stabilise the LCD Module
PIR.IOLine = 1 'Set PIR to Pin 7, I/O 1
PIR.Direction = cvInput 'PIR set to input
'********************************************************************
call Set_up 'Sub routine to stabilise PIR
call OK 'Sub routine for All Clear
call Body 'Sub routine detecting motion @ PIR
End Sub
'*****************************************************************
'*****************************************************************
Sub Set_up() 'Sub-routine to stabilise PIR
'Set the LCDD2 I2c address shifted right by 1 bit
LCD.Node = &h14 'Device address
LCD.Width = cv8bit 'Control info as 1 bit
LCD.Mode = cv10bit 'I2c mode is 1o-bit
LCD.NoInc = cvTrue 'No Increment
LCD.Location = 0 'Points to register R0
LCD = &h20 'Write ' '
LCD = &h20 'Write ' '
LCD = &h20 'Write ' '
LCD = &h20 'Write ' '
LCD = &h49 'Write 'I'
LCD = &h6e 'Write 'n'
LCD = &h69 'Write 'i'
LCD = &h74 'Write 't'
LCD = &h69 'Write 'i'
LCD = &h61 'Write 'a'
LCD = &h6c 'Write 'l'
LCD = &h69 'Write 'i'
LCD = &h73 'Write 's'
LCD = &h69 'Write 'i'
LCD = &h6e 'Write 'n'
LCD = &h67 'Write 'g'
LCD.Location = 1 'Points to register R1
LCD.Value = &hC0 'Command cursor to second line.
LCD.Location = 0 'Return to register R0
LCD = &h20 'Write ' '
LCD = &h20 'Write ' '
LCD = &h20 'Write ' '
LCD = &h20 'Write ' '
LCD = &h50 'Write 'P'
LCD = &h6c 'Write 'l'
LCD = &h65 'Write 'e'
LCD = &h61 'Write 'a'
LCD = &h73 'Write 's'
LCD = &h65 'Write 'e'
LCD = &h20 'Write ' '
LCD = &h57 'Write 'W'
LCD = &h61 'Write 'a'
LCD = &h69 'Write 'i'
LCD = &h74 'Write 't'
LCD = &h20 'Write ' '
LCD = &h20 'Write ' '
LCD = &h20 'Write ' '
LCD = &h20 'Write ' '
LCD = &h20 'Write ' '
oopic.delay = 3000 '30 second delay to allow PIR to stabilise
End Sub
'********************************************************************
Sub Body() 'Sub-routine detecting motion at PIR
Do
if PIR.Value = cvTrue then
call ALARM ' If motion detected then Alarm

End if 'Loop to look for motion.
Loop

End Sub
'********************************************************************
Sub OK() 'Sub-routine to output All clear
'Set the LCDD2 I2c address shifted right by 1 bit
LCD.Location = 1 'Points to register R1
LCD=&h01 'Clear screen command
LCD.Node = &h14 'Device address
LCD.Width = cv8bit 'Control info as 1 bit
LCD.Mode = cv10bit 'I2c mode is 1o-bit
LCD.NoInc = cvTrue 'No Increment
LCD.Location = 0 'Points to register R0
LCD = &h41 'Write 'A'
LCD = &h6c 'Write 'l'
LCD = &h6c 'Write 'l'
LCD = &h20 'Write ' '
LCD = &h43 'Write 'C'
LCD = &h6c 'Write 'l'
LCD = &h65 'Write 'e'
LCD = &h61 'Write 'a'
LCD = &h72 'Write 'r'End Sub
'********************************************************************
Sub ALARM() 'Sub-routine for Alarm
LCD.Location = 1 'Point to Register 1
LCD = &h01 'Clear Screen Command
'Set the LCDD2 I2c address shifted right by 1 bit
LCD.Node = &h14 'Device address
LCD.Width = cv8bit 'Control info as 1 bit
LCD.Mode = cv10bit 'I2c mode is 1o-bit
LCD.NoInc = cvTrue 'No Increment
LCD.Location = 0 'Point to register R0
LCD = &h41 'Write 'A'
LCD = &h4c 'Write 'L'
LCD = &h41 'Write 'A'
LCD = &h52 'Write 'R'
LCD = &h4d 'Write 'M'
oopic.delay = 500 'Delay to display alarm screen
call OK 'Sub-routine for All Clear.
End Sub
'*********************************************************************
'*********************************************************************


Examples | Shop