SlideShare a Scribd company logo
#include <Stepper.h>
#include<LiquidCrystal.h>
int tlPin = A0; //set variables for analog inputs
int trPin = A1;
int blPin = A2;
int brPin = A3;
int brValue = 0; //assigning variables to the values coming in from pins
int blValue = 0;
int tlValue = 0;
int trValue = 0;
int avgl = 0; //averaging of sum**** values
int avgr = 0;
int avgt = 0;
int avgb = 0;
bool up = false;//bool variables for motor operation
bool down =false;
bool left=false;
bool right = false;
int limit = 30; //setting variable for +/- limit to prevent back and forth movement
const int stepsPerRev=200;
Stepper TLstep (stepsPerRev, 50,51,52,53);//designating 4 motor connections
Stepper TRstep (stepsPerRev, 49,46,48,47);
Stepper BRstep (stepsPerRev, 38,39,40,41);
Stepper BLstep (stepsPerRev, 24,25,26,27);
const int rs = 32, en = 33, d4 = 34, d5 = 35, d6 = 36, d7 = 37;//mapping display pins
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
int step1=1;//setting step amount for each motor, simulates moving at the same time
void setup() {
lcd.begin(20, 4);
Serial.begin(9600);
}
void loop()
{
tlValue = analogRead(tlPin); //assigning values to the input from pins
trValue = analogRead(trPin);
blValue = analogRead(blPin);
brValue = analogRead(brPin);
avgt = (tlValue+trValue)/2; //averaging the values to get smoother movement
avgl = (tlValue+blValue)/2;
avgb = (blValue+brValue)/2;
avgr = (brValue+trValue)/2;
if (avgt > avgb){up = true;}
else up=false;
if (up==true){
TLstep.step(step1);
TRstep.step(-step1);
delay(2);
}
if (avgt<avgb+limit) {down=true;}
else down=false;
if (down==true){
TLstep.step(-step1);
TRstep.step(step1);
delay(2);
}
if(avgl>avgr-limit) {left=true;}
else left=false;
if (left==true){
BRstep.step(step1);
BLstep.step(-step1);
delay(2);
}
if(avgl<avgr+limit) {right=true;}
else right=false;
if(right==true){
BRstep.step(-step1);
BLstep.step(step1);
delay(2);
}
Serial.println("New Line");
Serial.println(avgl);
Serial.println(avgr);
Serial.println(avgt);
Serial.println(avgb);
lcd.setCursor(0,0); //start of display code
lcd.print("Top ");
lcd.print(avgt);
lcd.setCursor(0,1);
lcd.print("Left ");
lcd.print(avgl);
lcd.setCursor(0,2);
lcd.print("Right ");
lcd.print(avgr);
lcd.setCursor(0,3);
lcd.print("Bottom ");
lcd.print(avgb);
}

More Related Content

What's hot (16)

5 1. character processing
5 1. character processing5 1. character processing
5 1. character processing
웅식 전
 
Things to avoid in JavaScript
Things to avoid in JavaScriptThings to avoid in JavaScript
Things to avoid in JavaScript
Brian Moschel
 
Day4 順序控制的循序邏輯實現
Day4 順序控制的循序邏輯實現Day4 順序控制的循序邏輯實現
Day4 順序控制的循序邏輯實現
Ron Liu
 
Infix to-postfix examples
Infix to-postfix examplesInfix to-postfix examples
Infix to-postfix examples
mua99
 
Chp2 introduction to the 68000 microprocessor copy
Chp2 introduction to the 68000 microprocessor   copyChp2 introduction to the 68000 microprocessor   copy
Chp2 introduction to the 68000 microprocessor copy
mkazree
 
Circular queues
Circular queuesCircular queues
Circular queues
Ssankett Negi
 
Simple sensor-network
Simple sensor-networkSimple sensor-network
Simple sensor-network
Jaime Moreno
 
Vcs15
Vcs15Vcs15
Vcs15
Malikireddy Bramhananda Reddy
 
Lecture 3 c++
Lecture 3 c++Lecture 3 c++
Lecture 3 c++
emailharmeet
 
9. pointer, pointer & function
9. pointer, pointer & function9. pointer, pointer & function
9. pointer, pointer & function
웅식 전
 
Controlling Motors for Robot
Controlling Motors for RobotControlling Motors for Robot
Controlling Motors for Robot
Varad Manglekar
 
Fpga 09-behavioral-modeling-moore-machine
Fpga 09-behavioral-modeling-moore-machineFpga 09-behavioral-modeling-moore-machine
Fpga 09-behavioral-modeling-moore-machine
Malik Tauqir Hasan
 
Codigo fuente
Codigo fuenteCodigo fuente
Codigo fuente
BlackD10
 
JavaScript WTFs
JavaScript WTFsJavaScript WTFs
JavaScript WTFs
pigulla
 
Recursion
RecursionRecursion
Recursion
Nikxjon
 
C Programming Language Part 7
C Programming Language Part 7C Programming Language Part 7
C Programming Language Part 7
Rumman Ansari
 
5 1. character processing
5 1. character processing5 1. character processing
5 1. character processing
웅식 전
 
Things to avoid in JavaScript
Things to avoid in JavaScriptThings to avoid in JavaScript
Things to avoid in JavaScript
Brian Moschel
 
Day4 順序控制的循序邏輯實現
Day4 順序控制的循序邏輯實現Day4 順序控制的循序邏輯實現
Day4 順序控制的循序邏輯實現
Ron Liu
 
Infix to-postfix examples
Infix to-postfix examplesInfix to-postfix examples
Infix to-postfix examples
mua99
 
Chp2 introduction to the 68000 microprocessor copy
Chp2 introduction to the 68000 microprocessor   copyChp2 introduction to the 68000 microprocessor   copy
Chp2 introduction to the 68000 microprocessor copy
mkazree
 
Simple sensor-network
Simple sensor-networkSimple sensor-network
Simple sensor-network
Jaime Moreno
 
9. pointer, pointer & function
9. pointer, pointer & function9. pointer, pointer & function
9. pointer, pointer & function
웅식 전
 
Controlling Motors for Robot
Controlling Motors for RobotControlling Motors for Robot
Controlling Motors for Robot
Varad Manglekar
 
Fpga 09-behavioral-modeling-moore-machine
Fpga 09-behavioral-modeling-moore-machineFpga 09-behavioral-modeling-moore-machine
Fpga 09-behavioral-modeling-moore-machine
Malik Tauqir Hasan
 
Codigo fuente
Codigo fuenteCodigo fuente
Codigo fuente
BlackD10
 
JavaScript WTFs
JavaScript WTFsJavaScript WTFs
JavaScript WTFs
pigulla
 
Recursion
RecursionRecursion
Recursion
Nikxjon
 
C Programming Language Part 7
C Programming Language Part 7C Programming Language Part 7
C Programming Language Part 7
Rumman Ansari
 

Similar to Arduino light tracking code with 4 stepper motors (20)

Density Based Traffic System with emergency override Project Code
Density Based Traffic System with emergency override Project CodeDensity Based Traffic System with emergency override Project Code
Density Based Traffic System with emergency override Project Code
Chull Productions
 
arduino
arduinoarduino
arduino
Awopetu Oluwaseyi A.
 
Arduino and Robotics
Arduino and RoboticsArduino and Robotics
Arduino and Robotics
Mebin P M
 
Report - Line Following Robot
Report - Line Following RobotReport - Line Following Robot
Report - Line Following Robot
Divay Khatri
 
Lab Activity 3
Lab Activity 3Lab Activity 3
Lab Activity 3
Dwight Sabio
 
OpenBot-Code
OpenBot-CodeOpenBot-Code
OpenBot-Code
Anshuman Dhar
 
Applications of microcontroller(8051)
Applications of microcontroller(8051) Applications of microcontroller(8051)
Applications of microcontroller(8051)
vijaydeepakg
 
Open bot
Open bot Open bot
Open bot
Anshuman Dhar
 
Unit iv microcontrollers final
Unit iv microcontrollers finalUnit iv microcontrollers final
Unit iv microcontrollers final
SARITHA REDDY
 
Arduino: Arduino lcd
Arduino: Arduino lcdArduino: Arduino lcd
Arduino: Arduino lcd
SANTIAGO PABLO ALBERTO
 
Stepper Motor Control System
Stepper Motor Control SystemStepper Motor Control System
Stepper Motor Control System
Wanita Long
 
Arduino Code
Arduino CodeArduino Code
Arduino Code
shohanulislam5
 
PIC and LCD
PIC and LCDPIC and LCD
PIC and LCD
hairilfaiz86
 
Session 9 Stepper Motor Interfacing.pptx
Session 9 Stepper Motor Interfacing.pptxSession 9 Stepper Motor Interfacing.pptx
Session 9 Stepper Motor Interfacing.pptx
JaSa18
 
Howto Design a Stepper Motor System Using an 8-bit Freescale microcontroller ...
Howto Design a Stepper Motor System Using an 8-bit Freescale microcontroller ...Howto Design a Stepper Motor System Using an 8-bit Freescale microcontroller ...
Howto Design a Stepper Motor System Using an 8-bit Freescale microcontroller ...
Ionela
 
Topviewsimulator
TopviewsimulatorTopviewsimulator
Topviewsimulator
Rashmi
 
Motordrive
MotordriveMotordrive
Motordrive
Mahdi Babaei
 
22 microcontroller programs
22 microcontroller programs22 microcontroller programs
22 microcontroller programs
babak danyal
 
Experiment 16 x2 parallel lcd
Experiment   16 x2 parallel lcdExperiment   16 x2 parallel lcd
Experiment 16 x2 parallel lcd
Prashanta Chowdhury
 
Temperature Sensor with LED matrix Display BY ►iRFAN QADOOS◄ 9
Temperature Sensor with LED matrix Display BY ►iRFAN QADOOS◄ 9Temperature Sensor with LED matrix Display BY ►iRFAN QADOOS◄ 9
Temperature Sensor with LED matrix Display BY ►iRFAN QADOOS◄ 9
Irfan Qadoos
 
Density Based Traffic System with emergency override Project Code
Density Based Traffic System with emergency override Project CodeDensity Based Traffic System with emergency override Project Code
Density Based Traffic System with emergency override Project Code
Chull Productions
 
Arduino and Robotics
Arduino and RoboticsArduino and Robotics
Arduino and Robotics
Mebin P M
 
Report - Line Following Robot
Report - Line Following RobotReport - Line Following Robot
Report - Line Following Robot
Divay Khatri
 
Applications of microcontroller(8051)
Applications of microcontroller(8051) Applications of microcontroller(8051)
Applications of microcontroller(8051)
vijaydeepakg
 
Unit iv microcontrollers final
Unit iv microcontrollers finalUnit iv microcontrollers final
Unit iv microcontrollers final
SARITHA REDDY
 
Stepper Motor Control System
Stepper Motor Control SystemStepper Motor Control System
Stepper Motor Control System
Wanita Long
 
Session 9 Stepper Motor Interfacing.pptx
Session 9 Stepper Motor Interfacing.pptxSession 9 Stepper Motor Interfacing.pptx
Session 9 Stepper Motor Interfacing.pptx
JaSa18
 
Howto Design a Stepper Motor System Using an 8-bit Freescale microcontroller ...
Howto Design a Stepper Motor System Using an 8-bit Freescale microcontroller ...Howto Design a Stepper Motor System Using an 8-bit Freescale microcontroller ...
Howto Design a Stepper Motor System Using an 8-bit Freescale microcontroller ...
Ionela
 
Topviewsimulator
TopviewsimulatorTopviewsimulator
Topviewsimulator
Rashmi
 
22 microcontroller programs
22 microcontroller programs22 microcontroller programs
22 microcontroller programs
babak danyal
 
Temperature Sensor with LED matrix Display BY ►iRFAN QADOOS◄ 9
Temperature Sensor with LED matrix Display BY ►iRFAN QADOOS◄ 9Temperature Sensor with LED matrix Display BY ►iRFAN QADOOS◄ 9
Temperature Sensor with LED matrix Display BY ►iRFAN QADOOS◄ 9
Irfan Qadoos
 

Recently uploaded (20)

Design of a Hand Rehabilitation Device for Post-Stroke Patients..pptx
Design of a Hand Rehabilitation Device for Post-Stroke Patients..pptxDesign of a Hand Rehabilitation Device for Post-Stroke Patients..pptx
Design of a Hand Rehabilitation Device for Post-Stroke Patients..pptx
younisalsadah
 
1. Mix Design M20 CT.pdf for M20 Grade mix design
1. Mix Design M20 CT.pdf for M20 Grade mix design1. Mix Design M20 CT.pdf for M20 Grade mix design
1. Mix Design M20 CT.pdf for M20 Grade mix design
smghumare
 
DIGITAL ELECTRONICS: UNIT-III SYNCHRONOUS SEQUENTIAL CIRCUITS
DIGITAL ELECTRONICS: UNIT-III SYNCHRONOUS SEQUENTIAL CIRCUITSDIGITAL ELECTRONICS: UNIT-III SYNCHRONOUS SEQUENTIAL CIRCUITS
DIGITAL ELECTRONICS: UNIT-III SYNCHRONOUS SEQUENTIAL CIRCUITS
Sridhar191373
 
Fresh concrete Workability Measurement
Fresh concrete  Workability  MeasurementFresh concrete  Workability  Measurement
Fresh concrete Workability Measurement
SasiVarman5
 
Air Filter Flat Sheet Media-Catalouge-Final.pdf
Air Filter Flat Sheet Media-Catalouge-Final.pdfAir Filter Flat Sheet Media-Catalouge-Final.pdf
Air Filter Flat Sheet Media-Catalouge-Final.pdf
FILTRATION ENGINEERING & CUNSULTANT
 
Tesia Dobrydnia - A Leader In Her Industry
Tesia Dobrydnia - A Leader In Her IndustryTesia Dobrydnia - A Leader In Her Industry
Tesia Dobrydnia - A Leader In Her Industry
Tesia Dobrydnia
 
Department of Environment (DOE) Mix Design with Fly Ash.
Department of Environment (DOE) Mix Design with Fly Ash.Department of Environment (DOE) Mix Design with Fly Ash.
Department of Environment (DOE) Mix Design with Fly Ash.
MdManikurRahman
 
Unit 6 Message Digest Message Digest Message Digest
Unit 6  Message Digest  Message Digest  Message DigestUnit 6  Message Digest  Message Digest  Message Digest
Unit 6 Message Digest Message Digest Message Digest
ChatanBawankar
 
"The Enigmas of the Riemann Hypothesis" by Julio Chai
"The Enigmas of the Riemann Hypothesis" by Julio Chai"The Enigmas of the Riemann Hypothesis" by Julio Chai
"The Enigmas of the Riemann Hypothesis" by Julio Chai
Julio Chai
 
Structural Health and Factors affecting.pptx
Structural Health and Factors affecting.pptxStructural Health and Factors affecting.pptx
Structural Health and Factors affecting.pptx
gunjalsachin
 
ISO 5011 Air Filter Catalogues .pdf
ISO 5011 Air Filter Catalogues      .pdfISO 5011 Air Filter Catalogues      .pdf
ISO 5011 Air Filter Catalogues .pdf
FILTRATION ENGINEERING & CUNSULTANT
 
Introduction of Structural Audit and Health Montoring.pptx
Introduction of Structural Audit and Health Montoring.pptxIntroduction of Structural Audit and Health Montoring.pptx
Introduction of Structural Audit and Health Montoring.pptx
gunjalsachin
 
Forensic Science – Digital Forensics – Digital Evidence – The Digital Forensi...
Forensic Science – Digital Forensics – Digital Evidence – The Digital Forensi...Forensic Science – Digital Forensics – Digital Evidence – The Digital Forensi...
Forensic Science – Digital Forensics – Digital Evidence – The Digital Forensi...
ManiMaran230751
 
Filters for Electromagnetic Compatibility Applications
Filters for Electromagnetic Compatibility ApplicationsFilters for Electromagnetic Compatibility Applications
Filters for Electromagnetic Compatibility Applications
Mathias Magdowski
 
ISO 4020-6.1- Filter Cleanliness Test Rig Catalogue.pdf
ISO 4020-6.1- Filter Cleanliness Test Rig Catalogue.pdfISO 4020-6.1- Filter Cleanliness Test Rig Catalogue.pdf
ISO 4020-6.1- Filter Cleanliness Test Rig Catalogue.pdf
FILTRATION ENGINEERING & CUNSULTANT
 
ENERGY STORING DEVICES-Primary Battery.pdf
ENERGY STORING DEVICES-Primary Battery.pdfENERGY STORING DEVICES-Primary Battery.pdf
ENERGY STORING DEVICES-Primary Battery.pdf
TAMILISAI R
 
world subdivision.pdf...................
world subdivision.pdf...................world subdivision.pdf...................
world subdivision.pdf...................
bmmederos10
 
world subdivision.pdf...................
world subdivision.pdf...................world subdivision.pdf...................
world subdivision.pdf...................
bmmederos12
 
Silent-Aire Quality Orientation - OFCI_GC - EVAP Unit REV2.pdf
Silent-Aire Quality Orientation - OFCI_GC - EVAP Unit REV2.pdfSilent-Aire Quality Orientation - OFCI_GC - EVAP Unit REV2.pdf
Silent-Aire Quality Orientation - OFCI_GC - EVAP Unit REV2.pdf
EfrainGarrilloRuiz1
 
Design of a Hand Rehabilitation Device for Post-Stroke Patients..pptx
Design of a Hand Rehabilitation Device for Post-Stroke Patients..pptxDesign of a Hand Rehabilitation Device for Post-Stroke Patients..pptx
Design of a Hand Rehabilitation Device for Post-Stroke Patients..pptx
younisalsadah
 
1. Mix Design M20 CT.pdf for M20 Grade mix design
1. Mix Design M20 CT.pdf for M20 Grade mix design1. Mix Design M20 CT.pdf for M20 Grade mix design
1. Mix Design M20 CT.pdf for M20 Grade mix design
smghumare
 
DIGITAL ELECTRONICS: UNIT-III SYNCHRONOUS SEQUENTIAL CIRCUITS
DIGITAL ELECTRONICS: UNIT-III SYNCHRONOUS SEQUENTIAL CIRCUITSDIGITAL ELECTRONICS: UNIT-III SYNCHRONOUS SEQUENTIAL CIRCUITS
DIGITAL ELECTRONICS: UNIT-III SYNCHRONOUS SEQUENTIAL CIRCUITS
Sridhar191373
 
Fresh concrete Workability Measurement
Fresh concrete  Workability  MeasurementFresh concrete  Workability  Measurement
Fresh concrete Workability Measurement
SasiVarman5
 
Tesia Dobrydnia - A Leader In Her Industry
Tesia Dobrydnia - A Leader In Her IndustryTesia Dobrydnia - A Leader In Her Industry
Tesia Dobrydnia - A Leader In Her Industry
Tesia Dobrydnia
 
Department of Environment (DOE) Mix Design with Fly Ash.
Department of Environment (DOE) Mix Design with Fly Ash.Department of Environment (DOE) Mix Design with Fly Ash.
Department of Environment (DOE) Mix Design with Fly Ash.
MdManikurRahman
 
Unit 6 Message Digest Message Digest Message Digest
Unit 6  Message Digest  Message Digest  Message DigestUnit 6  Message Digest  Message Digest  Message Digest
Unit 6 Message Digest Message Digest Message Digest
ChatanBawankar
 
"The Enigmas of the Riemann Hypothesis" by Julio Chai
"The Enigmas of the Riemann Hypothesis" by Julio Chai"The Enigmas of the Riemann Hypothesis" by Julio Chai
"The Enigmas of the Riemann Hypothesis" by Julio Chai
Julio Chai
 
Structural Health and Factors affecting.pptx
Structural Health and Factors affecting.pptxStructural Health and Factors affecting.pptx
Structural Health and Factors affecting.pptx
gunjalsachin
 
Introduction of Structural Audit and Health Montoring.pptx
Introduction of Structural Audit and Health Montoring.pptxIntroduction of Structural Audit and Health Montoring.pptx
Introduction of Structural Audit and Health Montoring.pptx
gunjalsachin
 
Forensic Science – Digital Forensics – Digital Evidence – The Digital Forensi...
Forensic Science – Digital Forensics – Digital Evidence – The Digital Forensi...Forensic Science – Digital Forensics – Digital Evidence – The Digital Forensi...
Forensic Science – Digital Forensics – Digital Evidence – The Digital Forensi...
ManiMaran230751
 
Filters for Electromagnetic Compatibility Applications
Filters for Electromagnetic Compatibility ApplicationsFilters for Electromagnetic Compatibility Applications
Filters for Electromagnetic Compatibility Applications
Mathias Magdowski
 
ENERGY STORING DEVICES-Primary Battery.pdf
ENERGY STORING DEVICES-Primary Battery.pdfENERGY STORING DEVICES-Primary Battery.pdf
ENERGY STORING DEVICES-Primary Battery.pdf
TAMILISAI R
 
world subdivision.pdf...................
world subdivision.pdf...................world subdivision.pdf...................
world subdivision.pdf...................
bmmederos10
 
world subdivision.pdf...................
world subdivision.pdf...................world subdivision.pdf...................
world subdivision.pdf...................
bmmederos12
 
Silent-Aire Quality Orientation - OFCI_GC - EVAP Unit REV2.pdf
Silent-Aire Quality Orientation - OFCI_GC - EVAP Unit REV2.pdfSilent-Aire Quality Orientation - OFCI_GC - EVAP Unit REV2.pdf
Silent-Aire Quality Orientation - OFCI_GC - EVAP Unit REV2.pdf
EfrainGarrilloRuiz1
 

Arduino light tracking code with 4 stepper motors

  • 1. #include <Stepper.h> #include<LiquidCrystal.h> int tlPin = A0; //set variables for analog inputs int trPin = A1; int blPin = A2; int brPin = A3; int brValue = 0; //assigning variables to the values coming in from pins int blValue = 0; int tlValue = 0; int trValue = 0; int avgl = 0; //averaging of sum**** values int avgr = 0; int avgt = 0; int avgb = 0; bool up = false;//bool variables for motor operation bool down =false; bool left=false; bool right = false;
  • 2. int limit = 30; //setting variable for +/- limit to prevent back and forth movement const int stepsPerRev=200; Stepper TLstep (stepsPerRev, 50,51,52,53);//designating 4 motor connections Stepper TRstep (stepsPerRev, 49,46,48,47); Stepper BRstep (stepsPerRev, 38,39,40,41); Stepper BLstep (stepsPerRev, 24,25,26,27); const int rs = 32, en = 33, d4 = 34, d5 = 35, d6 = 36, d7 = 37;//mapping display pins LiquidCrystal lcd(rs, en, d4, d5, d6, d7); int step1=1;//setting step amount for each motor, simulates moving at the same time void setup() { lcd.begin(20, 4); Serial.begin(9600); } void loop() { tlValue = analogRead(tlPin); //assigning values to the input from pins trValue = analogRead(trPin);
  • 3. blValue = analogRead(blPin); brValue = analogRead(brPin); avgt = (tlValue+trValue)/2; //averaging the values to get smoother movement avgl = (tlValue+blValue)/2; avgb = (blValue+brValue)/2; avgr = (brValue+trValue)/2; if (avgt > avgb){up = true;} else up=false; if (up==true){ TLstep.step(step1); TRstep.step(-step1); delay(2); } if (avgt<avgb+limit) {down=true;} else down=false; if (down==true){ TLstep.step(-step1); TRstep.step(step1);
  • 4. delay(2); } if(avgl>avgr-limit) {left=true;} else left=false; if (left==true){ BRstep.step(step1); BLstep.step(-step1); delay(2); } if(avgl<avgr+limit) {right=true;} else right=false; if(right==true){ BRstep.step(-step1); BLstep.step(step1); delay(2); } Serial.println("New Line"); Serial.println(avgl);
  • 5. Serial.println(avgr); Serial.println(avgt); Serial.println(avgb); lcd.setCursor(0,0); //start of display code lcd.print("Top "); lcd.print(avgt); lcd.setCursor(0,1); lcd.print("Left "); lcd.print(avgl); lcd.setCursor(0,2); lcd.print("Right "); lcd.print(avgr); lcd.setCursor(0,3); lcd.print("Bottom "); lcd.print(avgb); }