IoT_lover
Published © GPL3+

Reset Arduino via Web

This shows two ways to reset Arduino via web, by software and hardware.

BeginnerFull instructions provided12,310

Things used in this project

Story

Read more

Schematics

software_reset_schematic

hardware_reset_schematic

Code

WebSoftwareReset

Arduino
/* arduino web server - remote control (push button) */

#include "SPI.h"
#include "Phpoc.h"

PhpocServer server(80);

int LED_PIN = 8;

void(* resetFunc) (void) = 0;//declare reset function at address 0

void setup() {
	Serial.begin(9600);
	while(!Serial)
		;

	//Phpoc.begin(PF_LOG_SPI | PF_LOG_NET);
	Phpoc.begin();

	server.beginWebSocket("remote_push");

	Serial.println("Arduino started");
	Serial.print("WebSocket server address : ");
	Serial.println(Phpoc.localIP());

	pinMode(LED_PIN, OUTPUT);
}

void loop() {
	// wait for a new client:
	PhpocClient client = server.available();

	if (client) {
		if (client.available() > 0) {
			// read the bytes incoming from the client:
			char thisChar = client.read();

			if(thisChar == 'A') {
				Serial.println("resetting...");
				// blink LED before reseting
				for( int i =0; i < 5; i++) {
					digitalWrite(LED_PIN, LOW);
					delay(100);
					digitalWrite(LED_PIN, HIGH);
					delay(100);
				}

				resetFunc();  //call reset
			}
		}
    }
}

WebHardwareReset

Arduino
/* arduino web server - remote control (push button) */

#include "SPI.h"
#include "Phpoc.h"

PhpocServer server(80);

int RESET_PIN = 9;
int LED_PIN = 8;

void(* resetFunc) (void) = 0;//declare reset function at address 0

void setup() {
	Serial.begin(9600);
	while(!Serial)
		;

	//Phpoc.begin(PF_LOG_SPI | PF_LOG_NET);
	Phpoc.begin();

	server.beginWebSocket("remote_push");

	Serial.println("Arduino started");
	Serial.print("WebSocket server address : ");
	Serial.println(Phpoc.localIP());

	// MUST change state of RESET_PIN to HIGH before changing its mode to OUTPUT. if not, Arduino is infinitely reset
	digitalWrite(RESET_PIN, HIGH);
	pinMode(RESET_PIN, OUTPUT);

	pinMode(LED_PIN, OUTPUT);
}

void loop() {
	// wait for a new client:
	PhpocClient client = server.available();

	if (client) {
		if (client.available() > 0) {
			// read the bytes incoming from the client:
			char thisChar = client.read();

			if(thisChar == 'A') {
				Serial.println("resetting...");
				// blink LED before reseting
				for( int i = 0; i < 5; i++) {
					digitalWrite(LED_PIN, LOW);
					delay(100);
					digitalWrite(LED_PIN, HIGH);
					delay(100);
				}

				digitalWrite(RESET_PIN, LOW);  //call reset
			}
		}
    }
}

Credits

IoT_lover

IoT_lover

10 projects • 191 followers

Comments