Tutorial: Controlando a Relay Board via Bluetooth Mate Prata

Olá garagista no tutorial de hoje iremos demonstrar como utilizar o modulo Bluetooth Mate Prata e como exemplo iremos controlar a Relay Board através de um celular com Android via Bluetooth.

Material utilizado:

Bluetooth Mate Prata

Arduíno UNO Rev.3

Protoboard

Relay Board

Jumper

Fonte 12V

Resistor 10KΩ

Jumper Premium F/F

Jumper Premium F/M

1. Bluetooth Mate Prata

Figura 1- Bluetooth Mate Prata

Características 

Com velocidade de de 9600 a 115200bps, o Mate Bluetooth tem os reguladores de tensão on-boardpara que possa ser alimentado a partir de qualquer fonte de alimentação de 3,3 a 6VDC. Todas as mudanças de níveis lógicos já são configuradas nos pinos RX e TXque trabalham na faixa 3-6VDC. Não ligue o dispositivo diretamente a uma porta serial RS-232 (+12/-12). 

2. Pinagem

Figura 2- Descrição

Mais informações clique aqui.

3. Relay Board

Figura 3-Relay Board

Mais informações clique aqui:

4. Montagem

Figura 4- Montagem

5. Aplicativo Android (Arduino Bluetooth Kawalan)

Figura 5 - Aplicativo utilizado para comunicar o Mate Prata com um dispositivo android 

O aplicativo utilizado neste tutorial pode ser encontrado neste link. Ele é bastante versátil, disponibilizando até 8 botões para acionamentos, onde cada botão envia um caractere pelo link serial para o dispositivo da outra ponta. Para o primeiro botão é enviado "A" quando em estado ON e "a" quando em estado OFF, para o segundo botão os caracteres "B" e "b" e assim por dia até os caracteres "H" e "h", pois o aplicativo disponibiliza até 8 botões. É possível alterar o nome dos botões, como por exemplo, o primeiro botão você nomear como Lâmpada e segundo como Motor.

Figura 6- Inserindo nomes aos dispositivos 

5. Sketch Configuração


/*
  Example Bluetooth Serial Passthrough Sketch
 by: Jim Lindblom
 SparkFun Electronics
 date: February 26, 2013
 license: Public domain

 This example sketch converts an RN-42 bluetooth module to
 communicate at 9600 bps (from 115200), and passes any serial
 data between Serial Monitor and bluetooth module.
 */
 
 //https://learn.sparkfun.com/tutorials/using-the-bluesmirf
#include <SoftwareSerial.h>  

int bluetoothTx = 7; // TX-O pin of bluetooth mate, Arduino D7
int bluetoothRx = 8; // RX-I pin of bluetooth mate, Arduino D8

SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);

void setup()
{
  Serial.begin(9600); // Begin the serial monitor at 9600bps

  bluetooth.begin(115200); // The Bluetooth Mate defaults to 115200bps
  bluetooth.print("$"); // Print three times individually
  bluetooth.print("$");
  bluetooth.print("$"); // Enter command mode
  delay(100); // Short delay, wait for the Mate to send back CMD
  bluetooth.println("U,9600,N"); // Temporarily Change the baudrate to 9600, no parity
  // 115200 can be too fast at times for NewSoftSerial to relay the data reliably
  bluetooth.begin(9600); // Start bluetooth serial at 9600
}

void loop()
{
  if(bluetooth.available()) // If the bluetooth sent any characters
  {
    // Send any characters the bluetooth prints to the serial monitor
    Serial.print((char)bluetooth.read());
  }
  if(Serial.available()) // If stuff was typed in the serial monitor
  {
    // Send any characters the Serial monitor prints to the bluetooth
    bluetooth.print((char)Serial.read());
  }
  // and loop forever and ever!
}

6. Configuração do Mate Prata

Realizar o upload apenas com o Mate Prata e o Arduíno, retirar a placa Relay Board. Após o upload ser realizado siga os seguintes procedimento abaixo:

6.1 Modo de configuração

Figura 7- 1º Passo

6.2 Verificando as configurações

Figura 8- 2º Passo

6.3 Modificando o nome do dispositivo

Figura 9- 3º Passo

6.4 Confirmando as modificações

Figura 10- 4º Passo

6.5 Finalizando a configuração

Figura 11- 5º Passo

6. Sketch Principal

Realizar o upload apenas com o Mate Prata e o Arduíno, retirar a placa Relay Board.

/*

  Example Bluetooth Serial Passthrough Sketch
 by: Jim Lindblom
 SparkFun Electronics
 date: February 26, 2013
 license: Public domain

 This example sketch converts an RN-42 bluetooth module to
 communicate at 9600 bps (from 115200), and passes any serial
 data between Serial Monitor and bluetooth module.
 */
 
 //Acesse http://labdegaragem.com/profiles/blogs/como-utilizar-a-relayboard funcionamento a Relay Board
 
#include <SoftwareSerial.h>//Inclui a biblioteca SoftwareSerial
#include <RelayBoard.h> //Inclui a biblioteca RelayBoard.h

#define data    6 //Define a palavra data como 6 para o pino D6 ser utilizado como o pino do DATA
#define strobe  3 //Define a palavra strobe como 4 para o pino D4 ser utilizado como o pino do STROBE
#define clock   2 //Define a palavra clock como 2 para o pino D2 ser utilizado como o pino do CLOCK
#define numberboards 1 //Define a palavra numberboards como 2, onde é definido quantas RelayBoard há no circuito

RelayBoard relay(data, strobe, clock, numberboards); //Cria a instância, informando os pinos de controle e o número de placas no circuito

int bluetoothTx = 7; // TX-O pin of bluetooth mate, Arduino D7
int bluetoothRx = 8; // RX-I pin of bluetooth mate, Arduino D8

SoftwareSerial bluetooth(bluetoothTx, bluetoothRx); //Cria a instância, informando os pinos de controle

void setup()
{
 
  bluetooth.begin(115200); // The Bluetooth Mate defaults to 115200bps
  bluetooth.print("$"); // Print three times individually
  bluetooth.print("$");
  bluetooth.print("$"); // Enter command mode
  delay(100); // Short delay, wait for the Mate to send back CMD
  bluetooth.println("U,9600,N"); // Temporarily Change the baudrate to 9600, no parity
  // 115200 can be too fast at times for NewSoftSerial to relay the data reliably
  bluetooth.begin(9600); // Start bluetooth serial at 9600
   for(int i=0;i<=7;i++)
  {
  relay.set(0,i,0);
  }
}

void loop()
{
 
   //relay.set(int board, int out, boolean status)
            //Board: Informa qual a placa que deverá ser utilizada, começando de 0.
            //Out: informa qual a saída da placa informada acima deverá ser acionada (ON/OFF), de 0 a 7
            //Status: Devemos informar "1" para LIGAR a saída ou "0" para DESLIGAR a saída.
//relay.load(int board, int out, boolean status)
            //Board: Informa qual a placa que deverá ser utilizada, começando de 0.
            //Out: informa qual a saída da placa informada acima deverá ser acionada (ON/OFF), de 0 a 7
            //Status: Devemos informar "1" para LIGAR a saída ou "0" para DESLIGAR a saída.
//relay.go()
            //Após carregar as saídas solicitadas na função LOAD, à função GO faz o acionamento simultâneo das //saídas solicitadas.

 if(bluetooth.available()) // If the bluetooth sent any characters
  {  
    char letra = bluetooth.read();//Recebe caracter via Bluetooth
 //Compara o valor recebido para que as saídas do relay board se acionem
   switch(letra)
   {
   case'A'://Se o caracter recebido for 'A' Maiúsculo
   relay.set(0,0,1);//Aciona a saída 0 da Relay board //Para mais informaçãos sobre a Relay Board //http://labdegaragem.com/profiles/blogs/como-utilizar-a-relayboard
   break;
   
   case'a'://Se o caracter recebido for 'a' Maiúsculo
   relay.set(0,0,0);//Desaciona a saída 0 da Relay board
   break;
   
   case'B':
   relay.set(0,1,1);
   break;
   
   case'b':
   relay.set(0,1,0);
   break;
   
   case'C':
   relay.set(0,2,1);
   break;
   
   case'c':
   relay.set(0,2,0);
   break;
   
   case'D':
   relay.set(0,3,1);
   break;
   
   case'd':
   relay.set(0,3,0);
   break;
   
   case'E':
   relay.set(0,4,1);
   break;
   
    case'e':
   relay.set(0,4,0);
   break;
   
   case'F':
   relay.set(0,5,1);
   break;

   case'f':
   relay.set(0,5,0);
   break;
   
   case'G':
   relay.set(0,6,1);
   break;

   case'g':
   relay.set(0,6,0);
   break;
   
   case'H':
   relay.set(0,7,1);
   break;

   case'h':
   relay.set(0,7,0);
   break;
  
   }
  }
 }

Referência:

https://learn.sparkfun.com/tutorials/using-the-bluesmirf

http://labdegaragem.com/profiles/blogs/tutorial-acionamentos-via-bluetooth-utilizando-bluetooth-shield-e

http://labdegaragem.com/profiles/blogs/como-utilizar-a-relayboard

Exibições: 5999

Comentar

Você precisa ser um membro de Laboratorio de Garagem (arduino, eletrônica, robotica, hacking) para adicionar comentários!

Entrar em Laboratorio de Garagem (arduino, eletrônica, robotica, hacking)

Comentário de Luan Frauzino Araujo em 28 junho 2015 às 13:19

Gostaria de saber se nao teria como me fornecer essa sketch mas para utilizar via ethernet e nao pelo bluetooth

© 2024   Criado por Marcelo Rodrigues.   Ativado por

Badges  |  Relatar um incidente  |  Termos de serviço