breadboard circuit and arduino programming.
cloned signal opens the garage door.
all parts ready
case drilled
the circuit is powered by 2 CR2032 button cell batteries.
pressing either button will power up the arduino. by using the internal pullups on both button inputs, the arduino detects which button is being pressed.
finished product.
the source code for this project is a modified version from
433 MHz RF REMOTE REPLAY sketch by Scott C
[code language=”cpp”]
/*
433 MHz RF REMOTE DUBLICATOR sketch
Written by ScottC 24 Jul 2014
http://arduinobasics.blogspot.ch/2014/07/433-mhz-rf-module-with-arduino-tutorial_30.html
Modified by ned Feb 2017
projects.whatimean.ch
Description: Use Arduino to receive and transmit RF 433 MHz Remote signals. (315MHz not tested)
there are 2 slots to save a signal.
button 1 will load and transmitting slot 1.
button 2 will load and transmitting slot 2.
when both buttons are pressed, after 4 seconds, it will record a signal.
releasing one button will store the signal into the slot of the still pressed button.
followed by transmitting the signal.
if the supply voltage is below 4.4V, it will still transmit, but using the red led.
————————————————————- */
#include <EEPROM.h>
#define rfReceivePin 14 //RF Receiver data pin
#define rfTransmitPin 15 //RF Transmitter pin
#define button 16 //button 1
#define ledRedPin 19 //Red led
#define ledGreenPin 18 //Green led
#define button2 17 //button 2
const int dataSize = 512; //Arduino memory is limited (max=1700)
byte storedData[dataSize]; //Create an array to store the data
const unsigned int threshold = 100; //signal threshold value
int maxSignalLength = 255; //Set the maximum length of the signal
int dataCounter = 0; //Variable to measure the length of the signal
int buttonState = 1; //Variable to control the flow of code using button presses
int buttonVal = 0; //Variable to hold the state of the button
int buttonVal2 = 0;
int timeDelaylisten = 1; //timedelay for listening (combination with code)
float timeDelaysend = 4; //timedelay for sending (combination with code)
int ledPin = 13;
void setup(){
Serial.begin(9600); //Initialise Serial communication – only required if you plan to print to the Serial monitor
pinMode(rfReceivePin, INPUT);
pinMode(rfTransmitPin, OUTPUT);
pinMode(ledPin, OUTPUT);
pinMode(ledRedPin, OUTPUT);
pinMode(ledGreenPin, OUTPUT);
pinMode(button, INPUT_PULLUP);
pinMode(button2, INPUT_PULLUP);
delay(10);
batterysense();
digitalWrite(ledPin, HIGH);
delay(200);
buttonVal = digitalRead(button);
buttonVal2 = digitalRead(button2);
//Serial.println(buttonVal);
//Serial.println(buttonVal2);
}
void loop(){
if((!buttonVal && !buttonVal2)==HIGH){ //if both buttons are pressed
digitalWrite(ledPin, LOW);
delay(4000);
batterysense();
digitalWrite(ledPin, HIGH);
delay(1000);
digitalWrite(ledPin, LOW);
batterysense();
if((buttonState>0 && !digitalRead(button) && !digitalRead(button2))==HIGH){
Serial.println("Listening for Signal..");
//initVariables();
buttonState=0;
listenForSignal();
Serial.println("Signal captured into Flash");
//storage selector
while(!digitalRead(button) && !digitalRead(button2) == HIGH){ //wait until one buttons has been released
delay(10);
}
delay(200);
batterysense();
if((!digitalRead(button) && digitalRead(button2))==HIGH){
Serial.println("storing Signal into EEPROM slot:0");
storeData(0);
}else{
if((digitalRead(button) && !digitalRead(button2))==HIGH){
Serial.println("storing Signal into EEPROM slot:1");
storeData(dataSize);
}
}
Serial.println("Signal stored, sending now..");
}
while(1){
while((buttonState<1 && (!digitalRead(button) || !digitalRead(button2)))==HIGH){
//Serial.println("Send Signal..");
batterysense();
sendSignal();
//Serial.println("Signal Sent");
}
}
}
if((buttonVal && !buttonVal2)==HIGH){
digitalWrite(ledPin, LOW);
Serial.println("loading signal from EEPROM slot:1..");
loadData(dataSize);
Serial.println("Signal loaded, sending now..");
while(1){
while(digitalRead(button) && !digitalRead(button2) == HIGH){
batterysense();
sendSignal();
}
}
}
if((!buttonVal && buttonVal2)==HIGH){
digitalWrite(ledPin, LOW);
Serial.println("loading signal from EEPROM slot:0..");
loadData(0);
Serial.println("Signal loaded, sending now..");
while(1){
while(!digitalRead(button) && digitalRead(button2) == HIGH){
batterysense();
sendSignal();
}
}
}
if((buttonVal && buttonVal2)==HIGH){
digitalWrite(ledPin, LOW);
batterysense();
Serial.println("no button is pressed, unspecified case..");
delay(3000);
}
delay(20);
}
long readVcc() {
long result; // Read 1.1V reference against AVcc
ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
delay(2); // Wait for Vref to settle
ADCSRA |= _BV(ADSC); // Convert
while (bit_is_set(ADCSRA,ADSC));
result = ADCL;
result |= ADCH<<8;
result = 1233285L / result; // Back-calculate AVcc in mV; norm: "1126400L"=4.5V; 1177600L = 4.3V; 1152000L =4.4V
//but, accounting for the diodes.. single diode: 290mV; double diode: 260mV
//the threshold arduino sees should then be 4.4V – 290mV = 4110mV (-> 1233285L)
return result;
}
void listenForSignal(){
digitalWrite(ledPin, HIGH);
//Read and store the rest of the signal into the storedData array
for(int i=0; i<dataSize; i=i+2){
//Identify the length of the HIGH signal—————HIGH
dataCounter=0; //reset the counter
while(digitalRead(rfReceivePin)==HIGH){
dataCounter++;
//delayMicroseconds(timeDelaylisten);
}
storedData[i]=dataCounter; //Store the length of the HIGH signal
//Identify the length of the LOW signal—————LOW
dataCounter=0;//reset the counter
while(digitalRead(rfReceivePin)==LOW){
dataCounter++;
//delayMicroseconds(timeDelaylisten);
}
storedData[i+1]=dataCounter; //Store the length of the LOW signal
}
storedData[0]++; //Account for the first AnalogRead>threshold = lost while listening for signal
digitalWrite(ledPin, LOW);
}
void batterysense(){
if(readVcc()<4400){
digitalWrite(ledRedPin, digitalRead(ledGreenPin));
digitalWrite(ledGreenPin, LOW);
ledPin = ledRedPin;
}
else{
digitalWrite(ledGreenPin, digitalRead(ledRedPin));
digitalWrite(ledRedPin, LOW);
ledPin = ledGreenPin;
}
}
void storeData(int offset){
digitalWrite(ledPin, HIGH);
for(int i=0; i<dataSize; i++){
EEPROM.write(i+offset,storedData[i]);
}
digitalWrite(ledPin, LOW);
}
void loadData(int offset){
digitalWrite(ledPin, HIGH);
for(int i=0; i<dataSize; i++){
storedData[i] = EEPROM.read(i+offset);
}
digitalWrite(ledPin, LOW);
}
void sendSignal(){
digitalWrite(ledPin, HIGH);
for(int i=0; i<dataSize; i=i+2){
//Send HIGH signal
digitalWrite(rfTransmitPin, HIGH);
delayMicroseconds(storedData[i]*timeDelaysend);
for(int u=0; (u*108)<(storedData[i]*100); u++){
__asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t");
}
//Send LOW signal
digitalWrite(rfTransmitPin, LOW);
delayMicroseconds(storedData[i+1]*timeDelaysend);
for(int u=0; (u*108)<(storedData[i+1]*100); u++){
__asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t");
}
}
digitalWrite(ledPin, LOW);
//delay(100);
}
[/code]