Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
arduinocc
Created December 5, 2019 © GPL3+

Low Power Door Monitor

Add an Arduino door monitor to your project, without worrying the power will run out with the 0ma consumption when idle!

BeginnerShowcase (no instructions)487
Low Power Door Monitor

Things used in this project

Hardware components

Arduino Nano 33 IoT
Arduino Nano 33 IoT
Any Wifi Enabled board would run this example, any board can harness this technique.
×1
Jumper wires (generic)
Jumper wires (generic)
×3
General Purpose Transistor NPN
General Purpose Transistor NPN
×2
Resistor 10k ohm
Resistor 10k ohm
×4
Resistor 100k ohm
Resistor 100k ohm
×1
Capacitor 100 nF
Capacitor 100 nF
×1
4xAA battery holder
4xAA battery holder
×1
Microswitch, Roller Lever
Microswitch, Roller Lever
×1

Software apps and online services

Arduino IDE
Arduino IDE
Visual Micro

Story

Read more

Schematics

Latching Transistor Wiring

Diagram to show how to wire up the latching part of the circuit.

Code

Example Nano33 IoT Software for Power Latch

Arduino
Add SSID and Pass and edit the end of Setup() to perform the actions you want while the board is on.

Alter FlashStorage to store all variables needed, and ONLY write when neccesary!
// Based on WebClient::https://www.arduino.cc/en/Tutorial/WiFiNINAWiFiWebClient 
#include <FlashStorage.h>
#include <FlashAsEEPROM.h>
#include <SPI.h>  
#include <WiFiNINA.h>


char ssid[] = "********";        // your network SSID (name)
char pass[] = "********";    // your network password (use for WPA, or use as key for WEP)
int keyIndex = 0;            // your network key Index number (needed only for WEP)

int status = WL_IDLE_STATUS;
// if you don't want to use DNS (and reduce your sketch size)
// use the numeric IP instead of the name for the server:
//IPAddress server(74,125,232,128);  // numeric IP for Google (no DNS)
char server[] = "www.visualmicro.com";    // name address forour website

bool LASTSTATE = false;
FlashStorage(state, int);

// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
WiFiClient client;

void setup() {

	

	//Initialize serial and wait for port to open:
	Serial.begin(9600);
	while (!Serial) {
		; // wait for serial port to connect. Needed for native USB port only
	}

	// check for the WiFi module:
	if (WiFi.status() == WL_NO_MODULE) {
		Serial.println("Communication with WiFi module failed!");
		// don't continue
		while (true);
	}

	String fv = WiFi.firmwareVersion();
	if (fv < WIFI_FIRMWARE_LATEST_VERSION) {
		Serial.println("Please upgrade the firmware");
	}

	// attempt to connect to Wifi network:
	while (status != WL_CONNECTED) {
		Serial.print("Attempting to connect to SSID: ");
		Serial.println(ssid);
		// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
		status = WiFi.begin(ssid, pass);

		// wait 10 seconds for connection:
		delay(10000);
	}
	Serial.println("Connected to wifi");

	Serial.println("\nStarting connection to server...");
	// if you get a connection, report back via serial:
	if (client.connect(server, 80)) {
		Serial.println("connected to server");
		// Make a HTTP request:
		if (LASTSTATE) {
			client.println("GET /data?v=1 HTTP/1.1");
		}
		else {
			client.println("GET /data?v=0 HTTP/1.1");
		}
		client.println("Host: www.visualmicro.com");
		client.println("Connection: close");
		client.println();
	}

	// Add our state data to EEPROM
	LASTSTATE = state.read(); // Get last state
	state.write(!LASTSTATE); // Invert it (as we trigger on inversion by hardware this is reliable)

	// We can simply power down now
	digitalWrite(12, LOW);
}
void loop() {
// Nothing to do
}

Credits

arduinocc
5 projects • 13 followers
Arduino compatible IDE for Microsoft Visual Studio and Atmel Studio 7 with unique USB Debugger, Trace, Pin Viewer and Plotter, GDB Debugging
Contact

Comments

Please log in or sign up to comment.