UltraSonic Sensors

Ebay Kit
The Sensor is powered by a +5v rail from pin 2 of the Pi. The trigger pin comes from pin 16 (Gpio23) and this tell the sensor to start measuring. The echo pin in normally low until the sensor sends an output then it goes +5v for the time the sensor took to measure the distance. This is the reason for the resistors as the GPIO can only handle a +3.3v.

Diagram

The Code

#!/usr/bin/python
# Import required Python libraries
import time
import RPi.GPIO as GPIO
# Use BCM GPIO references
# instead of physical pin numbers
GPIO.setmode(GPIO.BCM)
#
# Define GPIO to use on Pi
GPIO_TRIGGER = 23
GPIO_ECHO = 24
#
print "Ultrasonic Measurement"
#
# Set pins as output and input
GPIO.setup(GPIO_TRIGGER,GPIO.OUT) # Trigger
GPIO.setup(GPIO_ECHO,GPIO.IN) # Echo
#
# Set trigger to False (Low)
GPIO.output(GPIO_TRIGGER, False)
#
# Allow module to settle
time.sleep(0.5)
#
# Send 10us pulse to trigger
GPIO.output(GPIO_TRIGGER, True)
time.sleep(0.00001)
GPIO.output(GPIO_TRIGGER, False)
start = time.time()
while GPIO.input(GPIO_ECHO)==0:
start = time.time()
#
while GPIO.input(GPIO_ECHO)==1:
stop = time.time()
#
# Calculate pulse length
elapsed = stop-start
#
# Distance pulse travelled in that time is time
# multiplied by the speed of sound (cm/s)
distance = elapsed * 34000
#
# That was the distance there and back so halve the value
distance = distance / 2
#
print "Distance : %.1f" % distance
#
# Reset GPIO settings
GPIO.cleanup()

  

Time Lapse Code for the Raspberry.

2013-08-04 12.47.47

Ingredients 

1. Raspberry Pi with network / internet connection.

2. Camera

3. Something to support your camera .Lego works great .

2013-08-04 12.47.47

 

 

 

 

 

 

 

Pre Heat ( software you need to download)

Log into the pi via SSH and run the command sudo apt-get install memcoder 

This is the only bit of extra software you need it encodes all the pictures into a video at full HD.

Cooking ( adding it all together )

Create a folder called TL  ( mkdir TL ) and change directory into it ( cd TL )

To run the time lapse run the command

raspistill -o myimage_%04d.jpg -tl 30000 -t 43200000

Ok let`s break it down raspstill – o means take a picture with options

myimage is the file name and the _%04d increments by 1 each time a picture is takin .jpg is the file format.

-tl 30000 is the time between pictures . 30000 = 30 seconds.

-t 43200000 is the time for the project to run. 43200000 = 12 hours there 3600000 milli seconds in 1 hour.

Ok it should happily be taking pictures  just run ls -l to see all the pictures.

When it`s finished it run , run the command ls *.jpg > stills.txt this will create a text file form the mencoder software.

and finally run mencoder -nosound -ovc lavc -lavcopts vcodec=mpeg4:aspect=16/9:vbitrate=8000000 -vf scale=1920:1080 -o tlcam.avi -mf type=jpeg:fps=24 mf://@stills.txt

This will create the video file for you . I like doing on the PI however some people say it does run slow I don`t care it`s taking 12 hours to make whats and 30mins. Transfer the file or watch it on the Pi and hay presto you just cooked a Time Lapse.

One tip if your going to do a night shot then cover the led if your filming through a windows the reflection is a pain and could wreck the video.

<?php echo “Hello World”; ?>