Skip to content

Instantly share code, notes, and snippets.

@anugrahbsoe
Created May 19, 2019 13:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anugrahbsoe/54848c3001b2fe40b82cee638dfd60a0 to your computer and use it in GitHub Desktop.
Save anugrahbsoe/54848c3001b2fe40b82cee638dfd60a0 to your computer and use it in GitHub Desktop.
membuat analog
/*******
All the resources for this project:
https://www.hackster.io/Aritro
*******/
int redLed = 12;
int greenLed = 13;
int buzzer = 10;
int smokeA0 = a0;
// Your threshold value
int sensorThres = 400;
void setup() {
pinMode(redLed, OUTPUT);
pinMode(greenLed, OUTPUT);
pinMode(buzzer, OUTPUT);
pinMode(smokeA0, INPUT);
Serial.begin(9600);
}
void loop() {
int analogSensor = analogRead(smokeA0);
Serial.print("Pin A0: ");
Serial.println(analogSensor);
// Checks if it has reached the threshold value
if (analogSensor > sensorThres)
{
digitalWrite(redLed, HIGH);
digitalWrite(greenLed, LOW);
tone(buzzer, 1000, 200);
}
else
{
digitalWrite(redLed, LOW);
digitalWrite(greenLed, HIGH);
noTone(buzzer);
}
delay(100);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment