I have a problem that I do not understand. I have used Arduino IDE on local PC for years. Now I wanted to do a digitalRead for the first time. To my surprise I got only "1" in the reading, and I have god values on the input pin to either 5 volt and 0 volt. I copied the program to the WEB editor, and loaded the program to Arduino 2560, and the reading of the input pin functioned OK. I downloaded the Arduino IDE version 1.8.12 and compiled and loaded up the program again on local PC, but still wrong readings from digitalRead. I cannot understand this and need help.
Please post your sketch.
I have used Arduino IDE on local PC for years. Now I wanted to do a digitalRead for the first time
I cannot reconcile those two statements but anyway...
You have not posted any code so we cannot see what you have written nor have you provided any details as to how the input is wired but if it is not held in a known state when the input is not triggered then all bets are off
Please post your code, using code tags when you do, see Read this before posting a programming question and details of your circuit
NOTE : I am going to move this thread to Project Guidance
Thank you for your response. High voltage on pin 7 is: 5.05 volt and low voltage is 0.00 volt . I use Windows 10 on PC. Here is the program:
// SoftwareSerial - Version: Latest
#include <SoftwareSerial.h>
SoftwareSerial mySerial(10,11); //
int inPin = 7; // pushbutton connected to digital pin 7
int val = 0; // variable to store the read value
void setup()
{
mySerial.begin(9600); //
Serial.begin(9600); //
pinMode(inPin, INPUT); // sets the digital pin 7 as input
}
void loop()
{
val = digitalRead(inPin); // read the input pin 7
Serial.print("val : ");
Serial.print(val);
Serial.println();
delay (1000);
}
High voltage on pin 7 is: 5.05 volt and low voltage is 0.00 volt
If reading the state of pin 7 only ever gives a value of 1 then I would conclude that it is never being taken to GND
How exactly is the input wired ?
Which of these possibilities have you used ?
(Courtesy of LarryD)
Problem solved. Sorry, I have two Arduino 2560 connected to PC. Upload of program went to wrong Arduino. Disconnecting one solved the problem. Thank you.
