Using ATmega2560 to safeguard diesel engine

I will add a small resistor to shield MCU in case sensor goes short circuit, it is a harsh environment and it could happen. Ratiometric, exactly, thank you for that. And yes, will take multiple measurements and average it.

Next sensor is a stainless steel K type thermocouple for exhaust gas temperature measurement, capable of 0-1250C measurement.

For easy amplification of the thermocouple and interfacing it with SPI will use a MAX31855 board which takes 5V. Direct digital output temperature value, no amplifiers, no ADC 14-bit resolution, -200 to 1350C. Will try using Adafruit MAX31855.h as the library.

For this I plan not to use no other components.

Good choice.

Manufacturer’s page of the MAX31855: MAX31855 Cold-Junction Compensated Thermocouple-to-Digital Converter - Maxim Integrated.
With datasheet.

If you accidentally connect 12V to the thermocouple, expect the magic smoke to escape. There is not much you can do about that. The MAX31855 has protection against static voltage discharge, but it does not seem to protect against 12V.

Adafruit buys components from serious distributors.
This is the real thing: Thermocouple Amplifier MAX31855 breakout board (MAX6675 upgrade) : ID 269 : $14.95 : Adafruit Industries, Unique & fun DIY electronics and kits.
If you buy from Ebay/Amazon/AliExpress, then components can be counterfeit.

So far no problems.

What about the display and the 12V power ?
The display with its backlight might draw too much current and the 5V voltage regulator might get too hot.
I power my Arduino boards with 7.5V to the barrel jack or with 5V to the USB connector or with 5V directly to the 5V pin.
What else is there that needs some current ?
If you put your finger on the 5V voltage regulator on the Mega board, and you can not keep your finger on it, then it is too hot.

Powering the board with 5V to its 5V pin is recommended or not recommended, depending on who you ask :o

Yes aliexpress/baba and also ebay are notorious on being shoddy with quality. I try to pick ones that have reasonable amount of “five stars” and decent amount of orders, but yeah even that won’t ensure always that is works as they constantly switch providers and parts. However if it works, the components are so simple that it will probably work long time, and if it does not work, I’ll order new set.

Will add heatsink to MCU just in case, spray it with electronics lacquer, all connections soldered and probably will fill it with epoxy as well. If it breaks, simply replace it.

Display is an interesting part, 7" touch panel 800x480, 1000nits, STVA070WT-01, industrial advanced, powered directly from 12V converter and interfaced with plain TTL using simple “hex” commands. It is a RAD kind of equipment that gives you end results really fast due to their IDE where you can use JPG images + fonts + audio files to pre-program your display and then command it with any, even 8bit, MCU if you wish. I like this one a lot. Price 100eur fedexed from China to Finland in 7 days from order. This is surprisingly good looking product in every way, manuals, documentation and even the software to develop it is decent. Components feel great.

A few words about the background of this project. First build will be going to a boat with two big diesel engines, current consoles are 30+ years and not worth of investment any more money, they are not trustworthy either. I also got a guy who would like to get this to his car. So many old diesel engines out there with half broken consoles or not proper diagnostics like EGT or Turbo Boost gauges. In general people are paying big bucks just to find that specific gauge or sensor that also is probably 30+ years of old.

What is getting a heatsink and how would that help ?

I see that the display runs at 12V, so the Arduino does not have to power it.

We use Nextion displays, but the software to interface the Arduino to a Nextion display is not good. My Nextion display is running continuously for 4 years now. I dim the backlight according to the ambient light. I think it is half as bright now :(

Arduino is for fast prototyping and learning about electronics and programming. It is not for an industrial environment. There are more sturdy boards:

Thanks for tipping that Rugged MEGA, will do an inquiry of those in case more builds follow. I'll do the first prototype with ATMega, the temperature on the engine bay will be max 50C there for the Arduino part as it is big area and well ventilated, not getting water inside, I do not have to put it on top of engine but instead put it on quite safe place, I believe ATMega is more than rugged enough for this setup.

Heatsink wont hurt, I got plenty of them. I'd believe any IC circuit likes passive heating better than just not having one.

Displays do get more dimmer the more you use them, I believe all providers specify how fast they drop to e.g. 50% of original brightness. In this case (initial) 1000nits is a nice thing to have, if it drops to 500nits after some years, it is still OK as it is not used for navigation, you can have big gauges in it for decent usability.

So, engine bay MCU will have max 2 meter long wires to various sensors, I was thinking to wire with RJ45 STP (shielded) per each sensor but combine multiple wires together to have larger diameter, and then tape wires with heat resistant adhesive fabric tape. Have to check local shop for better shielded wire for the sensors, using RJ45 is a bit of a hack I guess, although I do have ample supply of STP back in my shop.

Then TTL to RS485 or probably this Arduino RS-485 board which is 5V to handle 7 meter communication wire to cockpit's MCU which will be either STM32 or Nano, have not yet decided which one I will use. (yes sorry, those RS485 boards are also from ali, if building more of these will order from better supplier).

On the cockpit another RS485 board and another MCU + STONE Display. Nothing in this setup is affecting the diesel engine's behaviour, instead it is handling the important matter of telling if temperatures and pressures are in proper order based on the load to the engine and other variants.

Really like that rugged Mega, will definitely use that on my next vehicle / industrial project. The good side on this project is that all sensors and MCUs are behind these voltage convertors that already handle stuff like what TVS diodes etc do, but the expense, even if rugged costs 100eur, it is OK for risk reasons.

Cheap Cat5 cable is used a lot for sensors. Shielded is better :smiley:
Some communication wires use the twisted-pair, others should not be close to each other.

If the distance is only 2 meters, then a lot can be done with basic TTL signals.
The RS-485 is for many decades the best choice. Using that for the 7 meters distance is very good.

The MKR Zero is a nice 3.3V board and it has a nice RS-485 shield.

The only trouble is still the 12V to the Mega board.
The voltage regulator is this poor little thing:

It makes 5V from 12V at maybe 100mA, so it dissipates 700 mW. The current depends on the sensors and leds and so.
A DC/DC-converter is often used when powering a Mega board with 12V.


Last crucial sensor topic is 12V sensors, RPM and temperature. These too get stable 12V from converter.

Using a voltage divider circuit where R2 = 10kΩ and R1 = 14 kΩ which makes Vout maximum of 5V.

RPM sensor

RPM is read from diesel fuel pump axle that has a sensor that produces 12V pulse every time the pump rotates based on hall effect. For this I am thinking of using MCU's digital pin with interrupts, sensing HIGH and then sensing LOW effectively calculating pulses per minute. This is very accurate way of calculating diesel engine RPM.

Temperature sensor

This I believe is an NTC thermistor, no datasheeta available but ambient vs boiling water tests produced T1 = 390Ω @ 25C and T2 = 25Ω @ 100C, then based on thermistor equation we get Bt1/t2 = 91.58 Note: Trying to follow article from Solarduino.


Is voltage divider itself enough to protect MCU in case either sensor malfunctions and gets e.g. short circuited?

Temperature sensor, it being 12V, but on Solarduino being 5V, I am a bit unsure how to handle voltage divider there, should I try doing it same way as with RPM sensor's voltage divider and use the same logic on programming side as with Solarduino?

Thank you!

The MCU runs on 5V, all the sensors run on 5V, why are you running the Mega board with 12V? It's puny 5V regulator can only supply about 150mA after dropping 12V to 5, 7V * 0.143A = 1 Watt, the regulator's rated maximum.

Yes, 12V would be stressing, will use external regulator or such to put it down to 7V so it is easier for ATMega. And will slap heatsink to ATMega regulator, it does not hurt and I got plenty of those.

Only part of the sensors are 5V, RPM and coolant sensors are 12V.

Why not drop the 12V to 5, the voltage the MCU is designed for, plug it into the 5V pin and forget about the near useless barrel jack and puny 5V regulator?

Voltage divider

When knowing the risks, and if calculated properly, then it is safe to use a voltage divider to measure 1kV or more. That is not the problem.
The ground might be a problem.
Can your RPM output drive a optocoupler ? Then you don’t have to connect the grounds.
Or does it already have a floating ground ?
Try to avoid that ground currents go through the Arduino board.

Background information:
It is allowed to push 1mA into a digital input. Via the internal ESD diodes it will flow to VCC.
Suppose you have 15k and 10k. When the input raises to 5.5V, then 1mA goes into the pin and 5.5V/10k to gnd. That means that it can measure 12V and is safe up to 28V (calculation). In real life a pulse of 10mA does not damage the ATmega chip, so a pulse of 280V is no problem.
For really high voltages, resistor R1 has to be divided into several resistors with enough spacing.

measure RPM speed

There are two well known frequency measure libraries. One for high frequencies that counts the pulses, and one for low frequencies that measures the time between the pulses.
This the low frequency one: FreqMeasure Library, for Measuring Frequencies in the 0.1 to 1000 Hz range, or RPM Tachometer Applications


NTCs of 390Ω (that is at 25°C) do exist, also NTCs with a beta of 4080 do exist. However, I can not find that combination.
How accurate are those 390Ω and 25Ω ?
Curve fitting requires at least three points. There are many online NTC calculators.
You can also add that protection resistor of 1k in front of the analog input.
You can power the NTC+resistor with 5V, or 1V, or whatever, as long as it is the same reference as the Arduino uses (same ratiometric principle). With a shielded cable, it does not matter how high or low the voltage is.
Suppose you want maximum accuracy from 25°C to 100°C, then you can choose the resistor somewhere in the middle. For example 100Ω.

I do have some optocouplers around.

By default, RPM and temperature sensors are grounded by the engine block. Other sensors I can isolate from engine block and connect ground to 12V converter or ATMega, if that helps.

Option 1) I'll let RPM and coolant temp ground to keep connecting to engine block, use voltage divider and connect through that to ATMega.

Option 2) I'll isolate RPM and coolant temp ground from engine block with specific tape, although I do not like this option as I have no idea how well this insulation really works in real life, probably well but still. Could also purchase new sensors that have a separate ground pin isolated from their chassis (motor block contact).

Option 3) Like option #1 but use optocouplers

Which one would be the best option?

Some background information: Diesel engines in general run max 4500rpm (idle, WOT), and fuel pump rotating half of that amount, so optocoupler can keep the pace up, they are not the fastest but here it does not matter.

In a boat environment, it is common to have common ground to the engine block. Just like with diesel engine powered car. Some feel it is bad practice with boats as it may cause extra corrosion, but zinc / aluminum anodes take that problem away anyways so..

Why not drop the 12V to 5, the voltage the MCU is designed for, plug it into the 5V pin and forget about the near useless barrel jack and puny 5V regulator?

I hear you, I guess I am trying to play it safe by having a tiny bit of extra voltage always around and letting MCU to regulate itself the perfect 5V, ensuring that the voltage is always at least 5V for the MCU and my 5V sensors. Then again, in real life, driving 7V or 5V should not matter as the reference can be the same always. Regarding the 12V → 5V regulator issue, that is stressing a lot ATMega, will make it easier for that little regulator by at least using 7V input.

The NTC has some kind of metal housing ? And that is attached to the metal of the engine ?
But is one of the two wires also connected to that metal housing ?
If there are multiple ways that a ground current can go, or if current from other things can go through the ground-wire of a sensor, then you should make a good plan.

It is very common practice that automotive & marine sensors are grounded to the engine block. Yes metal housing on many sensors with diesel engines.

In this case too at least the temperature sensor is grounded to the engine block as the sensor has only 1 wire.

Option 1) Therefore, if I connect this sensor’s signal wire to MCU and nothing more, I wonder how safe that would be as MCU’s ground would be in connection with 12V converter whereas temperature signal’s ground is in connection with boat’s common ground (engine block).

Option 2) Or should I leave temperature sensor as it is, give it dirty 12V and let it be grounded to engine block, then have an optocoupler reading that 12V level and through that optocoupler give info back to MCU together with reading multiple values per second, dropping min max and averaging it.

RPM sensor is probably same, although that does have 2 wires, it is based on hall effect sensing that metal going in revolutions. This would produce around 2000-2500 pulses per second.

I wonder if using zener, resistors etc perhaps like the circuit in here would be good to try.

A zener diode for low voltages has a very high leakage current. That can not be used for an analog signal.

As I wrote before, measuring 1kV is no problem. The ground is the problem.
I understand what you say about engines and the engine block. From a “sensor” approach, the ground wire of a sensor should be clean and is just as important as the signal wire.
I suppose that when the engine was build, no one thought about ground loops that could act an antenna for a smartphone signal and that a processor would read the signal :wink:

The 5V is okay for the NTC. Going to 12V and then back to Arduino level creates only more ways to go wrong. You need to draw a good plan for the ground.

Grounding is a craftsmanship on its own.
Is this a good start: ?

I don’t know what is the best way for grounding in that situation. Others might have trouble finding their way around with the new forum. You could start a new topic after one or two weeks, called: “How to connect a single ended NTC from an old diesel engine ?” or something like that. In your post, you can give a link to this topic.

At school some have learned to use a OpAmp (or instrumentation amplifier) in that situation, to subtract the ground signal. But I don’t want to go there.

Haha, yea, these old diesel engines were installed 1960-1990 and having a delicate electronics was not something the designers had to worry about.

Just came back from the boat and with this engine, I noticed that RPM sensor which has two pins, none of them is not connected to the engine block.

So, I think I’ll simply purchase new temperature sensors with 2 pins, these are isolated from the engine block. Original sensors tens of years back were this way as well, but nowadays many marine providers try to sell you compatible 1 pin sensors having grounding to engine block.

This way all my sensors and MCU are acting only after this 12V converter.

Does this sound better?

Yes :partying_face:
If possible, use 5V for the sensors. I even prefer to use separate ground wires for each sensor.
For example for the temperature: resistor at Arduino, signal + GND into twisted pair. At the end only the NTC and don’t connect that GND to anything else.

The DS18B20 is often used. Install the DallasTemperature library and it works. It has an absolute accuracy of ±0.5°C. It can be used for the room temperature, for a sous vide, for the heating pipes of a heating system, and so on. You could add it as extra to be sure what the temperature is. For example: outside, room, pipes, engine.
Don’t buy the cheap waterproof DS18B20 sensors, they are only waterproof for a day.