Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana membuat sebuah alat yang dapat menghasilkan sinyal kotak atau PWM dengan frekuensi yang dapat diatur selain itu ada waktu / timer untuk waktu PWM tersebut, alat ini menggunakan Arduino sebagai kontrollernya dan interface menggunakan LCD, kendali interface menggunakan 4 buah push button. aplikasi alat ini sangatlah banyak salah satunya yaitu untuk intensitas laser atau sinyal elektrostimulator, untuk lebih jelasnya berikut adalah skema dan programnya.
a. Arduino UNO
b. LCD 16x2
c. Program Arduino IDE
#include<Wire.h>
#include<LiquidCrystal.h>
#include <PWM.h>
LiquidCrystal lcd(6,7,8,10,11,12);
int led = 9; // the pin that the LED is attached to
int duty = 10; // duty cycle
int32_t frequency = 30; //frequency (in Hz)
int btup = 2;
int btdown = 3;
int btok = 4;
int btset = 5;
int frek = 20;
int waktu = 10;
int btupx, btdownx, btsetx, btokx;
int nilaifrek, nilaiwaktu;
int detik;
void setup()
{
lcd.begin(16,2);
lcd.clear();
lcd.noCursor();
//initialize all timers except for 0, to save time keeping functions
InitTimersSafe();
// Serial.begin(9600);
//sets the frequency for the specified pin
bool success = SetPinFrequencySafe(led, frequency);
//if the pin frequency was set successfully, turn pin 13 on
if(success) {
}
pinMode(btup,INPUT_PULLUP);
pinMode(btdown,INPUT_PULLUP);
pinMode(btok,INPUT_PULLUP);
pinMode(btset,INPUT_PULLUP);
pwmWrite(led, duty);
}
void loop()
{
btupx = digitalRead(btup);
btdownx = digitalRead(btdown);
btokx = digitalRead(btok);
btsetx = digitalRead(btset);
lcd.setCursor(0,0);
lcd.print("E STIMULATOR");
lcd.setCursor(0,1);
lcd.print("SET");
pwmWrite(led, 0);
if(btsetx == LOW){
delay(200);
lcd.clear();
setfrek();
delay(1000);
lcd.clear();
settime();
delay(1000);
lcd.clear();
mulai();
}
}
void setfrek(){
btupx = digitalRead(btup);
btdownx = digitalRead(btdown);
btokx = digitalRead(btok);
btsetx = digitalRead(btset);
lcd.setCursor(0,0);
lcd.print("PILIH FREK ");
lcd.setCursor(0,1);
lcd.print(frek);
lcd.print(" ");
if(frek < 20){
frek = 20;
}
if(frek > 50){
frek = 50;
}
if(btupx == LOW){
delay(200);
frek++;
}
if(btdownx == LOW){
delay(200);
frek--;
}
if(btokx == LOW){
delay(200);
nilaifrek = frek;
return;
}
setfrek();
}
void settime(){
btupx = digitalRead(btup);
btdownx = digitalRead(btdown);
btokx = digitalRead(btok);
btsetx = digitalRead(btset);
lcd.setCursor(0,0);
lcd.print("PILIH WAKTU ");
lcd.setCursor(0,1);
lcd.print(waktu);
lcd.print(" ");
if(waktu < 10){
waktu = 10;
}
if(waktu > 15){
waktu = 15;
}
if(btupx == LOW){
delay(200);
waktu++;
}
if(btdownx == LOW){
delay(200);
waktu--;
}
if(btokx == LOW){
delay(200);
nilaiwaktu = waktu;
return;
}
settime();
}
void mulai(){
lcd.setCursor(0,0);
lcd.print("FREK= ");
lcd.print(nilaifrek);
lcd.setCursor(0,1);
lcd.print(nilaiwaktu);
lcd.print(" : ");
lcd.print(detik);
lcd.print(" ");
detik--;
if((nilaiwaktu < 1)&&(detik < 1)){
delay(1000);
nilaiwaktu = 0;
detik = 0;
lcd.clear();
return;
}
if(detik < 1){
nilaiwaktu--;
detik = 59;
}
InitTimersSafe();
// Serial.begin(9600);
//sets the frequency for the specified pin
bool success = SetPinFrequencySafe(led, nilaifrek);
pwmWrite(led, duty);
delay(1000);
mulai();
}
#include<LiquidCrystal.h>
#include <PWM.h>
LiquidCrystal lcd(6,7,8,10,11,12);
int led = 9; // the pin that the LED is attached to
int duty = 10; // duty cycle
int32_t frequency = 30; //frequency (in Hz)
int btup = 2;
int btdown = 3;
int btok = 4;
int btset = 5;
int frek = 20;
int waktu = 10;
int btupx, btdownx, btsetx, btokx;
int nilaifrek, nilaiwaktu;
int detik;
void setup()
{
lcd.begin(16,2);
lcd.clear();
lcd.noCursor();
//initialize all timers except for 0, to save time keeping functions
InitTimersSafe();
// Serial.begin(9600);
//sets the frequency for the specified pin
bool success = SetPinFrequencySafe(led, frequency);
//if the pin frequency was set successfully, turn pin 13 on
if(success) {
}
pinMode(btup,INPUT_PULLUP);
pinMode(btdown,INPUT_PULLUP);
pinMode(btok,INPUT_PULLUP);
pinMode(btset,INPUT_PULLUP);
pwmWrite(led, duty);
}
void loop()
{
btupx = digitalRead(btup);
btdownx = digitalRead(btdown);
btokx = digitalRead(btok);
btsetx = digitalRead(btset);
lcd.setCursor(0,0);
lcd.print("E STIMULATOR");
lcd.setCursor(0,1);
lcd.print("SET");
pwmWrite(led, 0);
if(btsetx == LOW){
delay(200);
lcd.clear();
setfrek();
delay(1000);
lcd.clear();
settime();
delay(1000);
lcd.clear();
mulai();
}
}
void setfrek(){
btupx = digitalRead(btup);
btdownx = digitalRead(btdown);
btokx = digitalRead(btok);
btsetx = digitalRead(btset);
lcd.setCursor(0,0);
lcd.print("PILIH FREK ");
lcd.setCursor(0,1);
lcd.print(frek);
lcd.print(" ");
if(frek < 20){
frek = 20;
}
if(frek > 50){
frek = 50;
}
if(btupx == LOW){
delay(200);
frek++;
}
if(btdownx == LOW){
delay(200);
frek--;
}
if(btokx == LOW){
delay(200);
nilaifrek = frek;
return;
}
setfrek();
}
void settime(){
btupx = digitalRead(btup);
btdownx = digitalRead(btdown);
btokx = digitalRead(btok);
btsetx = digitalRead(btset);
lcd.setCursor(0,0);
lcd.print("PILIH WAKTU ");
lcd.setCursor(0,1);
lcd.print(waktu);
lcd.print(" ");
if(waktu < 10){
waktu = 10;
}
if(waktu > 15){
waktu = 15;
}
if(btupx == LOW){
delay(200);
waktu++;
}
if(btdownx == LOW){
delay(200);
waktu--;
}
if(btokx == LOW){
delay(200);
nilaiwaktu = waktu;
return;
}
settime();
}
void mulai(){
lcd.setCursor(0,0);
lcd.print("FREK= ");
lcd.print(nilaifrek);
lcd.setCursor(0,1);
lcd.print(nilaiwaktu);
lcd.print(" : ");
lcd.print(detik);
lcd.print(" ");
detik--;
if((nilaiwaktu < 1)&&(detik < 1)){
delay(1000);
nilaiwaktu = 0;
detik = 0;
lcd.clear();
return;
}
if(detik < 1){
nilaiwaktu--;
detik = 59;
}
InitTimersSafe();
// Serial.begin(9600);
//sets the frequency for the specified pin
bool success = SetPinFrequencySafe(led, nilaifrek);
pwmWrite(led, duty);
delay(1000);
mulai();
}
d. VIDEO HASILNYA
No comments:
Post a Comment