Hi every one, I would like to ask you a question. I'm doing a project in order to control a particolar lamp for a theatre. Simplifying the project, I created a C# interface connected to an arduino, which sends via 433 MHZ some codes to another arduino which is the slave that control the lamp. The project works, but there is a problem when I increase the distance. The problem is not that the 2 arduino can't comunicate, but if I send a particolar message(which turns off 2 relays) the arduino slave is not able to receive any thing else. However, if i turn off the slave and immediately turn on , all works. I was thinking about a problem in the code, but if the arduino are not too much far all works! Do you think if i change that particular message, the problem can be sort out? (if i don't send that message , the slave continues to received other one)
thanks.
You need to post your programs.
...R
This is the master code :
#include <RCSwitch.h>
RCSwitch mySwitch = RCSwitch();
byte incomingByte = 48;
byte segnale = 48;
const int led = 13;
const int serial = 2;
bool ctr=false;
void serialsend (byte);
void setup() {
mySwitch.enableTransmit(10); // Transmitter is connected to Arduino Pin #10
Serial.begin(250000);
serialsend(48);
pinMode(led,OUTPUT);
pinMode(serial,OUTPUT);
}
void loop() {
if (Serial.available() > 0){
digitalWrite(serial,HIGH);
incomingByte = Serial.read();
digitalWrite(serial,LOW);
ctr=true;
}
if (ctr==true){
for (int c=0;c<2;c++)
digitalWrite(serial,HIGH);
serialsend(incomingByte);
digitalWrite(serial,LOW);
}
if(incomingByte!=10)
segnale=incomingByte;
digitalWrite(led,HIGH);
mySwitch.send(segnale,24);
digitalWrite(led,LOW);
}
void serialsend(byte tx){
Serial.write(tx);
}
this is the slave
#include <RCSwitch.h>
RCSwitch mySwitch = RCSwitch();
const int led = 13;
const int npn = 10;
const int rel = 4; //rele1 output 4
const int rel2 = 5;
int value;
int velocita;
int voltnpn;
int tensione (int dato);
void velstrobo(int tensione);
void releon();
void releoff();
void rele2on();
void rele2off();
void setup() {
mySwitch.enableReceive(0); //pin 2 ricevitore
pinMode(led,OUTPUT);
pinMode(npn,OUTPUT);
pinMode(rel,OUTPUT);
pinMode(rel2,OUTPUT);
digitalWrite(rel2,HIGH);
digitalWrite(rel,HIGH);
}
void loop() {
if (mySwitch.available()) {
digitalWrite(led,HIGH);
value = mySwitch.getReceivedValue();
mySwitch.resetAvailable();
digitalWrite(led,LOW);
}
switch(value){
case 10: break;
case 48:releoff();
rele2off();
break;
default: releon();
rele2on();
voltnpn=tensione(value);
velstrobo(voltnpn);
break;
}
}
int tensione (int dato){
int out=0;
out= 16*(dato-100);
if(out==256)
out=255;
return out;
}
void releon(){
digitalWrite(rel,LOW);
}
void releoff(){
digitalWrite(rel,HIGH);
analogWrite(npn,0);
}
void rele2on(){
digitalWrite(rel2,LOW);
}
void rele2off(){
digitalWrite(rel2,HIGH);
analogWrite(npn,0);
}
void velstrobo(int tensione){
if(tensione>=0 && tensione <=255);
analogWrite(npn,tensione);
}
thank you
Please modify your post and use the code button </> so your code looks like this
and is easy to copy to a text editor. See How to use the Forum Your code is too long for me to study quickly without copying to a text editor.
…R
if(tensione>=0 && tensione <=255);
Do if statements normally end with semicolons?