I recently got an Arduino Uno Wifi (flashed it with WiFi link library - GitHub - arduino/UnoWiFi-FirmwareUpdater-Plugin: Arduino Uno WiFi Firmware Updater Tool for Arduino IDE) and i have created a simple code to read analog values from a Flex Sensor.
I am using the code below (copy paste from the official website)
const int FLEX_PIN = A4; // Pin connected to voltage divider output
// Measure the voltage at 5V and the actual resistance of your
// 47k resistor, and enter them below:
const float VCC = 4.98; // Measured voltage of Ardunio 5V line
const float R_DIV = 47500.0; // Measured resistance of 3.3k resistor
// Upload the code, then try to adjust these values to more
// accurately calculate bend degree.
const float STRAIGHT_RESISTANCE = 37300.0; // resistance when straight
const float BEND_RESISTANCE = 90000.0; // resistance at 90 deg
void setup()
{
Serial.begin(9600);
pinMode(FLEX_PIN, INPUT);
}
void loop()
{
// Read the ADC, and calculate voltage and resistance from it
int flexADC = analogRead(FLEX_PIN);
float flexV = flexADC * VCC / 1023.0;
float flexR = R_DIV * (VCC / flexV - 1.0);
Serial.println("Resistance: " + String(flexR) + " ohms");
// Use the calculated resistance to estimate the sensor's
// bend angle:
float angle = map(flexR, STRAIGHT_RESISTANCE, BEND_RESISTANCE,
0, 90.0);
Serial.println("Bend: " + String(angle) + " degrees");
Serial.println();
delay(500);
}
The code does not work in the Arduino Uno Wifi as it does not show any change in the bend degrees. However, it works in another Arduino Uno i have for testing.
Also i made a test and i found out that pins 4 and 5 in Arduino Uno Wifi produce current for some reason even with an empty script, capable of lighting a LED (while pins 0,1,2,3 do not light it up).
The same applies for the values for the sensors. For example if i put the flex sensor in analog pin 0 then the values change when i bend it (e.g. 362 read not bend and 600 bend which is fine).
On the other hand when i put the pin of the sensor in A4 or A5 there is a change from 1023 (starting value) to 982 and it wont change no matter if i bend the sensor.
Also posted in Read analog input from Arduino Uno Wifi Wire/TWI/I2C pins (A4 & A5) - Stack Overflow