First off, I am an Arduino noob but very experienced with electronics, wiring, troubleshooting etc... its the programming part that is over my head but I am starting to pick up a few things. anyway, I have a very simple application where I simply want to turn on/off devices via my computer and eventually iphone and tablet apps. seems pretty easy and it probably is...
I have an Arduino Uno r3 and I purchased a 433Mhz transmitter with 4 individual relays that will be connected to various devices that I will be able to control from a single location. (basically just a remote control but will eventually add other functions and remote access). I have began testing but with the sketch I uploaded I am not receiving an output. it looks like the program uses pin 10 to send out serial data to trigger each of the 4 RF receiver relay boards. the ebay store that I purchased the RF transmitter and relays from supplied me with a code that as far as I can tell should do exactly what I want it to at this stage. I also have a small LED array that connects an LED to pins 8-13 that helps me to troubleshoot. Pin 11 is high so I know that part of the program is working. Also I am getting the flashing pin 13 when I try to send anything thru the serial monitor although nothing displays below so it looks like nothing is actually being sent... Please let me know if you can help, thanks!
//Author: cantone-electonics
//More information welcome to : http://www.canton-electronics.com
//Arduino 1.0
//Arduino uno R3
//Making a wireless remote control with arduino
//const int data_out = 2;//encoder DOUT
//LED pin,When receiving the key from the serial port, LED flash
const int ledPin = 13; //LED pin
const int gnd_pin = 9; //AS GND
const int data_out = 10; //encoder DOUT
const int vcc_pin = 11; //AS VCC
// OSC Resistance is 3.3M
const int Osc_4xCycle = 359; //4 oscillating time periods
const int Osc_12xCycle = 1078;//12 oscillating time periods
unsigned long Temporary[3];//Temporary storage unit
//output bit "0"
void bit_0() {
digitalWrite(data_out, HIGH);
delayMicroseconds(Osc_4xCycle);//4 oscillating time periods High level
digitalWrite(data_out, LOW);
delayMicroseconds(Osc_12xCycle);//12 oscillating time periods Low level
digitalWrite(data_out, HIGH);
delayMicroseconds(Osc_4xCycle);//4 oscillating time periods High level
digitalWrite(data_out, LOW);
delayMicroseconds(Osc_12xCycle);//12 oscillating time periods Low level
}
//output bit "1"
void bit_1() {
digitalWrite(data_out, HIGH);
delayMicroseconds(Osc_12xCycle);//12 oscillating time periods High level
digitalWrite(data_out, LOW);
delayMicroseconds(Osc_4xCycle);//4 oscillating time periods Low level
digitalWrite(data_out, HIGH);
delayMicroseconds(Osc_12xCycle);//12 oscillating time periods High level
digitalWrite(data_out, LOW);
delayMicroseconds(Osc_4xCycle);//4 oscillating time periods Low level
}
//output bit "f"
void bit_f() {
digitalWrite(data_out, HIGH);
delayMicroseconds(Osc_4xCycle);//4 oscillating time periods High level
digitalWrite(data_out, LOW);
delayMicroseconds(Osc_12xCycle);//12 oscillating time periods Low level
digitalWrite(data_out, HIGH);
delayMicroseconds(Osc_12xCycle);//12 oscillating time periods High level
digitalWrite(data_out, LOW);
delayMicroseconds(Osc_4xCycle);//4 oscillating time periods Low level
}
//output synchronous bit
void bit_syn() {
digitalWrite(data_out, HIGH);
delayMicroseconds(Osc_4xCycle);//4 oscillating time periods High level
digitalWrite(data_out, LOW);
delayMicroseconds(Osc_4xCycle*31);//124 oscillating time periods Low level
}
//send:8 Address Bits, 4 Data Bits, Sync bit
void send_data(){
unsigned char temp,tab,i;
unsigned char j,k;
for(j=0;j<4;j++)
{
for(k=0;k<3;k++)//send 8 Address Bits, 4 Data Bits
{
tab = Temporary[k];
for(i=0;i<4;i++)
{
temp = tab;
temp &= 0xC0;
if(temp == 0xC0)//11 is bit "1"
{
bit_1();
}
else if(temp == 0x00)//00 is bit "0"
{
bit_0();
}
else //01 is bit "f"
{
bit_f();
}
tab = tab << 2;
}
}
bit_syn();//send Sync bit
}
}
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the encoder DOUT pin as an output
pinMode(data_out, OUTPUT);
pinMode(gnd_pin, OUTPUT);
pinMode(vcc_pin, OUTPUT);
digitalWrite(vcc_pin, HIGH);//SET VCC
digitalWrite(gnd_pin, LOW);//SET GND
Serial.begin(9600);
}
void loop()
{
int keydata = 0;
int receive_flag = 0;
Temporary[0] = 0xC5;//address A7-A4
Temporary[1] = 0x55;//address A3-A0
digitalWrite(ledPin, LOW);//Turn off led
while(1)
{
//get key from pc serial port
while (Serial.available() > 0)
{
keydata = Serial.read();
receive_flag = 1;
delay(2);
}
if(receive_flag == 1)//if get key,send key
{
receive_flag = 0;
if((keydata == 'a') || (keydata == 'A'))//trigger A channel relay.
{
Temporary[2] = 0xC0;// 0xC0 is A button key
digitalWrite(ledPin, HIGH);//Turn on led
send_data();//send code word
Serial.println(".....trigger A channel relay.....");
}
else if((keydata == 'b') || (keydata == 'B'))//trigger B channel relay.
{
Temporary[2] = 0x30;// 0x30 is B button key
digitalWrite(ledPin, HIGH);//Turn on led
send_data();//send code word
Serial.println(".....trigger B channel relay.....");
}
else if((keydata == 'c') || (keydata == 'C'))//trigger C channel relay.
{
Temporary[2] = 0x0C;// 0x0C is C button key
digitalWrite(ledPin, HIGH);//Turn on led
send_data();//send code word
Serial.println(".....trigger C channel relay.....");
}
else if((keydata == 'd') || (keydata == 'D'))//trigger D channel relay.
{
Temporary[2] = 0x03;// 0x03 is D button key
digitalWrite(ledPin, HIGH);//Turn on led
send_data();//send code word
Serial.println(".....trigger D channel relay.....");
}
keydata = 0;
//When receiving the key from the serial port, LED flash
digitalWrite(ledPin, LOW);//Turn off led
delay(50);//delay 100ms
digitalWrite(ledPin, HIGH);//Turn on led
delay(50);//delay 100ms
digitalWrite(ledPin, LOW);//Turn off led
delay(50);//delay 100ms
digitalWrite(ledPin, HIGH);//Turn on led
delay(50);//delay 100ms
digitalWrite(ledPin, LOW);//Turn off led
}
}
}


