I want to create a live current meter of a stepper motor for monitoring purposes.
The current sensor I am using is Acs712-20 with 20Amps monitoring capability.
The LCD I am using is a 20x4 SainSmart with a lcd2004 backpack.
I managed to drive the screen and I managed to drive the current meter and monitor the current from the Serial Monitor.
Now I want to:
-Feed the Current Values from the ACS712 to the SainSmart LCD 20x4.
-Have a refresh rate of 1000ms on the LCD Screen of the data that ACS712 gives out.
What I have done until now:
-I have given the analog.Read to the LCD but it gives out only the first column readings of the acs712 which is the Raw Value. No use for me.
Problems:
-I want the value of Amps to appear in the LCD
-To even update the rawValue, I have to reset the arduino, and it does not refresh as the serial monitor does.
ACS712 Datasheet:
https://www.allegromicro.com/~/media/Files/Datasheets/ACS712-Datasheet.ashx
SainSmart LCD 20x4 information (no Datasheet found)
-My wiring:
--LCD to Arduino UNO
VCC to +5V
GND to GND
SDA to A4
SCL to A5
---ACS712 to Arduino UNO
VCC to +5V
GND to GND
OUT to A1
And the sensor pins in series with a load
Serial Monitor Data
Raw Value = 504 mV = 2460.937 Amps = -0.391
Raw Value = 503 mV = 2456.055 Amps = -0.439
Raw Value = 503 mV = 2456.055 Amps = -0.439
Raw Value = 503 mV = 2456.055 Amps = -0.439
LCD Indicating
Reading
A1
503
My code
/*
Measuring Current Using ACS712
*/
const int analogIn = A1;
int mVperAmp = 100; // use 100 for 20A Module and 66 for 30A Module
int RawValue= 0;
int ACSoffset = 2500;
double Voltage = 0;
double Amps = 0;
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
#define I2C_ADDR 0x27 // Define I2C Address where the SainSmart LCD is
#define BACKLIGHT_PIN 3
#define En_pin 2
#define Rw_pin 1
#define Rs_pin 0
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7
LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);
void setup()
{
lcd.begin (20,4);
// Switch on the backlight
lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
lcd.setBacklight(HIGH);
int sensorValue = A1;
sensorValue = analogRead(A1); // read sensorOne value.
// Position cursor and write some text
lcd.home (); // go to the first line, first character
lcd.print("READING");
lcd.setCursor ( 0, 1 ); // go to the 2nd line
lcd.print("A1");
lcd.setCursor ( 0, 2 ); // go to the third line
lcd.print(sensorValue);
Serial.begin(9600);
}
void loop(){
RawValue = analogRead(analogIn);
Voltage = (RawValue / 1024.0) * 5000; // Gets you mV
Amps = ((Voltage - ACSoffset) / mVperAmp);
Serial.print("Raw Value = " ); // shows pre-scaled value
Serial.print(RawValue);
Serial.print("\t mV = "); // shows the voltage measured
Serial.print(Voltage,3); // the '3' after voltage allows you to display 3 digits after decimal point
Serial.print("\t Amps = "); // shows the voltage measured
Serial.println(Amps,3); // the '3' after voltage allows you to display 3 digits after decimal point
delay(1000);
}