Uno and Pololu Mc33926 plus toggle and LED for hidden Whiskey shelf

Hello. I'm brand new to the Arduino product. I have an interesting project that I need help with the coding. I've installed a hidden cabinet in a clients basement bar area. In general, here is what I'm trying to accomplish.

  1. When a rocker switch is turned ON, it initiates the process.
  2. a Linear Actuator (wired to Pololu MC33926 Motor shield) drives a wall mounted picture frame up the wall to expose the hidden cabinet. This actuator needs to run for 15 seconds and then STOP.
  3. A 12vdc light (run through a 5vdc external Relay) will turn on after the Rocker Switch has been ON for 10 seconds. This light is built into the bottom of a tray at the bottom of the cabinet.
  4. A second linear actuator will then drive the tray out of the wall (drive for 15 seconds and then STOP). An expensive Whiskey bottle is sitting on this tray (with the light shining through the bottom of it) as a "display item".
  5. The light turns OFF after 60 seconds (adjustable).
  6. When the Rocker Switch is turned OFF, the reverse sequence has to happen (tray actuator moves into the wall, light is turned OFF (if it isn't already OFF), and then 2nd actuator drives wall picture frame back into the original position.

I'm really confused on how to set all of this up in a sketch. I've spent the last 3 days looking at forum's, example code, demo code, etc and my braibn is overloaded to say the least.

Can anyone help with getting the code put together for this awesome project?

So... you are presumably being paid by this client, and you want our help for free?

Tell your client you have not been honest with them and you don't have all the skills you claimed to have. Don't forget to return their money. All of it. Even if that leaves you out of pocket.

I'm not looking for anyone to write the sketch for me. I'm just asking to be pointed in the right direction so I can learn the most efficient way to meet my objective. I can certainly accomplish my project with relays, etc and not even use the Arduino Uno. I wanted to try something new. Sorry for wasting your time.

Prove it. Show us the sketch you attempted to write. Your post just reads like a list of requirements you expected someone else to implement for you.

Show us the design and components you would have used. This will give you some credibility.

I’ll play.

Have you looked at any examples from the IDE? Have you an Arduino, any will do and/ but they cheap anyway, so get one if not, and experimented with just blinking the LED or responding to a switch?

What happens if the rocker switch is toggled before the first sequence is finished?

What happens if the rocker switch is toggled during the second sequence?

How is the time to be adjusted?

TBH this could be done as a trivial program, the challenge is connecting appropriate parts mechanically and supplying power and drive signals to them.

The logic itself is nothing, if you wait nice long enough there are ppl here who will fall all over themselves to prove it…

Have you talked to your friend google? This seems like a variation on a tots common theme, popular DIY stuff like Halowe’en or christmas animatronics or gags.

a7

Fools! They do the work and @tshulett takes the credit and the money.

In case you haven't figured it out yet, today @alto777 is "good cop" and I am "bad cop".

1 Like

Here is my layout with Arduino Uno, Pololu motor shield to drive 2 linear actuators, relay to turn on 12vdc light and rocker switch. There is 2 power supplies. #1 will power the Arduino. #2 will power the Pololu motor shield and the 12vdc light.




Nice parts.

I can almost see the equally nice schematic diagram you've drawn, even by hand, that you are working to.

Hint: that was a hint. :expressionless:

Now read my #6 above and tell us more!

Also, while it will be great fun to get this working, I would advise you to use just the Arduino, the serial monitor, the switch and one or two LEDs to start seeing what the program will look like and how it might act.

The hardware will bring issues of a different kind, no matter how carefully you proceed, and a "divide and conquer" approach will serve you well.

So, get the bits and pieces of hardware working with the very simplest code you can find or write. Google for examples, see if you can start reading code before you try writing it, and get tiny successes going.

Once you are getting happy or are perhaps even totally happy with the software progress and the hardware progress, combining them will be your last bit of fun.

And I honestly do mean fun, this should be lotsa, there's nothing here that hasn't can't you can't do.

a7

You should be ok powering the Uno from the 12V supply via its Vin pin or the barrel socket. It's on-board regulator only has to provide current at 5V for itself and maybe the relay (assuming you made the common mistake of buying a 5V relay for use in a 12V circuit).

I've been trying to set up my sketch using simple code for my toggle switch and then the Library code that came with the Pololu Motor Driver (MC33926). The motor driver code is not what I want. I want to close the rocker switch which then turns on my light and drives the 1st actuator. Once that actuator is fully driven, I want the 2nd actuator to drive 100%.
I have the rocker switch controlling the light. When I add the motor shield code, it drives the 2 actuators, but not how I want them. The library code also screws up my light now due to the 'delays' in the code.
I've tried adding an 'if' line of code (if the rocker is HIGH) to drive the 1st actuator, but I get errors. I'm obviously doing something wrong with using 'if' along with the 'for statements in the code.
Any thoughts on how to set up 'if's with the library code?

/*
 
turn rocker swith ON to start sequence.
 - linear actuator for picture frame (M1A on motor shield) extends arm for approx 30 seconds and then STOPS
 - when toggle switch is ON, send command to turn 12vdc light ON.
 - after M1A actuator is comlpletely stopped (after 30 seconds of driving), start M2A linear actuator (tray shelf)
 - linear actuator M2A extends arm for approx 30 seconds and then STOPS.
With rocker switch OFF: M2A actuator closes for 30 seconds(actuator arm returns), 12vdc light turns off, and actuator M1A then closes for 30 seconds.
*/

const int rockerSwitch = 6;  //give the switch pin a name 
#include "DualMC33926MotorShield.h"

DualMC33926MotorShield md;

void stopIfFault()
{
  if (md.getFault())
  {
    Serial.println("fault");
    while(1);
  }
 }

void setup() 
{
   Serial.begin(115200);
   pinMode(rockerSwitch, INPUT_PULLUP);   //the rocker switch input will be HIGH (1) when the switch is off and LOW (0)when the switch is ON
   Serial.println("Dual MC33926 Motor Shield");
   md.init();
}

void loop()

{  
  int rockerState = digitalRead(rockerSwitch);
  Serial.println(rockerState);
  
  for (int i = 0; i <= 7000; i++)
  {
    md.setM1Speed(i);
    stopIfFault();
    if (abs(i)%200 == 100)
    {
      Serial.print("M1 current: ");
      Serial.println(md.getM1CurrentMilliamps());
    }
    delay(2);
  }
  
  for (int i = 7000; i >= -7000; i--)
  {
    md.setM1Speed(i);
    stopIfFault();
    if (abs(i)%200 == 100)
    {
      Serial.print("M1 current: ");
      Serial.println(md.getM1CurrentMilliamps());
    }
    delay(2);
  }
  
  for (int i = -7000; i <= 0; i++)
  {
    md.setM1Speed(i);
    stopIfFault();
    if (abs(i)%200 == 100)
    {
      Serial.print("M1 current: ");
      Serial.println(md.getM1CurrentMilliamps());
    }
    delay(2);
  }

  for (int i = 0; i <= 7000; i++)
  {
    md.setM2Speed(i);
    stopIfFault();
    if (abs(i)%200 == 100)
    {
      Serial.print("M2 current: ");
      Serial.println(md.getM2CurrentMilliamps());
    }
    delay(2);
  }
  
  for (int i = 7000; i >= -7000; i--)
  {
    md.setM2Speed(i);
    stopIfFault();
    if (abs(i)%200 == 100)
    {
      Serial.print("M2 current: ");
      Serial.println(md.getM2CurrentMilliamps());
    }
    delay(2);
  }
  
  for (int i = -7000; i <= 0; i++)
  {
    md.setM2Speed(i);
    stopIfFault();
    if (abs(i)%200 == 100)
    {
      Serial.print("M2 current: ");
      Serial.println(md.getM2CurrentMilliamps());
    }
    delay(2);
  }
}

  

A valiant effort, no doubt.

I don't see the rocker switch controlling anything. Not in the code that is.

What is each of those very similar for loops doing? I don't think we all gonna go learn all about that library, what it is meant to do and how it is expected to be used for linear actuators. Tell us and we'll have a better idea of what you are doing, and that you know what you are doing.

Guesswork can, work that is, but neither we nor you will spend time best guessing.

And srsly, I say again at more than the risk of repeating myself, get something working to show the logic and flow and timing before you complicate things with the motor stuff. Even just with Serial.print statments.

BTW, what's showing up in the serial monitor? Does that making any sense?

There is no if statement in your code that appears to do anything other than print some diagnostical information about the motor current.

Have you worked with the linear actuators starting from some examples that were already written?

This stuff is a PITA, and can be hard until it isn't. Slow your roll, take small steps, get inspired by little successes.

a7

Here's my code for the rocker switch and the light. It works and I can see it on the serial monitor.


const int RELAY_PIN = 5;  // the Arduino pin, which connects to the IN pin of relay
const int rockerSwitch = 6;  //give the switch pin a name 
int curRel1;

void setup() {
 Serial.begin(115200);
   pinMode(rockerSwitch, INPUT_PULLUP);   //the rocker switch input will be HIGH (1) when the switch is off and LOW (0)when the switch is ON
   pinMode(RELAY_PIN, OUTPUT);
   curRel1 = digitalRead(RELAY_PIN);
}

void loop() {
  int rocker = digitalRead(rockerSwitch);
  {
  if(rocker == HIGH)
    { digitalWrite(RELAY_PIN, LOW);
    }
    if(rocker == LOW)
    {digitalWrite(RELAY_PIN, HIGH);
    }
   Serial.println(rocker);
   }

}

The Library code that I uploaded for the motor (from the Pololu site) is generic and not what I want. My trouble is in trying to modify this code. All the hardware links, etc are built into the code, so I want to keep the basics of it, but need to change most of the actual lines of code to do what I want. This is where I run into trouble.

Haha, that's where we all run into trouble and work.

Here's what I mean, see if you can take your English prose description and start writing the skeleton of a simple program that starts to do what you want:

It's just a dumb literal program that takes some steps based on the switch. I did not try to implement your sequence, this is just an example of getting somewhere before you start messing with the motors.

How are you planning to control the actuators so they, um, actuate the right amount?

The demo code you seem to be modifying looks like it just makes a regular motor gradually speed up, slow down, reverse and repeat.

You need to run an actuator until... well until it has travelled far enough, which might not be best done by simply running it for some time. But with the crude kind of code from the simulation, you can run them and see.

Imma guess

    md.setM1Speed(200);

might make it just go,

    md.setM1Speed(0);

might make it stop

and

    md.setM1Speed(-200);

might make it go the other way.

HTH

a7