use raspberry pi and Arduino together as web server

hey, is there a known way(relatively low cost) to use a raspberry pi as webserver to trigger commands on Arduino?? if there is a way to do it with an Arduino alone that would be great but I don't think that is possible

my final product should be a web page with an on and off button(s) that triggers the movement of servos.

I have a working project that works on infrared so it would be great if on the Arduino side I could just change the code to use the output from the raspberry pi instead of writing new code but anything works.

thx in advance

Search for Arduino + server.

if there is a way to do it with an Arduino alone that would be great but I don't think that is possible

Which Arduino have you got in mind >

A Nano 33 IOT, for instance, can run a Webserver that allows a user to interact with the Arduino to set the state of outputs, read inputs etc. This can be done over the Internet if required

Not strictly an Arduino but an ESP32 is an even more powerful board that can do the same

UKHeliBob:
Which Arduino have you got in mind >

A Nano 33 IOT, for instance, can run a Webserver that allows a user to interact with the Arduino to set the state of outputs, read inputs etc. This can be done over the Internet if required

Not strictly an Arduino but an ESP32 is an even more powerful board that can do the same

I have an Uno but if that can't work then I guess I don't really have a choice but to find a different one

and does the Nano 33 IOT work the same as a uno?? the way I have my circuit set up currently is a power module powering one servo and the IR reciver and the Arduino itself powering another servo

i also thought about wiring up a ir blaster to the Rpi and then making that blast out to the arduino but i couldnt find anything online on how to do that

The Wemos D1 Mini and NodeMCU boards will also work. You program them using the Arduino IDE, just as if they were an Arduino board, and they have WiFi built in. There's a couple of server example projects in the IDE.

does the Nano 33 IOT work the same as a uno??

Basically, yes, but be aware that it is a 3.3V device as are the ESP32 and other alternatives suggested but they all have the advantage of having built in WiFi systems so no external network connections are required

I can recommend the following

For the web interface

  • Node-RED on Raspberry Pi (it is part of Raspbian and programmed via Webeditor using graphical nodes and Javascript)

https://nodered.org/docs/getting-started/local

  • use MQTT protocol to exchange information, there are nodes in node-RED for that

https://cookbook.nodered.org/mqtt/connect-to-broker

MQTT needs a central node called a broker

  • install Eclipse Mosquitto MQTT broker on Raspberry PI (google for many tutorials on how to do that)

To test your MQTT setup and play with the protocol

  • install Eclipse Paho on your PC (this allows you to play with the MQTT protocol and helps you with debugging later, you can test everything with this software before you program your Arduino)

Arduino

  • use a board that has build in WiFi e.g. Arduino Nano 33 IoT, Adafruit Feather M0 WiFi, the before mentioned ESP32 boards seem also popular
  • use the ArduinoMqttClient library (I have used it with the Nano 33 IoT and the Feather)

As suggested above, I think an ESP should to the trick just fine. I'm not familiar with the others.

I did a similar project with an ESP8266 Huzzah board, programmed with the Arduino IDE. So just the ESP board, that actually "acts" like the arduino here.

I had a simple webserver running on the ESP that served a page with some buttons to input the access code. With the right code people would be able to open de front door.

  • the code below running on the ESP
  • relay connected to it to open the door
  • ESP connected to my wifi
  • my router forwarded the connection from outside to the ESP with port mapping

Here's the code:

#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>

#include <Streaming.h>

MDNSResponder mdns;
ESP8266WebServer server(80);

// Replace with your network credentials
const char* ssid = "  ";
const char* password = "  ";

//Variables to process input
int arrEnteredCode[] = {0,0,0};
int arrPassCode[] = {3,2,2};
String strReceived; 
int intDigitReceived;
int intIndex = 0;

String strStartSpace = "


";    //3 lines of spacing which are replaced by the entered code
String strStartPage;
String strNewPage;

//Relais connected to:
int gpio0_pin = 5;


void setup(void){
  
  // preparing GPIOs
  pinMode(gpio0_pin, OUTPUT);
  //digitalWrite(gpio0_pin, HIGH);
  
  delay(1000);
  Serial.begin(115200);
  WiFi.begin(ssid, password);

  // Wait for connection
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  
  if (mdns.begin("esp8266", WiFi.localIP())) {
    Serial.println("MDNS responder started");
  }
  
  server.on("/", fncIndex); 
  server.on("/c", fncCheckCode);
  
  server.begin();
  Serial.println("HTTP server started");

  strStartPage = "<center><a href=\"c?n=1\"> <button style=font-size:50px;width:50%;height:150> 1 </button>


";
  strStartPage += "<a href=\"c?n=2\"> <button style=font-size:50px;width:50%;height:150> 2 </button>


";
  strStartPage += "<a href=\"c?n=3\"> <button style=font-size:50px;width:50%;height:150> 3 </button>


";
  strStartPage += "<a href=\"c?n=4\"> <button style=font-size:50px;width:50%;height:150> OK </button>


";
  strStartPage += "</a></center>";

}

void fncIndex(){
  Serial.println(server.arg(0) );
  arrEnteredCode[0] = 0;
  arrEnteredCode[1] = 0;
  arrEnteredCode[2] = 0;
  server.send(200, "text/html", strStartSpace + strStartPage);
}

void fncCheckCode(){
  Serial.println(server.arg(0) );
  
  strReceived = server.arg(0);
  intDigitReceived = strReceived.toInt();

  Serial << "intDigitReceived= " << intDigitReceived << " arrEnteredCode[0]= " <<  arrEnteredCode[0] << " arrEnteredCode[1]= " <<  arrEnteredCode[1] <<  " arrEnteredCode[2]= " <<  arrEnteredCode[2] << endl;

  //app wil request /c?n=322 for instantly opening the door
  if(intDigitReceived == 322){
      digitalWrite(gpio0_pin, HIGH);
      delay(500);
      digitalWrite(gpio0_pin, LOW);
      arrEnteredCode[0] = 0;
      arrEnteredCode[1] = 0;
      arrEnteredCode[2] = 0;
  }

  
  //if OK is pressed and the code is correct, open the door
  if(intDigitReceived == 4 && arrEnteredCode[0] == arrPassCode[0] && arrEnteredCode[1] == arrPassCode[1] && arrEnteredCode[2] == arrPassCode[2]){
      arrEnteredCode[0] = 0;
      arrEnteredCode[1] = 0;
      arrEnteredCode[2] = 0;
      digitalWrite(gpio0_pin, HIGH);
      delay(500);
      digitalWrite(gpio0_pin, LOW);
      server.send(200, "text/html", strStartSpace + strStartPage);
    }else{
    
        // 3 is the first digit of the passcode, if three is entered start at the beginning of arrEnteredCode  
        if( intDigitReceived == 3){
          arrEnteredCode[0] = 3;
          arrEnteredCode[1] = 0;
          arrEnteredCode[2] = 0;
          intIndex = 1;
        }else{
          arrEnteredCode[intIndex] = intDigitReceived;
          intIndex++;
          if(intIndex == 3){
            intIndex = 0;
          }
        }
      
        //display entered code
        strNewPage = "
<center><font size=\"80\">" + String(arrEnteredCode[0]) + String(arrEnteredCode[1]) + String(arrEnteredCode[2]) + "</font></center>
" + strStartPage;
        server.send(200, "text/html", strNewPage);
    }
  
}
 
void loop(void){
  server.handleClient();
}

"my final product should be a web page with an on and off button(s) that triggers the movement of servos."

You will need something with internet type connectivity. I've made simple web pages that controlled servos connected to an arduino with an ethernet shield. The ESP based wifi boards might be a good choice now days due to more memory and ease of setup. A web control page can be very simple like below

<HTML>
<HEAD>
<H2>Simple Servo Control Page</H2>
<TITLE>Simple Servo Control Page</TITLE>
</HEAD>
<BODY>

<P>
Servo 1: 
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&000'>L</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&012'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&024'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&038'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&051'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&064'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&076'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&089'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&102'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&114'>C</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&127'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&140'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&154'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&165'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&178'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&191'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&203'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&216'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&229'>R</a>
<P>
Servo 2: 
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&000'>L</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&012'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&024'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&038'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&051'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&064'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&076'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&089'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&102'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&114'>C</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&127'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&140'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&154'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&165'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&178'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&191'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&203'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&216'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&229'>R</a>
<P>
Servo 3: 
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&000'>L</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&012'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&024'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&038'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&051'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&064'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&076'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&089'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&102'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&114'>C</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&127'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&140'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&154'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&165'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&178'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&191'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&203'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&216'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&229'>R</a>
<P>
Servo 4: 
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&000'>L</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&012'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&024'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&038'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&051'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&064'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&076'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&089'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&102'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&114'>C</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&127'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&140'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&154'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&165'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&178'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&191'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&203'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&216'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&229'>R</a>
<P>
Servo 5: 
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&000'>L</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&012'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&024'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&038'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&051'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&064'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&076'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&089'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&102'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&114'>C</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&127'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&140'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&154'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&165'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&178'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&191'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&203'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&216'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&229'>R</a>
<P>
Servo 6: 
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&000'>L</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&012'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&024'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&038'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&051'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&064'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&076'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&089'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&102'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&114'>C</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&127'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&140'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&154'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&165'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&178'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&191'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&203'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&216'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&229'>R</a>
<P>
Servo 7: 
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&000'>L</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&012'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&024'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&038'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&051'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&064'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&076'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&089'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&102'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&114'>C</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&127'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&140'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&154'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&165'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&178'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&191'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&203'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&216'>*</a>
<a href='http://zoomkat.d2g.com/cgi/ZK2PTB.bat?07&229'>R</a>
<P>
</body>
</html>

SteveMann:
The Wemos D1 Mini and NodeMCU boards will also work. You program them using the Arduino IDE, just as if they were an Arduino board, and they have WiFi built in. There's a couple of server example projects in the IDE.

would any of those work with the iot dashboard??

tank1334:
would any of those work with the iot dashboard??

What(?) IOT Dashboard?
If it will run on an Arduino, chances are very good that it will run on an ESP8266 board.

so i was decided to go on the "easy" route and just use my raspberry pi, i have a program running there that is controlled by a telegram bot to turn on and off an led and it works fine.

any idea how to make it control the arduino code?? btw i would also like if possible to keep the ir control functionality.

code for pi:(access token is fake)

#coder :- Salman Faris

import sys
import time
import random
import datetime
import telepot
import RPi.GPIO as GPIO

#LED
def on(pin):
        GPIO.output(pin,GPIO.HIGH)
        return
def off(pin):
        GPIO.output(pin,GPIO.LOW)
        return
# to use Raspberry Pi board pin numbers
GPIO.setmode(GPIO.BOARD)
# set up GPIO output channel
GPIO.setup(11, GPIO.OUT)

def handle(msg):
    chat_id = msg['chat']['id']
    command = msg['text']

    print 'Got command: %s' % command

    if command == 'on':
       bot.sendMessage(chat_id, on(11))
    elif command =='off':
       bot.sendMessage(chat_id, off(11))

bot = telepot.Bot('Bot Token')
bot.message_loop(handle)
print 'I am listening...'

while 1:
     time.sleep(10)

and for arduino:

#include <Servo.h>

#include <IRremote.h>

int servoPin = 3;
int servo1Pin = 8;

const int RECV_PIN = 7;
IRrecv irrecv(RECV_PIN);
decode_results results;

Servo Servo1;
Servo servo2;
void setup() {
  irrecv.enableIRIn();
  irrecv.blink13(true);
  Servo1.attach(3);  // attaches the servo on pin 3 to the servo object
  servo2.attach(8);

}

void loop() {
  if (irrecv.decode(&results)) {

    switch (results.value) {
      case 16726215: //Keypad button "5"
        on2();
        break;
    }
    switch (results.value) {
      case 16730805:
        off2();
        break;
    }

    irrecv.resume();
  }

}


  void on2() {

  servo2.write(180);
  delay(500);
  Servo1.writeMicroseconds(850);
  
}


void off2() {
 
    Servo1.writeMicroseconds(2500);
     delay(500);
     servo2.writeMicroseconds(850);

}