Hi This is my Tx and Rx and my Project, I have inserted the standard ‘Radio Head’ library but as I mentioned without the converted transmission I can’t move forward.
Receiver Code:
#include <SD.h>
#include <SPI.h>
#include <Wire.h> //new RadioHead stuff
#include <RH_ASK.h> //new RadioHead stuff
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 7, 5, 6, 3, 2);
File myFile;
RH_ASK driver; //new RadioHead stuff
int data; //new RadioHead stuff
int pow_pin = 8;
const int analogInPin = A0; // Analog input pin that the potentiometer is attached to
const int numReadings = 100;
const int Beep = A1;
const int EnterKey = A5; // Dat enter push button.
int sensorValue = 0; // value read from the pot
int TotalPinState = 1; // variable for reading the pushbutton status
const int led = 9; // Data transfered LED
const int TareButton = A4; /// the number of the Tare/Zero pushbutton pin
int buttonState = 0; /// variable for reading the pushbutton status
int TareValue;
int FinalWt;
int Pounds;
int Ounces;
int ZeroVal;
int Weight;
int Maths1;
int Maths2;
int Maths3;
long id = 1;
int readings[numReadings]; // the readings from the analog input
int index = 0; // the index of the current reading
int total = 0; // the running total
void setup()
{
pinMode(led, OUTPUT); //led on pin 9 ...needs to be set otherwise its very dull.
pinMode(Beep, OUTPUT);
pinMode(TareButton, INPUT);
pinMode(EnterKey, INPUT);
driver.init(); //new RadioHead stuff
Serial.begin(9600);
Serial.print("Initializing SD card...");
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.setCursor(2, 0);
lcd.print("Remote");
lcd.setCursor(4, 1);
lcd.print("Scales");
delay (3000);
if (!SD.begin(4)) {
Serial.println("initialization failed!");
return;
}
Serial.println("initialization done.");
// initialize all the readings to 0:
for (int thisReading = 0; thisReading < numReadings; thisReading++)
readings[thisReading] = 0; //Totalising setup of Indexing
}
void loop()
{
uint8_t buf[RH_ASK_MAX_MESSAGE_LEN];
uint8_t buflen = sizeof(buf);
Serial.println(buf[0]);
if (driver.recv(buf, &buflen)) // Non-blocking
{
}
//tarebutton code
//If tarebutton is pressed.
if ( digitalRead(TareButton) == LOW) {
digitalWrite(led, HIGH); //shows switchstate is HIGH *****
int TareValue = analogRead(A0); //analogRead(A0);
digitalWrite(Beep, HIGH);
ZeroVal = TareValue;
Serial.print("Tare Value = ");
Serial.println (TareValue);
buttonState = LOW; // *** need to reset this once you've done whats needed ****
delay (1);
lcd.clear();
delay (1);
lcd.setCursor (3, 1);
lcd.print ("NET ZERO'D");
}
//if tarebutton released
if ( digitalRead(TareButton) == HIGH) {
digitalWrite(led, LOW); // shows the process is finished
digitalWrite(Beep, LOW);
}
{
buttonState == digitalRead(EnterKey);
if (buttonState == HIGH)
digitalWrite(EnterKey, HIGH); //shows switchstate is HIGH *****
// digitalWrite(led, HIGH);
delay (10);
}
digitalWrite(EnterKey, LOW); //shows switchstate is HIGH *****
digitalWrite(led, LOW);
{
}
{
delay(10);
lcd.display();
if (digitalRead(EnterKey) == LOW)
{
digitalWrite(led, HIGH); //shows switchstate is HIGH *****
digitalWrite(Beep, HIGH); //beeps when Tare or Enter buttons pressed.
FinalWt = (analogRead(0) - ZeroVal);
Serial.print("Raw AnalogValue = ");
Serial.println (analogRead(0));
Serial.print ("RawVal-Tare = FinalWt = ");
Serial.println(FinalWt);
//Weight Calculation for SD and LCD
Pounds = (FinalWt * 6 / 28.34952 / 16);
Maths1 = (FinalWt * 6);
Serial.println(Maths1);
Maths2 = (Pounds * 28.34952 * 16);
Serial.println(Maths2);
Maths3 = (Maths1 - Maths2);
Serial.println(Maths3);
Ounces = (Maths3 / 28);
Serial.println(Ounces);
lcd.setCursor(5, 1); //Position of first digit
lcd.print(Pounds); //Position of Pb Wt Value
lcd.setCursor(11, 1); //Position of second letter
lcd.print(Ounces); //Position of Oz Wt Value
String dataString = String(id); //This is the number of fish caught count
lcd.setCursor (0, 1); //Botton Line
lcd.print (id); // Count Value
//Serial Monitor for checking code.
Serial.print("weight = " );
Serial.print(Pounds);
Serial.print("Lbs ");
Serial.print(Ounces);
Serial.print("oz");
//SD Card writing too.
myFile = SD.open("Results.txt", FILE_WRITE);
if (myFile)
myFile.println(FinalWt);
myFile.close();
myFile = SD.open("Weights.txt", FILE_WRITE);
if (myFile)
String dataString = String(id);
myFile.print(id);
myFile.print(" ");
myFile.print(Pounds);
myFile.print("Lb ");
myFile.print(Ounces);
myFile.print("oz");
myFile.println("");
myFile.close();
delay (100);
digitalWrite(led, LOW); // shows the process is finished and turns off LED
digitalWrite(Beep, LOW); //Turns pff beep
delay (5000);
lcd.clear();
//TotalPinState = digitalRead(TotalPin);
if (TotalPinState == LOW)
//subtract the last reading;
total = total - readings[index];
// read from the sensor:
readings[index] = (FinalWt);
sensorValue = (FinalWt);
// add the reading to the total:
total = total + readings[index];
// advance to the next position in the array:
index = index + 1;
// if we're at the end of the array...
if (index >= numReadings)
// ...wrap around to the beginning:
index = 0;
// calculate the average:
//average = total / numReadings;
// send it to the computer as ASCII digit
Serial.print("Weight=" );
Serial.println(FinalWt);
//Serial.println(inputPin);
//Serial.println(readings[index]);
Serial.print("Total=");
Serial.println(total);
//Weight Calculation for SD and LCD
Pounds = (total * 6 / 28.34952 / 16);
Maths1 = (total * 6);
Serial.println(Maths1);
Maths2 = (Pounds * 28.34952 * 16);
Serial.println(Maths2);
Maths3 = (Maths1 - Maths2);
Serial.println(Maths3);
Ounces = (Maths3 / 28);
Serial.println(Ounces);
//Serial Monitor for checking code.
Serial.print("Total weight = " );
Serial.print(Pounds);
Serial.print("Lbs ");
Serial.print(Ounces);
Serial.print("oz");
Serial.println();
lcd.setCursor(0, 0); //Total Page generated at end of weigh sequence
lcd.print("Total");
lcd.setCursor(7, 0);
lcd.print("Lbs");
lcd.setCursor(12, 0);
lcd.print("Ozs");
lcd.setCursor(0, 1);
lcd.print("No.");
lcd.setCursor(3, 1);
lcd.print (id); // Count Value
lcd.setCursor(7, 1);
lcd.print(Pounds);
lcd.setCursor(12, 1);
lcd.print(Ounces);
id++; //This INDEX command must stay here otherwise it will add +1 to the total caught value!!!
delay(500); // delay in between reads for stability
}
{
delay(500);
lcd.display();
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
lcd.setCursor(0, 0);
lcd.print("No.");
//lcd.setCursor(6,0);
//lcd.print("Weight");
lcd.setCursor(5, 0);
lcd.print("Lb");
lcd.setCursor(11, 0);
lcd.print("oz");
{
}
}
}
}