jeudi 13 avril 2023

433 Mhz switch command with GPIO with Raspberry Pi 3

Original thread :


Hardware :

Install g++ and Git :

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install gcc g++ make git

Install and compile 433Utils :

git clone --recursive https://github.com/ninjablocks/433Utils.git 
cd 433Utils/RPi_utils 
make all

sudo ./RFSniffer

... Then press the corresponding buttons on the remote control. The code received is then displayed (for me, it is 5510417 for on and 5510420 for off). 
After reading the code, you can also remove the 433Mhz receiver if you mind.

sudo nano control.cpp

Put in it :

#include "../rc-switch/RCSwitch.h"
#include <stdlib.h>
#include <stdio.h>

int main(int argc, char *argv[]) {
int PIN = 0; // cf. wiring Pi pinout
int codeSocketDon = 5510417;
int codeSocketDoff = 5510420;

if (wiringPiSetup() == -1) return 1;

RCSwitch mySwitch = RCSwitch();
mySwitch.enableTransmit(PIN);

if (atoi(argv[1]) == 1) { // you can set your own conditions here
    mySwitch.send(codeSocketDon, 24);
} else {
    mySwitch.send(codeSocketDoff, 24);
}
return 0;
}

Then compile :

g++ -DRPI ../rc-switch/RCSwitch.cpp control.cpp -o control -lwiringPi

Turn ON :

sudo ./control 1

Turn OFF :

sudo ./control 0



Aucun commentaire:

Enregistrer un commentaire