Вы находитесь на странице: 1из 19

Digital Bicycle Speedometer

By

Nitish Kumar Aerospace 4 th year IIST

Concept for measuring speed

RPM of wheel is measured by using IR sensor which is mounted in such a way that whenever one rotation is completed an interrupt is generated which keeps on increasing by one till another interrupt for one second is generated (using TIMERS). On 1sec interrupt counter for rotation is set zero and RPM is calculated using formula

for rotation is set zero and RPM is calculated using formula Diameter of wheel is assumed
for rotation is set zero and RPM is calculated using formula Diameter of wheel is assumed
for rotation is set zero and RPM is calculated using formula Diameter of wheel is assumed
for rotation is set zero and RPM is calculated using formula Diameter of wheel is assumed

Diameter of wheel is assumed to be “29 inch wheels/ISO 622” i.e. 0.7366 m

formula Diameter of wheel is assumed to be “ 29 inch wheels/ISO 622 ” i.e. 0.7366

Figure 1 Black & white ring

This black & white ring will we attached to the wheel by fixing it on spokes and sensor will face this ring for sensing rotation. The black portion of this ring will absorb the IR light while white portion while white portion will reflect it, hence two regions will we detected. In this way we will detect the rotation of wheel.

Construction for IR sensor

Figure 2 Components Required

S.No Item Value Quantity 1 NE555N 1 2 C1 & C2 10 nf 2 3
S.No
Item
Value
Quantity
1
NE555N
1
2
C1 & C2
10 nf
2
3
POT
4.7
k Ω
1
4
IR LED
1
5
R1
470
Ω
1
6
R2
22 Ω
1
7
TSOP1738
1
8
Capacitor
4.7 µf
1
9
Resistor
100
Ω
1

Figure 3 Schematic for IR Transmitter

Figure 3 Schematic for IR Transmitter Figure 4 Schematic for IR Receiver The POT shown in

Figure 4 Schematic for IR Receiver

The POT shown in figure 1 is adjusted in such a way that the square wave generated lies between 37 to 42 kHz so that the IR led glows in this frequency range.

Working of Sensor

When IR light of above frequency falls on TSOP1738 then its output becomes low and when it is not receiving any light then its output is high. So this transmission cause change from high to low which is sensed by microcontroller by using interrupt.

cause change from high to low which is sensed by microcontroller by using interrupt. Figure 5
cause change from high to low which is sensed by microcontroller by using interrupt. Figure 5

Figure 5 Fabricated IR Sensor

Figure 6 Assembled sensor

Figure 6 Assembled sensor

Construction for Display unit

For displaying the speed I have used 16x2 LCD which is connected to microcontroller port through the circuit shown below

to microcontroller port through the circuit shown below Figure 7 LCD Pins Figure 8 LCD is

Figure 7 LCD Pins

to microcontroller port through the circuit shown below Figure 7 LCD Pins Figure 8 LCD is

Figure 8 LCD is connected in 4 bit mode

Figure 9 Fabricated LCD Connector Power Supply Unit Figure 10 LCD & Connector Overview of
Figure 9 Fabricated LCD Connector Power Supply Unit Figure 10 LCD & Connector Overview of

Figure 9 Fabricated LCD Connector

Figure 9 Fabricated LCD Connector Power Supply Unit Figure 10 LCD & Connector Overview of circuit

Power Supply Unit

Figure 10 LCD & Connector

Overview of circuit

Figure 9 Fabricated LCD Connector Power Supply Unit Figure 10 LCD & Connector Overview of circuit

Figure 11 4-Bridge Rectifier circuit for Rectification

Figure 12 Components Required

S.No Item Value Quantity 1 LM7805 1 2 Capcitor C1 & C2 100 µf 2
S.No
Item
Value
Quantity
1 LM7805
1
2 Capcitor C1 & C2
100 µf
2
3 1N4007
4
4 Some wires

Voltage regulator circuit

µf 2 3 1N4007 4 4 Some wires Voltage regulator circuit Figure 13 Fabricated 5v Supply

Figure 13 Fabricated 5v Supply

This circuit provides the 5 v input supply for microcontroller and LCD

4-Bridge Rectifire circuit

4-Bridge Rectifire circuit Figure 14 Fabricated 4-bridge circuit This circuit provides the DC supply to the
4-Bridge Rectifire circuit Figure 14 Fabricated 4-bridge circuit This circuit provides the DC supply to the

Figure 14 Fabricated 4-bridge circuit

This circuit provides the DC supply to the voltage regulator

Program

/*****************************************************

This program was produced by the

CodeWizardAVR V2.05.0 Professional

Automatic Program Generator

© Copyright 1998-2010 Pavel Haiduc, HP InfoTech s.r.l.

http://www.hpinfotech.com

Project : Speedometer

Version : 1.0

Date

: 2/29/2012

Author : Nitish Kumar

Company : IIST

Comments: The Fuse bits must be set as follows

HIGH=D9

LOW=E1

The above fuse setting is for 1MHz

1.Sensor used is IR

2.Interrupt 0 is used to sense one rotation

3.Timer 1 is used for 1s time base

4.PORTB is connected to LCD

Chip type

: ATmega32L

Program type

: Application

AVR Core Clock frequency: 1.000000 MHz

Memory model

: Small

External RAM size

: 0

Data Stack size

: 512

*****************************************************/

#include <mega32.h>

#include <delay.h>

// Alphanumeric LCD Module functions

#include <alcd.h>

// Declare your global variables here

int count=0;

int rpm=0;

int rps=0;

int speed=0;

int distance=0;

int dis_count=0;

# define M_PI

3.14159265358979323846

void lcd_int( int val,unsigned int field_length)

{

/***************************************************************

This function writes a integer type value to LCD module

Arguments:

1)int val

: Value to print

2)unsigned int field_length : total length of field in which the value is printed

must be between 1-5 if it is -1 the field length is no of digits in the val

****************************************************************/

unsigned char str[5]={0,0,0,0,0};

unsigned int i=4,j=0;

while(val)

{

str[i]=val%10;

val=val/10;

i--;

}

if(field_length==-1)

while(str[j]==0) j++;

else

j=5-field_length;

if(val<0)

lcd_putchar('-');

for(i=j;i<5;i++)

{

lcd_putchar(48+str[i]);

}

}

// External Interrupt 0 service routine

interrupt [EXT_INT0] void ext_int0_isr(void)

{

// Place your code here

count++;

}

// Timer 1 output compare A interrupt service routine

interrupt [TIM1_COMPA] void timer1_compa_isr(void)

{

// Place your code here

rps=count;

rpm=rps*60;

speed = (int)((M_PI*0.7366*rpm*60)/1000);

dis_count=dis_count+count;

if(dis_count>44)

{

distance=distance+1;

dis_count=0;

}

count=0;

}

void main(void)

{

// Declare your local variables here

// Input/Output Ports initialization

// Port A initialization

// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In

// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T

PORTA=0x00;

DDRA=0x00;

// Port B initialization

// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In

// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T

PORTB=0x00;

DDRB=0x00;

// Port C initialization

// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In

// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T

PORTC=0x00;

DDRC=0x00;

// Port D initialization

// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In

// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T

PORTD=0x00;

DDRD=0x00;

// Timer/Counter 0 initialization

// Clock source: System Clock

// Clock value: Timer 0 Stopped

// Mode: Normal top=0xFF

// OC0 output: Disconnected

TCCR0=0x00;

TCNT0=0x00;

OCR0=0x00;

// Timer/Counter 1 initialization

// Clock source: System Clock

// Clock value: 0.977 kHz

// Mode: CTC top=OCR1A

// OC1A output: Discon.

// OC1B output: Discon.

// Noise Canceler: Off

// Input Capture on Falling Edge

// Timer1 Overflow Interrupt: Off

// Input Capture Interrupt: Off

// Compare A Match Interrupt: On

// Compare B Match Interrupt: Off

TCCR1A=0x00;

TCCR1B=0x0D;

TCNT1H=0x00;

TCNT1L=0x00;

ICR1H=0x00;

ICR1L=0x00;

OCR1AH=0x03;

OCR1AL=0xD0;

OCR1BH=0x00;

OCR1BL=0x00;

// Timer/Counter 2 initialization

// Clock source: System Clock

// Clock value: Timer2 Stopped

// Mode: Normal top=0xFF

// OC2 output: Disconnected

ASSR=0x00;

TCCR2=0x00;

TCNT2=0x00;

OCR2=0x00;

// External Interrupt(s) initialization

// INT0: On

// INT0 Mode: Falling Edge

// INT1: Off

// INT2: Off

GICR|=0x40;

MCUCR=0x02;

MCUCSR=0x00;

GIFR=0x40;

// Timer(s)/Counter(s) Interrupt(s) initialization

TIMSK=0x10;

// USART initialization

// USART disabled

UCSRB=0x00;

// Analog Comparator initialization

// Analog Comparator: Off

// Analog Comparator Input Capture by Timer/Counter 1: Off

ACSR=0x80;

SFIOR=0x00;

// ADC initialization

// ADC disabled

ADCSRA=0x00;

// SPI initialization

// SPI disabled

SPCR=0x00;

// TWI initialization

// TWI disabled

TWCR=0x00;

// Alphanumeric LCD initialization

// Connections specified in the

// Project|Configure|C Compiler|Libraries|Alphanumeric LCD menu:

// RS - PORTB Bit 0

// RD - PORTB Bit 1

// EN - PORTB Bit 2

// D4 - PORTB Bit 4

// D5 - PORTB Bit 5

// D6 - PORTB Bit 6

// D7 - PORTB Bit 7

// Characters/line: 16

lcd_init(16);

lcd_gotoxy(3,0) ;

lcd_putsf("Speedometer");

lcd_gotoxy(0,1);

lcd_putsf("- by Nitish IIST") ;

delay_ms(1000);

lcd_clear();

lcd_gotoxy(3,0) ;

lcd_putsf("Speedometer");

lcd_gotoxy(12,1);

lcd_putsf("kmph");

lcd_gotoxy(5,1);

lcd_putsf("mt");

// Global enable interrupts

#asm("sei")

while (1)

{

// Place your code here

lcd_gotoxy(1,1);

lcd_int(distance,4);

lcd_gotoxy(9,1);

lcd_int(speed,3);

}

}