Hi, I am a beginner to electronics and I am trying to make an arduino project which allows me to activate a servo motor by a browser switch. Adding to the complexity, the ethernet module and the servo motor are of separate arduino units, linked via the RF module, nrf24l01.
Currently, the recieving node does not seem to recieve the transmission as servo motor fails to activate. Additionally, successful transmission is not seen over the serial monitor of the IDE. I think I have some difficulties with interfacing the browser switch on the ethernet unit to trigger the transmission of data to the recieving unit. I appreciate if I could get some advice on correcting it.
Transmitting unit
#include <SPI.h>
#include "RF24.h"
#include <Ethernet2.h>
int msg[1];
RF24 radio(9,10);
const uint64_t pipe = 0xE8E8F0F0E1LL;
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192,168,1,101 };
const int MAX_PAGENAME_LEN = 8; // max characters in page name
char buffer[MAX_PAGENAME_LEN+1]; // additional character for terminating null
EthernetServer server(232);
void setup()
{
Serial.begin(9600); //Start serial port for debugging
radio.begin();
radio.openWritingPipe(pipe);
Ethernet.begin(mac, ip);
server.begin();
delay(2000);
}
void loop()
{
EthernetClient client = server.available();
if (client) {
int type = 0;
while (client.connected()) {
if (client.available()) {
// GET, POST, or HEAD
memset(buffer,0, sizeof(buffer)); // clear the buffer
if(client.readBytesUntil('/', buffer,sizeof(buffer))){
if(strcmp(buffer,"POST ") == 0){
client.find("\n\r"); // skip to the body
// find string starting with "pin", stop on first blank line
// the POST parameters expected in the form pinDx=Y
// where x is the pin number and Y is 0 for LOW and 1 for HIGH
while(client.findUntil("pinD", "\n\r")){
int pin = client.parseInt(); // the pin number
int val = client.parseInt(); // 0 or 1
pinMode(pin, OUTPUT);
if(pin == 1){
msg[0] = 111; //Send the 111 to the reciever
radio.write(msg, 1); }
}
}
sendHeader(client,"Post example");
//Control of Servo
client.print(
"<form action='/' method='POST'><p><input type='hidden' name='pinD7'");
client.println(" value='1'><input type='submit' value='Servo Right'/></form>");
client.println("</body></html>");
client.stop();
}
}
}
// give the web browser time to receive the data
delay(1);
client.stop();
}
}
void sendHeader(EthernetClient client, char *title)
{
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
client.print("<html><head><title>");
client.print(title);
client.println("</title><body>");
}
Recieving unit
#include <SPI.h>
#include <Servo.h>
#include "nRF24L01.h"
#include "RF24.h"
Servo myservo; // create servo object to control a servo
int msg[1];
RF24 radio(9,10); // NRF24L01 Pin
const uint64_t pipe = 0xE8E8F0F0E1LL; //Start Pipe Communication Address
void setup(void){
Serial.begin(9600);
myservo.attach(3);
radio.begin();
radio.openReadingPipe(1,pipe);
radio.startListening();
}
void loop(void){
if (radio.available()){
bool done = false;
while (!done){
done = radio.read(msg, 1);
Serial.println(msg[0]);
if (msg[0] == 111)
{myservo.write(90);}
else
delay(10);}}
else{Serial.println("Error: No Radio Transmission");}}