Category Archives: Arduino

Arduino programming and hardware questions answered

I’m trying out a new service.

A lot of my Arduino project building business comes from people who have an urgent project and got in way over their head. They’ve selected components, started learning about the Arduino ecosystem and begun learning to code.

Then Life Happens. The project has to be pushed back since they don’t have time to learn what they need to, or other issues come up, so they turn to me to redo the job from scratch, or clean it up.

However, a fair number of people are just stuck on a particular problem and could continue if they became “unstuck.” You can turn to online forums in this case, but they can be hit or miss. Sometimes you get the perfect answer, other times people are rude to newcomers, snarky, make you feel unwelcome, or just give bad info. Also, even when you’ve been told “just Google it,” it’s pretty hard to “just Google it” for something technical like an Arduino sensor if you don’t even know what the search terms would be. Does this sound familiar?

So here’s our new service. I’ll answer your Arduino questions for a set fee. You will receive polite, respectful, and timely help at reasonable rates. Unlike anonymous forums, we have a vested interested in proving useful help and keeping you happy.

As far as rates go, the introductory price is $25 for a single question, $100/week for one question per day or $350/month for unlimited questions.

An example question would be: “why does this function fail after it’s been running for a while? Or, what’s the difference between all these sensors and which one should I select, and why?”

Now, clearly with the cost of software development being what it is, we can’t write custom sketches at these prices, but we can point out where a sketch is wrong or should be rewritten. If you need help selecting a peripheral like a solenoid valve or a Photomultiplier tube for your Arduino, we’ll do the research for you. If we feel we can’t do your question justice, you will receive a refund.

For some of the more unusual or newer products, we may have to do substantial research, and there are likely going to be a few questions we will have to decline and refund your money because proprietary information that we don’t have access to can be involved. But by and large, I’m sure that the service will help a lot of people be successful with their Arduino projects.

But I feel it’s worth a try. I know there are people that need questions answered who aren’t getting the assistance they deserve.
Click on the button below and it will take you to a payment page for the single, $25 answer. I will respond to your question within 24 hours. I also use this $25 level as my “tip jar.” Sometimes when I help someone online (with no expectation of payment), they are so grateful they’d like to reciprocate, so this works to leave a small payment.


Single Arduino Question


If you prefer, I am also available for more extended help on codementor

To solder or not to solder…

… that is the question.

Should you solder connections between your Arduino and external boards?

Soldering is a method of making electrical and (usually) minor structural connections. It can be a permanent and reliable connection that lasts for decades. Sometimes, however, that can be a drawback since soldered connections make it harder to replace or upgrade external boards when they fail. It’s also not a panacea: while a properly constructed soldered joint can be very strong, the point where the solder ends tends to be brittle and can lead to failures if that section of the wire moves. The typical remedy for this is a strain relief — secure the wire so it can’t move or vibrated.

Pin and socket connections are a popular alternative to soldering, especially in the Arduino world where many newcomers don’t have soldering experience. They too can be very reliable: a snug fit between pin and socket can be gas-tight and resist corrosion for a very long time. It has a similar drawback to soldered connections when the item is in an area subject to vibration: the wires can come loose. Typical solutions for this are to use cable connectors with ramps, clips, or other locking mechanisms. For the popular Arduino wire jumpers, they can be bundled in groups and secured with wire ties.  By tying them together, they behave more like a single connector with a group of wires and it takes more force to dislodge them. Also, the wire bundle can be secured to a fixed point, so it won’t move.

Some single-wire terminations such as Faston terminals actually dislodge a small amount of metal when the connection is made. They fit so tightly that no additional wire restraint is needed.

So solder, or pins for wire to board connection? In the end they’re both quite useful and reliable, but my preference is generally for pin and socket. Their versatility far outstrips the few drawbacks.

Enclosures for Arduino projects

I made a post over at the popular Arduino forum on a topic where someone was inquiring about available enclosures. The community tends to respond “just 3D print one” but that’s a mistake in my opinion.

3D printing, while useful, seems pointless to me unless you’re looking for something not available off the shelf. Even then, the 3D  print falls short if you need a transparent cover, or a NEMA4X /IP66 (washdown-proof) rating, or any number of other structural properties. That off the shelf $20 polycarbonate case has a lot of engineering time put into it and provides a huge amount of convenience.
As far as laser cut enclosures are concerned, I’ve yet to find one that doesn’t look completely ugly like something a 6 year-old put together for a craft class.

Seriously, burnt wood edges is not a professional look! I have seen professional enclosures for large machines made out of wood and particle board and you’d never know what the material was.  When designed by an engineer who knows what he’s doing, wood can be a fantastic material.

The amateurish laser-cut “snap together jigsaw cases” all look like crap in my opinion. And that’s a pity, because you can do some great stuff with a laser cutter. It’s just that the community has apparently decided to embrace the lowest common denominator design quality.

My gotos for great cases are Polycase & Bud for plastic wall and desk mount enclosures. Hammond for metal enclosures (although Bud has some nice aluminum cast boxes). Serpac or OPC for handheld/belt mount types. Altech for industrial enclosures with electrical knockouts (although Polycase is now carrying those also).

I’ll probably update this list over time.

Connect bill acceptor or coin acceptor to PC

One interesting application for our PRT232 pulse counter is reading bill acceptors and coin acceptors from a desktop computer.

A coin acceptor is used to pay for a product or service. You’re probably quite familiar with them from using commercial laundry machines or video game arcades. In these situations, they are built into the equipment. However we are seeing an increase in cases where someone is adding a payment facility via a bill acceptor or a coin acceptor to equipment that was not designed for it. An example would be a kiosk that dispenses water. There are many of these in grocery stores where you can fill up your bottle with pure water and then pay for it at the counter. But many entrepreneurs are taking water dispensers and making it possible for the customer to pay directly at the point of sale.

These acceptors work by sending a number of pulses corresponding to the coin or bill that is entered. e.g., a quarter may provide a single pulse while a dollar bill gives four pulses. Our pulse counting devices are obviously a natural fit for the application. They will accept the pulse output from the coin acceptor, count the pulses and provide a  serial RS232  interface to the PC making it simple to tally the dollar amount entered.

By using a counter to RS232 device like our PRT232 or PRT232F (6 count inputs), now the PC computer can be used to track usage, make automated daily reports, provide the customer enhanced user interface and so improve your sales performance.

We provide a sample of software that uses the PRT232 as a dispense controller. It can be easily modified for your own use. We also offer custom software and hardware development in this area.

One example of what we have done is the situation when the bill acceptor must be connected to a machine that doesn’t correspond exactly with its operation. For example, perhaps you are building a vacuum cleaner that the operator pays to use (as often found at a car wash). The vacuum may have been designed to start with a contact closure, but in order to use your coin acceptor, you must translate the four pulses from four quarters being deposited into a single output. We have designed electronics to solve exactly this situation. If you need something similar, contact us.

Arduino Programming: About time

Time is probably the most commonly controlled process variable. Timers are all over the place in industrial control. Odds are, if you need some type of timer, no matter how strange, you can find it off the shelf.

Now, many of these timers used a chip usually referred to as the “555.” The LM555 originally made by (I think; someone will correct me) National Semiconductor was a very versatile device, but it was at the heart of many time-delay relays, short timing circuits, etc.

So once upon a time, if you wanted to build a basic timer, odds are you would wire up a 555 into a circuit. To build a handful, or just one, you’d use a perf board,

perfboardmaybe you might use wire wrap or even dead-bug construction (my favorite!)

deadbug

It would be time consuming,but maybe you had no choice because the timer had some weird requirement that no off the shelf timer had, or needed to fit into an oddly shaped space.

What does this have to do with Arduinos? Well, you can program any timing sequence into an Arduino. Say you want the heater on a commercial ironing board to come on for five seconds when the operator lowers it, a 555 does it easily. If you want the heater to come on for five seconds and when the board is raised again, a fan to blow for 10 seconds to cool the clothing, the 555 can still be used. Maybe you need two of them. But now, the Arduino becomes an easier solution. Whether you need one time sequence, or dozens, a single Arduino can be programmed to do it. When you factor in the labor of wiring a circuit board with the 555, the low off the shelf price of the Arduino makes it even more attractive.

This is the wonder of the time we live in: an off the shelf microprocessor board is now inexpensive enough to be used for logic replacement.

Amazing

Arduino Programming: Turn water on with Arduino and solenoid valve

Arduinos are popular small microcontroller boards that have many applications. However, they’re not designed to switch loads above a few milliamps: say a couple LEDs or so. While power-driver shields do provide this capability, they also can consume more resources than you may be able to give up.

We developed a high current driver to make it easy to control a solenoid valves with Arduino. It will also control pumps and motors. With an adapter cable, it can easily connect to your Arduino, BeagleBone, Raspberry Pi or other digital controller without soldering or crimping any connections. Doesn’t get any easier than that.

PwrDrvr1

The power driver board was born out of a need for controlling a 1 amp solenoid valve using an Arduino.  The solenoid valve was being used to control the water flow to fill a tank automatically. Now there’s a simple way to use your Arduino or compatible to switch up to 3A at 24VDC. Two output connections (the white wires shown above) connect directly the load (your solenoid, relay, motor, etc) and the power (red, black) go to the power supply (5 -24 volts). The orange lead is used to switch on and off. This is a low-voltage (5V) control that can connect directly to a microcontroller, or development board. An onboard LED indicates when the load is switched on.

Here’s some sample code that implements a timer with an Arduino. When the pushbutton is pressed, it turns on water flow for 3 seconds

// This sketch demonstrates a simple timer
// A load (motor, solenoid, relay, solenoid valve is on Pin 1
// A pushbutton to trigger the timer start is on pin 2
//
// When the pushbutton is held down for more than 0.1 second 
// then released, the timer starts
// and times out after 3 seconds
//
// Timer is retriggerable: if pushbutton pressed 
// during the timeout period, timer restarts
//
// Constant definitions
#define LOOP_INTERVAL 10
#define TIMEOUT 300 * LOOP_INTERVAL
#define TRIGGER_INTERVALS 10
#define TIMER_INACTIVE -1
#define TRIGGER_PIN 0
#define OUTPUT_PIN 1

void setup()
{
  pinMode(OUTPUT_PIN, OUTPUT);
  pinMode(TRIGGER_PIN, INPUT_PULLUP);
}

void loop()
{
  static int count = 0;
  static int timer = TIMER_INACTIVE;
  // Process loop periodically
  delay(LOOP_INTERVAL);
  
  // Check trigger input
  if (digitalRead(TRIGGER_PIN) == LOW)
  {
    // Must hold down pushbutton for the entire interval and 
    // then release to trigger
    count++;
  }
  else
  {
    // push button released. Check if we should start timing
    if (count >= TRIGGER_INTERVALS)
    {
      // Turn output ON (timeout is retriggerable)
      digitalWrite(OUTPUT_PIN, HIGH);
      timer = TIMEOUT;
    }
    count = 0;
  }
  
  // If timer active, count down
  if (timer != TIMER_INACTIVE)
  {
    timer -= LOOP_INTERVAL;
    if (timer == 0)
    {
      // Turn output OFF
      digitalWrite(OUTPUT_PIN, LOW);
      timer = TIMER_INACTIVE;
    }
  }
}      

Let’s find out what new applications you can come up with.

Power Driver ($11.95 shipping included)




Arduino Programming: hydraulic shock control from pushbutton

This was a response to an online request for help with code. A single  pushbutton cycles through three hydraulic damper valve settings. The code was too long to post on the site, so I’m showing it here.

As of today, I don’t know if it will work, but it explains the concept. I will get it working as time permits

// Digital output definitions
#define RED_OUTPUT 0
#define BLUE_OUTPUT 1
#define GREEN_OUTPUT 2

// Digital input definitions
#define SWITCH_INPUT 3

// Define states
#define RED 800
#define BLUE 801
#define GREEN 802

// Define message types
#define NONE 901
#define CLICK 902
#define PRESS 903
   
// Global state
int _state = GREEN;

// One-time call to initialize system
void setup()
{
   pinMode(SWITCH_INPUT, INPUT_PULLUP);
   pinMode(RED_OUTPUT, OUTPUT);
   pinMode(BLUE_OUTPUT, OUTPUT);
   pinMode(GREEN_OUTPUT, OUTPUT);
   // Enable GREEN state
   digitalWrite(GREEN_OUTPUT, HIGH);
}

// Continuously called by Arduino runtime
void loop()
{
   // Read pushbutton
   int message = readSwitch();
   // Update LEDs and hydraulic valve if state changed
   if (processState(message))
   {
      activateOutput(_state);
   }
}

// Read pushbutton and return the result
int readSwitch()
{
   const int CLICK_UPPER_LIMIT = 200;
   const int CLICK_LOWER_LIMIT = 25;
   const int PRESS_LOWER_LIMIT = 1000;
   const int PRESS_UPPER_LIMIT = 2000;

   int switchMessage = NONE;
   unsigned long start = micros();
   while (digitalRead(SWITCH_INPUT) == LOW);
   unsigned long duration = micros() - start;
   if (duration < CLICK_UPPER_LIMIT && duration > CLICK_LOWER_LIMIT)
   {
      switchMessage = CLICK;
   }
   else if (duration > PRESS_LOWER_LIMIT && duration < PRESS_UPPER_LIMIT)
   {
      switchMessage = PRESS;
   }
   return switchMessage;
}

bool processState(int message)
{
   static int lastState = GREEN;
   int retVal = 0;

   // PRESS overrides CLICK in all states
   if (message == PRESS)
   {
      _state = GREEN;
   }
   else
   {
      // Process states
      switch (_state)
      {
         case RED:
            if (message == CLICK)
            {
               _state = BLUE;
            }
         break;
            
         case BLUE:
            if (message == CLICK)
            {
               _state = RED;
            }
         break;
            
         case GREEN:
            if (message == CLICK)
            {
               _state = RED;
            }
         break;
            
         default:
         break;
      }
   }
   // Did state change?
   retVal = (lastState == _state);
   // Remember this state
   lastState = _state;
   // Return state changed information
   return retVal;
}

void activateOutput(int thisState)
{
   // Since this is only called on state change, OK to turn everything off first
   digitalWrite(RED_OUTPUT, LOW);
   digitalWrite(GREEN_OUTPUT, LOW);
   digitalWrite(BLUE_OUTPUT, LOW);
   // Turn on only the output corresponding to the state
   switch (thisState)
   {
       case RED:
         digitalWrite(RED_OUTPUT, HIGH);
         break;         
       case BLUE:
         digitalWrite(BLUE_OUTPUT, HIGH);
         break;      
       case GREEN:
         digitalWrite(GREEN_OUTPUT, HIGH);
         break;
      default:
         break;
   }   
}