Go Down

Topic: Arduino codes are uploaded but nothing is coming out on serial monitor  (Read 945 times) previous topic - next topic

yonas_abebe

433 Mhz RF transmitter code

#include <MPU6050_tockn.h>
#include <Wire.h>
#include <RH_ASK.h>
#include <SPI.h> // Not actually used but needed to compile

RH_ASK rf_driver;
MPU6050 mpu6050(Wire);

void setup() {
  
  Serial.begin(9600);
  rf_driver.init();
  mpu6050.update();
  Serial.println("angleX : ");
  Serial.println(mpu6050.getAngleX());
  if( mpu6050.getAngleX()<1)
  {
  Serial.println("WATER");
      const char *msg = "WATER!";
    rf_driver.send((uint8_t *)msg, strlen(msg));
    rf_driver.waitPacketSent();
    delay(1000);
}

else if ( mpu6050.getAngleX()>1&mpu6050.getAngleX()<1.8)
  {
  Serial.println("FOOD");
  const char *msg = "FOOD!";
    rf_driver.send((uint8_t *)msg, strlen(msg));
    rf_driver.waitPacketSent();
    delay(1000);
}
else if ( mpu6050.getAngleX()>1.8&mpu6050.getAngleX()<3)
{
  Serial.println("TOILET");
    const char *msg = "TOILET!";
    rf_driver.send((uint8_t *)msg, strlen(msg));
    rf_driver.waitPacketSent();
    delay(1000);
  }
  
  else 
{
  Serial.println("EMERGENCY");
   const char *msg = "EMERGENCY!";
    rf_driver.send((uint8_t *)msg, strlen(msg));
    rf_driver.waitPacketSent();
    delay(1000);
  }
}
 


void loop() {
  }




receiver code
// Include RadioHead Amplitude Shift Keying Library
#include <RH_ASK.h>
// Include dependant SPI Library 
#include <SPI.h> 
 
// Create Amplitude Shift Keying Object
RH_ASK rf_driver;
 
void setup()
{
    // Initialize ASK Object
    rf_driver.init();
    // Setup Serial Monitor
    Serial.begin(9600);
}
 
void loop()
{
    // Set buffer to size of expected message
    uint8_t buf[24];
    uint8_t buflen = sizeof(buf);
    // Check if received packet is correct size
    if (rf_driver.recv(buf, &buflen))
    {
      
      // Message received with valid checksum
      Serial.print("Message Received: ");
      Serial.println((char*)buf);         
    }
}

AWOL


PaulS

Quote
else if ( mpu6050.getAngleX()>1&mpu6050.getAngleX()<1.8)
If the angle is less than 1 smiley face? What the heck does THAT mean?

The logical and operator is &&, NOT &.

Why does the sender have all the code in setup()?
The art of getting good answers lies in asking good questions.

Go Up