- Arduino UNO & Genuino UNO
- PHPoC WiFi Shield 2 for Arduino
- DC Motor Controller
- DIY DC motor Car
- Jumper wires
Demonstration
Wiring
How To
1. Web App
We do not need to program for web app. PHPoC Shield has a bult-in web app, called "Web Remote Push". This web app is customizable via a setting page.
Default web app user interface
Click "setup" to customize
After changing the setting as above, we has new UI
2. Arduino Code
The Arduino code is the combination of two example "PHPoC -> WebRemotePush.ino" and "PHPoC Expansion -> ExpansionDCMotor"
Code:
#include <Phpoc.h> #include <PhpocExpansion.h> PhpocServer server(80); byte expansionId = 1; ExpansionDCMotor dcm1(expansionId, 1); ExpansionDCMotor dcm2(expansionId, 2); void setup() { Serial.begin(9600); while(!Serial) ; // initialize PHPoC [WiFi] Shield: Phpoc.begin(PF_LOG_SPI | PF_LOG_NET); //Phpoc.begin(); Expansion.begin(); // start WebSocket server server.beginWebSocket("remote_push"); // print IP address of PHPoC [WiFi] Shield to serial monitor: Serial.print("WebSocket server address : "); Serial.println(Phpoc.localIP()); dcm1.setPolarity(1); dcm2.setPolarity(-1); // set PWM period dcm1.setPeriod(10000); dcm2.setPeriod(10000); } void loop() { // wait for a new client: PhpocClient client = server.available(); if (client) { if (client.available() > 0) { // read a byte incoming from the client: char thisChar = client.read(); // when an user presses a button on the web apps, the web app sends an // uppercase character corresponding with the name of button to Arduino. // When an user releases a button on the web apps, the web app sends a // lowercase character corresponding with the name of button to Arduino. if(thisChar == 'B') { Serial.println("Move forward"); dcm1.setDirection(1); dcm2.setDirection(1); dcm1.setWidth(5000); dcm2.setWidth(5000); } if(thisChar == 'b') { Serial.println("Stop"); dcm1.setWidth(0); dcm2.setWidth(0); } if(thisChar == 'D') { Serial.println("Turn left"); dcm2.setDirection(1); dcm2.setWidth(5000); } if(thisChar == 'd') { Serial.println("Stop"); dcm1.setWidth(0); dcm2.setWidth(0); } if(thisChar == 'F') { Serial.println("turn right"); dcm1.setDirection(1); dcm1.setWidth(5000); } if(thisChar == 'f') { Serial.println("Stop"); dcm1.setWidth(0); dcm2.setWidth(0); } if(thisChar == 'H') { Serial.println("Move backward"); dcm1.setDirection(-1); dcm2.setDirection(-1); dcm1.setWidth(5000); dcm2.setWidth(5000); } if(thisChar == 'h') { Serial.println("Stop"); dcm1.setWidth(0); dcm2.setWidth(0); } } } }