Edward Nusinovich
Published © MIT

WiFi Robot

I have created the framework for WiFi and voice control of a robot. The MKR1000 chip enables us to receive controls over WiFi.

IntermediateShowcase (no instructions)3 hours1,453
WiFi Robot

Things used in this project

Story

Read more

Schematics

4_lRl9DgIE1F.jpg

Code

WiFi Server

Arduino
This is a generic server that allows us to read data that clients send. Specifically, when I get a connection from the Joystick, it can take the inputs.
#include <SPI.h>
#include <WiFi101.h>

char ssid[] = "";       // your network SSID (name) 
char pass[] = "";           // your network password
int status = WL_IDLE_STATUS;

WiFiServer server(80);

bool issetup = false;

void setup() {
   delay(5000);
   Serial.begin(9600);
   Serial.println("Attempting to connect to WPA network...");
   Serial.print("SSID: ");
   Serial.println(ssid);

   status = WiFi.begin(ssid, pass);

   Serial.print("IP: ");
   IPAddress ip = WiFi.localIP();
   Serial.println(ip);

   // check for the presence of the shield:
   if (WiFi.status() == WL_NO_SHIELD) {
     Serial.println("WiFi shield not present"); 
     // don't continue:
     while(true);
   } 
  
   // 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);
   } 
}
void loop() {
   WiFiClient client = server.available();
   if(client){                          // if there's a client, 
     Serial.println("New client: ");
     //if(client.available()) {         // if there's bytes to read from the client,
       Serial.println(client);
       char c = client.read();          // read a byte, then
       Serial.write(c);                 // print it out to the serial monitor
     //}
     client.stop();
   }
   //else{
   // Serial.print(".");
   //}
}

Motor

Arduino
This is sample code that shows how to write to a motor connected using an L298N module. Ultimately, this will be updated and written from the Client's controls in the Wifi server file.
//This is just sample code, ultimately this will read from the JS joystick

int pinI1=0;//define I1 port
int pinI2=1;//define I2 port
int speedpin=2;//define EA(PWM speed regulation)port
void setup()
{
 pinMode(pinI1,OUTPUT);//define this port as output
 pinMode(pinI2,OUTPUT);
 pinMode(speedpin,OUTPUT);
}
void loop()
{
 analogWrite(speedpin,100);//input a value to set the speed
 delay(2000);
 digitalWrite(pinI1,LOW);// DC motor rotates clockwise
 digitalWrite(pinI2,HIGH);
 analogWrite(speedpin,100);
 delay(2000);
 digitalWrite(pinI1,HIGH);// DC motor rotates anticlockwise
 digitalWrite(pinI2,LOW);
 analogWrite(speedpin,100);
 delay(2000);
 digitalWrite(pinI1,HIGH);// DC motor stop rotating
digitalWrite(pinI2,HIGH);
delay(2000);
}

Credits

Edward Nusinovich

Edward Nusinovich

1 project • 1 follower

Comments