Hi there, a very new user here, i am new to arduino , using it for few weeks already...
but now i am trying to do a project which uses force sensor for LEDs. Suppose i have 1 force sensor each to control 2 LEDs. But not sure where my fault is at.
int sensorPin1 = A0; //force sensitive resistor 1 connected to analog pin 0
int sensorPin2 = A1; //force sensitive resistor 2 connected to analog pin 1
int buzzer = 10; //buzzer connected to digital pin 10
int ledPin1 = 3; //LED pin 1 connected to digital pin 3
int ledPin2 = 5; //LED pin 2 connected to digital pin 5
int ledPin3 = 6; //LED pin 3 connected to digital pin 6
int ledPin4 = 9; //LED pin 4 connected to digital pin 9
int fsrReading; // the analog reading from the FSR resistor divider
int Sensorvalue1 = 0; // set sensor value 1 to 1
int Sensorvalue2 = 0; // set sensor value 2 to 1
void setup()
{
Serial.begin(9600);
pinMode(ledPin1,OUTPUT); //set the LED pin 1 for digital output
pinMode(ledPin2,OUTPUT); // set the LED pin 2 for digital output
pinMode(ledPin3,OUTPUT); // set the LED pin 3 for digital output
pinMode(ledPin4,OUTPUT); // set the LED pin 4 for digital output
pinMode(buzzer,OUTPUT); // set the buzzer for digital output
pinMode(sensorPin1,INPUT); //set the force sensitive resistor 1 for analog input
pinMode(sensorPin2,INPUT); //set the force sensitive resistor 2 for analog input
void loop ()
;{
int (Sensorvalue1 = analogRead(sensorPin1));
}
int (Sensorvalue2 = analogRead(sensorPin2));
{
//value = analogRead(sensorPin); //Read and save analog value from potentiometer
//Serial.println(value); //Print value
//value = map(value, 0, 1023, 0, 255); //Map value 0-1023 to 0-255 (PWM)
//analogWrite(ledPin, value); //Send PWM value to led
//delay(100); //Small delay
Serial.print("Sensorvalue1");
Serial.print("Sensorvalue2");
if
(int (Serial.print("Sensorvalue1 = 1023")));
(int (Serial.print("Sensorvalue2 = 1023")));
}
digitalWrite(ledPin2,HIGH);
digitalWrite(ledPin3,HIGH);
delay (1);
{
}
if
(int(Serial.print("Sensorvalue1 = <= 1023 ")));
(int(Serial.print("Sensorvalue2 = <= 1023 ")));
digitalWrite(ledPin1,HIGH);
digitalWrite(ledPin4,HIGH);
delay (1);
And.. i cant compile due to :
Arduino:1.6.9 (Windows 10), ボード:"Arduino/Genuino Uno"
C:\Users\lenovo\AppData\Local\Temp\builda2710c2fa712e52f445d6d21feedb4cc.tmp/core\core.a(main.cpp.o): In function `main':
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/main.cpp:46: undefined reference to `loop'
collect2.exe: error: ld returned 1 exit status
exit status 1
???Arduino/Genuino Uno??????????????????????
You have screwed up the loop function definition remove the ; before the {
You have also missed out the } at the end of the setup function.
In fact all your braces are screwed including the ones in the if statements.
if
(int(Serial.print("Sensorvalue1 = <= 1023 ")));
Is a total nonsense, what are you trying to say here?
Hi idme231, and welcome to the Arduino forum!
Mike is right, I can't understand your code either. The way to do this is to take baby steps first, so perhaps start with one LED and one force sensor. Like this:
#define led 9 // pin 9 --> (anode)led(cathode) --> 330 ohm resistor --> gnd
#define forceSensor A0 // pin A0 --> force sensor --> gnd
void setup() {
pinMode (led, OUTPUT);
pinMode (forceSensor, INPUT_PULLUP); // sensor is bottom of voltage divider
}
void loop() {
int force = analogRead(forceSensor);
analogWrite(led, force/4); // divide by 4 to change input range (1024) to output range (256)
}
Hi,
What model arduino are you using?
Tom... 
Grumpy_Mike:
You have screwed up the loop function definition remove the ; before the {
You have also missed out the } at the end of the setup function.
In fact all your braces are screwed including the ones in the if statements.
if
(int(Serial.print("Sensorvalue1 = <= 1023 ")));
Is a total nonsense, what are you trying to say here?
i am sorry, because i am stressed out with system sometimes. it was meant to on one of the LEDs with analog under serial print (1024). if the sensor detects it high, it will on one of the LEDs
and others it could happen would be if and the else function.
ChrisTenone:
Hi idme231, and welcome to the Arduino forum!
Mike is right, I can't understand your code either. The way to do this is to take baby steps first, so perhaps start with one LED and one force sensor. Like this:
#define led 9 // pin 9 --> (anode)led(cathode) --> 330 ohm resistor --> gnd
#define forceSensor A0 // pin A0 --> force sensor --> gnd
void setup() {
pinMode (led, OUTPUT);
pinMode (forceSensor, INPUT_PULLUP); // sensor is bottom of voltage divider
}
void loop() {
int force = analogRead(forceSensor);
analogWrite(led, force/4); // divide by 4 to change input range (1024) to output range (256)
}
pull_up ? what's that?
anyway, i proberly give it a try first.
idme231:
pull_up ? what's that?
anyway, i proberly give it a try first.
INPUT_PULLUP is one of three important and useful modes you can set with pinMode. You can set a pin to OUTPUT mode, as I did with pin 9. This means that you can digitalWrite() or analogWrite() to the pin, and affect the voltage on the pin from your sketch.
You can set a pin to INPUT. Then if you digitalRead() it, the pin can read HIGH or LOW depending on the voltage of what you attached to it. If you analogRead() a pin set to INPUT mode, the value will be between 0 and 1023, depending on the voltage applied to the pin.
You can also set a pin to INPUT_PULLUP. In this mode, if you read (analog or digital) from a pin with nothing attached, it will be HIGH, as there is actually a resistor inside the chip that connects it with the Vcc voltage. If you attach a sensor that works by changing it's resistance to a pin in INPUT_PULLUP mode, it forms a voltage divider with the pin attached to the middle of the divider. Then, when you analogRead() that pin, the value will be proportional to the resistance of the sensor. This is the easiest way to read an analog sensor, as you can tell from the simplicity of my demo.
ps, I can post a video of the device in action, running this exact sketch, if you'd like to see it.
idme231:
i am sorry,
No need to apologies, I am just telling you what is wrong.
For the need to use pull up resistors see here:-
http://www.thebox.myzen.co.uk/Tutorial/Inputs.html
If you put your cursor on an opening brace you will see the matching closing brace outlined, it is a very useful feature.
chris's code sort of worked out, it responded
but suppose now i actually have to control either of them. if force sensor is fully pressed, LED red is on. if the force sensor is released, green LED is on. do i actually have to add in the code for the requirement?
e.g.
if
sensor1 = > (value)
(led1,high)
else if
(sensor 1 = < value )
(led2,high)
idme231:
chris's code sort of worked out, it responded
but suppose now i actually have to control either of them. if force sensor is fully pressed, LED red is on. if the force sensor is released, green LED is on. do i actually have to add in the code for the requirement?
e.g.
if
sensor1 = > (value)
(led1,high)
else if
(sensor 1 = < value )
(led2,high)
Yeah. The arduino has no idea what you intend, so you have to instruct it very precisely.
i wasnt sure about which value to insert. (the force sensor value required to meet the requirements)
idme231:
i wasnt sure about which value to insert. (the force sensor value required to meet the requirements)
Only you can know the requirements. If you have no specification, you should write a test sketch to report values to the serial port where you can read them, and activate the sensor. In this way, you can measure the sensor values, and know what limits to apply.
aarg:
Only you can know the requirements. If you have no specification, you should write a test sketch to report values to the serial port where you can read them, and activate the sensor. In this way, you can measure the sensor values, and know what limits to apply.
you meant the COM3 system?
Hi guys,
just an update.
I know this thread has not been posted for a long time, but I finally got the code done at least. and, i showcased the project to the public. And I will be sharing the code that I made soon, as soon as I get my com fixed, as it breaks down quite often. yeap, I will be making use of Arduino for projects as it is really interesting and fun. Thanks!