Transmitting data even when the requirements are not met

I am trying to use an RF transmitter to transmit data when ever the voltage is equal to a certain amount. The only problem is that is transmitting no matter what(even when there is no power)
Here is my code:



#include <RH_ASK.h>
#include <SPI.h> // Not actually used but needed to compile
int analogInput = 1;
float Vout = 0.00;
float Vin = 0.00;
float R1 = 100000.00; // resistance of R1 (100K) 
float R2 = 10000.00; // resistance of R2 (10K) 
int val = 0;
        // Define variable to store the analog value coming from the Sound Sensor
int  digitalValue;

RH_ASK driver(2000, 4, 2, 5); // ESP8266 or ESP32: do not use pin 11

void setup(){
   pinMode(analogInput, INPUT); //assigning the input port
   Serial.begin(9600); //BaudRate
     if (!driver.init())
    Serial.println("init failed");
}
void loop(){
   
   val = analogRead(analogInput);//reads the analog input
   Vout = (val * 5.00) / 1024.00; // formula for calculating voltage out i.e. V+, here 5.00
   Vin = Vout / (R2/(R1+R2)); // formula for calculating voltage in i.e. GND
   if (Vin<0.09)//condition 
   {
     Vin=0.00;//statement to quash undesired reading !
  } 
Serial.print("\t Voltage of the given source = ");
Serial.print(Vin);
delay(1000); //for maintaining the speed of the output in serial moniter

 if (Vin=30)   // When the Sound Sensor sends signla, via voltage present, light LED13 (L)
  {
    const char *msg = "hello";

    driver.send((uint8_t *)msg, strlen(msg));
    driver.waitPacketSent();
       Serial.write("sent");
    delay(5000);
  }
}
  if (Vin = 30) // When the Sound Sensor sends signla, via voltage present, light LED13 (L)

= for assignment
== for comparison

What does that mean?

  • How do you set a variable to a value ?
  • How do you test 2 values to determine if they are equal ?

Thank You

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.