Automation of Lights

I have a college project in which I am using a raspberry pi pico w, relay, pir motion sensor and ldr(photo resistor).

Raspberry pi pico w runs on micropython. I need a code for this project which switches on and off the light depending on the values of the motion sensor and ldr. Further I also want to add manual control to it by creating a simple web page on the connected ip address.

If anyone could help me with this I would be very very thankful.

Firstly, welcome to the forums.

While we are primarily here to help people with their Free Code Camp progress, we are open to people on other paths, too. Some of what you are asking is pretty trivial in the Free Code Camp context, so you might find that if you’re not getting the instruction and material you need in your current studies, the FCC curriculum will really help you get started. At a modest guess I’d say investing a 4-5 hours working through the curriculum here will really pay off. You can find the curriculum at https://www.freecodecamp.org/learn.

With your current questions, we don’t have enough context to know what you already know or don’t know, so it is impossible to guide you without just telling you the answer (which we won’t do).

It is pretty typical on here for people to share a codepen / repl.it / jsfiddle example of what they have tried so that anyone helping has more of an idea of what help is actually helpful.

Please provide some example of what you’ve tried and I’m sure you’ll get more help.

Happy coding :slight_smile:

The basic web page I created using html is:

html = <!DOCTYPE html>
<html>
    <head>
        <title>Lighting Automation</title>
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <style>
            body {font-family: Arial, Helvetica, sans-serif;}
            h2 {text-align: center;}
            .slider {
              -webkit-appearance: none;
              width: 100%;
              height: 15px;
              background: #ddd;
              outline: none;
              opacity: 0.7;
              -webkit-transition: .2s;
              transition: opacity .2s;
            }
            .slider:hover {
              opacity: 1;
            }
            .slider::-webkit-slider-thumb {
              -webkit-appearance: none;
              appearance: none;
              width: 25px;
              height: 25px;
              background: #4CAF50;
              cursor: pointer;
            }
            .slider::-moz-range-thumb {
              width: 25px;
              height: 25px;
              background: #4CAF50;
              cursor: pointer;
            }
            .button {
              background-color: #4CAF50;
              border: none;
              color: white;
              padding: 15px 32px;
              text-align: center;
              text-decoration: none;
              display: inline-block;
              font-size: 16px;
              margin: 4px 2px;
              cursor: pointer;
            }
            .button2 {background-color: #008CBA;}
            .button3 {background-color: #f44336;}
            .button4 {background-color: #e7e7e7; color: black;} /* Gray */
            .button5 {background-color: #555555;} /* Black */
            .button6 {background-color: #555555; color: white;} /* Black */
            .animation {
                width: 50%;
                margin: 0 auto;
                position: relative;
                border-radius: 10px;
                height: 15px;
            }
            .animation:before,
            .animation:after {
                content: '';
                position: absolute;
                height: inherit;
                width: inherit;
                border-radius: inherit;
            }
            .animation:before {
                left: -40px;
                            background: linear-gradient(to right, #555, #888, #555);
            animation: animate2 1s linear infinite;
        }
        @keyframes animate1 {
            0% {
                transform: translateX(-100%);
            }
            100% {
                transform: translateX(100%);
            }
        }
        @keyframes animate2 {
            0% {
                transform: translateX(-100%);
            }
            100% {
                transform: translateX(100%);
            }
        }
    </style>
</head>
<body>
    <h2>Lighting Automation</h2>
    <h3>Manual Control</h3>
    <div>
        <h4>Light Control</h4>
        <label class="switch">
            <input type="checkbox" onchange="toggleLight(this)" id="lightSwitch">
            <span class="slider round"></span>
        </label>
    </div>
    <h3>Automation Status</h3>
    <div>
        <h4>Light:</h4>
        <p id="lightStatus">-</p>
    </div>
    <div>
        <h4>Motion:</h4>
        <p id="motionStatus">-</p>
    </div>
    <div>
        <h4>Light Sensor:</h4>
        <p id="lightSensorStatus">-</p>
    </div>
    <h3>Manual Control through Web Interface</h3>
    <div>
        <button class="button button2" onclick="toggleLightManually('on')">Turn On</button>
        <button class="button button3" onclick="toggleLightManually('off')">Turn Off</button>
    </div>
    <h3>Light Animation</h3>
    <div class="animation"></div>
    <script>
        // Websocket connection
        var websocket;
        var wsUri = "ws://" + window.location.hostname + ":81/";
        var lightSwitch = document.getElementById("lightSwitch");

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.