// C++ code
//
int ultrasonic (7);
int piezo (0);
void setup()
{
pinMode(piezo,OUTPUT);
pinMode(ultrasonic,INPUT);
Serial.begin(9600);
}
void loop()
{
ultrasonic=digitalRead(7);
Serial.println(ultrasonic);
if (ultrasonic < 30){
piezo = (HIGH);
}
}
The piezo just dosen't care and keeps on ringing in my ears even though I kept the object far away. And Yes, I didn't keep it too far so that the sensor can still sense it.
Pwease help
@asdfghjkwpt Installation and Troubleshooting is for Problems with the Arduino IDE itself NOT your project. It says so in the description of the section.
Therefore I have moved your post here. Please be more careful where you post in future.
I'm inferring from your initialization of the following global variables that these are pin numbers:
int ultrasonic (7);
int piezo (0);
However, in your code you seem to be conflating the pin number with the value of the input.
Is ultrasonic a pin number or an input value? In setup() you use it as a pin number and in loop() you use it as an input value.
You shouldn't use inputs 0 or 1 as they are reserved for serial communications
Why would you read a digital input and expect it to be anything but HIGH or LOW?