Go Down

Topic: Problem with signal being sent. (Read 219 times) previous topic - next topic

jnienstadt20

Apr 11, 2019, 05:32 pm Last Edit: Apr 11, 2019, 05:34 pm by jnienstadt20
Hi,
I'm trying to make an RC tanks out of an arduino uno, a HC-05 and an app I made in MIT App inventor. I am still kind of new to making thing with arduino. I think that the signal between the app and Bluetooth chip isn't going through or it's an issue with the code. The all the code is below or in the picture below.
Code: [Select]
int inputVariable = 0;
void setup() {
  Serial.begin(9600);
  
void loop() {
 while(Serial.available() >= 0){
  inputVariable = Serial.read();
 }
  if(inputVariable = 1){
  digitalWrite (6,HIGH);
  digitalWrite (7,LOW);
  analogWrite (10,100);
  digitalWrite (4,HIGH);
  digitalWrite (5,LOW);
  analogWrite (9,100);
  }
  if(inputVariable = 2){
  digitalWrite (6,LOW);
  digitalWrite (7,HIGH);
  analogWrite (10,100);
  digitalWrite (4,LOW);
  digitalWrite (5,HIGH);
  analogWrite (9,100);
  }
  if(inputVariable = 3){
  digitalWrite (6,HIGH);
  digitalWrite (7,LOW);
  analogWrite (10,100);
  digitalWrite (4,LOW);
  digitalWrite (5,HIGH);
  analogWrite (9,100);
  }
  if(inputVariable = 4){
  digitalWrite (6,LOW);
  digitalWrite (7,HIGH);
  analogWrite (10,100);
  digitalWrite (4,HIGH);
  digitalWrite (5,LOW);
  analogWrite (9,100);

  if(inputVariable = 0){
  digitalWrite (6,LOW);
  digitalWrite (7,LOW);
  analogWrite (10,100);
  digitalWrite (4,LOW);
  digitalWrite (5,LOW);
  analogWrite (9,100);

groundFungus

Code: [Select]
while(Serial.available() >= 0){
Why read an empty buffer?  

Code: [Select]
if (inputVariable = 1)
= for assignment, == for comparison.

Data from serial monitor is received as ASCII character codes.  So your cases should be '1', '2',...

Put a serial print after the serial read to see what is going on.


LightuC

Code: [Select]

 while(Serial.available() >= 0){
  inputVariable = Serial.read();
 }
 


This translates to:
Code: [Select]


As long as Serial.available() returns a value greater (or equal) to zero:
    Read a byte from the Serial class
    Store that byte into 'inputVariable'


Now what if you receive 2 bytes ('A','1'), before you enter the loop? After the loop inputVariable contains '1' and you missed the 'A'.

Go Up