Hi. Ich bin Neuling mit dem Arduino uno. Und komme aus Feldkirchen bei München. Habe auch schon einige basics realisieren können. :) Ich benötige Hilfe bei dem Code. Ich möchte mit einer app aus dem Android playstore 8 relais fernbedienen. Kann mir Evtl. Jemand beim Code helfen ? Ich habe ein Arduino Uno v3 Eine saintsmart 16 Fach relais Karte Und natürlich ein Bluetooth modul. Die app die ich benutzen möchte heisst:bt relay control Ich kann aus dem Code der app nicht rauslesen Wo ich was verbinden soll. Wo das ich rxd und txd vom BT Modul anklemmen soll. Und welche Kontakte dann meine outputs sind. Der Code: /*Total Relay Control for Arduino MEGA Enables Total Relay control using serial port 1 (and JY-MCU bluetooth serial converter) or Ethernet Shield and digital IO ports Relays[] as outputs. Feedback is provided sending back the state of the 8 relays in a byte, in which a bit '1' at the n position means the n relay is on. Circuit: * Ethernet shield attached to pins 10, 11, 12, 13 * Debug serially using Serial Monitor (serial port 0) Author: Juan Luis Gonzalez Bello Date: 03/08/2013 Get the app on google play: https://play.google.com/store/apps/details?id=com.apps.emim.btrelaycontrolfree&feature=search_result#?t=W251bGwsMSwxLDEsImNvbS5hcHBzLmVtaW0uYnRyZWxheWNvbnRyb2wiXQ.. ** For Arduino UNO, use Serial instead of Serial1 (serial one) */ #include <SPI.h> #include <Ethernet.h> #include <EEPROM.h> int MAX_RELAYS = 8; // Arrays used to "decode" incoming bytes and ports // Relay 1 is at pin 53, relay 2 is at pin 51 and so on. You can change this numbers in order to fit your circuit. int Relays[8] = {37, 53, 49, 47, 45, 43, 41, 39}; int KeysOn[8] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'}; int KeysOff[8] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'}; // Used to keep track of the relay status int RelayStatus = 0; int STATUS_EEADR = 20; // Enter a MAC address and IP address for your controller below. // The IP address will be dependent on your local network: byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; IPAddress ip(192,168,1,60); // Initialize the Ethernet server library // with the IP address and port you want to use // (port 80 is default for HTTP): EthernetServer server(80); void setup() { Serial1.begin(9600); // initialize BT serial port: Serial.begin(9600); // initialize debug serial port: while (!Serial && !Serial1) { ; // wait for serial ports to connect. Needed for Leonardo only } // start the Ethernet connection and the server: Ethernet.begin(mac, ip); server.begin(); Serial.print("server is at "); Serial.println(Ethernet.localIP()); // Initialize I/O PORTS for(int i = 0; i < MAX_RELAYS; i++){ pinMode(Relays[i], OUTPUT); } // Initialize relay status RelayStatus = EEPROM.read(STATUS_EEADR); for(int i = 0; i < MAX_RELAYS; i++){ if((RelayStatus & (1 << i)) == 0) digitalWrite(Relays[i], LOW); else digitalWrite(Relays[i], HIGH); } int zero = 0; // 0 cannot be used with .write directly, for some reason compiler gets errors Serial1.write(zero); // Send feedback in order to turn off buttons on Android app } void loop() { // Send FeedBack to Android App so you know if the relay is actually turned on. Serial1.write(RelayStatus); // listen for incoming clients EthernetClient client = server.available(); // BT Relay Control if (Serial1.available() > 0) { int inByte = Serial1.read(); for(int i = 0; i < MAX_RELAYS; i++){ TurnOn_Relay_on_Key(inByte, KeysOn[i], Relays[i]); TurnOn_Relay_off_Key(inByte, KeysOff[i], Relays[i]); } } // Wifi Relay Control if (client) { if (client.connected()) { if (client.available()) { char inByte = client.read(); for(int i = 0; i < MAX_RELAYS; i++){ TurnOn_Relay_on_Key(inByte, KeysOn[i], Relays[i]); TurnOn_Relay_off_Key(inByte, KeysOff[i], Relays[i]); } //Print to all available clients server.print(RelayStatus); server.println(); } } else{ // give the clients time to receive the data delay(1); // close the connection: client.stop(); Serial.println("client disonnected"); } } } // Tunr on relay selected relay void TurnOn_Relay_on_Key(int input, int key, int port){ if (input == key){ digitalWrite(port, HIGH); Serial.print("Relay turned On: "); // Debug Serial.println((char)key); RelayStatus |= (1 << (key - KeysOn[0])); // Set Status EEPROM.write(STATUS_EEADR, RelayStatus); // Save Status } } // Tunr off relay selected relay void TurnOn_Relay_off_Key(int input, int key, int port){ if (input == key){ digitalWrite(port, LOW); Serial.print("Relay turned Off: "); // Debug Serial.println((char)key); RelayStatus &= ~(1 << (key - KeysOff[0])); // Clear Status EEPROM.write(STATUS_EEADR, RelayStatus); // Save Status } } über eure Hilfe würde ich mich riesig freuen! Evtl. sogar in der Nähe! :-)
:
Verschoben durch Moderator
Lotsofmuc schrieb: > Ich kann aus dem Code der app nicht rauslesen > Wo ich was verbinden soll. Guck mal in deinen Code in der Setup Routine an die Stelle, wo für die Bluetooth-Verbindung der BT serial port geöffnet wird ;-) > Der Code: Wofür gibt es eigentlich hier im Forum die Anhang-Funktion?
Lotsofmuc schrieb: > Wo das ich rxd und txd vom BT Modul anklemmen soll. Blind geraten: An die RX und TX Leitungen von deinem Arduino. > Und welche Kontakte dann meine outputs sind. Steht im Code, auch wenn anscheinend schon jemand Sachen geändert hat: Lotsofmuc schrieb: > // Arrays used to "decode" incoming bytes and ports > // Relay 1 is at pin 53, relay 2 is at pin 51 and so on. You can change > this numbers in order to fit your circuit. > int Relays[8] = {37, 53, 49, 47, 45, 43, 41, 39}; > int KeysOn[8] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'}; > int KeysOff[8] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'}; Ohne den Code weiter gelesen zu haben bedeutet das ganze für mich dass, wenn du ein 'A' sendest, Pin 37 auf High gesetzt wird und bei einem 'a' dieser Pin wieder auf Low geht.
Lotsofmuc schrieb: > Ich bin Neuling mit dem Arduino uno. Lotsofmuc schrieb: > Der Code: > /*Total Relay Control for Arduino MEGA Du schreibst von Arduino UNO: http://arduino.cc/en/Main/ArduinoBoardUno der Code ist aber für den Arduino Mega: http://arduino.cc/de/Main/ArduinoBoardMega Dann passt auch das mit den Pins wie oben geschrieben
Hi ! Danke für die Tipps! Und tut mir leid das ich den Code so reingeschrieben hab. Kann ich den Code bzw. Bei int relay Einfach in die Ausgänge des arduino Uno eintragen ? Ich würde auch noch gerne das ganzen WiFi Sachen aus dem Code löschen. Weiss aber leider nicht was ich einfach so löschen kann und was nicht. MfG
Hi Ich habe jetzt folgendes Problem: Ich bekomme keine verbindung zum Arduino! Ich habe das BT Modul HC-05 gekreuzt an rx und tx angeschlossen. Habe den code auch schon umgeschrieben fürs Arduino uno. Über den Serial Monitor kann ich mit den befehlen A = on a =off arbeiten . Aber ich bekomme es einfach nicht das das alles über das Modul Funktioniert. Ich bin echt schon am verzweifeln!!! mit dem Bluetooth modul kann ich mich ohne Probleme Verbinden. Ich komm einfach nicht weiter. Bitte helft mir!!!
Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.