Wireless and gyro

I am working on a project where with the gryoscope we can control the led of another arduino wirelessly.

I tested them both separately and the receiver part works fine.

But in the transmission part the works when i have not connected the HC-12 wireless module.
I read the values using the serial port and everything works fine.
But when i connect the HC-12 module the button stare is being constant HIGH.

I am not able to understand the problem.

Here is the code.

NOTE: I removed the functions because its just big and lots of condition.Other parts of the program are
present

#include <SoftwareSerial.h>
SoftwareSerial mySerial(9,10); //RX, TX
int vcc=12;
int gnd=11;
int good;

#include <Wire.h>
const int MPU_addr=0x68; 
int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ;
int minVal=265; 
int maxVal=402;
double x;         //A4 (SDA), A5 (SCL)
double y; 
double z;
int button=7;
int power=0;


void setup(){
  pinMode(power,OUTPUT);
  pinMode(button,INPUT);
  mySerial.begin(9600);
  pinMode(vcc,OUTPUT);
  pinMode(gnd,OUTPUT);
  Wire.begin();
  Wire.beginTransmission(MPU_addr);
  Wire.write(0x6B); Wire.write(0);
  Wire.endTransmission(true);
  Serial.begin(9600); 
} 

void loop(){ 
  digitalWrite(power,HIGH);
   digitalWrite(vcc,HIGH);
  digitalWrite(gnd,LOW);
  Wire.beginTransmission(MPU_addr);
  Wire.write(0x3B);
  Wire.endTransmission(false); 
  Wire.requestFrom(MPU_addr,14,true);
  AcX=Wire.read()<<8|Wire.read(); 
  AcY=Wire.read()<<8|Wire.read();
  AcZ=Wire.read()<<8|Wire.read(); 
  int xAng = map(AcX,minVal,maxVal,-90,90);
  int yAng = map(AcY,minVal,maxVal,-90,90);
  int zAng = map(AcZ,minVal,maxVal,-90,90);
  x= RAD_TO_DEG * (atan2(-yAng, -zAng)+PI);
  y= RAD_TO_DEG * (atan2(-xAng, -zAng)+PI);
  z= RAD_TO_DEG * (atan2(-yAng, -xAng)+PI);

//x axis right and left
//----------------------------------------
good=digitalRead(button);
if(good==1){
if(x<10&&x>0){
  mySerial.println(1111);
  Serial.println("stop");
}
..........


}
//----------------------------------------
//y axis front and back
else{
if(y<10&&y>0){
  mySerial.println(1211);
  Serial.println("forward");
}
................

}


delay(100);

}

Pls help me.
Thank you very much in advance.

Moderator edit:
</mark> <mark>[code]</mark> <mark>

</mark> <mark>[/code]</mark> <mark>
tags added.

I there some limit where the arduino UNO can handle only one module and low processing power because i got a problem where the arduino is does not work properly when i use both the wireless HC-12 wireless comminication module and the gyroscope module at the same time but works perfectly well when the are worked upon individually.

1 - your code is messed up - there seem to be chunks missing toward the end of it. Read the 'How to use this forum ...' thread to learn how to post code.

2 - sounds like it's (at least in part) a hardware problem. Please show an accurate circuit diagram.

3 - how do you know "the transmission part the works when i have not connected the HC-12 wireless module." if you haven't tested it with the ... transmitter?

  1. specify exactly what hardware you are using. Links are appropriate.

ChrisTenone:
1 - your code is messed up - there seem to be chunks missing toward the end of it. Read the ‘How to use this forum …’ thread to learn how to post code.

2 - sounds like it’s (at least in part) a hardware problem. Please show an accurate circuit diagram.

3 - how do you know “the transmission part the works when i have not connected the HC-12 wireless module.” if you haven’t tested it with the … transmitter?

  1. specify exactly what hardware you are using. Links are appropriate.
  1. I didn’t post some last part of the code because it was just full of conditions. Still, now here is the full code
//this is a custon transmitter with gyro only lesft right motion with 3 levels and forward back motion with 4 levels

#include <SoftwareSerial.h>
SoftwareSerial mySerial(9,10); //RX, TX
int vcc=12;
int gnd=11;
int good;

#include <Wire.h>
const int MPU_addr=0x68; 
int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ;
int minVal=265; 
int maxVal=402;
double x;         //A4 (SDA), A5 (SCL)
double y; 
double z;
int button=7;
int power=0;


void setup(){
  pinMode(power,OUTPUT);
  pinMode(button,INPUT);
  mySerial.begin(9600);
  pinMode(vcc,OUTPUT);
  pinMode(gnd,OUTPUT);
  Wire.begin();
  Wire.beginTransmission(MPU_addr);
  Wire.write(0x6B); Wire.write(0);
  Wire.endTransmission(true);
  Serial.begin(9600); 
} 

void loop(){ 
  digitalWrite(power,HIGH);
   digitalWrite(vcc,HIGH);
  digitalWrite(gnd,LOW);
  Wire.beginTransmission(MPU_addr);
  Wire.write(0x3B);
  Wire.endTransmission(false); 
  Wire.requestFrom(MPU_addr,14,true);
  AcX=Wire.read()<<8|Wire.read(); 
  AcY=Wire.read()<<8|Wire.read();
  AcZ=Wire.read()<<8|Wire.read(); 
  int xAng = map(AcX,minVal,maxVal,-90,90);
  int yAng = map(AcY,minVal,maxVal,-90,90);
  int zAng = map(AcZ,minVal,maxVal,-90,90);
  x= RAD_TO_DEG * (atan2(-yAng, -zAng)+PI);
  y= RAD_TO_DEG * (atan2(-xAng, -zAng)+PI);
  z= RAD_TO_DEG * (atan2(-yAng, -xAng)+PI);

//x axis right and left
//----------------------------------------
good=digitalRead(button);
if(good==1){
if(x<10&&x>0){
  mySerial.println(1111);
  Serial.println("stop");
}
else if(x<360&&x>350){
  mySerial.println(1111);
  Serial.println("stop");
}
else if(x<350&&x>340){
  mySerial.println(2111);
  Serial.println("right1");
}
else if(x<340&&x>330){
  mySerial.println(3111);
  Serial.println("right2");
}
else if(x<330&&x>320){
  mySerial.println(4111);
  Serial.println("right3");
}
else if(x<320&&x>230){
  mySerial.println(5111);
  Serial.println("RIGHT");
}
else if(x<20&&x>10){
  mySerial.println(6111);
  Serial.println("left1");
}
else if(x<30&&x>20){
  mySerial.println(7111);
  Serial.println("left2");
}
else if(x<40&&x>30){
  mySerial.println(8111);
  Serial.println("left3");
}
else if(x<220&&x>40){
  mySerial.println(9111);
  Serial.println("LEFT");
}
}
//----------------------------------------
//y axis front and back
else{
if(y<10&&y>0){
  mySerial.println(1111);
  Serial.println("stop");
}
else if(y<360&&y>350){
  mySerial.println(1111);
  Serial.println("stop");
}
else if(y<350&&y>340){
  mySerial.println(1211);
  Serial.println("back1");
}
else if(y<340&&y>330){
  mySerial.println(1311);
  Serial.println("back2");
}
else if(y<330&&y>320){
  mySerial.println(1411);
  Serial.println("back3");
}
else if(y<320&&y>270){
  mySerial.println(1511);
  Serial.println("BACK");
}
else if(y<20&&y>10){
  mySerial.println(1611);
  Serial.println("forward1");
}
else if(y<30&&y>20){
  mySerial.println(1711);
  Serial.println("forward2");
}
else if(y<40&&y>30){
  mySerial.println(1811);
  Serial.println("forwars3");
}
else if(y<260&&y>40){
  mySerial.println(1911);
  Serial.println("FORWARD");
}
}


delay(100);

}

2.harwares i tested them individually and they worked. I dont have a circuit diagram but the connections are;
GYROSCOPE
vcc -5v
gnd -gnd
SCL -A5
SDA -A4

Push Button
Power for pushbutton -7
other terminal of button -0

HC-12(wireless module)
TXD -9
RXD -10
VCC -12
GND -11

  1. Yhea you seem to be right. BUT it only dosent work with this program. I tries using it for connunication and push button led and it worked for that.

4.HC-12-Arduino and HC-12 Long Range Wireless Communication Module - HowToMechatronics

Arduino Uno the regular one

gyroscope MPU 6050-Arduino and MPU6050 Accelerometer and Gyroscope Tutorial

Just an observation: I think the HC 12 is messing with the button as when I see the serial port the button state seems to be stuck in the HIGH state.

1 - Thanks for the [code] tags! one of the reasons to include code in a request for help is so people can load it into their own IDE and try it out, to see what is happening first hand.

2 - Ok, you are wiring 2 boards to the Arduino, a serial LoRa and an i2c gyroscope. But the way you have the button seems strange. Typically one side of a push button switch is attached to a digital pin that is set to INPUT_PULLUP uith pinMode(). The other side is attached to a GND pin, but your circuit attaches it to pin 0, the Serial RX pin. Since you are using hardware Serial in addition to software serial, might this cause a problem?

Come to think of it, why are you using SoftwareSerial? SoftwareSerial is not known for working well with I2C. Try it with hardware Serial and use some other method for indicating the movement states.

3 - Could be a problem with ... SoftwareSerial and I2C?

4 - Cool tutorial for the gyroscope. Can you link to the specific radio board you bought? I don't think that is the problem, but there could be subtle differences in various versions.

In short, try this with the button wired the way I described, and use pins 0 and 1 for the LoRa hardware serial communication. And use 5V for Vcc and GND for GND, not pins 11 and 12. Those IO pins might not be able to support the current you are drawing.

Let us know how all that worked.

ChrisTenone:
1 - Thanks for the [code] tags! one of the reasons to include code in a request for help is so people can load it into their own IDE and try it out, to see what is happening first hand.

2 - Ok, you are wiring 2 boards to the Arduino, a serial LoRa and an i2c gyroscope. But the way you have the button seems strange. Typically one side of a push button switch is attached to a digital pin that is set to INPUT_PULLUP uith pinMode(). The other side is attached to a GND pin, but your circuit attaches it to pin 0, the Serial RX pin. Since you are using hardware Serial in addition to software serial, might this cause a problem?

Come to think of it, why are you using SoftwareSerial? SoftwareSerial is not known for working well with I2C. Try it with hardware Serial and use some other method for indicating the movement states.

3 - Could be a problem with ... SoftwareSerial and I2C?

4 - Cool tutorial for the gyroscope. Can you link to the specific radio board you bought? I don't think that is the problem, but there could be subtle differences in various versions.

In short, try this with the button wired the way I described, and use pins 0 and 1 for the LoRa hardware serial communication. And use 5V for Vcc and GND for GND, not pins 11 and 12. Those IO pins might not be able to support the current you are drawing.

Let us know how all that worked.

First of all. I just repositioned the HC-12 wireless communication to pins TX-6 and RX-5 and it WORKED. I am curious to know what might be the reason.

1.I am little new to the forum....literally just started using it a few days befor....still thanks for the tip.

2.The program i wrote was to like directing the 5v signal directly to the button pin will gie a HIGH output.

And can you pls tel a littme more about the software serial and hardware serial.
I took the example program from the internet and just modify a little to my use. I literally didn't know there existed something like hardware serial.

3.I don't think so.

4.I don't have the link to that gyroscope program sorry. It is the same version I suppose brought from amazom. anayway the link is https://www.amazon.in/AdraXx-433Mhz-Wireless-Replace-Bluetooth/dp/B07GWNXB1Y/ref=sr_1_4?keywords=wireless+module+hc-12&qid=1559216851&s=gateway&sr=8-4

Thank you. :slight_smile:

That problem is almost certainly going to be in your code or the way you have connected everything. An Arduino should certainly be able to handle a gyroscope and HC12.

@PROBOT135, do not cross-post. Threads merged.