0% found this document useful (0 votes)
34 views12 pages

Lamp Iran

Nurul Widia Fatmawati is a student born in Semarang, Indonesia on August 4, 1997. She attended elementary, junior high, and vocational high school in Semarang. The document includes code for an Arduino program that controls a stepper motor and LCD display based on sensor input and button presses. It allows setting motor speed, angle limits, and run time.

Uploaded by

Naufal Jokam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views12 pages

Lamp Iran

Nurul Widia Fatmawati is a student born in Semarang, Indonesia on August 4, 1997. She attended elementary, junior high, and vocational high school in Semarang. The document includes code for an Arduino program that controls a stepper motor and LCD display based on sensor input and button presses. It allows setting motor speed, angle limits, and run time.

Uploaded by

Naufal Jokam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

BIO DATA PENULIS

PROFIL PENULIS

Nama : Nurul Widia Fatmawati


NIM : 019 16 076
Tempat, Tanggal Lahir : Semarang, 4 Agustus 1997
Alamat : Jl. Batursari VII RT 05 RW 06, Semarang
Hp : 089659692205
Riwayat Pendidikan : SDN Sawah Besar 02 Semarang
SMPN 38 Semarang
SMK Farmasi Yayasan Pharmasi Semarang
LISTING PROGRAM
PROGRAM ALAT

#include <Arduino.h>

// Motor steps per revolution. Most steppers are 200 steps or 1.8 degrees/step
#define MOTOR_STEPS 742
#define RPM 10

#define DIR 2
#define STEP 3
//#define SLEEP 13 // optional (just delete SLEEP from everywhere if not
used)

#include "A4988.h"
#define MS1 5
#define MS2 6
#define MS3 7
A4988 stepper(MOTOR_STEPS, DIR, STEP, MS1, MS2, MS3);

// #include "BasicStepperDriver.h" // generic


// BasicStepperDriver stepper(DIR, STEP);
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27 for a 16


chars and 2 line display
#define sw1 9
#define sw2 10
#define sw3 11
#define buz 8
void beep(){
digitalWrite(buz,HIGH);delay(50);
digitalWrite(buz,LOW);
}
void setup() {
pinMode(sw1,INPUT_PULLUP);
pinMode(sw2,INPUT_PULLUP);
pinMode(sw3,INPUT_PULLUP);
pinMode(buz,OUTPUT);
beep();
lcd.init(); // initialize the lcd
lcd.init();
lcd.backlight();

stepper.enable();
stepper.begin(80);
zero();
beep();

}
long baca_sensor(){
long jum=0,degre;
for(int g=0;g<100;g++){
jum=jum+analogRead(0);
}
jum=jum/100;
degre=map(jum,36,652,15,180);
return degre;
}
int hit=0;
int sudut_max=15,kec=30,timer=1;
int sudut_min=15,sudut;
signed int menit=0,detik=0;
void setting(){
beep();
while(digitalRead(sw1)==LOW){delay(500);}
while(digitalRead(sw1)==HIGH){
lcd.clear();
lcd.setCursor(0,0);
lcd.print("PENGATURAN");
if (digitalRead(sw2)==LOW){beep();sudut_max++;if
(sudut_max>100){sudut_max=100;}}
if (digitalRead(sw3)==LOW){beep();sudut_max--;if
(sudut_max<15){sudut_max=15;}}
lcd.setCursor(0,1);
lcd.print("Sudut Max: ");
lcd.print(sudut_max);
lcd.print(char(0xDF));
delay(200);
}
beep();
while(digitalRead(sw1)==LOW){delay(500);}
while(digitalRead(sw1)==HIGH){
lcd.clear();
lcd.setCursor(0,0);
lcd.print("PENGATURAN");
if (digitalRead(sw2)==LOW){beep();kec+=30;if (kec>100){kec=150;}}
if (digitalRead(sw3)==LOW){beep();kec-=30;if (kec<30){kec=30;}}
lcd.setCursor(0,1);
lcd.print("Kec: ");
lcd.print(kec);
lcd.print(char(0xDF));
lcd.print("/Mnt");
delay(200);
}
beep();
while(digitalRead(sw1)==LOW){delay(500);}
while(digitalRead(sw1)==HIGH){
lcd.clear();
lcd.setCursor(0,0);
lcd.print("PENGATURAN");
if (digitalRead(sw2)==LOW){beep();timer++;if (timer>120){timer=120;}}
if (digitalRead(sw3)==LOW){beep();timer--;if (timer<1){timer=1;}}
lcd.setCursor(0,1);
lcd.print("Timer: ");
lcd.print(timer);
lcd.print(" Menit");
delay(200);
}
beep();
}
void zero(){
long deg=0;
deg=baca_sensor();
while(deg>15){
deg=baca_sensor();
stepper.setMicrostep(8);
stepper.move(-200);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("ZEROING");
lcd.setCursor(0,1);
lcd.print("DEGREE: ");
lcd.print(deg);
}
}

void tampil(){
char buff[16];
sudut=baca_sensor();
sprintf(buff,"TIMER: %02d:%02d ",menit,detik);
lcd.clear();
lcd.setCursor(0,0);
lcd.print(buff);
lcd.setCursor(0,1);
sprintf(buff,"KEC:%03d DEG:%03d",kec,sudut);
lcd.print(buff);
}

bool flag=false;
void run(){

int vel=map(kec,30,150,20,80);
stepper.begin(vel);
while(flag==false){
while(sudut<sudut_max && flag==false){
stepper.setMicrostep(8);
stepper.move(300);
tampil();
}
while(sudut>sudut_min && flag==false){
stepper.setMicrostep(8);
stepper.move(-300);
tampil();
}
}
}
#include <TimerOne.h>
void tim(){
detik--;
if (detik<0){
detik=59;
menit--;
}
if (detik==0&&menit==0){
flag=true;

}
void loop() {
setting();

if (timer>0){menit=timer-1;detik=59;}
flag=false;
Timer1.initialize(1000000);
Timer1.attachInterrupt(tim); // blinkLED to run every 0.15 seconds
run();
Timer1.detachInterrupt();
digitalWrite(STEP,LOW);
detik=0;tampil();
beep();
while(digitalRead(sw1)==HIGH){tampil();}
beep();
zero();beep();
}
DATASHEET

You might also like