ESP Gate Opener

9 years 3 months ago - 9 years 3 months ago #216 by cdj
ESP Gate Opener was created by cdj
Hi, the idea is to make a gate opener with the follow sketch replacing RCSwitch with ESP IOT drivers (and obviously to integrate in EasyIOT)..Do u want to kill me ? :)
P.S. Sorry for italian, i try to translate comments...
#include <RCSwitch.h>
 
 
 
RCSwitch mySwitch = RCSwitch();
 
 
 
#define interruptAntenna 1 // pin 3
 
#define pinAlimentazione 4 //powerpin
 
#define pinScambioMarcia 5 //pin to change way of motor
 
#define pinFotocellule 6 // sensors pin when someone pass in front of gate
 
#define pinPulsante 7
 
 
 
int keycode = 5393;
 
boolean ultimaMarcia = false; // assumiamo FALSE = chiudi (CLOSE GATE) - TRUE = apri - (OPEN GATE)
 
boolean muovi = false; // muovi=move
 
unsigned long T;
 
int deltaT = 5000; // tempo di marcia del cancello/serranda per apertura/chiusura (da scegliersi in base alle proprie situazioni) - time necessary to open or close gate 
 
 
void setup()
 
{
 
pinMode(pinAlimentazione, OUTPUT);
 
pinMode(pinScambioMarcia, OUTPUT);
 
pinMode(pinFotocellule, INPUT);
 
pinMode(pinPulsante, INPUT);
 
 
 
mySwitch.enableReceive(interruptAntenna);
 
}
 
 
void loop()
 
{
 
 // se stiamo eseguendo la marcia "chiudi"
 
// e viene rilevato un ostacolo dalle fotocellule fermo tutto
 
 // if some person cross the sensors stop everything
 
if ( digitalRead(pinAlimentazione) == HIGH && ultimaMarcia && digitalRead(pinFotocellule) == LOW ) muovi = false;
 
 
 
// se ho ricevuto un segnale dal telecomando o dal pulsante
//if i receive a signal from remote control , in our case from EasyIOT ESP8266 Node :) 
 
 
if ( segnale() || digitalRead(pinPulsante) == HIGH )
 
{
 
// e il cancello/serranda è in movimento fermo tutto
 //if gate is moving stop everything 
 
 
if ( digitalRead(pinAlimentazione) == HIGH )
 
{
 
digitalWrite(pinAlimentazione, LOW);
 
muovi = false;
 
ultimaMarcia = ! ultimaMarcia;
 
}
 
// altrimenti setto il verso di marcia opposto al precedente.
// or i set inverse direction of gate  
 
 
else
 
{
 
if ( ultimaMarcia ) digitalWrite(pinScambioMarcia, LOW); // chiudi
 
else digitalWrite(pinScambioMarcia, HIGH); // apri
 
 
 
muovi = true;
 
T = millis();
 
}
 
}
 
 
 
// faccio partire la marcia finché non scade il tempo di marcia prestabilito
 
// oppure qualcuno o qualcosa bloccano la marcia
  
//let start gate open and stop after time defined.... 
 
if ( muovi && (millis() - T) < deltaT ) digitalWrite(pinAlimentazione, HIGH);
 
else
 
{
 
digitalWrite(pinAlimentazione, LOW);
 
muovi = false;
 
ultimaMarcia = ! ultimaMarcia;
 
}
 
}
 
 
 
// funzione per ricevere il segnale dal telecomando
 //function to receive signal from RF - must be  replaced with ESP....
 
 
boolean segnale()
 
{
 
if ( mySwitch.available() )
 
{
 
if ( mySwitch.getReceivedValue() == keycode ) return true;
 
else return false;
 
 
 
mySwitch.resetAvailable();
 
}
 
else return false;
 
}


What do you think about ???

Please Log in or Create an account to join the conversation.

9 years 3 months ago - 9 years 3 months ago #231 by EasyIoT
Replied by EasyIoT on topic ESP Gate Opener

cdj wrote: Hi, the idea is to make a gate opener with the follow sketch replacing RCSwitch with ESP IOT drivers (and obviously to integrate in EasyIOT)..Do u want to kill me ? :)
P.S. Sorry for italian, i try to translate comments...

#include <RCSwitch.h>
 
 
 
RCSwitch mySwitch = RCSwitch();
 
 
 
#define interruptAntenna 1 // pin 3
 
#define pinAlimentazione 4 //powerpin
 
#define pinScambioMarcia 5 //pin to change way of motor
 
#define pinFotocellule 6 // sensors pin when someone pass in front of gate
 
#define pinPulsante 7
 
 
 
int keycode = 5393;
 
boolean ultimaMarcia = false; // assumiamo FALSE = chiudi (CLOSE GATE) - TRUE = apri - (OPEN GATE)
 
boolean muovi = false; // muovi=move
 
unsigned long T;
 
int deltaT = 5000; // tempo di marcia del cancello/serranda per apertura/chiusura (da scegliersi in base alle proprie situazioni) - time necessary to open or close gate 
 
 
void setup()
 
{
 
pinMode(pinAlimentazione, OUTPUT);
 
pinMode(pinScambioMarcia, OUTPUT);
 
pinMode(pinFotocellule, INPUT);
 
pinMode(pinPulsante, INPUT);
 
 
 
mySwitch.enableReceive(interruptAntenna);
 
}
 
 
void loop()
 
{
 
 // se stiamo eseguendo la marcia "chiudi"
 
// e viene rilevato un ostacolo dalle fotocellule fermo tutto
 
 // if some person cross the sensors stop everything
 
if ( digitalRead(pinAlimentazione) == HIGH && ultimaMarcia && digitalRead(pinFotocellule) == LOW ) muovi = false;
 
 
 
// se ho ricevuto un segnale dal telecomando o dal pulsante
//if i receive a signal from remote control , in our case from EasyIOT ESP8266 Node :) 
 
 
if ( segnale() || digitalRead(pinPulsante) == HIGH )
 
{
 
// e il cancello/serranda è in movimento fermo tutto
 //if gate is moving stop everything 
 
 
if ( digitalRead(pinAlimentazione) == HIGH )
 
{
 
digitalWrite(pinAlimentazione, LOW);
 
muovi = false;
 
ultimaMarcia = ! ultimaMarcia;
 
}
 
// altrimenti setto il verso di marcia opposto al precedente.
// or i set inverse direction of gate  
 
 
else
 
{
 
if ( ultimaMarcia ) digitalWrite(pinScambioMarcia, LOW); // chiudi
 
else digitalWrite(pinScambioMarcia, HIGH); // apri
 
 
 
muovi = true;
 
T = millis();
 
}
 
}
 
 
 
// faccio partire la marcia finché non scade il tempo di marcia prestabilito
 
// oppure qualcuno o qualcosa bloccano la marcia
  
//let start gate open and stop after time defined.... 
 
if ( muovi && (millis() - T) < deltaT ) digitalWrite(pinAlimentazione, HIGH);
 
else
 
{
 
digitalWrite(pinAlimentazione, LOW);
 
muovi = false;
 
ultimaMarcia = ! ultimaMarcia;
 
}
 
}
 
 
 
// funzione per ricevere il segnale dal telecomando
 //function to receive signal from RF - must be  replaced with ESP....
 
 
boolean segnale()
 
{
 
if ( mySwitch.available() )
 
{
 
if ( mySwitch.getReceivedValue() == keycode ) return true;
 
else return false;
 
 
 
mySwitch.resetAvailable();
 
}
 
else return false;
 
}


What do you think about ???


Hi. It can be done with EasyIoT framework. I guess you want me to build you a project. Now we provide service for this. Please see consulting contact form.
Hope some other user in community with similar problem will help you to build gate opener if you do not decide for consulting service.

Please Log in or Create an account to join the conversation.

9 years 3 months ago #234 by cdj
Replied by cdj on topic ESP Gate Opener
Well, i try to adapt it by myself , and then i decide for consulting service ! thanks !
Dario

Please Log in or Create an account to join the conversation.

9 years 3 months ago #238 by EasyIoT
Replied by EasyIoT on topic ESP Gate Opener

cdj wrote: Well, i try to adapt it by myself , and then i decide for consulting service ! thanks !
Dario


I strongly suggest you to do it by yourself. You will have a lot of fun and you will learn a lot of new things. Actually I don't have time for "consulting service".
The following user(s) said Thank You: cdj

Please Log in or Create an account to join the conversation.

9 years 3 months ago #241 by cdj
Replied by cdj on topic ESP Gate Opener
I wanna try but i'm not sure that my newbies c programmer knowhow permit that :)

Please Log in or Create an account to join the conversation.

9 years 3 months ago - 9 years 2 months ago #281 by cdj
Replied by cdj on topic ESP Gate Opener
Ok I EDIT POST :

please i'm becoming crazy since 2 days.
Now i'm at this point :

Sorry for Italian in code :
#include <Esp8266EasyIoT.h>
#include <SoftwareSerial.h> 
Esp8266EasyIoT esp; 
SoftwareSerial serialEsp(2,3); 
 
#define pinAlimentazione 6
#define pinScambioMarcia 9
#define pinFotocellule 10
#define pinPulsante 11
#define CANCELLOAPERTO HIGH // GPIO value to write to turn on attached relay
#define CANCELLOCHIUSO LOW // GPIO value to write to turn off attached relay
 
boolean ultimaMarcia = false; // assumiamo FALSE = chiudi  - TRUE = apri
boolean muovi = false;
unsigned long T;
int deltaT = 5000; // tempo di marcia del cancello/serranda per apertura/chiusura (da scegliersi in base alle proprie situazioni)

 
void setup()
 
{

  serialEsp.begin(9600);
  Serial.begin(115200);  

  Serial.println("EasyIoTEsp init");

  esp.begin(incomingMessage, 3, &serialEsp, &Serial);

  
pinMode(pinAlimentazione, OUTPUT);
// esp.present(6, S_DIGITAL_OUTPUT);
pinMode(pinScambioMarcia, OUTPUT);
// esp.present(9, S_DIGITAL_OUTPUT);
pinMode(pinFotocellule, INPUT);
// esp.present(10, S_DIGITAL_INPUT);
pinMode(pinPulsante, INPUT);
  esp.present(11, S_DIGITAL_INPUT);
 
}
 
void loop()
 
{
   esp.process();
// se stiamo eseguendo la marcia "chiudi"
// e viene rilevato un ostacolo dalle fotocellule fermo tutto
 
if ( digitalRead(pinAlimentazione) == HIGH && ultimaMarcia && digitalRead(pinFotocellule) == LOW ) muovi = false;

// se ho ricevuto un segnale dal telecomando o dal pulsante
//if ( segnale() || digitalRead(pinPulsante) == HIGH )
 if ( digitalRead(pinPulsante) == HIGH )
{
 
// e il cancello/serranda è in movimento fermo tutto
if ( digitalRead(pinAlimentazione) == HIGH )
 
{
 
digitalWrite(pinAlimentazione, LOW);
muovi = false;
ultimaMarcia = ! ultimaMarcia;
}
 
// altrimenti setto il verso di marcia opposto al precedente.
 
else
{
if ( ultimaMarcia ) digitalWrite(pinScambioMarcia, LOW); // chiudi
else digitalWrite(pinScambioMarcia, HIGH); // apri
muovi = true;
 
T = millis();
 
}
 
}
// faccio partire la marcia finché non scade il tempo di marcia prestabilito
// oppure qualcuno o qualcosa bloccano la marcia

if ( muovi && (millis() - T) < deltaT ) digitalWrite(pinAlimentazione, HIGH);
 
else
 
{
digitalWrite(pinAlimentazione, LOW);
muovi = false;
ultimaMarcia = ! ultimaMarcia;
}
 
}


void incomingMessage(const Esp8266EasyIoTMsg &message) {
  // We only expect one type of message from controller. But we better check anyway.

  Serial.println("New message");
  if (message.type==V_DIGITAL_VALUE) {
    // Change pinPulsante state to on and to off again immediately to simulate pression of button ?
digitalWrite(message.sensor-1+pinPulsante, message.getBool()?CANCELLOAPERTO:CANCELLOCHIUSO);
digitalWrite(message.sensor-1+pinPulsante, message.getBool()?CANCELLOAPERTO:CANCELLOCHIUSO);
    Serial.print("Incoming change for sensor:");
    Serial.print(message.sensor);
    Serial.print(", New status: ");
    Serial.println(message.getBool());
  } 
}

In other words i need to simulate button pression from easyiot....

Pin interested is pinPulsante with HIGH and LOW value
This is a button
so i press the button and it immediately release.
I've tried also as digital input in my esp node that as digital output.
As digital output it seems to do something but doesn't activate relay... sob

PLEASE HELP ME, I'M REALLY DESPERATE


I'm a very bad programmer i know :)
Thanks
Dario

Please Log in or Create an account to join the conversation.

Time to create page: 0.327 seconds

Forum latest

  • No posts to display.