how would you work out speed between two sensors which is 500m apart. using speed=distance/time. when the car enters the first sensor say the time was 3:00 58 seconds. and the second sensor is 3:01 26 seconds. then the difference between the times ill be used in the formula, so speed=100/0.28. and if the car is over the sped limit the number plate will be recorded.

If this is a question in the python programming forum, you could start reformulating the problem by introducing your program. What should your program do ? How will it read the sensors values, how does it now the distance between the two sensors ? What should it do with the speed value ? Should it trigger a camera to record the number plate ? etc.

import time
Start = input("Press enter to show when you enter the first sensor: ")
Starttime = time.time()
Stop = input("Press enter to stop to show when you leave the last sensor: ")
Stoptime = time.time()
Dist = 0
Dist2 = input("Enter distance between two sensors in metres: ")
time = Stoptime-Starttime
print(time)
Distance = int(Dist2) - Dist
print(Distance)
Speed = int(Distance)/ time
print(Speed)

this is the programme so far but im unsure on how to record the number plate if the car is over the speed limit, i used the time module as a stopwatch. but how do i get the number plate in

Your program could generate a random plate. The rules for the UK are described here Click Here. A first way to choose randomly is to have a list and use the function random.choice

import random

plate_list = [
    'BD51 SMR','FF32 SVI','LK43 TLJ','NR21 QBU',
    'RY58 TVC','VA35 FNR', 'WO73 DGG']
plate = random.choice(plate_list)

Maybe of some help ...

import datetime as dt

# the two measured times in format hh:mm:ss
tm1 = "3:00:58"
tm2 = "3:01:26"

h1, m1, s1 = tm1.split(':')
h2, m2, s2 = tm2.split(':')

d1 = dt.timedelta(hours=int(h1), minutes=int(m1), seconds=int(s1))
d2 = dt.timedelta(hours=int(h2), minutes=int(m2), seconds=int(s2))
# time difference
delta = d2 - d1
# total seconds
seconds = delta.seconds
# time needed in hours
hours = seconds/3600.0

# distance needed in km
meters = 500
kilometers = meters/1000.0

speed = kilometers/hours

print("car moved {} meters in {} seconds".format(meters, seconds))
print("speed = {:0.2f} km/hr".format(speed))

''' result ...
car moved 500 meters in 28 seconds
speed = 64.29 km/hr
'''
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.