Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
Makertronics
Published © CC BY

Automatic Photo Capturing Turntable with MicroBit

An automatic turntable to assist in capturing images of your product from all the directions.

BeginnerFull instructions provided3 hours1,475

Things used in this project

Hardware components

BBC micro:bit board
BBC micro:bit board
×1
BBC Breadboard Adapter
×1
Stepper Motor, Power Step
Stepper Motor, Power Step
NEMA17 Stepper Motor
×1
A4988 stepper driver
×1
Omron Electronic Components LLC Power Swtich
×1
General Purpose Transistor PNP
General Purpose Transistor PNP
×1
Buzzer
Buzzer
×1
Rotary potentiometer (generic)
Rotary potentiometer (generic)
×1
Texas Instruments lm11173.3 Regulator
×1

Software apps and online services

GNAT Community
AdaCore GNAT Community
AdaCore ADA Core Micro Bit Library

Hand tools and fabrication machines

3D Printer (generic)
3D Printer (generic)

Story

Read more

Custom parts and enclosures

MicroBit Adapter Attachment

BBC MicroBit to BreadBoard adapter is fitted on this.

Circuit Enclosure

This part will cover the circuit and will be mounted on any board/ plywood near the stepper motor

Potentiometer Knob

In case you are using the same potentiometer, you can also 3D print the knob with it.

Stepper Motor Coupler/attachment for turn plate

your rotating turnplate will be mounted on the stepper motor using this coupler, It is designed for a round 5mm NEMA 17 shaft.

Schematics

Circuit Schematic

Code

ADA code for automatic Turntable

ADA
with MicroBit.IOs;
with MicroBit.Buttons; use MicroBit.Buttons;
with MicroBit.Display;
with MicroBit.Time;
with HAL;

procedure Main is
   --mod_Int is a data type with range 0,1 and further numbers will be modulus by 2
   type mod_Int is mod 2;

   stepPin : constant MicroBit.IOs.Pin_Id := 0;
   dirPin : constant MicroBit.IOs.Pin_Id := 1;
   potPin : constant MicroBit.IOs.Pin_Id := 2;
   buzzPin : constant MicroBit.IOs.Pin_Id := 19;
   cameraTriggerPin : constant MicroBit.IOs.Pin_Id := 20;
   potValue : MicroBit.IOs.Analog_Value := 0;
   lastPotValue : MicroBit.IOs.Analog_Value := 0;
   steps : Integer;
   imgNum : Integer ;
   mode : mod_Int := 0 ;

   --totalSteps : constant Integer := 200; --in full stpes stepping mode
   --totalSteps : constant Integer := 400; --in half steps stepping mode
   totalSteps : constant Integer := 800; --in quater steps stepping mode;
   --totalSteps : constant Integer := 1600; --in 1/8th steps stepping mode
   --totalSteps : constant Integer := 3200; --in 1/16th steps stepping mode
   

   procedure moveSteps(stp : Integer) is
      d : Integer := 25;
   begin
      if stp<0 then
         MicroBit.IOs.Set(dirPin,True);
      else
         MicroBit.IOs.Set(dirPin,False);
      end if;

      if abs(stp) <= 41 then
         for i in 1..abs(stp/2) loop
            MicroBit.IOs.Set(stepPin,False);
            MicroBit.Time.Delay_Ms (1);
            MicroBit.IOs.Set(stepPin,True);
            MicroBit.Time.Delay_Ms (HAL.UInt64(d));
            d := d-1;
         end loop;
         for i in 1..abs(stp/2) loop
            MicroBit.IOs.Set(stepPin,False);
            MicroBit.Time.Delay_Ms (1);
            MicroBit.IOs.Set(stepPin,True);
            MicroBit.Time.Delay_Ms (HAL.UInt64(d));
            d := d+1;
         end loop;
      else
         for i in 1..20 loop
            MicroBit.IOs.Set(stepPin,False);
            MicroBit.Time.Delay_Ms (1);
            MicroBit.IOs.Set(stepPin,True);
            MicroBit.Time.Delay_Ms (HAL.UInt64(d));
            d := d-1;
         end loop;

         for i in 1..abs(stp)-40 loop
            MicroBit.IOs.Set(stepPin,False);
            MicroBit.Time.Delay_Ms (1);
            MicroBit.IOs.Set(stepPin,True);
            MicroBit.Time.Delay_Ms (HAL.UInt64(d));
         end loop;

         for i in 1..20 loop
            MicroBit.IOs.Set(stepPin,False);
            MicroBit.Time.Delay_Ms (1);
            MicroBit.IOs.Set(stepPin,True);
            MicroBit.Time.Delay_Ms (HAL.UInt64(d));
            d := d+1;
         end loop;
      end if;
   end moveSteps;

   
   procedure moveSteps_2(stp : Integer) is
   begin
      if stp<0 then
         MicroBit.IOs.Set(dirPin,True);
      else
         MicroBit.IOs.Set(dirPin,False);
      end if;
      for i in 1..abs(stp) loop
            MicroBit.IOs.Set(stepPin,False);
            MicroBit.Time.Delay_Ms (1);
            MicroBit.IOs.Set(stepPin,True);
            MicroBit.Time.Delay_Ms (15);
      end loop;
   end moveSteps_2;
   
   
   procedure buzz(i : Integer) is
   begin
      for m in 1..i loop
         MicroBit.IOs.Set(buzzPin,True);
         MicroBit.Time.Delay_Ms (100);
         MicroBit.IOs.Set(buzzPin,False);
         MicroBit.Time.Delay_Ms (100);
      end loop;
   end buzz;

   procedure click is
   begin
      MicroBit.IOs.Set(cameraTriggerPin,False);
      MicroBit.Time.Delay_Ms (150);
      MicroBit.IOs.Set(cameraTriggerPin,True);
      MicroBit.Time.Delay_Ms (2000);
   end click;

   function minMax (num : Integer; min: Integer ; max : Integer) return Integer is
      x : Integer := num;
   begin
      if num < min then
         x := min;
      elsif num > max then
         x := max;
      end if;
      return x;
   end minMax;

   function map (num : Integer; fromMin : Integer ; fromMax : Integer ; toMin : Integer ; toMax : Integer)
                 return Integer is
   x : Integer;
   begin
      x := Integer(Float(toMax - toMin)/Float(fromMax-fromMin) * Float(num - fromMin) + Float(toMin));
      return x;
   end map;

begin
   --initial pin configuraitons
   MicroBit.IOs.Set(cameraTriggerPin,True);
   MicroBit.IOs.Set(stepPin,False);
   MicroBit.IOs.Set(dirPin,False);
   
   --starting buzzer tone
   buzz(2);
   
   --main loop
   loop
      --change modes
      if MicroBit.Buttons.State (Button_A) = Pressed then
         buzz(1);
         mode := mode+1;
         if mode = 0 then
            MicroBit.Display.Display('A');
            MicroBit.Time.Delay_Ms (1000);
            MicroBit.Display.Clear;
         elsif mode = 1 then
            MicroBit.Display.Display('B');
            MicroBit.Time.Delay_Ms (1000);
            MicroBit.Display.Clear;
         end if;
         
         --wait while the button is release to move forward
         while MicroBit.Buttons.State (Button_A) = Pressed loop
            null;
         end loop;
      end if;

      --running the mode
      if MicroBit.Buttons.State (Button_B) = Pressed then
         potValue := MicroBit.IOs.Analog(potPin);
         case mode is
            -- Number of Images selected by potentiometer
            when 0 =>
               -- number of images taken will be in between 5 to 50
               imgNum := map(Integer(potValue), 0, 1023,1,10) * 5;
               buzz(1);
               for i in 1..imgNum loop
                  moveSteps(totalSteps/imgNum);
                  MicroBit.Time.Delay_Ms (1000);
                  click;
               end loop;


               -- Manual changing the position of the turn table, running in main code
               -- here we only click the image when button is pressed
            when 1=>
               buzz(1);
               click;
         end case;
      end if;
      
      --if mode is 1 then this block will run in every loop to find difference between the potentiometer values and rotate the turn table accordingly
      if mode = 1 then
         potValue := MicroBit.IOs.Analog(potPin);
         steps := map(Integer(Integer(lastPotValue) - Integer(potValue)), 0 , 1023, 0, totalSteps);
         --steps := (Integer(lastPotValue) - Integer(potValue));
         if(abs(steps) > 40 ) then
            lastPotValue := potValue;
            moveSteps_2(steps);
         end if;
         --  MicroBit.Time.Delay_Ms(50);
      end if;

   end loop;
end Main;

Credits

Makertronics

Makertronics

2 projects • 1 follower
I am a maker who loves electronics.

Comments