Help in writing program

Hello. New'm in the forum and in the middle which is trying to unwind. Namely programming and mainly with Arduino. As a profession and I've studied electrician. And I attempt to develop a smart home project. But for the first time to control from 1 to 8 relays via smartphone. I have Arduino Mega relay module and Wifi module. Could someone help me with writing a program for this activity. Thanks in advance. :)

Welcome to the forum!

A quick internet search for "auduino wifi relay" leads to https://openhomeautomation.net/wireless-relay-arduino-wifi/ and lots of other projects as well. Hopefully you will find something to get you started.

rw950431: Welcome to the forum!

A quick internet search for "auduino wifi relay" leads to https://openhomeautomation.net/wireless-relay-arduino-wifi/ and lots of other projects as well. Hopefully you will find something to get you started.

I've been looking everywhere. But nothing concrete and completed on and drop topic. This topic you gave colleague does not help me. I have mega, relays and wifi esp8266. I do not know how to contact the scheme and program to write? Thank you and I apologize for the issues.

If you want someone to write code for you (and are prepared to pay them) then try posting in the “Gigs and collaborations” sections.

Otherwise you will have to break the project into small sections and solve each problem as it comes along. Usually each component sold for arduino will have some example code with it- its good to work through each example until you fully understand it. After you have understanding of each component then you begin to combine them.

Try the following steps.

  1. Make the mega blink its LED, then change the blink time. (This makes sure your computer is set up properly)

  2. Wire up the relay module. Write a short program to open and close each relay. Check with a multimeter or something. (This makes sure you understand the connection between the physical pins and the software codes).

  3. Wire up the ESP8266. Write a basic program that connects to your Wifi. Modify it so it fetches a simple web page. (this makes sure you can connect to the internet)

  4. After this the code for other projects on the web should start to make sense to you.

rw950431: If you want someone to write code for you (and are prepared to pay them) then try posting in the "Gigs and collaborations" sections.

Otherwise you will have to break the project into small sections and solve each problem as it comes along. Usually each component sold for arduino will have some example code with it- its good to work through each example until you fully understand it. After you have understanding of each component then you begin to combine them.

Try the following steps.

  1. Make the mega blink its LED, then change the blink time. (This makes sure your computer is set up properly)

  2. Wire up the relay module. Write a short program to open and close each relay. Check with a multimeter or something. (This makes sure you understand the connection between the physical pins and the software codes).

  3. Wire up the ESP8266. Write a basic program that connects to your Wifi. Modify it so it fetches a simple web page. (this makes sure you can connect to the internet)

  4. After this the code for other projects on the web should start to make sense to you.

I did not understand what you mean? To start from scratch you ...? I'm effected control 8 relays but in bluetooth. Everything works perfectly. But my problem is with esp8829 not know how to connect the module itself and to write the program. If anyone can help me I would be very grateful.

What exactly is your problem? Are you having problems in using the ESP8266 module?

WSGomes:
What exactly is your problem?
Are you having problems in using the ESP8266 module?

I found a project that was ready with a diagram and written program made whole lot which was described but did not work … This is a project. http://androidcontrol.blogspot.bg/2015/05/arduino-wifi-control-with-esp8266-module.html?m=1

It’s written program go to climb but I get error.

/*
ESP8266 library


When you use it with MEGA board, the connection should be like these:
ESP8266_TX->RX1(D19)
ESP8266_RX->TX1(D18)
ESP8266_CH_PD->3.3V
ESP8266_VCC->3.3V
ESP8266_GND->GND


When you want to output the debug information, please use DebugSerial. For example,

DebugSerial.println("hello");


Note: The size of message from ESP8266 is too big for arduino sometimes, so the library can't receive the whole buffer because  
the size of the hardware serial buffer which is defined in HardwareSerial.h is too small.

Open the file from \arduino\hardware\arduino\avr\cores\arduino\HardwareSerial.h.
See the follow line in the HardwareSerial.h file.

#define SERIAL_BUFFER_SIZE 64

The default size of the buffer is 64. Change it into a bigger number, like 256 or more.

*/


//#define SSID       "dlink"
//#define PASSWORD   "0814931872"

#define SSID       "SmartHome"
#define PASSWORD   "0816452400"

#include "uartWIFIUNO.h"
#include <SoftwareSerial.h>
#include <LiquidCrystal.h>
#include "declare.h"


void setup()
{
 pinMode(ledPin, OUTPUT); 
 pinMode(relay1, OUTPUT); 
 pinMode(relay2, OUTPUT);
 pinMode(relay3, OUTPUT);
 pinMode(relay4, OUTPUT);
 
 //pinMode(ESP8266_CHPD, OUTPUT);
 //digitalWrite(ESP8266_CHPD,LOW);
 
 digitalWrite(relay1,LOW);
 digitalWrite(relay2,LOW);
 digitalWrite(relay3,LOW);
 digitalWrite(relay4,LOW);
 
  DebugSerial.println("ESP8266 Server v0.2");
  
  // set up the LCD's number of columns and rows: 
 lcd.begin(16, 2);  
 lcd.print("ESP8266 Control");            // Print a message to the LCD.
 
 lcd.setCursor(0,1);                               // set the cursor to (16,1):
 lcd.print("Init...");                             // Print a message to the LCD.
 
 
 if(!wifi.begin())
 {
  DebugSerial.println("Begin error");
 }
 bool b = wifi.Initialize(STA, SSID, PASSWORD);
 if(!b)
 {
   DebugSerial.println("Init error");
    resetFunc();
   
   
 }
 delay(8000);  //make sure the module can have enough time to get an IP address 
 String ipstring  = wifi.showIP();
 DebugSerial.println(ipstring); //show the ip address of module
       lcd.setCursor(0,0);                               // set the cursor to (16,1):
       lcd.print(ipstring);
 
 delay(1000);
 wifi.confMux(1);
 delay(100);
 if(wifi.confServer(1,80))
DebugSerial.println("Server is set up");

       lcd.setCursor(0,1);                               // set the cursor to (16,1):
       lcd.print("Start Server"); 
       lcd.setCursor(0,1);                               // set the cursor to (16,1):
       lcd.print("online      "); 


}
void loop()
{
 
 char buf[500];
 int iLen = wifi.ReceiveMessage(buf);
 
 if(iLen > 0)
 {
   
     DebugSerial.print(buf);
     //delay(100);
         
      if (strncmp(buf, "GET /?status1=1", 15) == 0) {               
          //DebugSerial.print("RELAY 1 ON");
          digitalWrite(relay1, HIGH); 
          device1 = true;           
      }   
      else if (strncmp(buf, "GET /?status1=0", 15) == 0) {               
          //DebugSerial.print("RELAY 1 OFF");
          digitalWrite(relay1, LOW); 
          device1 = false;           
      } 
               
   
   if (strncmp(buf, "GET /?status2=1", 15) == 0) {               
          //DebugSerial.print("RELAY 2 ON");
          digitalWrite(relay2, HIGH); 
          device2 = true;           
      }   
      else if (strncmp(buf, "GET /?status2=0", 15) == 0) {               
          //DebugSerial.print("RELAY 2 OFF");
          digitalWrite(relay2, LOW); 
          device2 = false;           
      } 
      
      
      if (strncmp(buf, "GET /?status3=1", 15) == 0) {               
          //DebugSerial.print("RELAY 3 ON");
          digitalWrite(relay3, HIGH); 
          device3 = true;           
      }   
      else if (strncmp(buf, "GET /?status3=0", 15) == 0) {               
          //DebugSerial.print("RELAY 3 OFF");
          digitalWrite(relay3, LOW); 
          device3 = false;           
      } 
      
      if (strncmp(buf, "GET /?status4=1", 15) == 0) {               
          //DebugSerial.print("RELAY 4 ON");
          digitalWrite(relay4, HIGH); 
          device4 = true;           
      }   
      else if (strncmp(buf, "GET /?status4=0", 15) == 0) {               
          //DebugSerial.print("RELAY 4 OFF");
          digitalWrite(relay4, LOW); 
          device4 = false;           
      } 
     
     
     String cmd;
     cmd = "HTTP/1.1 200 OK\r\n";
     cmd += "Content-Type: text/html\r\n";
     cmd += "Connection: close\r\n";
     cmd += "Refresh: 15\r\n";
     cmd += "\r\n";
     cmd += "<!DOCTYPE HTML>\r\n";
     cmd += "<html>\r\n";
     //cmd += "<header><title>ESP8266 Webserver</title><h1>\"ESP8266 Web Server Control\"</h1></header>";
     
     
     if(device1){
       cmd +=("
<h2>Device1  : ON</h2>");
     }
     else{
       cmd +=("
<h2>Device1  : OFF</h2>");
     }
     
     if(device2){
       cmd +=("
<h2>Device2  : ON</h2>");
     }
     else{
       cmd +=("
<h2>Device2  : OFF</h2>");
     }
     
     
      if(device3){
       cmd +=("
<h2>Device3  : ON</h2>");
     }
     else{
       cmd +=("
<h2>Device3  : OFF</h2>");
     }
     
     if(device4){
       cmd +=("
<h2>Device4  : ON</h2>");
     }
     else{
       cmd +=("
<h2>Device4  : OFF</h2>");
     }
     
     
     cmd += "<html>\r\n";

       wifi.Send(chlID,cmd);
       //delay(100);
       wifi.closeMux(chlID);
//delay(1000);

 }
} 


// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);


WIFIUNO wifi;

extern int chlID;

// set pin numbers:
const int ledPin =  13;      // the number of the LED pin

const int relay1 =  22;
const int relay2 =  23;
const int relay3 =  24;
const int relay4 =  25; 

boolean device1 = false;
boolean device2 = false;
boolean device3 = false;
boolean device4 = false;

const int ESP8266_CHPD = 8;


boolean readyy = false;

int result = 0;
int OK = 1;
int TIMEOUT = 2 ;
int CANCEL = 3;
int NOT_FOUND = 4;

int i;
int m=0;
int lp = 0;

char inputChar[500];
int len = 0;


//String serverip="192.168.1.37";
String port="80";
String cmd;
String myIP;

int currentID;

int ch_id, packet_len;
char *pb;


void(* resetFunc) (void) = 0;                          //declare reset function at address 0

The error is this - C:\Users\User\Desktop\Arduino Mega Code\webserver_MEGA\webserver_MEGA.ino:37:25: fatal error: uartWIFIUNO.h: No such file or directory

#include “uartWIFIUNO.h”

^

compilation terminated.

exit status 1
Error compiling for board Arduino/Genuino Mega or Mega 2560.

?

First of all, to post code use the “code” tags

now, the error is very trivial: “No such file or directory”

that’s because you don’t have an “uartWIFIUNO.h” file in your libraries folder. is probably an external library that you must download

nanofede: First of all, to post code use the "code" tags

now, the error is very trivial: "No such file or directory"

that's because you don't have an "uartWIFIUNO.h" file in your libraries folder. is probably an external library that you must download

I apologize but I did not understand what you mean error (library)?

i recommend you read some basics stuffs before start your projects

Libraries

nanofede: i recommend you read some basics stuffs before start your projects

Libraries

well .... I wanted a little help to direct me where my mistakes. but apparently will not get this help thanks

Lubomir,

welcome to the forum. I think there is misunderstanding. The language? Read carefully. I think nanofede's advice was correct. First of all you should post the code in the code tags to be better readable (the leftmost button above edit window). It is one of the forum rules and would be nice to respect it. Your problem is quite simple, you are missing the "uartWIFIUNO.h" file. May be it is just in wrong folder. Finally, little advice: be patient and wait. People here are willing to help you.

Budvar10: Lubomir,

welcome to the forum. I think there is misunderstanding. The language? Read carefully. I think nanofede's advice was correct. First of all you should post the code in the code tags to be better readable (the leftmost button above edit window). It is one of the forum rules and would be nice to respect it. Your problem is quite simple, you are missing the "uartWIFIUNO.h" file. May be it is just in wrong folder. Finally, little advice: be patient and wait. People here are willing to help you.

Thanks. I fixed my mistake with the introduction of the code. Please be excused. The questions I think it's clear that I'm a novice. For this and maybe the ask stupid questions. But I want to learn and to accomplish my project. But still do not understand what is missing or what is wrong wrote code If you can explain to me in simple ... Thanks a lot

I apologize if I was rude.

if you read the link about libraries, you may see that are some standard libraries (like ethernet, eeprom, softwareserial, etc) already included in the ide when you download it, but some other special libraries (like nrf24l01 or the one you try to use) are made by external people to the arduino project and must be downloaded manualy and placed in the “Libraries” folder where you install your ide

almost allways these libraries are finded in github

Excellent, I like the way how the things were solved. Karma for both. :)

nanofede: I apologize if I was rude.

if you read the link about libraries, you may see that are some standard libraries (like ethernet, eeprom, softwareserial, etc) already included in the ide when you download it, but some other special libraries (like nrf24l01 or the one you try to use) are made by external people to the arduino project and must be downloaded manualy and placed in the "Libraries" folder where you install your ide

almost allways these libraries are finded in github

Thanks for the explanation. And I apologize if I offended anyone. I uploaded the code in the library. I tried to get it but it gave me another error. I can not understand why. If someone is willing and wants to try to upload code to check why it is so I will be grateful.

error that gave now; C: \ Program Files (x86) \ Arduino \ libraries \ esp8266 \ webserver_MEGA \ webserver_MEGA.ino: In function 'void setup ()':

webserver_MEGA: 59: error: 'DebugSerial' was not declared in this scope

DebugSerial.println ( "ESP8266 Server v0.2");

^

webserver_MEGA: 69: error: 'wifi' was not declared in this scope

if (! wifi.begin ())

^

webserver_MEGA: 73: error: 'wifi' was not declared in this scope

bool b = wifi.Initialize (STA, SSID, PASSWORD);

^

webserver_MEGA: 73: error: 'STA' was not declared in this scope

bool b = wifi.Initialize (STA, SSID, PASSWORD);

^

C: \ Program Files (x86) \ Arduino \ libraries \ esp8266 \ webserver_MEGA \ webserver_MEGA.ino: In function 'void loop ()':

webserver_MEGA: 104: error: 'wifi' was not declared in this scope

int iLen = wifi.ReceiveMessage (buf);

^

webserver_MEGA: 109: error: 'DebugSerial' was not declared in this scope

DebugSerial.print (buf);

^

exit status 1 'DebugSerial' was not declared in this scope

help ? ???

Post your code. I'm not familiar with the ESP8266, but the errors you reported are quite basic mistakes in C programming and they mean that declaration of object is missing. Compiler cannot find used objects (wrong folder, missing header etc.). I think, you have to either #include a header or insert the declaration directly to the code. If it is library, something missing then?