Skip to content

Instantly share code, notes, and snippets.

@arn-ob
Last active August 2, 2021 10:11
Show Gist options
  • Select an option

  • Save arn-ob/d007ef2719f9131ba519aeee93e77b66 to your computer and use it in GitHub Desktop.

Select an option

Save arn-ob/d007ef2719f9131ba519aeee93e77b66 to your computer and use it in GitHub Desktop.
Current Sence Utpl Bhaiya Code
#include <SoftwareSerial.h>
const byte rxPin = 2;
const byte txPin = 3;
SoftwareSerial SIM900(rxPin, txPin);
char msg;
float voltageB = 0;
float amp = 0;
boolean sendata = false;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
SIM900.begin(9600);
SIM900.print("AT+CMGF=1\r");
delay(100);
SIM900.print("AT+CNMI=2,2,0,0,0\r");
delay(100);
// SendMessage();
}
void loop() {
// put your main code here, to run repeatedly:
if (SIM900.available() > 0)
{
Serial.println("in");
if (msg == 'F') {
Serial.println("F");
String s = "Voltage = ";
String d = String(voltageB);
String e = " and Current = ";
String f = String(amp);
String t = s + d + e + f;
Serial.println(t);
SendMessage(t);
msg = "";
}
}
// int a = 2;
// String msgs = String(a);
// SendMessage(msgs);
msg = SIM900.read();
delay(100);
getCurrent();
}
void getCurrent() {
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
float voltage = sensorValue * (5.0 / 1023.0);
// print out the value you read:
voltageB= voltage*(220/5);
Serial.println("Voltage");
Serial.println(voltageB);
int sensorValue1 = analogRead(A1);
float voltageA = sensorValue1 * (5000.0 / 1023.0);
float amps=((voltageA-2500)/66);
amp=abs(amps);
Serial.println("Current");
Serial.println(amp); //gsm will sent the value of voltageB [voltage] and voltageA[current]
}
void SendMessage(String msg)
{
SIM900.println("AT+CMGF=1"); //Sets the GSM Module in Text Mode
delay(1000); // Delay of 1000 milli seconds or 1 second
// SIM900.println("AT+CMGS=\"+8801770722247\"\r"); // Replace x with mobile number
SIM900.println("AT+CMGS=\"+8801991768446\"\r");
delay(1000);
SIM900.println(msg);// The SMS text you want to send
delay(100);
SIM900.println((char)26);// ASCII code of CTRL+Z
delay(1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment