Created
May 19, 2019 13:39
-
-
Save anugrahbsoe/54848c3001b2fe40b82cee638dfd60a0 to your computer and use it in GitHub Desktop.
membuat analog
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/******* | |
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