One last question, a feature that I didn't think about until now that'd be good to have. A battery voltage check command for the launch pad. I've used the :
int sensorValue = analogRead(A0);
float voltage = sensorValue * (5.0/1023.0);
hc12.println(voltage);
one the launch pad to check voltage of the 12 volt battery I'll have tied to the circuit. I'm using pin A0 as input, and reducing the voltage from 12 volts to a maximum of 5 volts using 3 5.1k ohm resistors to voltage divide (tapping into the line after resistor 3, at 15 volts max would give me 5 volts)
How do I go about reading the string (if I have my terminology correct) (example 11.80) on the sending arduino? I've attached both codes as they are so far:
Control Arduino:
// forum 668348, control end
// 4 mar 2020
// code from https://forum.arduino.cc/index.php?topic=668348.0 #5
// with software serial added to send the command from serial out again to launch site
// (seen lines marked //new)
const unsigned int BAUD_RATE = 9600;
char command;
#include <SoftwareSerial.h> //new
SoftwareSerial hc12(10, 12); // RX, TX //new
void setup()
{
while (!Serial);
hc12.begin(9600); //new
pinMode(13, OUTPUT);
Serial.begin(BAUD_RATE);
Serial.println("Welcome to Launch Command... ");
delay(1000);
Serial.println("Initilizaing Setup... ");
delay(1000);
Serial.println("Transmit Module OPEN");
delay(1000);
Serial.println("INSTRUCTIONS: 'L' to load capacitor bank for ejection charge, 'A' to arm rocket engine, 'F' to launch rocket engine, 'C' to clear launchpad electrical, 'T' to test wireless connection");
delay(500);
Serial.println("Waiting for command...");
delay(1000);
}//setup
void loop()
{
if (Serial.available() > 0)
{
command = Serial.read();
if (command == 'L' ) {
Serial.println("Loading Ejection Charge Circuit...3");
delay(500);
Serial.println("Loading Ejection Charge Circuit...2");
delay(500);
Serial.println("Loading Ejection Charge Circuit...1");
delay(500);
Serial.println("Loading Ejection Charge Circuit...");
Serial.println("500mAh Ejection Charge Circuit CLOSED");
hc12.println('L'); //new
delay(16000);
Serial.println("500mAh Ejection Charge Circuit OPEN");
Serial.println("Ejection Charge Circuit Loaded***ROCKET EJECTION ARMED***");
delay(500);
Serial.println("Waiting for command...");
delay(1000);
}//L
if (command == 'C' ) {
Serial.println("Launch Pad Circuits OPEN ***ALL CLEAR***");
hc12.println('C'); //new
Serial.println("Waiting for command...");
delay(1000);
}//C
if (command == 'F' ) {
delay(750);
Serial.println("ROCKET FIRING!!!");
Serial.println("2A Launch Circuit CLOSED/Umblical Disconnect OPEN");
hc12.println('F');
delay(2000);
Serial.println("2A Launch Circuit OPEN/Umblical Disconnect OPEN");
Serial.println("Launchpad ****CLEAR*** Ejection charge circuit ****CLEAR***");
Serial.println("Waiting for command... READY to Reload");
delay(1000);
}//F
if (command == 'H' ) {
Serial.println("INSTRUCTIONS: 'L' to load capacitor bank for ejection charge, 'A' to arm rocket engine, 'F' to launch rocket engine, 'C' to clear launchpad electrical, 'T' to test wireless connection");;
}//H
if (command == 'T' ) {
delay(750);
Serial.println("Hand Shake Up");
hc12.println('T');
}//T
if (command == 'A' ) {
delay(750);
hc12.println('A');
delay(500);
Serial.println("***ROCKET ARMED***");
Serial.println("Waiting for command... READY to FIRE");
}//A
if (command == 'B' ) {
Serial.println("...checking battery status...");
hc12.println('B');
}
}
if (hc12.available() > 0)
{
command = hc12.read();
if (command == 'z' ){
Serial.println("***Packet Received***1/5");
}
if (command == 'x' ) {
Serial.println("***Packet Received***2/5");
}
if (command == 'c' ) {
Serial.println("***Packet Received***3/5");
}
if (command == 'v' ) {
Serial.println("***Packet Received***4/5");
}
if (command == 'b' ) {
Serial.println("***Packet Received***5/5");
Serial.println("Handshake Down");
}
}
}//loop
Launch Pad Arduino
// forum 668348, launch site
// 4 mar 2020
// proof of concept....
// listens to software serial for an L, C or F
// turns on one led for each
// a while after an F, all leds go off
char command;
#include <SoftwareSerial.h> //new
SoftwareSerial hc12(10, 12); // RX, TX //new
void setup()
{
Serial.begin(9600);
hc12.begin(9600);
pinMode(13, OUTPUT);
digitalWrite(13, LOW);
Serial.println("setup() starting...");
Serial.println("listening for commands on serial");
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(3, OUTPUT);
pinMode(A0, INPUT);
digitalWrite(3,HIGH);
digitalWrite(7,HIGH);
digitalWrite(8,HIGH);
Serial.println("Launch Relay OPEN");
}
void loop()
{
if (hc12.available() > 0)
command = hc12.read();
if (command == 'L' )
{
Serial.print("Load Received");
digitalWrite(13, HIGH);
delay(15000);
digitalWrite(13, LOW);
}
if (command == 'C' )
{
digitalWrite(7,HIGH);
digitalWrite(8,HIGH);
Serial.print("Clear Circuits Received");
}
if (command == 'F' )
{
Serial.print("Fire Command Received");
digitalWrite(8, LOW);
delay(2000);
digitalWrite(8,HIGH);
digitalWrite(7, HIGH);
Serial.println(".... done");
}
if (command == 'T' ) {
Serial.println("Hand Shake Initiated");
hc12.println('z');
delay(500);
hc12.println('x');
delay(500);
hc12.println('c');
delay(500);
hc12.println('v');
delay(500);
hc12.println('b');
delay(500);
}
if (command == 'A' ) {
digitalWrite(7,LOW);
Serial.println("***Rocket Armed***");
}//A
if (command == 'B') {
int sensorValue = analogRead(A0);
float voltage = sensorValue * (5.0/1023.0);
hc12.println(voltage);
}
}//loop