Hello everyone! I am trying to create a project where i will have an MQ-7 gas sensor connected to an Arduino Uno to measure CO levels. I have already created a pwm cirquit for the sensor to work and i am using pin 2 as a pwm pin. What i want is after the sensor measures, to send the data via wifi to another Arduino Uno (Using the NRF24L01+ module).
I have written the code for the "sender" Arduino but i am getting "sensorValue was not declared on this scope".
My code is"
#include <SPI.h>
#include "RF24.h"
RF24 myRadio (7, 8);
byte addresses[][6] = {"0"};
int sensorPin = A0; // select the input pin for the CO sensor
// initialize digital pin ledPin as an output
int ledPin = 2;
struct package
{
int id=1;
char text[100] = "CO Level:";
public: int sensorValue = 0; // variable to store the value coming from the sensor
};
typedef struct package Package;
Package data;
void setup()
{
Serial.begin(9600);
delay(1000);
myRadio.begin();
myRadio.setChannel(115);
myRadio.setPALevel(RF24_PA_MAX);
myRadio.setDataRate( RF24_250KBPS ) ;
myRadio.openWritingPipe( addresses[0]);
delay(1000);
pinMode(ledPin, OUTPUT);
}
void loop()
{
analogWrite(ledPin, 255); // "HIGH" state - 5V
delay(60000); // HIGH" state lasts 60 seconds
// After heating it's time to go to "LOW" state
analogWrite(ledPin, 72); // "LOW" state - 1.4V
delay(90000); // "LOW" state lasts for 90 seconds
// Waiting 90 more seconds
digitalWrite(ledPin, HIGH);
delay (50); //small delay so that the sensor does not heat too much
// Reading Sensor
sensorValue = analogRead(sensorPin);
myRadio.write(&data, sizeof(data));
Serial.print("\nPackage:");
Serial.print(data.id);
Serial.print("\n");
Serial.println(data.text);
Serial.println(data.sensorValue);
data.id = data.id + 1;
data.temperature = data.temperature+0.1;
delay(1000);
}
i am getting a exit status 1
"'sensorValue' was not declared in this scope" errir in the sensorValue = analogRead(sensorPin); line
What am i doing wrong? Can someone help me? Thanks.
P.S. Sorry about my English.