Git Product home page Git Product logo

iot-labs's Introduction

Monitoring the on/off status of a power supply using a GPIO input on a Raspberry Pi

To monitor the on/off status of a power supply using a GPIO input on a Raspberry Pi using shell commands, you can utilize the gpio command-line utility and some shell scripting. The gpio utility allows you to manipulate GPIO pins directly from the command line. Here's how you can do it:

1. Enable the GPIO Pins:

Before you can use GPIO pins from the command line, you need to make sure they are enabled. You can do this by running:

sudo raspi-config

Then, navigate to "Interfacing Options" and enable the "GPIO" interface.

2. Check the GPIO Pin Status:

You can use the gpio command to read the status of a GPIO pin. For example, if you want to monitor GPIO17:

gpio read 17

This command will return 0 if the pin is LOW (off) and 1 if the pin is HIGH (on).

You can create a shell script to continuously monitor the GPIO pin's status and display it in the terminal. Here's a simple example:

#!/bin/bash

# Set the GPIO pin number
GPIO_PIN=17

# Configure the GPIO pin as an input
gpio mode $GPIO_PIN in

while true; do
    STATUS=$(gpio read $GPIO_PIN)
    
    if [ $STATUS -eq 1 ]; then
        echo "Power supply is ON"
    else
        echo "Power supply is OFF"
    fi
    
    sleep 5  # Adjust the sleep interval as needed
done

Save this script to a file (e.g., monitor_power_supply.sh) and make it executable:

The script will continuously check the status of the GPIO pin and print whether the power supply is ON or OFF. Remember to customize the GPIO_PIN variable with the actual GPIO pin number you are using, and adjust the sleep interval (sleep) to control how often the script checks the status.

iot-labs's People

Contributors

gsrit avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.