-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 65248ae
Showing
108 changed files
with
15,955 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#include <WiFi.h> | ||
#include <ThingerESP32.h> | ||
|
||
#define USERNAME "atmduino" | ||
#define DEVICE_ID "Esp32_trial" | ||
#define DEVICE_CREDENTIAL "GruAmtNTKkzd" | ||
|
||
#define SSID "Pkm_asia" | ||
#define SSID_PASSWORD "sistemkomputer" | ||
|
||
// define your board pin here | ||
#define LED_PIN 15 | ||
|
||
ThingerESP32 thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL); | ||
|
||
void setup() { | ||
pinMode(LED_PIN, OUTPUT); | ||
|
||
thing.add_wifi(SSID, SSID_PASSWORD); | ||
|
||
// digital pin control example (i.e. turning on/off a light, a relay, configuring a parameter, etc) | ||
thing["led"] << digitalPin(LED_PIN); | ||
|
||
// resource output example (i.e. reading a sensor value) | ||
thing["millis"] >> outputValue(millis()); | ||
|
||
// more details at http://docs.thinger.io/arduino/ | ||
} | ||
|
||
void loop() { | ||
thing.handle(); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#include "DHT.h" // including the library of DHT11 temperature and humidity sensor | ||
#define DHTTYPE DHT11 // DHT 11 | ||
|
||
#define dht_dpin D5 | ||
DHT dht(dht_dpin, DHTTYPE); | ||
|
||
#include <ESP8266WiFi.h> | ||
#include <ThingerESP8266.h> | ||
|
||
#define USERNAME "atmduino" | ||
#define DEVICE_ID "IoT_Tranning" | ||
#define DEVICE_CREDENTIAL "zi5pTaWVGoeH" | ||
|
||
#define SSID "Pkm_asia" | ||
#define SSID_PASSWORD "sistemkomputer" | ||
|
||
// thinger.io config | ||
ThingerESP8266 thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL); | ||
|
||
void setup() { | ||
dht.begin(); | ||
pinMode(D4, OUTPUT); | ||
pinMode(D5, INPUT) ; | ||
pinMode(D6, OUTPUT); | ||
pinMode(D7, OUTPUT); | ||
|
||
thing.add_wifi(SSID, SSID_PASSWORD); | ||
|
||
|
||
|
||
// digital pin control example (i.e. turning on/off a light, a relay, configuring a parameter, etc) | ||
thing["Stop Kontak"] << digitalPin(D6); | ||
thing["Lampu"] << digitalPin(D7); | ||
// resource output example (i.e. reading a sensor value) | ||
//thing["millis"] >> outputValue(millis()); | ||
//pembacaan sensor dht11 | ||
thing["dht11"] >>[](pson & out){ | ||
out["humidity"] = dht.readHumidity(); | ||
out["celsius"] = dht.readTemperature(); | ||
out["fahrenheit"] = dht.readTemperature(true); | ||
|
||
}; | ||
|
||
// more details at http://docs.thinger.io/arduino/ | ||
} | ||
|
||
void loop() { | ||
thing.handle(); | ||
digitalWrite(D4, HIGH); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#include "FirebaseESP8266.h" | ||
#include "DHT.h" | ||
#include <ESP8266WiFi.h> | ||
|
||
#define FIREBASE_HOST "smarthomeasia1.firebaseio.com" | ||
#define FIREBASE_AUTH "HYv6JMXLZP2PSKZTZFvcyiQssQw2d6SZ8gxKESjK" | ||
#define WIFI_SSID "ggwp" // Change the name of your WIFI | ||
#define WIFI_PASSWORD "sksaturasa" // Change the password of your WIFI | ||
FirebaseData firebaseData; | ||
#define DHTPIN D5 // Data Pin of DHT 11 , for NodeMCU D5 GPIO no. is 14 | ||
#define lamp D6 | ||
#define kipa D7 | ||
#define DHTTYPE DHT11 // DHT 11 | ||
DHT dht(DHTPIN, DHTTYPE); | ||
int kip,lam; | ||
|
||
void setup() { | ||
Serial.begin(9600); | ||
pinMode(D4,OUTPUT); | ||
pinMode(lamp,OUTPUT); | ||
pinMode(DHTPIN,INPUT); | ||
pinMode(kipa,OUTPUT); | ||
WiFi.begin (WIFI_SSID, WIFI_PASSWORD); | ||
while (WiFi.status() != WL_CONNECTED) { | ||
delay(500); | ||
Serial.print("."); | ||
} | ||
dht.begin(); | ||
Serial.println (""); | ||
Serial.println ("WiFi Connected!"); | ||
Firebase.begin(FIREBASE_HOST,FIREBASE_AUTH); | ||
|
||
} | ||
|
||
void loop() { | ||
|
||
kip=Firebase.getInt(firebaseData,"lampu22"); | ||
lam=Firebase.getInt(firebaseData,"lampu12"); | ||
if(kip==1){ | ||
digitalWrite(kipa,HIGH); | ||
digitalWrite(D4,HIGH); | ||
Firebase.setInt(firebaseData,"k",3); | ||
} | ||
if(kip==0){ | ||
digitalWrite(D4,LOW); | ||
digitalWrite(kipa,LOW); | ||
Firebase.setInt(firebaseData,"k",2); | ||
} | ||
if(lam==1){ | ||
digitalWrite(lamp,HIGH); | ||
} | ||
if(lam==0){ | ||
digitalWrite(lamp,LOW); | ||
} | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
/************************** | ||
light follower robot | ||
www.muhilham.com | ||
30/07/2018 | ||
***********************/ | ||
|
||
//Motor Kiri | ||
#define DIR_KI1 4 // IN4 | ||
#define DIR_KI2 5 // IN3 | ||
#define PWM_KI 3 // ENB | ||
//Motor Kanan | ||
#define DIR_KA1 7 // IN2 | ||
#define DIR_KA2 8 // IN1 | ||
#define PWM_KA 9 // ENA | ||
|
||
const int pinSensor[3] = {A0, A1, A2}; | ||
int level = 150; | ||
int threshold_SenKiri, threshold_SenTengah, threshold_SenKanan; | ||
int baca[3]; | ||
|
||
int Kec_Min = -170; | ||
int Kec_Max = 200; // Max = 255 | ||
|
||
void setup() { | ||
//Serial.begin(9600); | ||
pinMode(13, OUTPUT); | ||
digitalWrite(13, LOW); | ||
for (int i = 4; i <= 9; i++) { // Set pin digital 4 - 9 sebagai output (direction motor) | ||
pinMode(i, OUTPUT); | ||
} | ||
for (int i = 0; i <= 2; i++) { // Kalibrasi batas ambang nilai sensor | ||
pinMode(pinSensor[i], INPUT); | ||
baca[i] = analogRead(pinSensor[i]); | ||
} | ||
threshold_SenKiri = baca[0] + level; | ||
threshold_SenTengah = baca[1] + level; | ||
threshold_SenKanan = baca[2] + level; | ||
} | ||
|
||
void loop() { | ||
for (int i = 0; i <= 2; i++) { | ||
baca[i] = analogRead(pinSensor[i]); | ||
} | ||
Serial.print(threshold_SenKiri); | ||
Serial.print("|"); | ||
Serial.print(threshold_SenTengah); | ||
Serial.print("|"); | ||
Serial.print(threshold_SenKanan); | ||
Serial.print("\t"); | ||
Serial.print(baca[0]); | ||
Serial.print("|"); | ||
Serial.print(baca[1]); | ||
Serial.print("|"); | ||
Serial.print(baca[2]); | ||
Serial.print("\t"); | ||
followLight(); | ||
} | ||
|
||
void followLight() { | ||
int sensor = BacaSensor(); | ||
if (sensor != 0b000) { | ||
switch (sensor) { | ||
case 0b001 : driveMotor(Kec_Max / 2, Kec_Max); break; | ||
case 0b011 : driveMotor(Kec_Max / 3, Kec_Max / 2); break; | ||
case 0b010 : driveMotor(Kec_Max, Kec_Max); break; | ||
case 0b111 : driveMotor(Kec_Max, Kec_Max); break; | ||
case 0b110 : driveMotor(Kec_Max / 2, Kec_Max / 3); break; | ||
case 0b100 : driveMotor(Kec_Max, Kec_Max / 2); break; | ||
} | ||
} | ||
else { | ||
driveMotor(0, 0); | ||
} | ||
} | ||
|
||
void driveMotor(int KEC_KI, int KEC_KA) { | ||
/** Motor Kiri **/ | ||
if (KEC_KI < 0) { | ||
digitalWrite(DIR_KI1, LOW); | ||
digitalWrite(DIR_KI2, HIGH); | ||
} | ||
else if (KEC_KI > 0) { | ||
digitalWrite(DIR_KI1, HIGH); | ||
digitalWrite(DIR_KI2, LOW); | ||
} | ||
else { | ||
digitalWrite(DIR_KI1, HIGH); | ||
digitalWrite(DIR_KI2, HIGH); | ||
} | ||
|
||
/** Motor Kanan **/ | ||
if (KEC_KA < 0) { | ||
digitalWrite(DIR_KA1, LOW); | ||
digitalWrite(DIR_KA2, HIGH); | ||
} | ||
else if (KEC_KA > 0) { | ||
digitalWrite(DIR_KA1, HIGH); | ||
digitalWrite(DIR_KA2, LOW); | ||
} | ||
else { | ||
digitalWrite(DIR_KA1, HIGH); | ||
digitalWrite(DIR_KA2, HIGH); | ||
} | ||
|
||
analogWrite(PWM_KI, abs(KEC_KI)); // Kirim PWM Kiri | ||
analogWrite(PWM_KA, abs(KEC_KA)); // Kirim PWM Kanan | ||
|
||
/*** Pembatasan kecepatan ***/ | ||
if (KEC_KI > Kec_Max)KEC_KI = Kec_Max; | ||
if (KEC_KI < Kec_Min)KEC_KI = Kec_Min; | ||
if (KEC_KA > Kec_Max)KEC_KA = Kec_Max; | ||
if (KEC_KA < Kec_Min)KEC_KA = Kec_Min; | ||
|
||
Serial.print("PWM Kiri : "); | ||
Serial.print(KEC_KI); | ||
Serial.print(" | "); | ||
Serial.print("PWM Kanan : "); | ||
Serial.print(KEC_KA); | ||
Serial.print(" | "); | ||
Serial.print(" "); | ||
} | ||
|
||
int BacaSensor() { | ||
int SenKiri, SenTengah, SenKanan; | ||
int Sensor = 0; | ||
|
||
if (baca[0] > threshold_SenKiri) SenKiri = 1; | ||
else SenKiri = 0; | ||
if (baca[1] > threshold_SenTengah) SenTengah = 1; | ||
else SenTengah = 0; | ||
if (baca[2] > threshold_SenKanan) SenKanan = 1; | ||
else SenKanan = 0; | ||
|
||
int Sen[3] = {SenKiri, SenTengah, SenKanan}; | ||
for (int i = 0; i <= 2; i++) { | ||
if (Sen[i] == 1) { | ||
Sensor = Sensor | (0b100 >> i); | ||
} | ||
Serial.print("|"); | ||
Serial.print(Sen[i]); | ||
Serial.print("|"); | ||
if (i == 2) Serial.println(" "); | ||
} | ||
return Sensor; | ||
} |
Oops, something went wrong.