Wireless Robot Friend

Waving from a far 

With this modification you can have your robot friend from the Creator Set react to stimulus from far away.

Modules 

Gather the following parts to complete this project.

Parts

All Parts
All Parts
Arduino with Base Shield
Ardunio Without Base Shield
WiFi Module
Servo
Potentiometer
Cables
PartQuantity
Arduino with Base Shield 1
Ardunio Without Base Shield 1
WiFi Module 2
Servo 1
Potentiometer 1
Cables 3

Robot Side Assembly 

This part will use the Arduino without the base shield. We are going upload code first then add the components. We are using the UART socket so programming must be done first.

Robot parts
Robot parts
Take USB
Plug in

Upload

Uploading the following code.

Download file Copy to clipboard
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//All the libraries used
#include <WiFiEsp.h>
#include <WiFiEspUdp.h>
#include "SoftwareSerial.h"
#include <Servo.h>

//Change here if you're using a different socket
#define servoSocket A5 //<- digital socket number

//Create a Servo object
Servo robotArm;

//Variable for received dervo position
int pos;

//Create UDP object
WiFiEspUDP Udp;

//IP and broadcasting varibles
IPAddress apIP = IPAddress(192, 168, 111, 111);
IPAddress stationIP = IPAddress(192, 168, 111, 112);
IPAddress broadcastIP = IPAddress(0, 0, 0, 0);
IPAddress remoteIp;
bool broadcasting = false;

//WiFi network settings
char ssid[] = "robotRec";            // your network SSID (name)
char pass[] = "password";        // your network password
int status = WL_IDLE_STATUS;     // the Wifi radio's status


//Ports to be used
unsigned int listeningPort = 10002;  // local port to listen on
unsigned int sendingPort = 10003;  // local port to listen on
char packetBuffer[255];          // buffer to hold incoming packet

void setup() {
  // initialize serial for debugging
  Serial.begin(9600);

  // Connect serial to Wifi module
  WiFi.init(&Serial);
  WiFi.configAP(apIP);

  // attempt to connect to WiFi network
  while ( status != WL_CONNECTED) {
    // Make a network
    status =  WiFi.beginAP(ssid, 10, pass, ENC_TYPE_WPA2_PSK);
  }

  // Set up UDP listener on port
  Udp.begin(listeningPort);

  // Print out which port
  Serial.print(F("Listening on port "));
  Serial.println(listeningPort);

  //Attach servo object to servo socket
  robotArm.attach(servoSocket);
}

void loop() {
  // if there's data available, read a packet
  int packetSize = Udp.parsePacket();
  if (packetSize) {
    // read the packet into packetBufffer
    int len = Udp.read(packetBuffer, 255);
    if (len > 0) {
      packetBuffer[len] = 0;
    }

    //Convert received data to an int
    pos = atoi(packetBuffer);
  }

  //Tell Servo to move to received position
  robotArm.write(pos);
}

Adding the components

Unwrap a cable and connect one end to a WiFi Module and the other end to the UART socket on the Arduino. Plug the servo to either I2C Socket.

Unplug
Unplug
Take a cable
Unwrap it
Connect one end to a WiFi Module
The other end to the UART socket
Take the Servo
Connect to either I2C socket
Ready for the Controller

Control Side Assembly 

This part doesn't use the UART socket so it can be put together normally. Unwrap a cable and connect one end to the unused WiFi module and the other to the D8 socket. Unwrap another cable and plug one end into the Potentiometer socket with the other going into the A0 socket.

All the parts
All the parts
Take a cable
Unwrap it
Plug one end to the WiFi Module
The other to the D8 socket
Take the other cable
Unwrap it
Plug into the Potentiometer socket
the other into A0

Upload

Upload the following code.

Download file Copy to clipboard
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
//All the libraries used
#include <WiFiEsp.h>
#include <WiFiEspUdp.h>
#include "SoftwareSerial.h"

//Change here if you're using a different socket
#define dialSocket A0//<- analog socket number

//Variables for store dial position
int pos;
int val;

//Char array for sending position data
char posData[8];

//Socket of the WiFi module
SoftwareSerial Serial1(8, 9); // RX, TX
//Create UDP object
WiFiEspUDP Udp;

//IP and broadcasting varibles
IPAddress apIP = IPAddress(192, 168, 111, 111);
IPAddress stationIP = IPAddress(192, 168, 111, 112);
IPAddress broadcastIP = IPAddress(0, 0, 0, 0);
IPAddress remoteIp;
bool broadcasting = false;

//WiFi network settings
char ssid[] = "robotRec";            // your network SSID (name)
char pass[] = "password";        // your network password
int status = WL_IDLE_STATUS;     // the Wifi radio's status

//Ports to be used
unsigned int listeningPort = 10003;  // local port to listen on
unsigned int sendingPort = 10002;  // local port to listen on

void setup() {
  // initialize serial for debugging
  Serial.begin(9600);
  // initialize serial for ESP module
  Serial1.begin(9600);
  // Connect serial to Wifi module
  WiFi.init(&Serial1);
  WiFi.config(stationIP);

  // attempt to connect to WiFi network
  while ( status != WL_CONNECTED) {
    // Print which SSID it's trying to connect to
    Serial.print(F("Attempting to connect to WPA SSID: "));
    Serial.println(ssid);
    // Connect to WPA/WPA2 network
    status = WiFi.begin(ssid, pass);
  }

  // Set up UDP listener on port
  Udp.begin(listeningPort);

  // Print out which port
  Serial.print(F("Listening on port "));
  Serial.println(listeningPort);
}


void loop() {
  //Read dial voltage
  val = analogRead(dialSocket);

  //Convert reading to degree
  pos = map(val, 0, 1024, 0, 180);

  //Store degrees in char array
  sprintf (posData, "%03i", pos);
  Serial.println(posData);

  //Open packet to certain ip at certain port
  Udp.beginPacket(broadcastIP, sendingPort);
  //Write message to packet
  Udp.write(posData);
  //End the packet
  Udp.endPacket();
}

Info

You must have both Arduinos powered for this to work.

Observe

The sending Arduino will connect to a network made by the receiving Arduino. Once connected it will send updated dial position data. The other Arduino receives this and drives the servo.

My set up
My set up
This dial control the servo
These two are connected via WiFi
Turn this to move the servo
Turn this to move the servo

Modify

The Potentiometer can be swapped with any sensor such as light or sound.