This weeks assignment was about designing and building a wired &/or wireless network connecting at least two processors. I decided to do something, that would be useful for my future project - an wireless connection between my smart planter and my computer, where I will develop an application that will show, when the water tank is empty and when it is full.
A quick intro: for that assignment I used my final presentation board. As I already explained in Output & Input assignment, this board will control all the Output devices(water pump, LED strip, WS2812) depending on input sensors(water level, humidity & light). Here is the schematic and board:
I used an HC05 bluetooth module (Datasheet ). The module uses a serial connection over the RX and TX pin and my final board processor ATmega328 has such a pins, there should be no problem. Here is an instruction, how to set and connect the bluetooth module:
After that I could find bluetooth on my laptop and connect it:
After that I programmed my board using serial communication:
So now, if I will open serial Monitor for a device - Bluetooth, I will see what bluetooth module receives :
I also did serial communication between two boards(using wires). For that it has to be a common ground between the two boards(that means that ground of boards are connected) or else it will not function properly. Also, note that TX goes to RX and RX goes to TX. Here is the sample code for sender board and receiver one:
I did set up a processing app to work with the bluetooth module on my PCB. The app simply connects to the bluetooth module and receives the information (0 when water tank is empty and 1 when it is full).
Here is the code:
import processing.serial.*;
boolean toggle = true;
PImage LEDonImage;
PImage LEDoffImage;
Serial myPort;
int portNumber;
void setup() {
size(500, 500);
LEDonImage = loadImage("LEDonImage.png");
LEDonImage.resize(500, 500);
LEDoffImage = loadImage("LEDoffImage.png");
LEDoffImage.resize(500, 500);
image(LEDoffImage, 0, 0);
for (int count = 0; count < Serial.list().length; count++){
if (Serial.list()[count].length() > 20){
if (Serial.list()[count].substring(0,21).equals("/dev/cu.LANABT-SPPDev")){
portNumber = count;
}
}
}
println(Serial.list());
println(portNumber);
String portName = Serial.list()[portNumber];
myPort = new Serial(this, portName, 9600);
//myPort.write("0");
//mainLoop();
}
char water = 0;
char last = 1;
void serialEvent(Serial myPort) {
water = myPort.readChar();
if(water == 0){
image(LEDonImage, 0, 0);
//println("water on");
}
else{
image(LEDoffImage, 0, 0);
//println("water off");
}
println(water);
}
void draw() {
if(water == '0'){
image(LEDonImage, 0, 0);
//println("water on");
}
else{
image(LEDoffImage, 0, 0);
//println("water off");
}
}
So, that how it looks:
And live demo: