Hi Jim.
For that I use the original car ignition.
I have been testing my code and something is not working. Can you check it? Right now my head can't find what I'm doing wrong and I“m going frustrated.
#include <Wire.h>
#include <doxygen.h>
#include <NexButton.h>
#include <NexCheckbox.h>
#include <NexConfig.h>
#include <NexCrop.h>
#include <NexDualStateButton.h>
#include <NexGauge.h>
#include <NexGpio.h>
#include <NexHardware.h>
#include <NexHotspot.h>
#include <NexNumber.h>
#include <NexObject.h>
#include <NexPage.h>
#include <NexPicture.h>
#include <NexProgressBar.h>
#include <NexRadio.h>
#include <NexRtc.h>
#include <NexScrolltext.h>
#include <NexSlider.h>
#include <NexText.h>
#include <NexTimer.h>
#include <Nextion.h>
#include <NexTouch.h>
#include <NexUpload.h>
#include <NexVariable.h>
#include <NexWaveform.h>
#include <mapper.h>
#include <multimap.h>
///*****GPS*****/////
#include <SoftwareSerial.h>
#include <TinyGPS++.h>
#define rxPin 14
#define txPin 13
SoftwareSerial neogps(rxPin,txPin);
TinyGPSPlus gps;
#define WATER_TEMP_PIN A0 // signal from water temp sensor.
#define OIL_PSI_PIN A1 // signal from oil PSI sensor.
#define OIL_TEMP_PIN A2 // signal from oil temp sensor.
///SENSOR TURBO*******************///
#define sensorTurbo_Pin A3 // signal from Turbo sensor.
#define refTurbo_Pin A4 // signal from Turbo reference.
//#define WINDOW_SIZE 6
////VOLTAGE////
const int sensorPin = A5;
int sensorValue_VOLTS;
float valorVolts;
///FUEL******//
int fuelPin = 6;
int lectura_fuel;
int porcentaje_fuel;
/// TURBO///
float presionTurboSoplado;
float presionTurboAtmosfera;
float bares;
uint32_t next, MyInt = 0;
//************** LED ALARM************//
int LED1=13; // ALARMA TEMP AGUA
int LED2=12; // ALARMA BATERIA
int LED3=11; // ALARMA TURBO
int LED4=10; // ALARMA TEMP ACEITE
int LED5=9; //ALARMA PRESION ACEITE
int LED6=8; //ALARMA GASOLINA
int LED_RPM1=7; //3.5M rpm
int LED_RPM2=6; //4M rpm
int LED_RPM3=5; //4.5M rpm
int LED_RPM4=4; //5M rpm
int LED_RPM5=3; //5.5M rpm
int LED_RPM6=2; //6M rpm
//***************** NEXTION EDITOR **************//
NexNumber gn0 = NexNumber(1, 4, "gn0");
NexNumber vn1 = NexNumber(1, 5, "vn1");
NexNumber wn2 = NexNumber(1, 6, "wn2");
NexNumber fn3 = NexNumber(1, 8, "fn3");
NexNumber rn6 = NexNumber(1, 10, "rn6");
NexNumber rn8 = NexNumber(1, 12, "rn8");
NexNumber rn0 = NexNumber(2, 5, "rn0");
NexNumber an1 = NexNumber(2, 6, "an1");
NexNumber on2 = NexNumber(2, 9, "on2");
NexNumber mwt = NexNumber(3, 4, "mwt");
NexNumber mta = NexNumber(3, 5, "mta");
NexProgressBar j0 = NexProgressBar(2, 2, "j0");
NexText bt4 = NexText(1, 7, "bt4");
NexText rt5 = NexText(1, 9, "rt5");
NexText at7 = NexText(1, 11, "at7");
NexText bt1 = NexText(2, 7, "bt1");
NexText tt2 = NexText(2, 8, "tt2");
NexText ot3 = NexText(2, 10, "ot3");
NexText mpa = NexText(3, 6, "mpa");
NexText mpt = NexText(3, 7, "mpt");
// ************* BUFFER SENSOR **************//
char bt [100]={0};
char rt [100]={0};
char at [100]={0};
char ma [100]={0};
char mt [100]={0};
long int Set_background_color_bco; //cambiar color fondo numeros
///MAPEADO SENSOR********************////////
mapper aToVMapper(0,1023,0,5); // Analog to volts.
multiMap vToWaterTempMapper; // This will be volts to temp.
multiMap vToOilPSIMapper; // This will be volts to Oil PSI.
multiMap vToOilTempMapper; // This will be volts to Oil TEMP.
////RPMspark////
const int DATA_PIN = 36;
const int LED_GROUND_PIN = 50;
const int PINS_COUNT = 4;
const int LED_PINS[PINS_COUNT] = {21,22,23,24};
const int LED_SWITCH_RPM[PINS_COUNT] ={4000, 4500, 5000};
const int REV_LIMITER_RPM = 5800;
const int NUMBER_OF_CYLINDERS = 4;
const int LED_UPDATE_INTERVAL = 200;
unsigned long lastUpdateTime = 0;
volatile int sparkFireCount = 0;
int lastRpmValue = 0;
bool revLimiterOn = false;
void incrementRpmCount() {
sparkFireCount++;
}
void setGlobalState(bool state){
for (int i = 0; i < PINS_COUNT; i++){
digitalWrite(LED_PINS[i], state);
}
}
void setLedState(int rpm){
setGlobalState(LOW);
for (int i = 0; i< PINS_COUNT; i++){
if (rpm > LED_SWITCH_RPM[i]){
digitalWrite(LED_PINS[i], HIGH);
}
}
if (rpm>REV_LIMITER_RPM){
setGlobalState(LOW);
}
else{
setGlobalState(HIGH);
}
revLimiterOn= !revLimiterOn;
return;
}
void setup() {
Serial.begin(115200);
// Serial3.begin;
// Serial1.begin;
nexSerial.begin(115200);
neogps.begin(115200);
pinMode(fuelPin, INPUT);
pinMode(sensorValue_VOLTS, INPUT);
pinMode(sensorTurbo_Pin, INPUT);
pinMode(refTurbo_Pin, INPUT);
//////RPMspark
for (int i=0; i> PINS_COUNT; i++){
pinMode(LED_PINS[i], OUTPUT);
}
pinMode(LED_GROUND_PIN, OUTPUT);
digitalWrite(LED_GROUND_PIN, LOW);
setGlobalState(HIGH);
delay(500);
setGlobalState(LOW);
pinMode(DATA_PIN, INPUT_PULLUP);
attachInterrupt(1, incrementRpmCount, FALLING);
pinMode (LED1, OUTPUT);
pinMode (LED2, OUTPUT);
pinMode (LED3, OUTPUT);
pinMode (LED4, OUTPUT);
pinMode (LED5, OUTPUT);
pinMode (LED6, OUTPUT);
pinMode (LED_RPM1, OUTPUT);
pinMode (LED_RPM2, OUTPUT);
pinMode (LED_RPM3, OUTPUT);
pinMode (LED_RPM4, OUTPUT);
pinMode (LED_RPM5, OUTPUT);
pinMode (LED_RPM6, OUTPUT);
vToWaterTempMapper.addPoint(2,0);
//vToWaterTempMapper.addPoint(4.75,50);// Set datapoints TEMP WATER into the mapper.
//vToWaterTempMapper.addPoint(3.0,20);
//vToWaterTempMapper.addPoint(2.9,85);
//vToWaterTempMapper.addPoint(2.03,90);
//vToWaterTempMapper.addPoint(5.0,95);
//vToWaterTempMapper.addPoint(3.0,110);
vToWaterTempMapper.addPoint(3,120);
vToOilPSIMapper.addPoint(2,0); // Set datapoints PRES OIL into the mapper.
//vToOilPSIMapper.addPoint(1.2,2.5);
vToOilPSIMapper.addPoint(3,5);
//vToOilPSIMapper.addPoint(1,7.5);
vToOilPSIMapper.addPoint(4,10);
vToOilTempMapper.addPoint(4,20); // Set datapoints TEMP OIL into the mapper.
//vToOilTempMapper.addPoint(5,60);
vToOilTempMapper.addPoint(5.05,90);
//vToOilTempMapper.addPoint(5.2,130);
vToOilTempMapper.addPoint(5.25,140);
vToOilTempMapper.addPoint(5.3,150);
//vToOilTempMapper.addPoint(0.08,160);
//vToOilTempMapper.addPoint(0.06,170);
vToOilTempMapper.addPoint(5.40,190);
}
const int FIRES_PER_REV=(360/(720 / NUMBER_OF_CYLINDERS));
// This takes the reading from analogInput() and gives back... temp.
float getTemp(int aVal) {
float volts;
float tempWater;
volts = aToVMapper.map(aVal);
tempWater = vToWaterTempMapper.map(volts);
return tempWater;
}
// This takes the reading from analogInput() and gives back... OIl PSI.
float getOilPSI(int aVal) {
float volts;
float PSI;
volts = aToVMapper.map(aVal);
PSI = vToOilPSIMapper.map(volts);
return PSI;
}
// This takes the reading from analogInput() and gives back... temp.
float getTempOil(int aVal) {
float volts;
float tempOil;
volts = aToVMapper.map(aVal);
tempOil = vToOilTempMapper.map(volts);
return tempOil;
}
void loop() {
int val;
float tempWater;
float oilPSI;
float tempOil;
val = analogRead(WATER_TEMP_PIN); // read the input pin WATER
tempWater = getTemp(val);
Serial.print("sensorAGUA = ");
Serial.println(tempWater);
if (tempWater>100){
digitalWrite (LED1, HIGH);
wn2.Set_background_color_bco (63488);
an1.Set_background_color_bco (63488);
wn2.setValue (tempWater);
an1.setValue (tempWater);
}
else{
digitalWrite (LED1, LOW);
wn2.Set_background_color_bco (48631);
an1.Set_background_color_bco (48631);
wn2.setValue (tempWater);
an1.setValue (tempWater);
}
val = analogRead(OIL_PSI_PIN); // read the input pin OIL PRESS
oilPSI = getOilPSI(val);
Serial.print("sensorP OIL = ");
Serial.println(oilPSI);
if (oilPSI<3.3){
digitalWrite (LED5, HIGH);
at7.Set_background_color_bco (63488);
ot3.Set_background_color_bco (63488);
dtostrf(oilPSI,5,2,at);
ot3.setText(at);
at7.setText(at);
}
else{
digitalWrite (LED5, LOW);
at7.Set_background_color_bco (48631);
ot3.Set_background_color_bco (48631);
dtostrf(oilPSI,5,2,at);
ot3.setText(at);
at7.setText(at);
}
val = analogRead(OIL_TEMP_PIN); // read the input pin OIL TEMP
tempOil = getTempOil(val);
Serial.print("sensorT OIL = ");
Serial.println(tempOil);
if (tempOil>155){
digitalWrite (LED4, HIGH);
rn6.Set_background_color_bco (63488);
on2.Set_background_color_bco (63488);
rn6.setValue(tempOil);
on2.setValue(tempOil);
}
else{
digitalWrite (LED4, LOW);
rn6.Set_background_color_bco (48631);
on2.Set_background_color_bco (48631);
rn6.setValue(tempOil);
on2.setValue(tempOil);
}
//*******FUEL****//
lectura_fuel = analogRead(fuelPin);
porcentaje_fuel = map(lectura_fuel,0, 830, 35, 0);
fn3.setValue(porcentaje_fuel);
Serial.print("FUEL = ");
Serial.println(porcentaje_fuel);
if (porcentaje_fuel<55) {
digitalWrite (LED6, HIGH);
}
else{
digitalWrite (LED6, LOW);
}
//////VOLTAGE
float voltaje;
//sensorValue_VOLTS = analogRead(sensorPin);
//vin = map(sensorValue_VOLTS, 0, 1023, 0, 26.2);
sensorValue_VOLTS=analogRead(sensorPin);
voltaje=sensorValue_VOLTS/4.043;
valorVolts=(voltaje/10);
Serial.print("VOLTAJE = ");
Serial.println(voltaje);
if (valorVolts<11,5){
digitalWrite (LED2, HIGH);
//bt4.Set_background_color_bco (63488);
//bt1.Set_background_color_bco (63488);
dtostrf(valorVolts,5,2,bt);
bt4.setText(bt);
bt1.setText(bt);
}
else{
digitalWrite (LED2, LOW);
//bt4.Set_background_color_bco (48631);
//bt1.Set_background_color_bco (48631);
dtostrf(valorVolts,5,2,bt);
bt4.setText(bt);
bt1.setText(bt);
}
///*****TURBO****////
analogRead(sensorTurbo_Pin);
presionTurboSoplado = map(analogRead(sensorTurbo_Pin),0,1023,0,4.92);
//int boost1 = map(analogRead(sensorTurbo_Pin),21,961,100,2600);
analogRead(refTurbo_Pin);
presionTurboAtmosfera = map(analogRead(refTurbo_Pin),0,1023,0,4.92);
bares = (presionTurboSoplado-presionTurboAtmosfera);
if (bares>1.5){
digitalWrite (LED2, HIGH);
bt4.Set_background_color_bco(63488);
bt1.Set_background_color_bco(63488);
dtostrf(bares,5,2,rt);
rt5.setText(rt);
tt2.setText(rt);
}
else{
digitalWrite (LED2, LOW);
bt4.Set_background_color_bco(48631);
bt1.Set_background_color_bco(48631);
dtostrf(bares,5,2,rt);
rt5.setText(rt);
tt2.setText(rt);
}
dtostrf(bares,4,2,rt);
rt5.setText(rt);
tt2.setText(rt);
/////GPS Loop////
boolean newData = false;
for (unsigned long start = millis(); millis() - start < 1000;)
{
while (neogps.available())
{
if (gps.encode(neogps.read()))
{
newData = true;
}
}
}
//If newData is true
if(newData == true)
{
newData = false;
print_speed();
}
//endif
}
void print_speed()
{
if (gps.location.isValid() == 1)
{
//String gps_speed = String(gps.speed.kmph());
gn0.setValue(gps.speed.kmph());
vn1.setValue(gps.satellites.value());
}
/////RPM SPARK
if ((millis() - lastUpdateTime)>LED_UPDATE_INTERVAL){
int currentRpm = (sparkFireCount*(1000/LED_UPDATE_INTERVAL)*60)/FIRES_PER_REV;
int averagedRpm =(currentRpm+lastRpmValue)/2;
setLedState(averagedRpm);
Serial.println(averagedRpm);
sparkFireCount = 0;
lastUpdateTime = millis();
lastRpmValue = currentRpm;
int RpmNextion=map(averagedRpm,0,1023,0,100);
rn8.setValue(averagedRpm);
rn0.setValue(averagedRpm);
j0.setValue(RpmNextion);
delay (1); //delay for stability
}
}
the voltage gets with a 5v-25v arduino module
Thanks a lot for your time. Best Regards