O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Raspberry Pi Sensors

Book Description

Integrate sensors into your Raspberry Pi projects and let your powerful microcomputer interact with the physical world

In Detail

The tiny Raspberry Pi device contains the power to revolutionize the way we understand computing. Built with a Linux-based operating system, it is a tool that invites exploration and experimentation, and can be repurposed and integrated with other hardware and software to help create some truly exciting projects.

With Raspberry Pi Sensors you will learn how to get more from your Raspberry Pi and dive deeper into its engineering by exploring its Linux-based OS before learning how to develop and execute programs on it using Python and C. You'll then find a range of projects like creating your own ultrasonic sensor to monitor the atmosphere, connect your Raspberry Pi to the Internet so you can upload data online and use it as a launchpad to create Internet of Things based projects. Learn how to create your own image sensor using a simple USB camera and the innovative OpenCV library to perform motion detection.

What You Will Learn

  • Set up your Raspberry Pi board and integrate it with powerful sensors
  • Discover how to operate your Raspberry Pi by exploring its Linux-based OS
  • Develop a deep understanding of your Raspberry Pi's GPIOs and access them through Python, C, and shell scripting
  • Create an ultrasonic distance meter and use it to make an aid for visually impaired or blind people
  • Interface a temperature-humidity sensor and photocells together with your Raspberry Pi to log the data
  • Find out how to upload the data you collect online and receive regular notifications of irregularities
  • Integrate OpenCV with your Raspberry Pi and learn how you can master the latest in image processing technology with the power of computer vision

Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.

Table of Contents

  1. Raspberry Pi Sensors
    1. Table of Contents
    2. Raspberry Pi Sensors
    3. Credits
    4. About the Author
    5. Acknowledgements
    6. About the Reviewers
    7. www.PacktPub.com
      1. Support files, eBooks, discount offers, and more
        1. Why subscribe?
        2. Free access for Packt account holders
    8. Preface
      1. What this book covers
      2. What you need for this book
      3. Who this book is for
      4. Conventions
      5. Reader feedback
      6. Customer support
        1. Errata
        2. Piracy
        3. Questions
    9. 1. Meeting Your Buddy – the Raspberry Pi
      1. A glance at the Raspberry Pi board
      2. Setting up for the first time
        1. Installing the operating system
          1. Purchasing your SD card
          2. Downloading the required software
            1. Windows
            2. Mac OS X
            3. Linux
          3. Expanding the root filesystem
          4. Logging in to the RasPi
          5. Opening the desktop
      3. Connecting the Raspberry Pi to the Internet
        1. Internet connection through Wi-Fi dongle
        2. Internet connection through Ethernet from a PC
          1. Editing the command-line file of the RasPi
          2. Turning on the RasPi
          3. Changing cmdline.txt again to add the PC's Ethernet port IP address
          4. Sharing the Internet connection between your PC and an Ethernet connection
          5. Installing and opening the free SSH client on your PC
      4. A crash course on Linux
        1. The terminal and shell
        2. Useful and frequently used Linux commands
      5. Installing useful libraries
        1. git-core
        2. wiringPi
      6. python-gpio
      7. Be ready with Python and C
        1. Writing and executing the Python program
        2. Writing and executing the C program
      8. Practice makes you perfect
      9. Summary
    10. 2. Meeting the World of Electronics
      1. Basic terminologies of electronics
        1. Voltage
        2. Current
        3. Resistor
        4. Capacitor
        5. Open circuit and short circuit
        6. Series and parallel connections
        7. Pull-up and pull-down resistors
      2. Communication protocols
        1. UART
        2. Serial Peripheral Interface
        3. Inter-Integrated Circuit
      3. Useful tips and precautions
      4. Understanding the GPIO port
      5. It's time to glow LEDs!
        1. Shell script and GPIO
        2. LED blink and Python
        3. Let's blink the LED with C code
      6. Summary
    11. 3. Measuring Distance Using Ultrasonic Sensors
      1. The mysterious ultrasonic sensor
        1. Distance calculation
      2. Building the project!
        1. Hardware setup
        2. Software setup
          1. Initial configuration
          2. Setting the GPIO pins on the default mode
          3. Sending and receiving the pulses
        3. Calculation of distance
      3. Fixing common problems
        1. Is it showing the distance incorrectly?
        2. Is the module not responding?
        3. Are you measuring the distance less than 2 cm?
      4. A wearable device for the visually impaired
        1. Building the hardware
        2. Software setup
      5. Summary
    12. 4. Monitoring the Atmosphere Using Sensors
      1. Sensor selection process
        1. Criticality of an application
        2. Selecting a sensor package
        3. Sensor properties
        4. Purchasing the sensor
        5. Available sensors
      2. InsideDHT – temperature and humidity sensors
      3. Introducing the photoresistor (photocell)
      4. Building the project
        1. Hardware setup
          1. Breadboard setup
        2. Preparing the code
          1. Code the DHT sensor and measure relative humidity and temperature
          2. Code the LDR sensor and measure light variations
      5. Putting all the parts together
      6. Troubleshooting common problems
        1. Received DHT data is not valid
        2. The LDR sensor gives a zero value
        3. Is the voltage correct?
      7. Summary
    13. 5. Using an ADC to Interface any Analog Sensor with the Raspberry Pi
      1. Analog-to-digital convertors
        1. Data reception and signal conditioning
        2. Amplification
        3. Sampling and quantization
        4. Types of ADC
        5. Resolution of the ADC
        6. The math behind ADC
        7. Data output
      2. MCP3008 for analog-to-digital conversion
        1. Channels
        2. Ground
        3. SPI
        4. Reference voltage
        5. Supply voltage
      3. Making your own sensor station
      4. Generic software preparation
      5. Using your sensor station – make a temperature logger
        1. Know the LM36 temperature sensor
        2. Write the application
      6. Summary
    14. 6. Uploading Data Online – Spreadsheets, Mobile, and E-mails
      1. Internet of Things
        1. Sensor nodes
        2. Communication
        3. The cloud
        4. Data analytics
        5. Security concerns
      2. Hardware setup
      3. Synchronizing the clock with the Internet
      4. Uploading data on Google spreadsheets
        1. Live feed on mobile phones
      5. Getting notified by e-mails
      6. Integrating everything
      7. Common problems faced
      8. Summary
    15. 7. Creating an Image Sensor Using a Camera and OpenCV
      1. Image processing
      2. OpenCV
      3. Camera interfacing with the RasPi
        1. The RasPi camera modules
        2. USB webcam
      4. Live streaming using a network camera
      5. Porting OpenCV
        1. Testing
      6. Create a motion detector
        1. Preparing shell to compile OpenCV and wiringPi
      7. Amazing projects for you
      8. Summary
    16. A. Shopping List
      1. Basic requirements
      2. Sensors
      3. Integrated chips
      4. Components
      5. Others
    17. Index