Selfie with Raspberry Pi

INTRODUCTION

In this lesson, we will learn on how to use a push button to take a selfie using a Pi Camera. It’s simple and easy project to do.  

HARDWARE PREPARATION

This tutorial use :

  1. Raspberry Pi
  2. Maker pHAT
  3. USB Micro B Cable
  4. Raspberry Pi 8MP Camera Module

You can make the hardware connection based on the diagram and table below.

Sample Code

This is the sample code used for this tutorial. Try it!

import RPi.GPIO as GPIO
from picamera import PiCamera
import time
from time import sleep
camera = PiCamera()
Button = 20
Buzzer = 26
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(Button, GPIO.IN, GPIO.PUD_UP)
GPIO.setup(Buzzer,GPIO.OUT)
def beep(times, sec):
for x in range(times):
GPIO.output(Buzzer,GPIO.HIGH)
sleep(sec)
GPIO.output(Buzzer,GPIO.LOW)
sleep(sec)
try:
while True:
if GPIO.input(Button) == 0:
beep(2, 0.07)
filename = (time.strftime("%y%b%d_%H:%M:%S"))
camera.rotation = 180
camera.start_preview(fullscreen=False, window = (600, 10, 640, 480))
sleep(5)
beep(1, 0.5)
variable = "/home/pi/Desktop/" + filename + ".jpg"
camera.capture(variable)
camera.stop_preview()
except KeyboardInterrupt:
GPIO.cleanup()
view raw selfie.py hosted with ❤ by GitHub

Thank you

Thank you for reading this tutorial and we hope it helps your project development. If you have any technical inquiry, please post at Cytron Technical Forum.

3 thoughts on “Selfie with Raspberry Pi”

Leave a Comment

Your email address will not be published.

Share this Tutorial

Share on facebook
Share on whatsapp
Share on email
Share on print
Share on twitter
Share on pinterest
Share on facebook
Share on whatsapp
Share on email
Share on print
Share on twitter
Share on pinterest

Latest Tutorial

DIY Digital Alarm Clock Using REKA:BIT With Micro:bit
Display Internet Time (NTP) on micro:bit
DIY Interactive Robot Using REKA:BIT With Micro:bit
BLTouch Installation for Ender 3 with 32-bit V4.2.2 Board
Pick and Send Random Meal’s Option and Locations through Telegram Bot Using Grove WiFi 8266 on micro:bit
Tutorials of Cytron Technologies Scroll to Top