FSR driven Stepper Motor and recording sensors data in SD card

Dear Experts,

Greetings to all… :slight_smile:

This is my first post in Arduino forum, so please excuse me (as well guide me) if I am making any mistake while posting my questions.

By profession I am a researcher in Medical field, so I have very little knowledge about Electronics and very basic knowledge of programming.(just learning along with Arduino)

The details about my project is as below

My project :

As my subjects describes I am doing very basic project in which I have Stepper Motor which is controlled by FSR. This is pretty easy task, so to execute the same I went to some of the knowledgeable post posted by lot of experts in this forum and also referred Arudino example code posted by Tom Igoe and jump started on my project. It went very well and smooth …in just 2 days I created the circuit and its working perfectly.

But problem is started when I introduce SD card code, as now I wanted to save FSR force readings (all data like FSR conductance, resistance, Force in newtons etc) as well I wanted to save Stepper Motor readings like Motor Speed, RPM etc in csv file.

The problem is when I execute the code, it works pretty well with saving data i.e.

  • It checks whether SD card is present or not
  • It checks whether File is got created / present or not
  • It also records all FSR readings
    BUT then it fails in
  • Starting Stepper Motor, stepper motor just gives humming sound but fails to rotate.

After doing lot of investigation also I failed to understand what could be the possible cause behind. The part which I never understood is that when I comment the SD card and file recording code then Stepper starts but as soon as I start with SD card and file recording It fails to rotate and gives humming sound.

So I request you all can you please help me to understand where I am making mistake.

The hardware which I am using is as below

  • Arduino - Generic Uno R3 ATmega328P
  • Quad Store Ethernet W5100 Shield Network Expansion Board with Micro SD Card Slot for Arduino
  • Force Sensor 12.7 mm Circle
  • xcluma 28Ybj-48 Dc 5V 4 Phase 5 Wire Stepper Motor With Uln2003 Driver Board
  • Lots of jumper wires
  • SD card Toshiba

The below is (the) most basic code -

/*
 cStepper Motor Control - speed control
 
 */

#include <Stepper.h>
#include <SPI.h>
#include <SD.h>

const int stepsPerRevolution = 200;  // change this to fit the number of steps per revolution
// for your motor


// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);

int stepCount = 0;  // number of steps the motor has taken
int buzzer = 5;
const int chipSelect = 4;

void setup() {
  // nothing to do inside the setup
  Serial.begin(9600);

  pinMode(5, OUTPUT);   
  pinMode(6, OUTPUT); 
  pinMode(7, OUTPUT);
  myStepper.setSpeed(60); // RPM
  Serial.println("Starting Initiation Process");
  
  tone(buzzer,100,1000);
  myStepper.step(200);
  tone(buzzer,200,1000);  
  Serial.println("Initiation process finished");

  sdCard();

}

void sdCard()
{
  Serial.print(F("Initializing SD card..."));
  
  while (!Serial) 
  {
    ; // wait for serial port to connect. Needed for native USB port only
  }
  // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) {
    Serial.println(F("Card failed, or not present"));
    // don't do anything more:
    while (1);
  }
  Serial.println(F("card initialized."));
     
}

void motorRoller()
{
int rpm ;
int sensorReading = analogRead(A0);
int motorSpeed = map(sensorReading, 0, 1023, 0, 100);
if (sensorReading < 0){

    int sensorReading = analogRead(A0);
    Serial.print("Sensor Reading : ");
    Serial.println(sensorReading);
    Serial.println(" - No pressure");
            
  }else if(sensorReading < 100){
   //int motorSpeed = map(sensorReading, 0, 1023, 0, 100);
   if (motorSpeed > 0){
    myStepper.setSpeed(motorSpeed);
    rpm = stepsPerRevolution * 1;
    // step 1/100 of a revolution:
    //myStepper.step(stepsPerRevolution / 100);
    myStepper.step(rpm);
    
   }
  }else if(sensorReading < 200){

    //int motorSpeed = map(sensorReading, 0, 1023, 0, 100);
   if (motorSpeed > 0){
    myStepper.setSpeed(motorSpeed);
    rpm = stepsPerRevolution * 1.5;
    myStepper.step(rpm);
    digitalWrite(7, HIGH);
    delay(20);
    digitalWrite(7, LOW);

   }
   
  }else if(sensorReading < 500){
     
   int motorSpeed = map(sensorReading, 0, 1023, 0, 100);
   int sensorReading = analogRead(A0);
   if (motorSpeed > 0){
    myStepper.setSpeed(motorSpeed);
    rpm = stepsPerRevolution *2;
    // step 1/100 of a revolution:
    //myStepper.step(stepsPerRevolution / 100);
    myStepper.step(rpm);
    digitalWrite(6, HIGH);
    delay(20);
    digitalWrite(6, LOW);
  
   }
   
  }else if(sensorReading < 800){
 
   
   int motorSpeed = map(sensorReading, 0, 1023, 0, 100);
   if (motorSpeed > 0){
    myStepper.setSpeed(motorSpeed);
    rpm = stepsPerRevolution * 2.5;
    myStepper.step(rpm);
    digitalWrite(5, HIGH);
    delay(20);
    digitalWrite(5, LOW);
    
   }
   
  }else if(sensorReading < 900){
    
   int motorSpeed = map(sensorReading, 0, 1023, 0, 100);
   if (motorSpeed > 0){
    myStepper.setSpeed(motorSpeed);
    rpm = stepsPerRevolution * 3;
    myStepper.step(rpm);
    digitalWrite(6, HIGH);
    delay(20);
    digitalWrite(6, LOW);
   }
   
  }else if(sensorReading < 1000){

   
   int motorSpeed = map(sensorReading, 0, 1023, 0, 100);
   if (motorSpeed > 0){
    myStepper.setSpeed(motorSpeed);
    rpm = stepsPerRevolution *3.5;
    myStepper.step(rpm);
    digitalWrite(7, HIGH);
    delay(20);
    digitalWrite(7, LOW);

    }
   
  }
  else{
    Serial.println("Nothing works - check the code");
  }
  delay(100);
}
void fileCapture()
{
  File myFile;
  myFile = SD.open("logger5.txt", FILE_WRITE);
  int sensorReading = analogRead(A0);
  int rpm;
  
  int motorSpeed = map(sensorReading, 0, 1023, 0, 100);
  // if the file is available, write to it:
  if (myFile) {
   // String dataString = "";
  // read the sensor value:
    int sensorReading = analogRead(A0);
      
  if (sensorReading < 0){

   myFile.print("MP");
   myFile.print(",");
   myFile.print(String(sensorReading));
   myFile.println('\n');
   
          
  }
  else if(sensorReading < 100){

    myFile.print("A");
    myFile.print(",");
    myFile.print(String(sensorReading));
    myFile.println('\n');
    
   }
  else if(sensorReading < 200){

    myFile.print("B");
    myFile.print(",");
    myFile.print(String(sensorReading));
    myFile.println('\n');
 
   }else if(sensorReading <= 500){

    
    myFile.print("C");
    myFile.print(",");
    myFile.print(String(sensorReading));
    myFile.println('\n');

   } else if(sensorReading <= 800){
    
    myFile.print("D");
    myFile.print(",");
    myFile.print(String(sensorReading));
    myFile.println('\n');

   
   
  }else if(sensorReading < 900){
    
    myFile.print("E");
    myFile.print(",");
    myFile.print(String(sensorReading));
    myFile.println('\n');
   
   
  }else if(sensorReading < 1000){
    myFile.print("F");
    myFile.print(",");
    myFile.print(String(sensorReading));
    myFile.println('\n');
   
   
  }
  else{
    Serial.println("All nonsense");
  }
  delay(100);
  
}else {
    Serial.println(F("error opening file"));
  }
myFile.close();
}

int rpm;

void loop() {
motorRoller();
fileCapture();
   
}

Move your stepper motor to different I/O pins. Pins 11,12 and 13 are used by SPI and pin 10 is probably also used as part of the SPI process by the SD Card library.

…R

Bravo…!!!

Its working as expected …

Thanks so much for helping in my initial project …

But I do have one more question in respect of Arduino which is

  • How Arduino track that all sensors (mostly analogue sensor like FSR, Temperature sensor etc.) for which we coded in program are connected or not? and if they are not connected then does arduino send some reading which we can capture in our program?

Thanks in advance …

The only way to know if a sensor is connected is by analysing the data from it.

What value would you get if there was nothing connected, and could that value legitimately arise when it is connected? Unfortunately I suspect that there may not be a value that unequivocally tells you the sensor is disconnected.

Do some tests and see what values you get.

The other thing to consider is whether the risk of sensor not being connected is big enough to be worth worrying about. In what circumstances might a sensor be disconnected by accident?

...R

Its so weird, I tried lots of combinations till now … but its not showing one perfect reading, that is

  • Initially I disconnected the FSR (i.e. physically removed FSR from circuit) and I tried capturing its reading, it was showing 0. I tried this test case at least 30 minutes but reading was the same.
    So my test case was I removed the FSR and then recording the reading at times it was -1 but then next time when i again executed the code as fresh that is by taking off connection of Arduino from computer and again connnecting back to computer (as if we are switching ON and OFF) it was back to 0.

I tested this at least 15 more times, but only 2 times I recorded -1 and rest all times it was 0

  • Then I tried removing the power input only for FSR, and repeated all steps above mentioned and here also it shown the same result as above, that is mostly it was 0, but at times 5, 23 etc and -1 came only 3 times

So it is really difficult to capture. Please look into my code and guide me, this code also i found from Arduino examples…

void sensorCheck(){
    fsrAnalogPin = analogRead(A0);
    // if the file is available, write to it:
    int fsrVoltage = 0;
    int fsrReading = 0;
    int fsrResistance = 0;
    
    fsrReading = analogRead(fsrAnalogPin);
    //LEDbrightness = map(fsrReading, 0, 1023, 0, 255);
    fsrVoltage = map(fsrReading, 0, 1023, 0, 5000);
    fsrResistance = 5000 - fsrVoltage;     // fsrVoltage is in millivolts so 5V = 5000mV
    fsrResistance *= 10000;                // 10K resistor
    fsrResistance /= fsrVoltage;
    Serial.print("FSR resistance in ohms = ");
    Serial.println(fsrResistance);

  if ( fsrResistance < 0 )
  {
    Serial.println("Sensor is not connected");
    while (1);
  
   }
  else{
    
    Serial.println("Sensor is connected");
    } 
}

Little about my project

Actually I am trying to make one medical Device prototype (under patent technology), the actual device will go inside human body for capturing some data and this device includes FSR sensor so while inserting this device inside human body if it gets disconnected then user should be able to get that reading from this device to avoid wrong readings. This is the main reason behind.

Please guide me …
Thanks in advance …

fsrAnalogPin = analogRead(A0);
fsrReading = analogRead(fsrAnalogPin);

This is wrong. I think you want

fsrAnalogPin = A0;
fsrReading = analogRead(fsrAnalogPin);

veliotprojects:
I tested this at least 15 more times, but only 2 times I recorded -1 and rest all times it was 0

  • Then I tried removing the power input only for FSR, and repeated all steps above mentioned and here also it shown the same result as above, that is mostly it was 0, but at times 5, 23 etc and -1 came only 3 times

So it is really difficult to capture.

Won’t <= 0 capture both cases?

…R

No its not working ....

After applying the changes which you both suggested ...I am getting initially - negative reading even if the Sensor is connected to the circuit ...I think I am doing some mistakes in my circuit... i need to revisit my entire circuit.

Just in curiosity I would like to ask one question here that when we compile our code and after Arduino compiles the code we get to see compilation message from Arduino, which is something similar to below

Sketch uses 16644 bytes (51%) of program storage space. Maximum is 32256 bytes.
Global variables use 1528 bytes (74%) of dynamic memory, leaving 520 bytes for local variables. Maximum is 2048 bytes.

I observed that when I write some big messages to get stored in File then the Program Storage Space gets increases as well Dynamic Memory also get increases, and it displays the warning / error message of Low Space and failed to compile the code even it fails to upload the code too...
So ..

  1. Can I increase this Storage space as well as Dynamic memory space and if yes then
  2. In which setting shall I go and change it?

AND

If Arduino does not allow to do this settings then how do I write code which have lots of sensors, LED's, Buzzers and some complex business logic but then it should also occupy very limited storage and dynamic space ?

Sir, basically I am not a programmer so I really don't know Program Guidelines etc...

So can you please guide with this by sending some referrals links for beginners like me for writing best Arduino code...

veliotprojects:
No its not working …

After applying the changes which you both suggested …

You need to post the complete latest version of your program so we can see exactly what changes you made.

And “it’s not working” does not give us any useful info with which to help you. Post an example of the output from the program and tell us what it ought to be if the program was working correctly.

…R

I observed that when I write some big messages to get stored in File then the Program Storage Space gets increases as well Dynamic Memory also get increases, and it displays the warning / error message of Low Space and failed to compile the code even it fails to upload the code too...

You will need to be more specific about these "big messages" and how they are handled.

The most simple hardware solution is to use a MEGA instead of a UNO as there is 8x the Flash and 4x the SRAM. https://www.arduino.cc/en/tutorial/memory

First, I would recommend that you use SdFat.h instead of SD.h. A lot of work has gone into optimizing it for memory usage.

You may also have the option of using an older sd card with Fat16 which can also save memory.

Sir, basically I am not a programmer

Yes, you are a medical researcher and you appear to have a very complex medical application with multiple issues, and your current programming/hardware skills may not be up to this project. Are you working in a team? Do you have programming assistance other than this forum? Are you a student?

Absolutely Correct Sir,…I need to show it to you before I am coming at any conclusion

The below is my entire code which now I change according to you suggested

/*
 
*/

#include <Stepper.h>
#include <SPI.h>
#include <SD.h>


int fsrAnalogPin = 0; // FSR is connected to analog 0
const int stepsPerRevolution = 200;  // change this to fit the number of steps per revolution
// for your motor

// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 6, 7, 8, 9);

int stepCount = 0;  // number of steps the motor has taken
int buzzer = 5;
const int chipSelect = 4;
void setup() {
  // nothing to do inside the setup
  Serial.begin(9600);

  pinMode(5, OUTPUT);   
  pinMode(3, OUTPUT); 
  pinMode(2, OUTPUT);
  myStepper.setSpeed(60); // RPM
  Serial.println("Starting Initiation Process");
  myRGBlight();
  tone(buzzer,100,1000);
  myStepper.step(200);
  tone(buzzer,200,1000);  
  Serial.println("Initiation process finished");

  sdCard();
  sensorCheck();
}

void sdCard()
{
  Serial.print(F("Initializing SD card..."));
  
  while (!Serial) 
  {
    ; // wait for serial port to connect. Needed for native USB port only
  }
  // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) {
    Serial.println(F("Card failed, or not present"));
    // don't do anything more:
    while (1);
  }
  Serial.println(F("card initialized."));
     
}

void myRGBlight(){
  digitalWrite(2, LOW);  
  digitalWrite(3, LOW); 
  digitalWrite(5, HIGH);  // set the LED on
  delay(500);              // wait for a second
  digitalWrite(2, LOW); 
 digitalWrite(3, LOW);
 digitalWrite(5, LOW); // set the LED off
  delay(500);              // wait for a second
  digitalWrite(2, LOW);  
  digitalWrite(3, HIGH); 
  digitalWrite(5, LOW);  // set the LED on
  delay(500);              // wait for a second
  digitalWrite(2, LOW); 
 digitalWrite(3, LOW);
 digitalWrite(5, LOW); // set the LED off
  delay(500);              // wait for a second
  digitalWrite(2, HIGH);  
  digitalWrite(3, LOW); 
  digitalWrite(5, LOW);  // set the LED on
  delay(500);              // wait for a second
  digitalWrite(2, LOW); 
 digitalWrite(3, LOW);
 digitalWrite(5, LOW); // set the LED off
  delay(500);
}

void motorRoller(){

int rpm ;
int sensorReading = analogRead(A0);
int motorSpeed = map(sensorReading, 0, 1023, 0, 100);


if (sensorReading < 0){

    int sensorReading = analogRead(A0);
    Serial.print("Sensor Reading : ");
    Serial.println(sensorReading);
    Serial.println(" - No pressure");
            
  }else if(sensorReading < 100){
   //int motorSpeed = map(sensorReading, 0, 1023, 0, 100);
   if (motorSpeed > 0){
    myStepper.setSpeed(motorSpeed);
    Serial.print("Motor Speed  when Sensor reading < 100: ");
    Serial.println(motorSpeed);
    rpm = stepsPerRevolution /50;
    // step 1/100 of a revolution:
    //myStepper.step(stepsPerRevolution / 100);
    myStepper.step(rpm);
    Serial.print("RPM when sensor sensed < 100 : ");
    Serial.println(rpm);
   }
  }else if(sensorReading < 200){

    //int motorSpeed = map(sensorReading, 0, 1023, 0, 100);
   if (motorSpeed > 0){
    myStepper.setSpeed(motorSpeed);
    Serial.print("Motor Speed  when Aensor reading < 200: ");
    Serial.println(motorSpeed);
    rpm = stepsPerRevolution /25 ;
    // step 1/100 of a revolution:
    //myStepper.step(stepsPerRevolution / 100);
    myStepper.step(rpm);
    Serial.print("RPM when sensor sensed < 200 : ");
   
    Serial.println(rpm);
    digitalWrite(5, HIGH);
    delay(20);
    digitalWrite(5, LOW);

   }
   
  }else if(sensorReading < 500){
     
   int motorSpeed = map(sensorReading, 0, 1023, 0, 100);
   int sensorReading = analogRead(A0);
   if (motorSpeed > 0){
    myStepper.setSpeed(motorSpeed);
    Serial.print("Motor Speed  when Sensor reading < 500: ");
    Serial.println(motorSpeed);
    rpm = stepsPerRevolution / 10;
    // step 1/100 of a revolution:
    //myStepper.step(stepsPerRevolution / 100);
    myStepper.step(rpm);
    Serial.print("RPM when sensor sensed < 500 : ");
    
    Serial.println(rpm);
    digitalWrite(3, HIGH);
    delay(20);
    digitalWrite(3, LOW);
  
   }
   
  }else if(sensorReading < 800){
 
   
   int motorSpeed = map(sensorReading, 0, 1023, 0, 100);
   if (motorSpeed > 0){
    myStepper.setSpeed(motorSpeed);
    Serial.print("Motor Speed  when Sensor reading < 800: ");
    Serial.println(motorSpeed);
    rpm = stepsPerRevolution / 5;
    // step 1/100 of a revolution:
    //myStepper.step(stepsPerRevolution / 100);
    myStepper.step(rpm);
    
    Serial.print("RPM when sensor sensed  < 800: ");
    Serial.println(rpm);
    digitalWrite(2, HIGH);
    delay(20);
    digitalWrite(2, LOW);
    
   }
   
  }else if(sensorReading < 900){
    
   int motorSpeed = map(sensorReading, 0, 1023, 0, 100);
   if (motorSpeed > 0){
    myStepper.setSpeed(motorSpeed);
    Serial.print("Motor Speed  when Sensor reading < 900: ");
    Serial.println(motorSpeed);
    rpm = stepsPerRevolution / 3;
    // step 1/100 of a revolution:
    //myStepper.step(stepsPerRevolution / 100);
    myStepper.step(rpm);
    Serial.print("RPM when sensor sensed < 900 : ");
    Serial.println(rpm);
    
    digitalWrite(3, HIGH);
    delay(20);
    digitalWrite(3, LOW);

    
   }
   
  }else if(sensorReading < 1000){

   
   int motorSpeed = map(sensorReading, 0, 1023, 0, 100);
   if (motorSpeed > 0){
    myStepper.setSpeed(motorSpeed);
    Serial.print("Motor Speed  when Sensor reading < 1000: ");
    Serial.println(motorSpeed);
    rpm = stepsPerRevolution /2;
    // step 1/100 of a revolution:
    //myStepper.step(stepsPerRevolution / 100);
    myStepper.step(rpm);
    Serial.print("RPM when sensor sensed < 1000  : ");
    Serial.println(rpm);
    
    digitalWrite(5, HIGH);
    delay(20);
    digitalWrite(5, LOW);

    }
   
  }
  else{
    Serial.println("All nonsense");
  }
  delay(100);
 
}

void sensorCheck(){

    fsrAnalogPin = A0;
  
  // if the file is available, write to it:
    int fsrVoltage = 0;
    int fsrReading = 0;
    int fsrResistance = 0;
    
    fsrReading = analogRead(fsrAnalogPin);
    //LEDbrightness = map(fsrReading, 0, 1023, 0, 255);
    fsrVoltage = map(fsrReading, 0, 1023, 0, 5000);
    fsrResistance = 5000 - fsrVoltage;     // fsrVoltage is in millivolts so 5V = 5000mV
    fsrResistance *= 10000;                // 10K resistor
    fsrResistance /= fsrVoltage;
    Serial.print("FSR resistance in ohms = ");
    Serial.println(fsrResistance);

  if ( fsrResistance <= 0 )
  {
    Serial.println("Sensor is not connected");
    while (1);
  
   }
  else{
    
    Serial.println("Sensor is connected");
    } 
}


void fileCapture()
{
  File myFile;
  myFile = SD.open("logger10.txt", FILE_WRITE);
  int sensorReading = analogRead(A0);
  int rpm;
  int motorSpeed = map(sensorReading, 0, 1023, 0, 100);  
  if (myFile) {
   // String dataString = "";
  // read the sensor value:
    int sensorReading = analogRead(A0);
    Serial.print("Sensor Reading : ");
    Serial.println(sensorReading);
    Serial.println(" - No pressure");
    
  if (sensorReading < 0){

   myFile.print("Healthy Vagina");
   myFile.print(",");
   myFile.print(String(sensorReading));
   myFile.println('\n');
   
          
  }
  else if(sensorReading > 10 && sensorReading < 100){

    myFile.print("A");
    myFile.print(",");
    myFile.print(String(sensorReading));
    myFile.println('\n');
    
   }
  else if(sensorReading <= 200){

    myFile.print("B");
    myFile.print(",");
    myFile.print(String(sensorReading));
    myFile.println('\n');
 
   }else if(sensorReading <= 500){

    
    myFile.print("C");
    myFile.print(",");
    myFile.print(String(sensorReading));
    myFile.println('\n');
   } else if(sensorReading <= 800){
    
    myFile.print("D");
    myFile.print(",");
    myFile.print(String(sensorReading));
    myFile.println('\n');

   
   
  }else if(sensorReading < 900){
    
    myFile.print("E");
    myFile.print(",");
    myFile.print(String(sensorReading));
    myFile.println('\n');
   
   
  }else if(sensorReading < 1000){
    myFile.print("F");
    myFile.print(",");
    myFile.print(String(sensorReading));
    myFile.println('\n');
   
   
  }
  else{
    Serial.println("All nonsense");
  }
  delay(100);
  
}else {
    Serial.println(F("error opening file"));
  }

myFile.close();
}
int rpm;

void loop() {

   
delay(100);

sensorCheck();
motorRoller();
fileCapture();

}

As well have a look at serial monitor output

I created a function sensorCheck(), in my code which I am executing in setup() and in loop too…why am executing the same function in loop because I want to make sure that while treatment the sensor should be connected and due to some accident if it gets disconnected then it should send signals accordingly…
The below is the ouput of sensorCheck() after execution

when sensorCheck() is in setup()

Condition 1
Sensor is connected with power supply

Starting Initiation Process
Initiation process finished
Initializing SD card…card initialized.
FSR resistance in ohms = 14
Sensor is connected

Condition 2
Sensor is dis-connected and power supply is connected

Starting Initiation Process
Initiation process finished
Initializing SD card…card initialized.
FSR resistance in ohms = 1
Sensor is connected
Motor Speed when Sensor reading < 100: 5
RPM when sensor sensed < 100 : 4
Sensor Reading : 0

  • No pressure
    ==========
    Condition 2
    Sensor is connected but power supply is disconnected
    ======
    Starting Initiation Process
    Initiation process finished
    Initializing SD card…card initialized.
    FSR resistance in ohms = 1
    Sensor is connected
    Motor Speed when Sensor reading < 100: 5
    RPM when sensor sensed < 100 : 4
    Sensor Reading : 0
  • No pressure
    =====
    My Conclusion: sensorCheck () fails to work in setup()

when sensorCheck() is inside loop()

Condition 1
Sensor is connected physically as well power supply is also connected serial monitor output

Starting Initiation Process
Initiation process finished
Initializing SD card…card initialized.
FSR resistance in ohms = -30
Sensor is not connected

condition 2
Sensor is dis-connected physically power supply is connected output at starting is as below

Starting Initiation Process
Initiation process finished
Initializing SD card…card initialized.
FSR resistance in ohms = 1
Sensor is connected
FSR resistance in ohms = -58
Sensor is not connected

Condition 3
Sensor is connected physically power supply is dis-connected output at starting is as below

Starting Initiation Process
Initiation process finished
Initializing SD card…card initialized.
FSR resistance in ohms = 1
Sensor is connected
FSR resistance in ohms = -89
Sensor is not connected

When I said in my comment that i need to revisit my entire circuit because yesterday I read in some of the issue reported on this FORUM was that on Reverse Current,I thought may be I even after disconnecting the power supply of FSR i am getting - negative reading is because of that? but then i thought that i am not connecting any external power supply to it, so its my mistake only…but its not, I tested all possible scenarios, but I am getting same thing. Please have a look of my code execution Serial Print lines.

Yes, I am a JR.K.G. Student in Arduino University :slight_smile: ..I am learning from this Forum (University) only.

For this project I don't have any programming backup nor anybody apart from You are helping me.

Currently In my circuit the below components are attached

  1. Entire circuit is on Breadboard
  2. Few Jumpers
  3. Stepper Motor with its driver (make: xcluma 28Ybj-48 Dc 5V 4 Phase 5 Wire Stepper Motor With Uln2003 Driver Board)
  4. Arduino (make: Arduino - Generic Uno R3 ATmega328P)
  5. SD Card Shield (make: Quad Store Ethernet W5100 Shield Network Expansion Board with Micro SD Card Slot for Arduino)
  6. RGB led (make: Quad Store)
  7. Passive buzzer (make: Quad Store)
  8. FSR sensor (make: Force Sensor 12.7 mm Circle)
  9. 10k Resistor
    No external power supply yet

But as the functionality become complex there will be some more sensor are going to get attached like

  1. Blood detection sensor
  2. some IR sensors
  3. Thermal sensor
  4. LCD screen etc..

Thanks for the Memory Tutorial as well information on SD card Fat16 very very informative, but for me to understand the entire functionality will take some time...but as a beginner I understood what you want to suggest to me..thanks again ..

In my code I have to keep messages which will get stored in file, currently when you read A, B, C, D, and E in fileCapture() which are very short now (initially i tried to keep it big but then as i told i faced memory issue thn i cut to A, B C etc..) but will be going to get converted in big readings stored in File for e.g A -> Stage 0 Development of XXXX, B -> Stage 1 Developmental stage of XXXX etc.... that will easy to understand for us as a medical researcher / practitioners rather that technical people...

Yesterday, I was reading some info on Arudino Mega 2560, as this contains lots of more PINS for lots of different functionality to execute. But i have seen people are reporting /facing lots of issue too while using Mega, i think its not as simple as UNO, so my question here is
in UNO can we use 1 PWM PIN for 2 different purposes for e.g if on my UNO board i am using pins 6.7.8.9 for stepper then can I use the same pins for LCD screen? is it possible that they can give me desired output according to functionality? I have not tried yet cause my LCD module is on its way......but I myself doubt but still I am asking you.

I doubt because this discussion started from that point only as my SD card and Stepper motor was using same pins and when I start SD card functionality Stepper Motor was not functioning and when I commented SD card functionality then it was started, then Mr. Robin asked me to changed the PINs for both and now its all working.

As a researcher i have a habit to writing very elaborate response ...please excuse me this time ...next time I will try to keep it as less as possible

i am using pins 6.7.8.9 for stepper then can I use the same pins for LCD screen?

No. But also remember that the analog input edit: inputs plural on the opposite edge of the Uno ar digital pins too.

I have not tried yet cause my LCD module is on its way....

It would help if it's an I2C LCD, or if not that you can swap it for one, or add a so-called backpack, then it will work on the I2C bus pins A4 and A5 on an Uno.

Yesterday, I was reading some info on Arudino Mega 2560, as this contains lots of more PINS for lots of different functionality to execute. But i have seen people are reporting /facing lots of issue too while using Mega, i think its not as simple as UNO

I've never used a Mega but I don't recall seeing anything that would indicate it's not as simple as, or any more difficult to use than an Uno, except for the programmer having to mentally keep track of many more connected devices. But good programming practices will go a long way to keeping things tidy.

Referring to the code in Reply #10 ...

I would omit this code in the sensorCheck() function

    fsrVoltage = map(fsrReading, 0, 1023, 0, 5000);
    fsrResistance = 5000 - fsrVoltage;     // fsrVoltage is in millivolts so 5V = 5000mV
    fsrResistance *= 10000;                // 10K resistor
    fsrResistance /= fsrVoltage;
    Serial.print("FSR resistance in ohms = ");
    Serial.println(fsrResistance);

It should be sufficient to verify the existence of the sensor directly with the value from analogRead() - and probably more accurate. Keep things simple.

Also, until you are satisfied with the sensor check process take all the other irrelevant code out of the program. Short programs make it much easier to help you.

...R

Thanks for your reply,

I changed the function accordingly and after removing sensor OR its power supply code execution it shows below (note: even if the sensor and power supply is connected, then also same output)

void sensorCheck(){

    fsrAnalogPin = A0;
    int fsrReading = 0;
       
    fsrReading = analogRead(fsrAnalogPin);
    Serial.print("FSR reading :");
    Serial.println(fsrReading);
    Serial.println(fsrResistance);

  if ( fsrReading <= 0 )
  {
    Serial.println("Sensor is not connected");
    while (1);
  
   }
  else{
    
    Serial.println("Sensor is connected");
    } 
}

condition = > if ( fsrReading < 0 )

Starting Initiation Process
Initiation process finished
Initializing SD card…card initialized.
FSR reading : 0
Sensor is connected
FSR reading35
Sensor is connected
Motor Speed when Sensor reading < 100: 3
RPM when sensor sensed < 100 : 4
Sensor Reading : 0

  • No pressure
    FSR reading : 0
    Sensor is connected
    Motor Speed when Sensor reading < 100: 3
    RPM when sensor sensed < 100 : 4
    Sensor Reading : 0
  • No pressure
    FSR reading : 0
    Sensor is connected
    Sensor Reading : 0
  • No pressure
    FSR reading: 0
    Sensor is connected

==========================

After removing sensor OR its power supply code execution it shows below (note: even if the sensor and power supply is connected, then also same output)
condition => if ( fsrReading <= 0 )

Starting Initiation Process
Initiation process finished
Initializing SD card…card initialized.
FSR reading :0
Sensor is not connected

Do you feel that my breadboard is faulty? … i am clueless now.

veliotprojects:
Do you feel that my breadboard is faulty? ... i am clueless now.

Please post the complete latest version of your program - snippets are not useful.

I mentioned, back in Reply #3 that it may not be possible to be certain that a sensor is disconnected, or not functioning. To do that you need a formal calibration process in which you check the sensor readings against values from an independent external instrument.

...R

Robin2:
To do that you need a formal calibration process ..

Or at least as an informal sense check, take it out of the circuit, and stick your ohmmeter across the contacts while you flex it and at least see if the readings go in the right direction. Do that regularly, so at least you can say "well this morning it worked..."

But unless the sensor (and its library) are specifically devised to report their status, like the dht11 library I use that includes the following, it's a bit of a lottery at best.

chk = DHT.read(DHT11_PIN);    // READ DATA
switch (chk){
    case DHTLIB_OK:  
                Serial.print("OK,\t"); 
                break;
    case DHTLIB_ERROR_CHECKSUM: 
                Serial.print("Checksum error,\t"); 
                break;
    case DHTLIB_ERROR_TIMEOUT: 
                Serial.print("Time out error,\t"); 
                break;
    default: 
                Serial.print("Unknown error,\t"); 
                break;
  }

the actual device will go inside human body for capturing some data and this device includes FSR sensor

Is the FSR sensor you are testing with, the same make and model as will go inside the patient? If not, it makes no sense to fixate now on figuring out how to detect it, since the actual one may work differently in that respect. (If it is, I hope it's of the right medical grade or somehow insulated in a little box or something?)