im trying to make a wind measurement thing and it works by when it spins, it lets electricity pass through a wire for a short time (kind of like a switch) and im trying to write code to detect when this happens
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(2, INPUT);
digitalWrite(2, LOW);
}
void loop() {
// put your main code here, to run repeatedly:
if(digitalRead(2) == LOW);
Serial.println("spin");
}
this is my code but it always prints "spin"
i havent usede arduino programming for a really long time so this is not as obvious to me
pls help
Are you trying to build your own anemometer sensor or is it an "off the shelf" device? If it's an "off the shelf" device, provide a link to the datasheet for it if you would like more help.
That sounds like you may be trying to describe a reed switch or similar.
You need to detect the moment when pin 2 changes state, rather than whether it is simply high or low.
Use a DVM (Digital Volt Meter) in both AC and DC Mode, measure the voltage when the Wind Mill spins, and post the values. This voltage could be conditioned to interrupt the MCU of the Arduino UNO Board via INT0-pin/DPin-2.
oops. you have an extra semicolon in there which decouples your println() statement from your if() statement. If you auto format your code in the IDE (Ctrl-T). You will notice the indentation change.