Im trying to make this project. Im using gsm sim900a and 433 Mhz Rf module.
Sensor node code:
#include <VirtualWire.h>
#include <DataCoder.h>
#include <DHT.h>
#define DHTPIN 5
#define DHTTYPE DHT11
DHT dht (DHTPIN, DHTTYPE);
int TX_PIN = 10;
void setup() {
dht.begin();
Serial.begin(115200);
vw_set_tx_pin(TX_PIN);
vw_setup(4000);
}
void loop() {
int soilM = analogRead(A1);
float t, h, sm;
sm = soilM;
h = dht.readHumidity();
t = dht.readTemperature();
float data[RF_DATA_ARRAY_SIZE];
data[0] = t;
data[1] = h;
data[2] = sm;
union RFData outDataSeq;
EncodeRFData(data, outDataSeq);
TransmitRFData(outDataSeq);
delay(500);
}
Base node code:
#define BLYNK_PRINT Serial
#define TINY_GSM_MODEM_SIM900
#include <TinyGsmClient.h>
#include <BlynkSimpleSIM800.h>
#include <VirtualWire.h>
#include <DataCoder.h>
const int RX_PIN = 9;
char auth[] = "XXXXXXXXXXXXXXXXXXXXXXXX";
char apn[] = "XXXXXXXXX";
char user[] = "";
char pass[] = "";
#include <SoftwareSerial.h>
SoftwareSerial GPRS(2, 3);
TinyGsm modem(GPRS);
//BlynkTimer timer;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
vw_set_rx_pin(RX_PIN);
vw_set_ptt_inverted(true);
vw_setup(4000);
vw_rx_start();
delay(10);
GPRS.begin(115200);
delay(3000);
Serial.println("Initializing modem...");
modem.restart();
Blynk.begin(auth,modem, apn, user, pass);
//timer.setInterval(1000L, sendSensor);
}
void loop() {
// put your main code here, to run repeatedly:
Blynk.run();
sendSensor();
}
void sendSensor(){
uint8_t msg[VW_MAX_MESSAGE_LEN];
uint8_t msglen = VW_MAX_MESSAGE_LEN;
union RFData inDataSeq;
float data[RF_DATA_ARRAY_SIZE];
if (vw_get_message(msg, &msglen)){
int i;
for (i = 0; i < msglen; i++){
inDataSeq.s[i] = msg[i];
}
DecodeRFData(data, inDataSeq);
for(int i = 0; i < RF_DATA_ARRAY_SIZE-1; i++){
if(i == 0){
Blynk.virtualWrite(V1, data[i]);
}
if(i == 1){
Blynk.virtualWrite(V2, data[i]);
}
if(i == 2){
Blynk.virtualWrite(V3, data[i]);
}
}
}
}
No error after uploading these codes but after I tried to open the serial monitor for the base node to see if it was connected, all I can see was ‘cannot init’. Im new to blynk so I really dont know what was wrong with this. I really need to figure out whats the problem so please help me with this.
Thank you.