The goal of this project is to make a device that can open my school locker at the press of a button. I plan on using two adafruit trinkets. When the button on the remote is pressed, a 555 timer (monostable) will allow voltage to pass to the trinket, which will send the signal over IR to the receiver, which basically works the same, but in reverse. Here is the code, let me know if it will work and how I might improve it. REMOTE:
int irPin = 0; //Ir LED
int code[] = {0,1,0,0,1,1,1,0,1,0}; //array of values to by transmitted
void setup(){
pinMode(irPin,OUTPUT);
digitalWrite(irPin,HIGH); //Send a long pulse to wake up the receiver
delay(100);
digitalWrite(irPin,LOW);
}
void loop(){
for(x=1;x<=10;x++){
if (code[x]==1){ //the for loop goes through the array and transmitts each value
digitalWrite(irPin,HIGH);
}
else{
digitalWrite(irPin,LOW);
}
}
delay(1000000); //wait until the timer capacitor keeping the power supply on turns off
}
RECEIVER:
int irPin = 0; //IR decoder
int m1Pin = 1; //Motor trigger transistor
int test = 0; //store value of irPin to this
int check = 0; //value of code received
int code[] = {0,2,2,2,7,13,20,20,29,29}; //code received = {0,1,0,0,1,1,1,0,1,0}
void setup()
{
pinMode(m1Pin, OUTPUT);
pinMode(irPin, INPUT);
while (digitalRead(irPin)==1){ //wait for the long "wake up" pulse to end
delay(1);
}
}
void loop()
{
for(int x = 1; x <= 10; x++){ //go through 10 cycles
test = digitalRead(irPin); //read the ir decoder
check = check + (x * test); //add tested value to the checksum
if (check != code[x]){ //If the checksum doesn't match the set code
break; //exit the for loop
}
if (x == 10 and check == code[x]){ //if it's the last cycle and the checksum stil matches the code
digitalWrite(m1Pin,HIGH); //open the locker
}
}
delay(1000000); //wait until the timer capacitor keeping the power supply on turns off
}
Thanks!