/*
* Arduino Sketch for Allegro ACS758 Current Sensor (Basic Simple)
* this sensor can measure current at range of up to 200A
* It operates with 3.3 or 5V (the module works with 5V, sensor can work with 3.3 or 5V)
* Please watch video instruction and explanation for this code.
*
* Written by Ahmad Shamshiri on Saturday May 26,2018 at 19:05 at Ajax, Ontario, Canada
* for Robojax.com
* View the video instruction at https://youtu.be/SiHfjzcqnU4
* This code has been downloaded from Robojax.com
*/
#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#define TFT_DC 9
#define TFT_CS 10
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
#define VIN A0
const float vcc = 5.00;// supply voltage 5V or 3.3V
const float factor = 0.02;// 20mV/A is the factor
float voltage;
float currentEx = 0;
void setup() {
tft.begin();
tft.setCursor(26, 120);
tft.setTextColor(ILI9341_RED);
tft.setTextSize(2);
tft.println("CargoRunner");
tft.setCursor(20, 260);
tft.setTextColor(ILI9341_GREEN);
tft.setTextSize(2);
tft.println("grün = Antrieb, rot = Laden");
// Meme reference: https://english.stackexchange.com/questions/20356/origin-of-i-can-haz
//Robojax.com ACS758 Current Sensor
Serial.begin(9600);
Serial.println("Robojax Tutorial");
Serial.println("ACS758 Current Tester");
Serial.println("Basic Simple Code");
delay(3000);
tft.setCursor(26, 120);
tft.setTextColor(ILI9341_BLACK);
tft.setTextSize(2);
tft.println("CargoRunner");
}
void loop() {
//Robojax.com ACS758 Current Sensor
voltage = (5.0 / 1023.0)* analogRead(VIN);// Read the voltage from sensor---Lesen Sie die Spannung vom Sensor ab
voltage = voltage - (vcc * 0.5) + 0.012 ;// 0.007 is a value to make voltage zero when there is no current--- 0,007 ist ein Wert, um die Spannung Null zu machen, wenn kein Strom vorhanden ist
float current = voltage / factor;
tft.setCursor(26, 120);
tft.setTextColor(ILI9341_BLUE);
tft.setTextSize(2);
tft.println("Strom in A: ");
if(currentEx != current)
{
tft.setCursor(26, 160);
tft.setTextColor(ILI9341_BLACK);
tft.setTextSize(3);
tft.println(currentEx,2);
}
tft.setCursor(26, 160);
if(current < 0)
{
tft.setTextColor(ILI9341_RED);
}
else
{
tft.setTextColor(ILI9341_GREEN);
}
tft.setTextSize(3);
tft.println(current,2);
// tft.setCursor(36, 120);
//tft.print("Spannung in V:");
Serial.print("V: ");
Serial.print(voltage,3);
Serial.print("V, I: ");
Serial.print(current,2); Serial.println("A");
currentEx = current;
delay(100);
}