I bought RF433Mhz set of STX882 and SRX882 and I studied at first this type
of wireless communcation with a simply applications of them, with Arduinos or Espressif.
I studied many web instructions about this RF communication ,
the most important and working are from Github website
and I started with this Simple example for receiving, too.
And I found on the web next good or better applications with this RF433MHz communication.
So I started with Arduinos or with Arduino Uno R3 or Arduino Nano Clone,
the cheap and reliable modules.
Instead of I tried to use ESP8266 NodeMcu modules and with very similar schetches,
but in the end I used Arduinos with more reliable function and I let ESP8266 for another application for example for their excelent ESP-now function, what is very similar to RF one . Instead of I programmed one RF433 tester for NodeMcu V0.9 .
So I started with RF-scanner example, what is the best practice to understand
to some basic principles os RF433 MHz technics.
And then I planned to create simple muster for next applications according to this RF technics
and I used to for them similar name to IOT - as RFOT .
I created as example system for traffic lights (or called semafors in my and next countries)
and here I public for this Forum my realization.
I erase my codes here and I add improved ones again
Since you posted in the “General Guidance” part of the forum, are you offering general guidance for others to read or are you asking for general guidance for this project of yours?
I see … my english is not excelent, I am sorry, but I know that every english word has more meanings .. so I must to use sometime my english dictionary, what I do sure .. and I am sorry again, but this forum is not simply in a meanings and as never has time to read all instruction, I must to follow my normal expectations what to do here or there .. so again back to meaning of the work Guidance so my dictionary translates it and in red rectangle is what a meaning I choosed for my post :
As I see, I am offering guindance according to my previous post .. but if there is another more suitable forum for this RF matter , I do not see the problem to change one.
I tested all my RF sketches on Arduino Uno R3 or Arduino Nano Clone with set of RF modules STX882 and SRX882 (exceptionally I use NodeMCU V0.9 for tester one) and all these schetches work well .. but there can be a problem with pasting them or copy them from forum .. but when this problem will occur, I am here and I can it discuss or correct here .. or explain it .. if I could explain it ...
Thanks. It might have been better to post in the Tutorial section. But wherever the thread is located you do need to first get all five sketches into the required form.They are hard to read, and would be difficult to work with.
Your text and code comments are sometimes hard to understand. Try writing them again in you native language and translating, to see if that improves understanding. And use a spell-checker!
Or, more radically, you could just summarise it something like this: ”Here are five examples of 433 MHz RF sketches covering scanning, transmitting and receiving. I’ve included brief explanations on their source and intended use. Feedback would be welcomed.”
Thank you for your advices .. what can I do is … I can read once more my comments in my sketches and then to get them here in right code fields .. but if there will be an interest to create from ones a tutorial, I let it from another forum member this next work with pleasure …
Let's see what other feedback you get. But for a start you could take the advice I offered about communication. Various tools are available for non-english posters to maximise readabilty in an english forum. Here is what I think you meant to say:
"Thank you for your advice. What I can do is read through the comments in my sketches again and then post them here using the proper code formatting. If anyone is interested in turning them into a tutorial, I would be happy to let another forum member take on that task."
//RF-433MHz-STX882-tester-1
//Arduino Uno R3 or Nano Clone as sender
/*
Sketch for sending RF data readed from serial monitor
Data are coupled with special (or crypto) pre-defined code
Examples : special code is set on 56000 here
command code switching a led on can be 101, off 100 etc.
Aketch is based on library and examles from https://github.com/sui77/rc-switch/
Reprogrammed by PavelOu
*/
// RF 433 library
#include <RCSwitch.h>
String sketchName = "RF-433MHz-STX882-tester-1.ino";
const int ledPin = 13;
byte protocolNr = 2;
long int specialCode = 56000;
byte nrBits = 32;
int intervalDat = 1000; // ms
// creating objekt senderRF from library
RCSwitch senderRF = RCSwitch();
void setup()
{
Serial.begin(9600);
pinMode(ledPin,OUTPUT);
digitalWrite(ledPin,HIGH);
delay(1000);
digitalWrite(ledPin,LOW);
Serial.println();
Serial.println(sketchName);
Serial.println("RF-OT 433 Mhz sender is starting ...");
// start of sending on pin D10
senderRF.enableTransmit(10);
// optional set of protocol on nr.2
// senderRF.setProtocol(2);
// optional set of protocol nr.5
// senderRF.setProtocol(5);
// optional
// senderRF.setRepeatTransmit(5);
protocolNr = 5;
Serial.print("Protocol: ");
Serial.println(protocolNr);
//testData = 22;
//Serial.print("Tested data: ");
//Serial.println(testData);
Serial.print("special data set: ");
Serial.println(specialCode);
nrBits = 32;
Serial.print("Used nr of bits: ");
Serial.println(nrBits);
intervalDat = 3000;
Serial.print("Interval dat: "); //optional
Serial.println(intervalDat);
senderRF.setProtocol(protocolNr);
}
void loop()
{
if (Serial.available() > 0)
{
// time from start of sketch
unsigned long casLong = millis() ;
// reading and command for sending - example 101 for set on a virtual Led
String textToSend = Serial.readString();
long int textInt = textToSend.toInt();
Serial.print("Sending Int Data: ");
Serial.println(textInt);
Serial.print("Sending special Code + Data: ");
Serial.println(specialCode+textInt);
float cas = (float)casLong / 1000;
// vypsani aktualniho casu s delkou
//Serial.print(" time in sec: "); // cas (cz) is time (en)
//Serial.println(cas);
Serial.print(" time (long) in millisec: ");
Serial.println(casLong);
Serial.print(" time (long)/ 1000 sec: ");
Serial.println((float)casLong/1000);
senderRF.send(specialCode+textInt,nrBits);
// pause before new reading of next data
digitalWrite(ledPin,HIGH);
delay(1000);
digitalWrite(ledPin,LOW);
delay(intervalDat);
}
}
//RF-OT-433-STX882-semafor-sender
//Arduino Uno R3 or Nano Clone as sender
/*
RF433-OT = RF Of Things example
semafor (cz) = traffic lights (en)
Sketch for sending of data from buttons for green, yellow and red Leds on semafor
Time for pre-defined changing of traffic light is set from serial monitor
Example : specialized code is set for my semafor to 56000 (and in receiver too)
code for switching of green led on = 101, yellow led = 201, red led = 301
specialized code is added with code for switching on leds
Sketch is based on library and examles from https://github.com/sui77/rc-switch/
Reprogrammed by PavelOu
*/
// RF 433 library
#include <RCSwitch.h>
// creating objekt senderRFe from library
RCSwitch senderRF = RCSwitch();
String sketchName = "RF-OT-433-STX882-semafor-sender.ino";
const int ledPin = 4;
const int buttonPinR = 5;
const int buttonPinY = 6;
const int buttonPinG = 7;
int buttonR = 1;
int buttonY = 1;
int buttonG = 1;
byte protocolNr = 2;
long int specialCode = 56000;
byte nrBits = 32;
int intervalDat = 1000; // ms
int rfData = 100;
long int semaforInterval = 0;
int semaforTime = 0;
bool semaforTimeRedOn = false;
bool semaforTimeGreenOn = false;
byte dataMode = 0;
void setup()
{
Serial.begin(9600);
while (!Serial)
{
delay(1000);
// wait for serial port to connect. Needed for native USB port only
}
pinMode(ledPin,OUTPUT);
pinMode(buttonPinR,INPUT_PULLUP);
pinMode(buttonPinY,INPUT_PULLUP);
pinMode(buttonPinG,INPUT_PULLUP);
digitalWrite(ledPin,HIGH);
delay(1000);
digitalWrite(ledPin,LOW);
Serial.println();
Serial.println(sketchName);
Serial.println("RF-OT 433 Mhz sender for semafor is starting ...");
// start of sending on pin D10
// optional set of protocol on nr.2
// senderRF.setProtocol(2);
// optional set of protocol nr.5
// senderRF.setProtocol(5);
protocolNr = 2;
Serial.print("Protocol: ");
Serial.println(protocolNr);
//testData = 22;
//Serial.print("Tested data: ");
//Serial.println(testData);
Serial.print("special data set: ");
Serial.println(specialCode);
nrBits = 32;
Serial.print("Used nr of bits: ");
Serial.println(nrBits);
intervalDat = 1000;
Serial.print("Interval dat: "); //optional
Serial.println(intervalDat);
semaforTime = 0;
semaforTimeRedOn = true; // semafor on interval start with Red light always
semaforTimeGreenOn = false;
buttonR = 1;
buttonY = 1;
buttonG = 1;
dataMode = 0;
Serial.println("Press one of buttons for Green, Yellow or Red Light on your semafor ...");
senderRF.setProtocol(protocolNr);
senderRF.enableTransmit(10);
}
void loop()
{
if (dataMode == 0)
{
//semafor is waiting for commands from serial link or from buttons
//or semafor will blinking with yellow led
}
if (Serial.available())
{
String serialData = Serial.readString();
semaforInterval = serialData.toInt();
if (semaforInterval > 29) // interval has to be longer then half minute
{
Serial.print("Interval of semafor: ");
Serial.print(semaforInterval);
Serial.println(" sec");
dataMode = 5;
semaforTimeRedOn = true;
}
else
{
Serial.print("Minimal time interval for semafor (your have set ");
Serial.print(semaforInterval);
Serial.println(") is 30 sec !!");
semaforInterval = 0;
dataMode = 0;
}
}
// test of buttons
buttonR = digitalRead(buttonPinR);
if (buttonR == 0)
{
Serial.println();
Serial.println("button for semafor red light was pressed ...");
rfData = 301;
dataMode = 1;
delay(1000);
}
buttonY = digitalRead(buttonPinY);
if (buttonY == 0)
{
Serial.println();
Serial.println("button for semafor yellow light was pressed ...");
rfData = 201;
dataMode = 1;
delay(1000);
}
buttonG = digitalRead(buttonPinG);
if (buttonG == 0)
{
Serial.println();
Serial.println("button for semafor green light was pressed ...");
rfData = 101;
dataMode = 1;
delay(1000);
}
// accepting choosed command from buttons - example 101 was set for green Led
if (dataMode == 1)
{
digitalWrite(ledPin,HIGH);
delay(1000);
dataMode = 2;
}
if (dataMode == 2)
{
while ((buttonR == 0)||(buttonY == 0)||(buttonG == 0))
{
buttonG = digitalRead(buttonPinG);
buttonY = digitalRead(buttonPinY);
buttonR = digitalRead(buttonPinR);
delay(500);
}
digitalWrite(ledPin,LOW);
delay(1000);
Serial.print("RF command data: ");
Serial.println(rfData);
Serial.print("Special Code + RF Data: ");
Serial.println(specialCode+rfData);
unsigned long casLong = millis() ;
float cas = (float)casLong / 1000; //cas (cz) = time (en)
// actual cas (time) in milisec and in sec
Serial.print(" time (long) in millisec: ");
Serial.println(casLong);
Serial.print(" time (long)/ 1000 in sec: ");
Serial.println((float)casLong/1000);
senderRF.send(specialCode+rfData,nrBits);
dataMode = 3;
}
if (dataMode == 3)
{
// pause before new reading of next data
digitalWrite(ledPin,HIGH);
delay(1000);
delay(intervalDat);
digitalWrite(ledPin,LOW);
delay(1000);
//delay(intervalDat);
dataMode = 0;
}
if (dataMode == 5) // set on RF data for traffic lights
{
if (semaforTimeRedOn)
{
buttonR = 1;
buttonY = 0;
buttonG = 0;
rfData = 301;
}
if (semaforTimeGreenOn)
{
buttonR = 0;
buttonY = 0;
buttonG = 1;
rfData = 101;
}
semaforTime = 0;
Serial.println(specialCode+rfData);
unsigned long casLong = millis() ;
float cas = (float)casLong / 1000; // cas = time
// vypsani aktualniho casu s delkou
Serial.print(" time in sec: ");
Serial.println(cas);
/*
Serial.print(" cas (long) in millisec: ");
Serial.println(casLong);
Serial.print(" cas (long)/ 1000 sec: ");
Serial.println((float)casLong/1000);
*/
senderRF.send(specialCode+rfData,nrBits);
dataMode = 6;
}
if (dataMode == 6) // counting time for change in traffic lights
{
semaforTime += 1;
if (semaforTime > semaforInterval)
{
dataMode = 7;
}
else
{
delay(1000);
}
}
if (dataMode == 7) // there is time on for change in traffic lights
{
if (semaforTimeRedOn)
{
semaforTimeRedOn = false;
semaforTimeGreenOn = true;
}
else
{
semaforTimeRedOn = true;
semaforTimeGreenOn = false;
}
dataMode = 5;
}
}