I am using an Arduino Uno with Windows 10, and neither my DigitalRead nor my AnalogRead functions seem to be working. For instance, if I use a light-dependent-resistor (or a thermoresistor or any analog sensor for that matter) plugged into any of the analog in's (1 through 5), and I try to Serial.println(sensor), the reading continually reads the Euro symbol, which I assume is indicating some sort of error. Additionally, if I am sending analogWrite(LED,sensor), the LED does not change brightness as a function of light if I am using an LDR. The LED will seem to flicker a bit if I put my hand close to it.
I get similar problems when using DigitalRead using nearly all the pins (pin 13 seems to work OK). Even using the simple LED button (Example 2) script does not work. The LED only responds with a flicker when I put my hand close to the circuit board, but it does not respond to the push button. DigitalWrite and AnalogWrite seem to work from all the pins. I have successfully used these codes in the past, but they no longer work.
Nope, not until you post your code here: don't tell us that you're using this example or that example, post your actual code, ie a copy/paste from your IDE as you code exists with the problem.
And a schematic of the way you have things wired up.
#define LED 11 // port 11 is defined as an LED #define button 7 // port 7 is defined as a push button
int val=0; // val will be used to store the state of the input button pin
void setup() {
pinMode(LED,OUTPUT); // tells Arduino that LED is an output
pinMode(button,INPUT); // says button is an input
}
void loop() {
val=digitalRead(button); // read the input value and store it as val
//check whether the input is HIGH (button pressed)
if (val==HIGH)
{
analogWrite(LED,255); // turn LED on when button is pressed
}
else
{
analogWrite(LED,0); // turn LED off if button is not being pressed
}
}
Here (attached) are pictures of the setup, oddly having the LED lit even though the button is not pressed, but just because my hand is nearby.
Edit your post by selecting your code, then press this button then click "Save" so it shows correctly.
You're missing a pulldown resistor (could use 10K) for the button. Alternately, you could re-wire the button so it's connected from pin 7 to GND, then use INPUT_PULLUP when configuring pin 7.