element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Arduino Forum Help needed with browser switch project with nrf24l01 and servo
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 2 replies
  • Subscribers 391 subscribers
  • Views 345 views
  • Users 0 members are here
  • ethernet_shield
  • servo
  • nrf24l01
Related

Help needed with browser switch project with nrf24l01 and servo

Former Member
Former Member over 9 years ago

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");}}

  • Sign in to reply
  • Cancel
  • shabaz
    shabaz over 9 years ago

    Hi Thomas,

     

    You have created a serial interface for debugging, but not used it.

    If you think the problem is in the transmission unit code then you can use the serial interface to pass debug information to understand

    where the code execution has reached and the value of key variables to see where the code begins to deviate from expected behaviour.

    Sometimes even an LED can be useful to understand code flow, but you've got a serial interface you could be using.,

     

    The demo examples from the Ethernet2 library contain Serial debug, so you can see from those how to go about this.

    https://github.com/adafruit/Ethernet2/blob/master/examples/WebServer/WebServer.ino

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • Former Member
    Former Member over 9 years ago in reply to shabaz

    Thanks for the advice. I have modified codes of both the transmitting and recieving units since. To better determine the cause of the issue, I've also changed the output of the recieving unit to a blinking LED instead of a servo. I've ran a serial debug of the transmitting unit and it appears that the recieving unit is able to sent the data as seen by the serial input 'Sent' when the web browser button is clicked on. However, the recieving unit does not seem to recieve the data. Again, I ran the serial debug on this end and it seems that it stops at the point when the radio coding interface kicks in. Can anyone help me identify the error in my code?

     

    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);

                  Serial.println(pin);

                  Serial.println(OUTPUT);

                  if (OUTPUT == 1) {

                  msg[0] = 111; //Send the 111 to the reciever

                  radio.write(msg, 1);

                  Serial.println("Sent"); //This works

                  }

              }

     

         

              }

              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 <nRF24L01.h>

    #include <RF24.h>

     

    int msg[1];

    RF24 radio(9,10); // NRF24L01 Pin

    const uint64_t pipe = 0xE8E8F0F0E1LL; //Start Pipe Communication Address

    int led=3;

     

    void setup()

    {

    Serial.begin(9600);

    radio.begin();

    radio.openReadingPipe(1,pipe);

    radio.startListening();

      pinMode(led, OUTPUT);

    }

     

    void loop(void){

       Serial.println("Hello"); //Successful serial print stops at this point until serial error message at the end

    if (radio.available()){

       bool done = false;   

       while (!done){

         done = radio.read(msg, 1);     

         Serial.println(msg[0]);

         if (msg[0] == 111)

         {digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)

          Serial.println("Data recieved");

          delay(3000);              // wait for a second

          digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW

           delay(1000);              // wait for a second

          }

         else

         delay(10);}}

    else{Serial.println("Error: No Radio Transmission");}}

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube