Things used in this project

Hardware components:
A000066 iso both
Arduino UNO & Genuino UNO
×1
Phpoc shield for arduino per pztifwjlwk
PHPoC Shield for Arduino
×1
7V LED By KINGBRIGHT
×3
12002 04
Breadboard (generic)
×1
Screen shot 2017 02 16 at 2 2fejqs9vfo
MikroElektronika RELAY click
×2
11026 02
Jumper wires (generic)
×1

Schematics

Wiring
Wiring i3uunejif2

Code

Normal code for controlling LED via webpageArduino
/* arduino web server - remote control (push button) */

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

#define STATE_YELLOW	'A'
#define STATE_GREEN		'B'
#define STATE_RED		'C'

#define PIN_LED_YELLOW 		3
#define PIN_LED_GREEN 		8
#define PIN_LED_RED			9

PhpocServer server(80);

char current_led = STATE_RED;
int pins[3] = {PIN_LED_YELLOW, PIN_LED_GREEN, PIN_LED_RED};

void handleEvent(char stt);

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

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

	server.beginWebSocket("remote_push");

	Serial.print("WebSocket server address : ");
	Serial.println(Phpoc.localIP());  
	
	pinMode(PIN_LED_YELLOW, OUTPUT);
	pinMode(PIN_LED_GREEN, OUTPUT);
	pinMode(PIN_LED_RED, OUTPUT);
	
	digitalWrite(PIN_LED_RED, HIGH);
	
}

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 event = client.read();
			if(event == 'A' || event == 'B' || event == 'C')
				if(event != current_led)
					handleEvent(event);
		}
	}
}

void handleEvent(char event){
	
	for(int i = 0; i < 5; i++){
		digitalWrite(pins[current_led - 'A'], (i%2));
		delay(100);
	}
	//Turn on green led
	digitalWrite(pins[event - 'A'], HIGH);
	
	// update current state
	current_led = event;
}
Finite State Machine Code for controlling LED via webpageArduino
This code have the same functionality as normal code but using Finite State Machine model
/* arduino web server - remote control (push button) */

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

#define STATE_YELLOW	'A'
#define STATE_GREEN		'B'
#define STATE_RED		'C'

#define PIN_LED_YELLOW 		3
#define PIN_LED_GREEN 		8
#define PIN_LED_RED			9

PhpocServer server(80);

char fsm_state = STATE_RED;

void FSMEvent(char stt);

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

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

	server.beginWebSocket("remote_push");

	Serial.print("WebSocket server address : ");
	Serial.println(Phpoc.localIP());  
	
	pinMode(PIN_LED_YELLOW, OUTPUT);
	pinMode(PIN_LED_GREEN, OUTPUT);
	pinMode(PIN_LED_RED, OUTPUT);
	
	digitalWrite(PIN_LED_RED, HIGH);
}

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 event = client.read();
			if(event == 'A' || event == 'B' || event == 'C')
				if(event != fsm_state)
					FSMEvent(event);
		}
	}
}

void FSMEvent(char event){
	
	//Action is taken based on current state and event
	switch(fsm_state){
		case STATE_YELLOW:
			
			if(event == STATE_GREEN){
				//Blink yellow led in a second and then turn off
				for(int i = 0; i < 5; i++){
					digitalWrite(PIN_LED_YELLOW, (i%2));
					delay(100);
				}
				//Turn on green led
				digitalWrite(PIN_LED_GREEN, HIGH);
			}
			else if(event == STATE_RED){
				//Blink yellow led in a second and then turn off
				for(int i = 0; i < 5; i++){
					digitalWrite(PIN_LED_YELLOW, (i%2));
					delay(100);
				}
				//Turn on red led
				digitalWrite(PIN_LED_RED, HIGH);
			}
			
			break;
			
		case STATE_GREEN:
			
			if(event == STATE_YELLOW){
				//Blink green led in a second and then turn off
				for(int i = 0; i < 5; i++){
					digitalWrite(PIN_LED_GREEN, (i%2));
					delay(100);
				}
				//Turn on yellow led
				digitalWrite(PIN_LED_YELLOW, HIGH);
			}
			else if(event == STATE_RED){
				//Blink green led in a second and then turn off
				for(int i = 0; i < 5; i++){
					digitalWrite(PIN_LED_GREEN, (i%2));
					delay(100);
				}
				//Turn on red led
				digitalWrite(PIN_LED_RED, HIGH);
			}
			
			break;
			
		case STATE_RED:
			
			if(event == STATE_YELLOW){
				//Blink red led in a second and then turn off
				for(int i = 0; i < 5; i++){
					digitalWrite(PIN_LED_RED, (i%2));
					delay(100);
				}
				//Turn on yellow led
				digitalWrite(PIN_LED_YELLOW, HIGH);
			}
			else if(event == STATE_GREEN){
				//Blink red led in a second and then turn off
				for(int i = 0; i < 5; i++){
					digitalWrite(PIN_LED_RED, (i%2));
					delay(100);
				}
				//Turn on green led
				digitalWrite(PIN_LED_GREEN, HIGH);
			}
			
			break;
	}
	
	// update current state
	fsm_state = event;
}

Credits

Replications

Did you replicate this project? Share it!

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Similar projects you might like

IFTTT’s Maker channel with PHPoC Blue.
Intermediate
  • 85
  • 4

This project shows how to use IFTTT maker channel.

IoT Drone - Part 2 - Sensors
Intermediate
  • 399
  • 4

Work in progress

Part 2 incorperates a GPS receiver, 10 DOF IMU, and Ultrasonic distance sensor to be used for flight controls.

HiSens Lake Monitoring System
Intermediate
  • 280
  • 5

Full instructions

We are proposing a multi-function system to monitor algal blooms in Lake Erie and other affected bodies of water.

HiSens Lake Monitoring System

Team Calvary Engineering LLC

PHPoC Blue with Wiegand RFID Reader
Intermediate
  • 291
  • 8

Reading RFID tags from an RFID reader with Wiegand protocol and displaying it in a web browser through a web socket.

ESP8266 MikroE Buggy
Intermediate
  • 1,806
  • 23

Full instructions

ESP8266 web server - driver for MikroE Buggy. Web server provides simple HTML5 canvas as driving joystick.

IoT temperature logging using Creator Ci40
Intermediate
  • 138
  • 2

Full instructions

Project looks at building an IoT temperature logging solution using an open-source LWM2M + IPSO object framework for security & scalabity

ProjectsCommunitiesContestsLiveAppsBetaFree StoreBlogAdd projectSign up / Login
Respect project
Feedback