How do I control an ESP32 via Wifi and with physical buttons?

Hello together

I am new to this forum as well as dealing with arduino and programming languages. If I do something wrong please tell me. Thanks for your help.

Edit: The post was temporarily locked. I am sorry if I am doing something wrong or have expressed myself incorrectly. Please just tell me what to change, as I said I am new to this forum.

So I'm trying to control three leds with the ESP32 NodeMCU developer board. I want to control the brightness of two of them independently with a potentiometer. And the red one I want to switch on and off with a simple button press.

So far so good. I have been inspired on the internet and tinkered a code with which these functions work properly. (code is attached)

Now to my question / problem:
I would like to be able to control the same function via smartphone or Pc in the home Wifi. I do not need a web overlay, a simple URL which executes the commands would be enough.

I found these two projects which show a similar functionality to how I want it to work:

  1. ESP32 Web Server
  2. ESP32 Web Server with Slider

The first one would be great to control the red LED and the second one would be perfect to control the brightness of the two yellow ones with HTTP requests.

But I have not managed to combine these two, as well as to create two sliders. I think it would be very easy, but as I said I am new to all this.

Also, I haven't figured out how to run the old code (pasted below) at the same time to control everything physically.

I am glad for any help. Thanks a lot!

My old code:

#include <analogWrite.h>

#define LED1 5
#define LED2 18
#define LED3 19
#define BUTTON 23
#define POTI1 35
#define POTI2 13

int LED1VALUE = 150;
int LED2VALUE = 150;
int BUTTONSTATE;
int LED3STATE = 0;
boolean lastBUTTONSTATE = LOW;

void setup() //setup Code
{
  pinMode(LED1, OUTPUT);
  pinMode(LED2, OUTPUT);
  pinMode(LED3, OUTPUT);
  pinMode(POTI1, INPUT);
  pinMode(POTI2, INPUT);
  pinMode(BUTTON, INPUT_PULLUP);
}

void loop()
{
   BUTTONSTATE = digitalRead(BUTTON);
   if (BUTTONSTATE != lastBUTTONSTATE) {
   lastBUTTONSTATE = BUTTONSTATE;
   if (BUTTONSTATE == LOW) {
   LED3STATE = (LED3STATE == HIGH) ? LOW: HIGH;
   digitalWrite(LED3, LED3STATE);}}
   
   int potentiometerValue1 = analogRead(POTI1);
   LED1VALUE = potentiometerValue1 / 16.06;
   analogWrite(LED1, LED1VALUE);

   int potentiometerValue2 = analogRead(POTI2);
   LED2VALUE = potentiometerValue2 / 16.06;
   analogWrite(LED2, LED2VALUE);
  
  }

My setup:

The random nerd web site is a good resource.

One way but not necessarily the way is to use an MQTT Broker as a go between the ESP32 and the other thing.

The other thing could publish messages to the MQTT Broker. The subscribed ESP32 could then get the message and respond to the message.

As an example.

I have a ESP32 in place of my thermostat. I go to my website and run my homes HVAC system or I can water my plants or set the humidity or read the information that the weather station is sending from my backyard. I've got 13 ESP32's doing things around the property all managed remotely.

Okay, this sounds interesting. As I said, I'm not really familiar with the subject. But as I understand it, you need an extra device or a cloud solution as a broker, and that's not my goal. I think it must be somehow possible to implement this locally on the device...
But thanks for your answer, I will have a closer look.

Nope. Nothing to do with you. @system is just surprisingly stupid and, with each passing day, gets stupider. In other words, @system flagged your posts because @system is being taught to harass the moderators.

In any case, good luck with your project.

1 Like

Hi @Simiba. I apologize for any confusion caused by the false detection from the forum's automated spam prevention system.

As @Coding_Badly explained, the automated system is sometimes triggered incorrectly by legitimate posts. This is why human moderators review every action taken by the automated system. So we are sure to correct any errors, but sometimes that results in an unfortunate delay where a post or account is locked down until a human arrives to take a look.


In this case, no teaching was involved. It is a simple bit of arithmetic you can see here in the Discourse forum software source code:

https://github.com/discourse/discourse/blob/c88ca23e8f657de747a5ad864978970f1bd3fa56/app/models/post.rb#L405

  # Prevent new users from posting the same hosts too many times.
  def has_host_spam?
    return false if acting_user.present? && (acting_user.staged? || acting_user.mature_staged? || acting_user.has_trust_level?(TrustLevel[1]))
    return false if topic&.private_message?

    total_hosts_usage.values.any? { |count| count >= SiteSetting.newuser_spam_host_threshold }
  end

The action was explained by the message the system sent to the moderators:

(text via Google Translate)


The system is triggered when all of the following conditions are present:

  • User has "trust level" 0.
  • User made public posts containing links to a given domain at least the number of times set in the forum's newuser_spam_host_threshold configuration.
  • The domain is not in the list of allowed domains set in the forum's allowed_spam_host_domains configuration.

The Arduino forum has newuser_spam_host_threshold set to 3. Prior to the edits, there were three links to the randomnerdtutorials.com domain in posts made by Simiba:

  1. ESP32 Web Server - Arduino IDE | Random Nerd Tutorials
  2. ESP32 Web Server with Slider: Control LED Brightness (PWM) | Random Nerd Tutorials
  3. ESP32 Web Server - Arduino IDE | Random Nerd Tutorials

At that time, randomnerdtutorials.com was not included in the Arduino Forum's allowed_spam_host_domains configuration.


I have now added randomnerdtutorials.com to our allowed_spam_host_domains configuration, so the newuser_spam_host_threshold will not apply to links to that domain in any future posts.

2 Likes

Ah, I'm glad I didn't do anything wrong. Thanks for your detailed explanation! Exciting to see how the system works. :smile:

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.