I’m having a problem with my code. My hopes were to have a code that would make a light flash whenever an object was farther than 20 cm away.
Here is my code:
#define TRIGGER_PIN 12
#define ECHO_PIN 11
#define MAX_DISTANCE 300
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);
int led = 5;
unsigned int uS = sonar.ping();
if(uS / US_ROUNDTRIP_CM >= 20);
else if(uS / US_ROUNDTRIP_CM <= 20)
And here are my errors:
NewPingExample.ino: In function ‘void loop()’:
NewPingExample:33: error: ‘else’ without a previous ‘if’
The “error” is highlited
I can’t figure out why it would say this. Can you help?