Hi I am new to Arduino programming so facing errors while performing experiments
I am using digitalWrite function to make any digital pin HIGH or LOW. But the problem is I am getting 1.30 v at digital pin Which is defined as HIGH(measuring via digital voltmeter ) instead of 5v
Please help
here is my program
// here I am trying to make the limit switch for rotating motor with button_brake1 & button_brake2
//button1 & button2 are control buttons for the motor to rotate clockwise or anticlockwise.
int button1=0;
int button2=0;
int button_brake1=0;
int button_brake2=0;
void setup() {
Serial.begin(9600);
pinMode(2,INPUT);
pinMode(4,INPUT);
pinMode(7,INPUT);
pinMode(8,INPUT);
pinMode(12,OUTPUT);
pinMode(13,OUTPUT);
}
int arm_forward(){
digitalWrite(12,HIGH);
digitalWrite(13,LOW);
}
int arm_backward(){
digitalWrite(12,LOW);
digitalWrite(13,HIGH);
}
int arm_forward_brake(){
digitalWrite(12,LOW);
digitalWrite(13,LOW);
}
int arm_backward_brake(){
digitalWrite(12,LOW);
digitalWrite(13,LOW);
}
int arm_stable_mode(){
digitalWrite(12,LOW);
digitalWrite(13,LOW);
}
void loop() {
button1=digitalRead(2);
button2=digitalRead(4);
button_brake1=digitalRead(7);
button_brake2=digitalRead(8);
if (button1==HIGH){
arm_forward();
}
if (button2==HIGH){
arm_backward();
}
if (button_brake1==HIGH){
arm_forward_brake();
}
if ( button_brake2==HIGH){
arm_backward_brake();
}
else{
arm_stable_mode();
}
}
//Thank You
First of all, go back and edit your post to put all that code inside code tags, as per the forum rules.
This sounds more like a hardware problem so please provide wiring diagrams and/or photographs of your hardware setup. Have you tried measuring the supply voltage (Vcc)?
Before you go any further please help us and yourself and look at this Read this before posting a programming question and post your code in code tags. Unless, of course, it has a smiley in it
Doesn’t pin13 have an LED?
it have but just ignore it i have tried other digital pins but they are also doing the same
i saw your diagram
you can check voltage with respect to ground each pin 12 and 13.
OP image:
Please answer my question! Did you check 5V power, and also where are you measuring the voltage? Is the "voltmeter" in your diagram displaying the 1.30V, or are you seeing it somewhere else.
It is extremely difficult to remotely troubleshoot something like this. Please respond and be detailed with answers to questions you are asked.
What happens when you disconnect the voltmeter, limit switches and controller? So that the Arduino is running stand alone.
Write a program to ONLY set a pin high and nothing else. What does your meter indicate is the voltage on that pin?
Paul
Print out the values you are getting from the digitalRead()'s, sounds like you are switching the output on and off rapidly.
no there is no pullup resistors involved
& the other side of the buttons are connected to 5v of arduino(to give signal(HIGH)in input)
#aarg
my arduino is connected to usb power supply of laptop which gives 5 v output
yes 1 the 1.3 v is the value shown by voltmeter connected to arduino pin 12 and 13 as shown in diagram
please ignore my stupidness while a am replying because i dont know anything about this forum how to use it
So if you’re checking with one probe on 12 and one on 13 you are checking for differential voltage, again there’s an led on 13 and the difference may be VCC-led diode fwd voltage. This is assuming they are both high. Why not measure with reference to ground?
//This program is working correctly
//This means that the problem is in code not in hardware
//Please anyone review my program and correct it
void setup() {
pinMode(13,INPUT);
}
void loop() {
digitalWrite(13,HIGH);
}
arightkerfuffle:
Here for completeness is OP's code fixed for:
- else if rather than if
- input_pullup rather than input, look for lows on inputs (buttons re-wired ofc)
// here I am trying to make the limit switch for rotating motor with button_brake1 & button_brake2
//button1 & button2 are control buttons for the motor to rotate clockwise or anticlockwise.
int button1=0;
int button2=0;
int button_brake1=0;
int button_brake2=0;
void setup() {
Serial.begin(9600);
pinMode(2,INPUT_PULLUP);
pinMode(4,INPUT_PULLUP);
pinMode(7,INPUT_PULLUP);
pinMode(8,INPUT_PULLUP);
pinMode(12,OUTPUT);
pinMode(11,OUTPUT);
}
int arm_forward(){
digitalWrite(12,HIGH);
digitalWrite(11,LOW);
}
int arm_backward(){
digitalWrite(12,LOW);
digitalWrite(11,HIGH);
}
int arm_forward_brake(){
digitalWrite(12,LOW);
digitalWrite(11,LOW);
}
int arm_backward_brake(){
digitalWrite(12,LOW);
digitalWrite(11,LOW);
}
int arm_stable_mode(){
digitalWrite(12,LOW);
digitalWrite(11,LOW);
}
void loop() {
button1=digitalRead(2);
button2=digitalRead(4);
button_brake1=digitalRead(7);
button_brake2=digitalRead(8);
if (button1==LOW){
arm_forward();
}
else if (button2==LOW){
arm_backward();
}
else if (button_brake1==LOW){
arm_forward_brake();
}
else if ( button_brake2==LOW){
arm_backward_brake();
}
else{
arm_stable_mode();
}
}
if every pin will read LOW then how they will get input????
if (button1==LOW){
arm_forward();
}
else if (button2==LOW){
arm_backward();
}
else if (button_brake1==LOW){
arm_forward_brake();
}
else if ( button_brake2==LOW){
arm_backward_brake();
}
else{
arm_stable_mode();
}
arightkerfuffle:
Here for completeness is OP's code fixed for:
- else if rather than if
- input_pullup rather than input, look for lows on inputs (buttons re-wired ofc)
// here I am trying to make the limit switch for rotating motor with button_brake1 & button_brake2
//button1 & button2 are control buttons for the motor to rotate clockwise or anticlockwise.
int button1=0;
int button2=0;
int button_brake1=0;
int button_brake2=0;
void setup() {
Serial.begin(9600);
pinMode(2,INPUT_PULLUP);
pinMode(4,INPUT_PULLUP);
pinMode(7,INPUT_PULLUP);
pinMode(8,INPUT_PULLUP);
pinMode(12,OUTPUT);
pinMode(11,OUTPUT);
}
int arm_forward(){
digitalWrite(12,HIGH);
digitalWrite(11,LOW);
}
int arm_backward(){
digitalWrite(12,LOW);
digitalWrite(11,HIGH);
}
int arm_forward_brake(){
digitalWrite(12,LOW);
digitalWrite(11,LOW);
}
int arm_backward_brake(){
digitalWrite(12,LOW);
digitalWrite(11,LOW);
}
int arm_stable_mode(){
digitalWrite(12,LOW);
digitalWrite(11,LOW);
}
void loop() {
button1=digitalRead(2);
button2=digitalRead(4);
button_brake1=digitalRead(7);
button_brake2=digitalRead(8);
if (button1==LOW){
arm_forward();
}
else if (button2==LOW){
arm_backward();
}
else if (button_brake1==LOW){
arm_forward_brake();
}
else if ( button_brake2==LOW){
arm_backward_brake();
}
else{
arm_stable_mode();
}
}
NEW PROBLEM IN CODE
arightkerfuffle:
Because the pullup resistors will keep them high while not pressed; it's sop.
Can't read this...
Rather quote the message as text.
code problem is fixed
but with your new code pin 13 is constantly high
but I want is --
if button1 is pressed then the motor rotates in clockwise
if button2 is pressed then the motor rotates in anticlockwise
if button_brake1 is pressed then motor stops
if button_brake2 is pressed then motor stops
here I am using 4 push buttons
in which 2 are control buttons to rotate clockwise or anti-clockwise
and 2 are brake buttons so any of them is pressed the motor stops with the respect of their rotation
arightkerfuffle:
Oh yeah in my code I changed to pins 11 and 12 just incase the led and resistor on pin 13 where a contributing factor...
You should probably also consider and'ing your buttons to make sure the combinations are all properly covered, for example:
if (button2==LOW && button1==HIGH && blah blah){
ok thank you very much for your lovely support
going to try your code