Go Down

Topic: Using an HC-12 bluetooth in order to turn on and off an LED (Read 303 times) previous topic - next topic

mikeisnice

I am using an HC-12 Bluetooth to communicate between two Arduinos in order to to push a button on one Arduino in order to turn on an LED on another Arduino. The problem is the light is not turning on and  I am not receiving messages between my serial monitors. I am pretty sure my wiring is correct, so I think it is my code. I have attached pictures of my circuit just in case.

Sender Code:

Code: [Select]
#include <SoftwareSerial.h>

SoftwareSerial mySerial(2, 3); //RX, TX

int buttonPin = 8;

void setup() {
  pinMode(buttonPin, INPUT);
  mySerial.begin(9600);
}

void loop() {
 
  int buttonState = digitalRead(buttonPin);
  
  if(buttonState == 1){//if button is down
    mySerial.println(1234);//send unique code to the receiver in this case 1234
  }
  delay(20);//delay little for better serial communication
}



Receiver Code:
Code: [Select]
#include <SoftwareSerial.h>

SoftwareSerial mySerial(2, 3); //RX, TX

int buttonPin = 8;

void setup() {
  pinMode(buttonPin, INPUT);
  mySerial.begin(9600);
}

void loop() {
 
  int buttonState = digitalRead(buttonPin);
  
  if(buttonState == 1){//if button is down
    mySerial.println(1234);//send unique code to the receiver in this case 1234
  }
  delay(20);//delay little for better serial communication
}




ballscrewbob

@mikeisnice

Other post/duplicate DELETED
Please do NOT cross post / duplicate as it wastes peoples time and efforts to have more than one post for a single topic.

Continued cross posting could result in a time out from the forum.

Could you also take a few moments to Learn How To Use The Forum.

Other general help and troubleshooting advice can be found here.
It will help you get the best out of the forum in the future.



It may not be the answer you were looking for but its the one I am giving based on either experience, educated guess, google (who would have thunk it ! ) or the fact that you gave nothing to go with in the first place so I used my wonky crystal ball.

runaway_pancake

The "Receiver" sketch is the same as the "Sender" sketch.
Are they really the same - or did you post the "Sender" sketch twice?
The "Receiver" sketch should enable the means to. . . receive (if mySerial available, Serial.read, and all that).

Instead of sending a number, perhaps try a char (maybe "A" ?)
"Who is like unto the beast? who is able to make war with him?"
When all else fails, check your wiring!


Go Up