Hi guys, i am working on a project which involves the usage of 5 analog input pins in arduino. For this project i am using flex sensors. I started with a basic code to get analog inputs and print in in the serial monitor.
void setup() {
Serial.begin(9600);
}
void loop() {
int sensorValue = analogRead(A0);
Serial.print("A0 Reading: ");
Serial.println(sensorValue);
delay(100);
}
When i upload this code, even when not connected any sensors to the pins,
random values are being returned. But when i connect any sensor to the pin, it
starts returning only 0. I tried with all analog input pins and also changing the
names "A0" to simply "0". Still no results. I thought there was some issue with the board, so i changed the board itself but the issue has not been resolved. I have
checked the circuit connections over 100 times. but there seems to be no issues
with the circuit connection. for this case, i am providing a voltage divider circuit
for the flex sensor with one pin connected to 3.3v and other one connected to a
resistor and then to pin A0. the other end of the resistor is connected to gnd.
There is no issues with the wiring tightness and circuit correctness. I even tried using this in my code.
pinMode(A0, INPUT);
So, why does this issue occurs and how to resolve this?
Please help me
"Floating" pins produce random values. It is a fact of life and due to stray electromagnetic effects.
1 Like
Thank you. but that answers why it returns random values when not connected. for the other part, what could be the reason?
when connected any sensor to the analog pins, only the value 0 is being returned. no other value is being returned
More information is required. Post a link to the sensor data sheet or product page, and a wiring diagram, with all pins, parts and connections clearly labeled. Pencil and paper is best.
With the voltage dvider circuit, are you getting expected value? Which Arduino are you using?
The above image consists of the circuit diagram
the above link consists of the details about the flex sensor.
Code:
void setup() {
Serial.begin(9600);
}
void loop() {
int sensorValue = analogRead(A0);
Serial.print("A0 Reading: ");
Serial.println(sensorValue);
delay(100);
}
nope, even with the voltage divider circuit, i am getting only 0s, and i am using arduino UNO
Please, post the picture of your voltage divider setup with UNO.
You probably have a bad connection. Use your multimeter to check wiring continuity, the voltages at various points in the circuit and to check the resistance values of the sensor and divider resistor.
Not this one. Use the camera of your mobile, take a photo and post here.
i currently don't have my board now. i will upload it tomorrow. And i am using a custom sensor, like i built my own flex sensor. i checked it with a multi-meter and it works pretty well.
That means that you are doing simulation.
Tried that too, connections don't have any problem.
Check the resistances and voltages (especially from A0 to GND) and report their values.
1 Like
not really. i changed my board 3 days ago, bought another uno. i left it at college , so i will be having the board with me tomorrow at college