Introduction: Arduino Lesser Known Features
This is more a listing of not so often mentioned features of Arduino platforms typically used (e.g. Uno, Nano). This listing should act as a reference whenever you need to look up those features and to spread the word.
Look at the code in order to see examples for all of those feature as I used them in several of mine projects here on instructable (e.g. Arduino 1-wire Display (144 Chars)). The steps following explain one feature each.
Attachments
Step 1: Supply Voltage
The Arduino can measure it's own supply voltage in an indirect way. By measuring the internal reference with the supply voltage as upper bound reference you can get the ratio between internal reference and supply voltage (the supply voltage acting as upper bound for the analog/ADC reading). As you know the exact value of the internal voltage reference you can then calculate the supply voltage.
For exact details on how to do this including example code see:
Secret Arduino Voltmeter – Measure Battery Voltage: https://provideyourown.com/2012/secret-arduino-vol...
Can Arduino measure its own Vin?: http://forum.arduino.cc/index.php?topic=15629.0
Step 2: Internal Temperature
Some Arduino are equipped with an internal temperature sensor and can therefore measure their internal (semicoductor) temperature.
For exact details on how to do this including example code see:
- Internal Temperature Sensor: https://playground.arduino.cc/Main/InternalTemper...
- Can Arduino measure its own Vin?: http://forum.arduino.cc/index.php?topic=15629.0
Step 3: Analog Comparator (Interrupt)
Arduino can setup an analog comparator between pin A0 and A1. So one gives the voltage level and the other one is checked for a crossing of this voltage. An interrupt gets raised depending on whether the crossing is a rising or falling edge (or both). The interrupt can then be catched by software and acted accordingly.
For exact details on how to do this including example code see:
- Analog Comparator Interrupt: http://forum.arduino.cc/index.php?topic=149840.0
Step 4: Counter
Of course the AVR have several counter included. Usually they are used to setup timer of various frequencies and raise interrupts on need. Another may be very old-fashioned use is to use them just as counters without any additional magic, just read the value when you need it (poll). A intressting use of this could be to de-bounce buttons e.g. Confer for example this post: AVR Example T1 counter
Step 5: Predefined Constants
There are some predefined variables that can be used to add version and compilation info to your project.
For exact details on how to do this including example code see:
Serial.println(__DATE__); // compilation date
Serial.println(__TIME__); // compilation time
String stringOne = String(ARDUINO, DEC);
Serial.println(stringOne); // arduino ide version
Serial.println(__VERSION__); // gcc version
Serial.println(__FILE__); // file compiled
these code snipplets will output those data to serial console.
Step 6: Retain Variable in RAM Through Reset
It well known that Arduino Uno (ATmega328) have internal EEPROM that allows you to preserve values and settings during power-off and restore them at the next power-up. A not so well known fact might be that it is actually possible to preserve value during reset even in RAM - however the values get lost during power cycle - with the syntax:
unsigned long variable_that_is_preserved __attribute__ ((section (".noinit")));
This allows you for example to count the number of RESETs and by using EEPROM also the number of power-ups.
For exact details on how to do this including example code see:
- Retain Variable in Ram through Reset: https://forum.arduino.cc/index.php?topic=232362.0
EEPROM Library: https://www.arduino.cc/en/Reference/EEPROM
Step 7: Access the Clock Signal
Arduinos and other AVR (like ATtiny) have an internal clock allowing you to run them without using an external crystal oscillator. Furthermore at the same time they are also able to connect this signal to outside by putting it on a pin (e.g. PB4). The tricky part here is that you need to change the chips fuse bits in order to enable that feature and changing fuse bits allways bears the risk of bricking the chip.
You have to enable the CKOUT fuse and easiest way to do this is by following the instructable on How to Change Fuse Bits of AVR Atmega328p - 8bit Microcontroller Using Arduino.
For exact details on how to do this including example code see:
Tuning ATtiny internal oscillator: http://becomingmaker.com/tuning-attiny-oscillator...
- How to Change Fuse Bits of AVR Atmega328p - 8bit Microcontroller Using Arduino: https://www.instructables.com/id/How-to-change-fu...
Step 8: Port Internal Structure of ATmega328P
Knowing the ports internal structure of ATmega328P allows us to go beyond the standard usage limits. Confer the section about Capacitance Meter for Range 20 pF to 1000 nF for more details and a schematic of the internal circuit.
The simple example is to use buttons with digital ports not needing any resistor due to the use of internal pull-up resistor as shown by the Input Pullup Serial Example or the instructable Arduino Button With No Resistor.
More advanced is the use of this knowledge as mentioned for measuring capactors as small as 20 pF and furthermore without any additional wiring! In order to achive that performance, the example makes use of the internal/input impedance, the internal pull-up resistor and the stray capacitor. Compare to the Arduino CapacitanceMeter Tutorial which cannot go lower than a few nF.
Step 9: On-Board (builtin) LED As Photodetector
A lot of Arduino boards have on-board or builtin LEDs that can be controlled from code, e.g. the Uno or Nano boards on pin 13. By adding one single wire from this pin to an analog input pin (e.g. A0) we can also use this LED as photodetector. This can be used in a varity of different ways like; use to measure the environmental illumination, use LED as button, use LED for bidrectional communication (PJON AnalogSampling), etc.