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.
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.
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;
}
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.
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