r/ArduinoProjects • u/Rude_Rub4102 • Feb 24 '24
Code is not uploading in Aurdino
define sensorDigital A1
define relay 9
define buzzer 8
define sensorAnalog A0
void setup() {
pinMode(sensorDigital, INPUT);
pinMode(relay, OUTPUT);
pinMode(buzzer, OUTPUT);
Serial.begin(9600);
}
void loop() {
bool digital = digitalRead(sensorDigital);
int analog = analogRead(sensorAnalog);Serial.print("Analog value : ");
Serial.print(analog);
Serial.print("t");
Serial.print("Digital value :");
Serial.println(digital);if (digital == 0) {
digitalWrite(relay, LOW);
digitalWrite(buzzer, HIGH);
delay(5000);
digitalWrite(relay, HIGH);
digitalWrite(buzzer, LOW);
} else {
digitalWrite(relay, HIGH);
digitalWrite(buzzer, LOW);
}
}2
u/computer_fetzen Feb 24 '24
you forgot to set pinmode for analog sensor?
2
u/Rude_Rub4102 Feb 24 '24
No
2
u/computer_fetzen Feb 24 '24
-did you check com port -did you select your device -does the code compile?
1
2
u/No_Ad9574 Feb 24 '24
One thing not yet mentioned: can the Arduino IDE read the board type? If it can, then it may be a board problem. If the IDE cannot read the board, then it’s either a port problem or perhaps the wrong board type is selected.
2
u/HelLBee908 Feb 24 '24
If the above replies are not useful try disconnecting every wire or jumper cables from the board , connect the cable to pc and then try uploading th code
1
u/Smart_Comfortable_31 Feb 24 '24
Unplug the battery and try again, also possible due to no delay in the serial.println that the serial port cant transfer the data, recommend adding a delay(10), and just span the upload button, these changes have always worked for me.
1
u/Super-Cool-Seaweed Feb 25 '24
I suspect some of the pins you are using interfere with it, just disconnect them and then upload, then reconnect.
1
u/gm310509 Feb 27 '24
There will be some sort of message in the arduino ide explaining what the problem is. You might not understand it, but others will.
The error message is important as it narrows the number of possibilities from the millions down to the hundreds (or even just one or two).
By not sharing the errors, you are just wasting everybody's time including g yours.




2
u/i-am-cow-01 Feb 24 '24
Did u check ur com port?
Any error message ur getting?