I have several ceiling fans with lights controlled by hunter remote controls. I've been trying to automate them with and arduino and a PC. They run on 350mhz.
Big thanks to Retroplayer for his advice in another thread in the project guidance forum. It was getting out of disorganized and this is more of a programming issue so I thought I'd create a new thread.
One of my remotes has a "button board" (the board with the pushbuttons) and a "transmitter" (the transmitter). I desoldered the transmitter from the button board.
Power and ground for the button board and the transmitter come from the arduino.
If I directly connect sig out on the button board to sig in on the transmitter - control works.
If I forward the signal though the arduino with this bit of code - control works
int inpin = 2; // makes the input pin pin 2
int outpin = 3; // makes the output pin pin 3
void setup() {
Serial.begin(9600); // initialize serial communication at 9600 bits per second:
pinMode(inpin, INPUT); // makes inpin the input pin
pinMode(outpin, OUTPUT); // makes outpin the output pin
}
void loop() {
int inpinState = digitalRead(inpin); //reads the state of the input pin
digitalWrite(outpin, inpinState); //writes the state of the input pin on the output
//Serial.print(inpinState); //swap comments out with digitalwrite to see output on screen. they dont work together!!
}
If I connect the output of the button board to RX pin 0 and run this bit of code to look at whats happening - I receive data printed on the screen. (I can even do the same thing with //digitalWrite(outpin, inpinState); in the previous example
int incomingByte = 0; // for incoming serial data
void setup() {
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
}
void loop() {
// send data only when you receive data:
if (Serial.available() > 0) {
// read the incoming byte:
incomingByte = Serial.read();
// say what you got:
Serial.print(incomingByte, BIN);;
}
}
Here is the interesting part. If I use a library like RCSwitch, or VirtualWire and load their example receive examples, I get NOTHING. No errors, no invalid data, no unknown coding, no result period. Why? I dont understand. Serial.read and digitalread at least give me something.
I even hooked a pushbutton up so that when I pressed the button it would start to write binary data to the screen. If I didn't press the lighttoggle button, it would write 0s. If I pushed the lighttoggle button, it would write some codes.
Without RCSwitch or VirtualWire is the project dead?
I've been trying to make a way to capture some of the data or replay it. I've tried
digitalwrite bit
digitalwrite bit
digitalwrite bit
etc.. (it never worked)
until I discovered arrays and started playing with those.
int inpin = 2; //sets the recieve pin from button board
int outpin = 3; //sets the tx pin to transmitter
int logpin = 13; //ground on this pin start code
int Array[]={}; //array. I've tried it with precought values too.
int countin = 0; //keeps track of array values read
int countout = 0; //keeps track of array values sent
int ArraySize = sizeof(Array); //generates array size for max array values
void setup()
{
Serial.begin(9600);
pinMode(inpin, INPUT);
pinMode(outpin, OUTPUT);
pinMode(logpin, INPUT);
digitalWrite(logpin, HIGH);
if (digitalRead(logpin) == 0) //if I press the code-in button then the light toggle it will read code
{
Array[countin] = digitalRead(logpin);
countin++;
}
}
void loop()
{
if(countout <= ArraySize)
{
digitalWrite(outpin, Array[countout]);
countout++;
}
}
Hard coded Array
int outpin = 3; //sets the tx pin to transmitter
int Array[155]={0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,1,0,0,0,0,0,0,0,0,1,1,0,1,1,0,0,1,0,0,0,0,0,0,0,0,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,1,1,0,1,0,0,0,0,0,0,0,0,1,1,0,1,1,0,1,0,0,0,0,0,0,0,0,1,1,0,1,1,0,1,0,0,0,0,0,0,0,0,1,1,1,0,1,0,0,0,0,0,0,0,0,1,1,0,1,1,0,1,0,0,0,0,0,0,0,0,1,1,0,1,1,0,1,0,0,0,0,0,0,0,0,1,1,0,1,1,0,1,0,0,0,0,0,0,0,0}; //array. I've tried it with precought values too.
int countout = 0; //keeps track of array values read
int ArraySize = 155; //generates array size for max array values
void setup()
{
Serial.begin(9600);
pinMode(outpin, OUTPUT);
}
void loop()
{
if(countout <= ArraySize)
{
digitalWrite(outpin, Array[countout]);
countout++;
}
}
Whats the deal here?