Hello everyone, I typed in this code
void setup() {
// put your setup code here, to run once
pinMode(8, OUTPUT);
pinMode(5, OUTPUT);
Serial.begin(9600);
pinMode(3, OUTPUT);
}
Please post your sketch, using code tags when you do. This prevents parts of it being interpreted as HTML coding and makes it easier to copy for examination
In my experience the easiest way to tidy up the code and add the code tags is as follows
Start by tidying up your code by using Tools/Auto Format in the IDE to make it easier to read. Then use Edit/Copy for Forum and paste what was copied in a new reply. Code tags will have been added to the code to make it easy to read in the forum thus making it easier to provide help.
Please edit your post, select all code and click the <CODE/> button; next safe your post. Thies will make it easier to read the code, easier to copy and the forum software will display it properly.
Even without the semicolon that line of code is meaningless as Serial.prinln() will never return a value of zero so the statement will never be anything other than true
if (Serial.println (analogRead (A0))) ;
delay(1000);
{
in above
a semicolon following an if statement becomes the body of the statement, what is done when the condition is true; hence in the case, nothing is done
invoking a Serial print within the conditon of an if statement doesn't make sense
it appears the the body of the if statement may have been intended as the code after the brace, '{', but the delay(1000) would become the body if the semi colon weren't there.
in above
the while 1 traps the code in that loop, presumably turning on/off some LED.
the following is a guess at what is intended and will turn on/off a buzzer and LED when the sensor is > 100
const byte PinLed = 5;
const byte PinBuz = 8;
void setup ()
{
Serial.begin (9600);
pinMode (PinBuz, OUTPUT);
pinMode (PinLed, OUTPUT);
}
void loop ()
{
int val = analogRead (A0); // read sensor
Serial.println (val); // display sensor value
if (100 < val) { // check if sensor > some value
digitalWrite (PinLed, HIGH); // turn led and buzzer on
tone (PinBuz, 494, 250);
delay (325); // wait 1/3 sec
digitalWrite (PinLed, LOW); // turn led and buzzer off
tone (PinBuz, 440, 250);
delay (325); // wait again
}
}