The obniz Board 1Y now has a sleep function. This feature can be used to create a device that can run for a year on batteries alone.
click here for details about sleep function.
This time, we’ll be creating a program that uses the sleep function to water regularly.
Materials- obniz Board 1Y
- pump : Amazon
- hose
- plant
Hardware connection
Connect the obniz to the pump as shown in the following table.
obniz pump 0 white 1 red
Software
Register your obniz Board!
Go to the developer console in obniz and click on “Devices” → “Add Device”.
When the dialog opens, click on “Use OBNIZ Official Device”. Follow the instructions on the screen to register.
▼
Let’s write a program.
Save the program to a repository for use in serverless events.
Go to the developer console of obniz and select “Repository” → “New”.
A dialog will appear, and you can set it as follows
- Type : WebApp
- Access level : Non-public
- File name : As you like (this time it’s sleep_motor)
Once configured, click “Create”. After doing so, the program input screen will appear, and you will be able to replace the program with the one you have completed.
※This program operates normally only with obniz Board 1Y.
When the program is ready, hover your mouse over the file name in the upper left corner, and click “Save” to display “Save”.
Configuring a Serverless Event
Serverless events are a feature that makes it easy to use obniz without having to prepare the servers that each one of you will need.
From the obniz console, click on “Serverless Events” → “New”.
Let’s set them in order.
- Name : As you like (this time it’s SleepMotorEvent)
- WebApp to run : Name of the program you just saved
- Trigger : obniz Hardware Event
- obniz : obnizID to measure the temperature this time
- Event : online
Once you’re set up, click “Create”! Now you’re ready to go.
ExecuteI started watering them once every 12 hours. The obniz Board 1Y sleeps as soon as the watering is complete.
Also, with the obniz Board 1Y, the power can be supplied directly from the power input/output pins, without having to connect via USB.
You can easily create a power-saving watering device using the sleep function like this.
You can change the sleep interval, even if it’s in a remote location, and you have the advantage of being able to easily update the program with a different kind of sensor replacement.
Program<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link
rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"
/>
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.3/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
<script src="https://unpkg.com/obniz@3.x/obniz.js"></script>
</head>
<body>
<div id="obniz-debug"></div>
<script>
//Timeout 25s
let tid = setTimeout(() => {
//activated every 12 hours.
obniz.sleepMinute(720);
}, 25000);
//-----------------------------
// obniz setting
//-----------------------------
let obniz = new Obniz("OBNIZ_ID_HERE");
obniz.onconnect = async () => {
var motor = obniz.wired("DCMotor", { forward: 0, back: 1 });
motor.forward();
//move moter 10 minutes.
await obniz.wait(10000);
motor.stop();
//activated every 12 hours.
obniz.sleepMinute(720);
//program finish wait...
await obniz.wait(1000);
clearTimeout(tid);
if (typeof done === "function") {
done();
}
};
</script>
</body>
</html>
What is obniz?Before we get into the project, let's look into obniz.
Here → obniz for DIY electronics
obniz is a cloud-connected IoT development board. You can program on the web browser of any smartphone or computer and the command is sent to obniz through the internet via obniz cloud. By connecting the obniz to the cloud through wifi, users can remotely control devices that are physically connected to obniz.
Thanks to this cloud based approach, you can program with Python, Javascript, or other languages you prefer and control hardware directly. You don't need to integrate firmware into the device side. Recording and analyzing data is also easy with obniz cloud service.
Want to control hardware things with your current Python or Javascript skill? Want to start IoT project but don't know where to start? Want to learn programming with languages you prefer?
obniz will help you broaden your viewpoint and develop both your SW and HW skills.
For more information, please visit our official website → Official Website
Where to get obniz board? → Amazon /Official Store
Comments
Please log in or sign up to comment.