Hello, I am currently developing a maglev train location tracking system utilizing IR sensors, LEDs, and LCDs for monitoring a single station. These components are connected to an Arduino Uno. My objective is to replicate the setup on a second station, using an Arduino Nano, and to enable communication between the two stations through 433 MHz transmitter and receiver modules.
During the prototype phase, the communication between the transmitter and receiver worked as expected. However, in the final phase of the project, this functionality ceased. The code on the transmitter side indicates that data is being transmitted, but when running a separate sketch on the Nano, there is no indication that the receiver module is successfully receiving any data.
here is the transmitter code:
#include <LiquidCrystal_I2C.h>
#include <RH_ASK.h>
#include <SPI.h> // Not actually used but needed to compile
// LCD setup
LiquidCrystal_I2C lcd(0x27, 16, 2);
// RF setup
RH_ASK driver;
// IR sensor pins
const int pinIRd1 = 0;
int IRvalueD1 = 0;
const int pinIRd2 = 7;
int IRvalueD2 = 0;
const int pinIRd3 = 2;
int IRvalueD3 = 0;
const int pinIRd4 = 3;
int IRvalueD4 = 0;
const int pinIRd5 = 4;
int IRvalueD5 = 0;
const int pinIRd6 = 5;
int IRvalueD6 = 0;
const int pinIRd7 = 6;
int IRvalueD7 = 0;
// LED setup
const int pinLED = 13;
void setup() {
// Initialize LCD
lcd.init();
lcd.backlight();
lcd.setCursor(3, 0);
lcd.print("Hello World!");
lcd.setCursor(2, 1);
lcd.print("Laksh Smart");
// Initialize RF module
Serial.begin(9600);
if (!driver.init()) {
Serial.println("init failed");
}
// Setup IR sensor pins
pinMode(pinIRd1, INPUT);
pinMode(pinIRd2, INPUT);
pinMode(pinIRd3, INPUT);
pinMode(pinIRd4, INPUT);
pinMode(pinIRd5, INPUT);
pinMode(pinIRd6, INPUT);
pinMode(pinIRd7, INPUT);
pinMode(pinLED, OUTPUT);
}
void loop() {
// Read IR sensor values first
IRvalueD1 = digitalRead(pinIRd1);
IRvalueD2 = digitalRead(pinIRd2);
IRvalueD3 = digitalRead(pinIRd3);
IRvalueD4 = digitalRead(pinIRd4);
IRvalueD5 = digitalRead(pinIRd5);
IRvalueD6 = digitalRead(pinIRd6);
IRvalueD7 = digitalRead(pinIRd7);
// Check each IR sensor and update the LCD, send messages, and handle LEDs
if (IRvalueD1 == LOW) {
const char *msg1 = "0";
driver.send((uint8_t *)msg1, strlen(msg1));
driver.waitPacketSent();
Serial.println("Message Sent: 0");
digitalWrite(LED_BUILTIN, HIGH);
digitalWrite(pinLED, HIGH);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Mile:");
lcd.setCursor(0, 1);
lcd.print("6");
} else if (IRvalueD2 == LOW) {
const char *msg2 = "1";
driver.send((uint8_t *)msg2, strlen(msg2));
driver.waitPacketSent();
Serial.println("Message Sent: 1");
digitalWrite(LED_BUILTIN, HIGH);
digitalWrite(pinLED, HIGH);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Mile:");
lcd.setCursor(0, 1);
lcd.print("5");
} else if (IRvalueD3 == LOW) {
const char *msg3 = "2";
driver.send((uint8_t *)msg3, strlen(msg3));
driver.waitPacketSent();
Serial.println("Message Sent: 2");
digitalWrite(LED_BUILTIN, HIGH);
digitalWrite(pinLED, HIGH);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Mile:");
lcd.setCursor(0, 1);
lcd.print("4");
} else if (IRvalueD4 == LOW) {
const char *msg4 = "3";
driver.send((uint8_t *)msg4, strlen(msg4));
driver.waitPacketSent();
Serial.println("Message Sent: 3");
digitalWrite(LED_BUILTIN, HIGH);
digitalWrite(pinLED, HIGH);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Mile:");
lcd.setCursor(0, 1);
lcd.print("3");
} else if (IRvalueD5 == LOW) {
const char *msg5 = "4";
driver.send((uint8_t *)msg5, strlen(msg5));
driver.waitPacketSent();
Serial.println("Message Sent: 4");
digitalWrite(LED_BUILTIN, HIGH);
digitalWrite(pinLED, HIGH);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Mile:");
lcd.setCursor(0, 1);
lcd.print("2");
} else if (IRvalueD6 == LOW) {
const char *msg6 = "5";
driver.send((uint8_t *)msg6, strlen(msg6));
driver.waitPacketSent();
Serial.println("Message Sent: 5");
digitalWrite(LED_BUILTIN, HIGH);
digitalWrite(pinLED, HIGH);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Mile:");
lcd.setCursor(0, 1);
lcd.print("1");
} else if (IRvalueD7 == LOW) {
const char *msg7 = "6";
driver.send((uint8_t *)msg7, strlen(msg7));
driver.waitPacketSent();
Serial.println("Message Sent: 6");
digitalWrite(LED_BUILTIN, HIGH);
digitalWrite(pinLED, HIGH);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Mile:");
lcd.setCursor(0, 1);
lcd.print("0");
}
delay(500); // Delay to prevent rapid cycling of sensor reads
}
and Here is the reciver code:
#include <RH_ASK.h> // RadioHead Receiver Library (crucial)
#include <SPI.h> // Not actually used but needed to compile
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
RH_ASK driver; // Create a driver to process the message being received
const int LED_PIN = 6; // Pin connected to the LED
int EXPECTED_CODE; // Replace with the actual code to match
void setup()
{
pinMode(LED_PIN, OUTPUT); // Set the LED pin as output
digitalWrite(LED_PIN, LOW); // Ensure the LED is off initially
if (!driver.init()) {
Serial.println("Initialization Process Failed.");
} else {
Serial.println("Initialization Process Success.");
}
Serial.println("BETATEST1");
lcd.init();
lcd.backlight();
}
//int i = 0; (deprecated)
void loop()
{
lcd.setCursor(1,0);
lcd.print("Mile:");
lcd.setCursor(1,1);
lcd.print("6");
//Serial.println(i); (deprecated)
uint8_t buf[2]; // Sets a buffer length limit to help read the message for LED (Eventually Train)
uint8_t buflen = sizeof(buf); // Monitors the length of the variable buf (See above ^)
if (driver.recv(buf, &buflen)) // Non-blocking
{
EXPECTED_CODE = atoi((char*)buf); // Converts the Integer to a String to Process for the println
Serial.println("Code: ");
//Serial.println((char*)buf); // Print the received message (deprecated)
Serial.println(EXPECTED_CODE); // Print the received message
// Check if the received message matches the expected code
switch (EXPECTED_CODE) {
//Stop Relay 2 and Reverse to Relay 1 After 15 secs and Start
case 0:
Serial.println("Turning LED on!");
digitalWrite(LED_PIN, HIGH); // Turn LED on
break;
case 1:
Serial.println("Turning LED off!");
digitalWrite(LED_PIN, LOW); // Turn LED off
break;
case 2:
Serial.println("Turning LED on!");
digitalWrite(LED_PIN, HIGH); // Turn LED on
break;
case 3:
Serial.println("Turning LED off!");
digitalWrite(LED_PIN, LOW); // Turn LED off
break;
case 4:
Serial.println("Turning LED on!");
digitalWrite(LED_PIN, HIGH); // Turn LED on
break;
case 5:
Serial.println("Turning LED off!");
digitalWrite(LED_PIN, LOW); // Turn LED off
break;
case 6:
Serial.println("Turning LED off!");
digitalWrite(LED_PIN, LOW); // Turn LED off
break;
default: // In case of any other code (not a case) being received by transmitter
Serial.println("Unknown code received!");
Serial.println(EXPECTED_CODE);
break;
}
}
//i++; (deprecated)
//delay(5000); (deprecated)
}
Please note that I still need to integrate the LCD and LEDs into the receiver code; however, this serves as the baseline I am currently working with.
Any assistance with this issue would be greatly appreciated, as it has been a significant source of stress and frustration. The challenge has caused considerable setbacks in my project, and despite my best efforts, I am struggling to identify the root cause of the communication failure. Any guidance or insights from experienced individuals would mean a great deal to me at this stage.