PIC Lesson: Tilt Sensor


Tilt Sensor adalah sensor yang boleh mengesan kecondongan. Di bawah adalah gambar tilt sensor.

Tilt Sensor

Tilt Sensor Ex

Sensor ini disambungkan 5V, GND, digital signal dan analog signal.

Berikut adalah videonya.

PIC Source Code

/*
Programmer: Shahrulnizam Mat Rejab
PIC (Crystal Frequency):
PIC16F877A (20MHz), PIC16F887 (20MHz), PIC16F1939 (Internal 32MHz) 
PIC18F4520 (10MHz), PIC18F4550 (10MHz), PIC18F46K22 (Internal 16MHz)
Compiler: HI-TECH C for PIC10/12/16 V9.83, PIC18 V9.80
Last Modified: 14 November 2013
Website: http://shahrulnizam.com
*/

#if defined (_16F877A) || (_16F887)
	#define	A0		PORTAbits.RA0
	#define	D0		PORTAbits.RA1
#elif defined (_16F1939) || (_18F4520) || (_18F4550) || (_18F46K22)
	#define	A0		LATAbits.LATA0
	#define	D0		LATAbits.LATA1
#endif
#define	ADC
#define	HD44780

#include "LibraryHardware.h"
#include "LibraryPeripheral.h"
#include "LibraryUniversalDisplay.h"

void setup()
{
initialize();
TRISA=0b00000011;
TRISB=0b00000000;
TRISC=0b00000000;
TRISD=0b00000000;
TRISE=0b00000000;
BUZZER=1;
adc_init(0);
lcd_init();						
lcd_goto(0,0);						
lcd_string(" TILT SENSOR EX ");	
}

void loop()
{
int value;
value=(int)(4.888*adc_read(0));
BUZZER=D0;

lcd_goto(0,1);				
lcd_string(" D0:");	
lcd_number(D0,DEC,1);
lcd_string(" A0:");
lcd_number(value/1000,DEC,1);
lcd_string(".");
lcd_number(value%1000,DEC,3);
lcd_string("V ");

delay(100);
}

5 responses to “PIC Lesson: Tilt Sensor”

  1. berapa? sy berminat. cuma nk tanya, pin A0 dalam litar module tu sendiri sambung ke mana dan dari pin A0 ke board pic sambung ke mana?

Leave a Reply

Your email address will not be published. Required fields are marked *