VVibration motor + pressure sensor

Hello, I am a big newbie in the subject, just started to work with Arduino.

I've been looking through internet, but I couldn't find any hint on what I want to achive, mixing tutorials doesn't really work, so I've decided to ask in here.

I am making a project in which I want to use a pressure sensor as a switch for vibration motor- when we move something off the pressure sensor ( literally when we lift the object which was standing on a sensor) the vibration motor goes on.

I can't cope with code and not sure about the full order on breadboard.

I would be very grateful for any help!

I can't cope with code

Might as well put the project away, then. Reading the pressure sensor should be trivial. Turning a pin on should be trivial.

Yh, I know how to control them saparately, but when I try to combine them together it just doesn't work. I want to understand it and I thought that Arduino forum is the best place to get started if I can't find the answer in tutorials and the work is not going well when I work on it by myslef.

but when I try to combine them together it just doesn't work.

I can't see that.

and the work is not going well when I work on it by myslef.

If you need help with the code, print it out and hold it up in front of your camera so we can see it. Or post it!

void loop()
{

if (readSensor()<someValue)
  {
   //do something here to turn on the vibration motor;
  }
else
  {
   //do something here to make sure the motor is OFF
  }
}

int readSensor()
{
int value=0;
//do what you have to do here to read the pressure sensor
//and makesure you put the value into the variable "value";


return value;
}

So I did sth like this:

const int analogInPin = A0
const int analogOutPin = 3
int pressPin = A1;

int initReading;

int reading;

boolean startUp;

void setup()
{
;
initReading = 0;

reading = analogRead(pressPin);

startUp = false;

pinMode(analogOutPin, OUTPUT);
}
void loop()
{
calibrate();
reading = analogRead(pressPin);

if(reading > initReading*.1)
{
digitalWrite(HIGH);
}
else
{
digitalWrite(analogOutPi,LOW);
}
}
void calibrate()
{
if(startUp = false)
{
initReading = reading;

startUp = true;
}
}
I made it only basing on tutorials, referances so it may be all wrong, but it would be nice if someone coulkd see what's wrong

but it would be nice if someone coulkd see what's wrong

No code tags.
No semicolons on many of the statements.
Piss-poor indenting.
No description of what the code actually does.
Shall I go on?

you need to add an '=' sign here

if(startUp = false)

should be

if(startUp == false)

Otherwise you are assigning false to startup. The will therefore cause initReading = reading to run EVERY time. Hence, no change will ever be detected within your loop.

You've also got some problems here

if(reading > initReading*.1)         
{                                           
digitalWrite(HIGH);         
}
else                                         
{
digitalWrite(analogOutPi,LOW);           
}

should read

if(reading > initReading*.1)         
  {                                           
  digitalWrite(analogOutPin,HIGH);         
  }
else                                         
  {
  digitalWrite(analogOutPin,LOW);           
  }

Note miss spelling of analogOutPin AND it's complete absence in the first condition.

Thank you Ken, I've made it work with the other code! I'm attaching this proper one

//Arduino to I/O for RAPID, ABB control
int pressPin = 0; //pressure sensor to Arduino A0
int initReading; //variable for the initial reading,
// of the pressure sensor.
int reading; //variable for storing current pressure
//reading
boolean startUp; //sets up a calibration ‘switch’

int di1Pin = 9; //sends signal to robot controller

void setup()
{
//Serial.begin(9600); //Setup a serial connection for debug.

initReading = 0; //Initialize initReading.
reading = analogRead(pressPin); //Reading equals the value,
//returned by the sensor.
startUp = true; //Initialize the calibration switch to ‘on’
pinMode(di1Pin, OUTPUT); //Pin 9 is set to SEND a signal.

}

void loop()
{
calibrate(); //calls the function defined below

reading = analogRead(pressPin); //Reading equals the value,
//from the sensor
if(reading < initReading*.9) //If reading is less than 90%,
{ //of the initial sensor value,
digitalWrite(di1Pin, HIGH); //send a signal to the controller.
}
else
{
digitalWrite(di1Pin,LOW); //send no signal
}
}

void calibrate() //The first thing to do in the loop,
{
if(startUp == true) //if the calibration switch is on (which it is),
{
initReading = reading; //set initReading equal to the sensor
//value.
startUp = false; //And shut of the calibration switch.
}
}
this was a code from a diffrent project with LEDs I can attached the photos of arduino and breadboard with a vibration motor later :slight_smile: