3 Connect Arduino ProMini 3.3V 8Mhz Atmega328 to Raspberry Pi
21 #include <DallasTemperature.h>
23 RCSwitch mySwitch = RCSwitch();
27 DallasTemperature sensors(&oneWire);
31 mySwitch.enableReceive(0); // Receiver on inerrupt 0 => that is pin #2
32 mySwitch.enableTransmit(10); // with sender wired in receiving doesn't work, pin #10
37 Serial.print("press buttons on remote or send AB where A = socket (0..9), B = state (0 = off, 1 = on)\nB00...00 (24 digits) to send binary\n");
41 char serial_data[2]; // socket (0-9), state (0-1)
45 if (mySwitch.available()) {
46 Serial.print(mySwitch.getReceivedBitlength());
47 Serial.print(" bits ");
48 Serial.println(mySwitch.getReceivedValue(), BIN);
49 mySwitch.resetAvailable();
51 if (Serial.available() > 0) {
52 char input = Serial.read();
54 Serial.print("DS18B20 temperature = ");
55 sensors.requestTemperatures();
56 Serial.println( sensors.getTempCByIndex(0) );
59 Serial.readBytesUntil('\n', binary_data, sizeof(binary_data));
60 Serial.print("send B");
61 Serial.println( binary_data );
62 mySwitch.send( binary_data );
64 if ( input >= 0x30 && input <= 0x39 ) {
65 input = input - 0x30; // ASCII to number
66 serial_data[serial_pos++] = input;
68 Serial.print("ignore: ");
69 Serial.println(input, HEX);
72 if ( serial_pos == 2 ) {
73 Serial.print("socket: ");
74 Serial.print(serial_data[0], DEC);
75 Serial.print(" state: ");
76 Serial.println(serial_data[1] ? "on" : "off");
78 if ( serial_data[1] ) { // on
79 switch ( serial_data[0] ) {
81 mySwitch.send("110101011101010000001100");
84 mySwitch.send("110101010111010000001100");
87 mySwitch.send("110101010101110000001100");
90 Serial.print("invalid switch on number ");
91 Serial.println(serial_data[0], DEC);
94 switch ( serial_data[0] ) {
96 mySwitch.send("110101011101010000000011");
99 mySwitch.send("110101010111010000000011");
102 mySwitch.send("110101010101110000000011");
105 Serial.print("invalid switch off number ");
106 Serial.println(serial_data[0], DEC);