Yun Jin YongSeonggyu Oh이하늘gledel
Published

Makers (Cubecon) #5 Completion of Cubecon

This Cubecon is for people who can't use a remote control. Cubecon can toggle TV power, adjust volume and change channels.

BeginnerWork in progress1 hour3,516
Makers (Cubecon) #5 Completion of Cubecon

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×2
Breadboard (generic)
Breadboard (generic)
×1
Arduino BreadBoard mini
×2
Arduino MPU-6050
×1
HC-06 Bluetooth Module
×2
Arduino RGB LED
×1
Arduino Infrared transmitter
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Cubecon

Signal converter

Code

Cubecon

Arduino
#include<Wire.h>
#include<SoftwareSerial.h>

SoftwareSerial btSerial(7, 8);

const int MPU_addr = 0x68; 
int16_t GyX, GyY, GyZ; 
int red = 6;
int green = 5;
int blue = 4;
int tvonoff = 9;
int volup = 10;
int voldown = 11;
String A;
String B;
int tvonoffa;
int volupa;
int voldowna; 

void setup() {
  Wire.begin(); 
  Wire.beginTransmission(MPU_addr);
  Wire.write(0x6B); 
  Wire.write(0); 
  Wire.endTransmission(true);
  Serial.begin(9600);
  btSerial.begin(9600);
  pinMode(red, OUTPUT);
  pinMode(green, OUTPUT);
  pinMode(blue, OUTPUT);
  pinMode(tvonoff, INPUT);
  pinMode(volup, INPUT);
  pinMode(voldown, INPUT);
}

void loop() {
  gyro();
  check();
  button();
  led();
}

void gyro() {
  Wire.beginTransmission(MPU_addr); 
  Wire.write(0x3B);
  Wire.endTransmission(false); 
  Wire.requestFrom(MPU_addr, 14, true); 
  GyX = Wire.read() << 8|Wire.read(); 
  GyY = Wire.read() << 8|Wire.read(); 
  GyZ = Wire.read() << 8|Wire.read();
  GyX = GyX / 100; 
  GyY = GyY / 100;
  GyZ = GyZ / 100;
  Serial.print(F("gyro x,y,z : "));
  Serial.print("| GyX = ");
  Serial.print(GyX);
  Serial.print("| GyY = ");
  Serial.print(GyY);
  Serial.print("| GyZ = ");
  Serial.print(GyZ);
  Serial.println();
  delay(300);
}

void check() {
  // EBS
    if (GyX >= -35 && GyX <= -5) {
    if (GyY >= -15 && GyY <= 15) {
    if (GyZ >= 135 && GyZ <= 165) {
      A = "EBS";
  }
  }
  }
  // KBS 
    else if (GyY >= -185 && GyY <= -155) {
    if (GyX >= -10 && GyX <= 20) {
    if (GyZ >= -30 && GyZ <= 0) {
      A = "KBS";
  }
  }
  }
  // MBC
    else if (GyX >= 155 && GyX <= 185) {
    if (GyY >= -20 && GyY <= 10) {
    if (GyZ >= -5 && GyZ <= 25) {
      A = "MBC";
  }
  }
  }
  // SBS
    else if (GyX >= -165 && GyX <= -135) {
    if (GyY >= -15 && GyY <= 15) {
    if (GyZ >= -60 && GyZ <= -30) {
      A = "SBS";
  }
  }
  }
   // KBS2 
    else if (GyX >= 0 && GyX <= 30) {
    if (GyY >= 145 && GyY <= 175) {
    if (GyZ >= -30 && GyZ <= 0) {
      A = "KKBS";
  }
  }
  }
  else {
    A = "X";
  }
}

void button() {
  tvonoffa = digitalRead(tvonoff);
  volupa = digitalRead(volup);
  voldowna = digitalRead(voldown);

  if (tvonoffa == LOW) {
    btSerial.write('O');
    Serial.println(tvonoff);
  }
  if (volupa == LOW) {
    btSerial.write('P');
    Serial.println(volupa);
  }
  if (voldowna == LOW) {
    btSerial.write('N');
    Serial.println(voldowna);
  }
}

void led() {
  if (A == B) {
    
  }
  else if (A != B) {
    // EBS
    if (A == "EBS") {
      btSerial.write('A');
      digitalWrite(red, HIGH);
      digitalWrite(green, HIGH);
      digitalWrite(blue, HIGH);
      B = "EBS";
  }
  // KBS 
    else if (A == "KBS") {
      btSerial.write('B');
      digitalWrite(red, HIGH);
      digitalWrite(green, LOW);
      digitalWrite(blue, LOW);
      B = "KBS";
  }
  // MBC
    else if (A == "MBC") {
      btSerial.write('C');
      digitalWrite(red, LOW);
      digitalWrite(green, HIGH);
      digitalWrite(blue, LOW);
      B = "MBC";
  }
  // SBS
    else if (A == "SBS") {
      btSerial.write('D');
      digitalWrite(red, LOW);
      digitalWrite(green, LOW);
      digitalWrite(blue, HIGH);
      B = "SBS";
  }
   // KBS2
    else if (A == "KKBS") {
      btSerial.write('E');
      digitalWrite(red, HIGH);
      digitalWrite(green, LOW);
      digitalWrite(blue, HIGH);
      B = "KKBS";
  }
 }
}

Signal converter

Arduino
#include <SoftwareSerial.h>
#include <boarddefs.h>
#include <IRremote.h>
#include <IRremoteInt.h>
#include <ir_Lego_PF_BitStreamEncoder.h>

SoftwareSerial btSerial(7, 8);
IRsend irsend;

byte adata;
byte ddata;

void setup() {
  Serial.begin(9600);
  btSerial.begin(9600);
}
void loop() {
  bluetooth();
  IR();
  buttonIR();
}

void bluetooth() {
  byte data;
  data = btSerial.read();
  adata = data;
  Serial.println(data);
}

void IR() {
  if (adata == ddata) {
    
  }

  else if (adata != ddata) {
  // EBS
  if(adata == 'A') {
    irsend.sendSAMSUNG(0xE0E020DF, 32); 
    delay(100);
    irsend.sendSAMSUNG(0xE0E0609F, 32);
    ddata = 'A';
  }
  // KBS
  else if(adata == 'B') {
    irsend.sendSAMSUNG(0xE0E030CF, 32);   
    ddata = 'B';
  }
  // MBC
  else if(adata == 'C') {
    irsend.sendSAMSUNG(0xE0E020DF, 32); 
    delay(100);
    irsend.sendSAMSUNG(0xE0E020DF, 32); 
    ddata = 'C';
  }
  // SBS
  else if(adata == 'D') {
    irsend.sendSAMSUNG(0xE0E0906F, 32); 
    ddata = 'D';
  }
  // KBS2
  else if(adata == 'E') {
    irsend.sendSAMSUNG(0xE0E0708F, 32); 
    ddata = 'E';
  }
 }
}

void buttonIR() {
  if (adata == 'O') {
    irsend.sendSAMSUNG(0xE0E040BF, 32);
    adata == 'X';
  }
  else if (adata == 'P') {
    irsend.sendSAMSUNG(0xE0E0E01F, 32);
    adata == 'X';
  }
  else if (adata == 'N') {
    irsend.sendSAMSUNG(0xE0E0D02F, 32);
    adata == 'X';
  }
}

Credits

Yun Jin Yong

Yun Jin Yong

6 projects • 10 followers
Seonggyu Oh

Seonggyu Oh

5 projects • 1 follower
이하늘

이하늘

5 projects • 3 followers
gledel

gledel

100 projects • 115 followers
Looking back on my childhood, I was happy when I was making something and I was proud of myself. "Making is instinct!"

Comments