Links to the most popular posts.
A short while ago I was contacted by Seeed Studios to see if I was interested in receiving some of their product for review. They would give me US $50 to spend in their shop on anything I wanted and in return I would review and write about the items I received. I have been offered stuff before and generally don’t accept. Many of the things offered are not really relevant to this site or the things I play with. I also get guilty because few things I did receive I never got time to actually write about. A few years ago I received some of the very first ESP32 development boards and they are still in the box they came in. Ironically I have bought many more ESP32 modules since and haven’t used those either (I’m still learning ESP8266). Any way, after some back and forth with Seeed by email I agreed and started looking at the items in the Seeed shop.
A very short post I made sometime ago has been more popular that it should have been. It wasn’t particularly detailed and it was in desperate need of an update. So here is the update, this time giving more details and adding mosfets.
Arduinos are limited in the current and voltage they can supply. A typical 5V Arduino can provide 5V and 3.3v at a maximum 40mA from a single pin. 40mA is the maximum and ideally the current draw should be kept to around 20mA. 20mA is fine for a LED but not so good for motors, solenoid valves or long strings of RGB LEDs. For these we need a separate power supply and a way of controlling it.
One of the problems many beginners have is knowing what can be connected to and Arduino and what should not be. This post does not really help with this except to show how to use a high voltage/high current device with the Arduino. The high voltage/current is not connected directly to the Arduino but it can controlled by the Arduino by using devices that act as digital switches.
Knowing what to connect and what not to comes from experience and a little understanding of volts and current. I do not cover this here beyond saying voltages should match and currents are more difficult to determine. I have killed/partially killed more things because of current than I have because of volts simply because most things clearly say what voltage they are, A 24v power supply says 24v on it and I know I shouldn’t connect it to an Arduino. A very small 6v motor that looks like it hardly required power melted an Arduino with seconds. Finding a devices current requirement may mean reading data sheets and extensive online searches. Unfortunately Arduinos do not give a warning when a device wants more current than they can supply, they simply tries to provide it. This leads to over heating and mini explosions (or at least a dead Arduino and the smell of burnt plastic).
In this post I am using DC voltage solenoid valves only. Valves that use AC have very different requirements and the below does not apply. Most DC solenoid valves tend to use a voltage any where from 6v up and 12V and 24V are very common. The one I am using below is 24v. The Arduino cannot handle these voltages and so cannot (or should not) be connected directly to the valve. Instead, we use another device as a middleman, one that can accept the 5v signal from the Arduino as a control signal and also handle the higher voltage and current required by the valve. There are various different devices that can fulfill this role. I am using transistors. The Arduino controls the transistor and the transistor controls the valve. A simple way of thinking about this is we are using the transistor as a switch. The Arduino is controlling the switch and the switch is controlling the valve.
There are many transistors you can use and you pick one depending on the voltage and current you need to control. To know the voltage and current required means knowing about the device you want use. Here I am using the good old TIP120 and the IRFZ44N mosfet. Why these 2 devices? Because they are what I have. They were purchased sometime ago purely because they are suitable for use with 5v Arduinos.
In part 3 we sent and received single characters to control LEDs using a fairly simple technique. If all you need is to remotely turn a few things on and off then this method is probably the best. It is simple, easy to program, and reliable. Sometimes though single characters are not enough and we need to use more complex commands or we may want to send sensor data that comprises more than one character.
In this post I look at a few different techniques for sending complex data and commands; starting with functions that are built in the Arduino language and moving to our own functions that, IMHO, perform better and allow for better code.
In the last post I briefly talked about different data formats and how I recommend keeping things as simple as possible. With this is mind for a first project let’s create a simple blinking LED. We will have one Arduino controlling an LED on a second Arduino. Controls to turn the LED on or off will be sent via serial from the first Arduino to the second Arduino. This is as basic as it gets. Arduino Blink by remote control. The LED has only two states so simple control codes can be used and to start I am using 1 of on and 0 for off.
In these examples I am using Arduino Nanos but any kind of Arduino can be used and for this series I am using Arduino to Arduino communication. The techniques are exactly the same for any UART to UART device. For example, in Arduino to Arduino by Bluetooth I use exactly the same serial communication techniques wirelessly over Bluetooth.
In the previous post I went through the basics of using serial on an Arduino and ran through the different commands. In this post I want to talk about different types of serial data and some of the things you should consider before starting to create code. The type of communication you use or can use will depend largely on the project but there are things that can be considered before starting.
- Type of communication? 1-way or 2-way
- Type of data? Values or strings? Simple or complex?
- How much data and how frequent? A couple of values every few seconds or a high rate continuous stream.
- Is the data critical? Must you be sure you receive all the data or can you afford to lose some of it.
Here we look at using serial communication on the Arduino. Serial UART is one of the various ways an Arduino can communicate with other devices. This includes a host PC and using the Arduino serial monitor is communicating with the PC using serial UART.
Arduino Serial Monitor
End Of Line Characters
Formatting output using the tab command
How fast is serial
Different Arduino Serials
Using a software UART and usb adapter to talk to a PC
So far I have gone through controlling LEDs from a simple web app where all control is done via buttons in the app. This works well but you need to click a button in the app to make things happen, some kind of user action is required to update the webpage. Here we start to look at getting a webpage to update itself.
We have seen how to control one LED, here we add two more.
The RN4870/1 is a small (only 12mm wide) BLE module from Microchip. What makes this a little bit special (when compared to modules like the HM-10) are the advanced features that allow you to create your own services and characteristics. This opens up true BLE functionality. It has been available for a while now and I am surprised it is not more popular in the hobby area.
The RN4870 is very different to common hobbyist modules like the HM-10, AT-09, and BT05 and if this is all you have used you may need a refresher on BLE. Especially if you want to use your own services and characteristics.
This is a first look / getting started guide that I will add to as I get time.
Latest update: May 27, 2018
In the previous guides we connected the ESP8266 to a local network using hard coded credentials. It is fine for messing around with examples and when developing sketches but not very convenient or practicle for final projects.
What happens if you want to move the ESP8266 to another network or if you buy a new router? You need to change the sketch and re-upload. It would be better if we could pick the network to use at run time. This is exactly what WifiManager allows.
This post continues the Arduino, HM-10 and App Inventor 2 guide. A few people asked about adding a slider so here it is. Please beware; this is not a basic guide for using a slider in App Inventor 2. I am adding a slider to an existing app and have certain things (semi advanced) that I want to achieve.
In the previous guide we created a basic Android app to control 3 LEDs. The app was developed in such a way to make adapting it as easy as possible. So let’s see if that is true and add a slider to control the brightness of one of the LEDs. We start with extending the app and then update the Arduino sketch.
Using the same command method as before, we will create an ascii command and send it to the Arduino. The command will be in the form “[Snnn]”. Where S is used to denote slider and nnn is a value from 0 to 255, or more specifically “000” to “255”. The Arduino will read the command and set the LED brightness accordingly. Using ascii for this keeps things fairly simply but it is not the fastest way to do it. The slider value will be from 0 to 255, this is actually the same value range as an 8bit byte. Using the ascii command we need 6 characters (including the square brackets). To send the actual value only would require 1 character (2 with a label/marker character). If all you are using is a single slider then there is no reason to use ascii.
Here we create a basic Classic Bluetooth joypad for use on an Android device to control a microprocessor (Arduino) connected to a Bluetooth module. The app is fairly simply. There are 2 screens; the first is the main control panel and the second is a connection page.
When the CONNECT button on the main screen is clicked the second screen is opened to allow the user to connect to a Bluetooth device. The direction buttons, when clicked, transmit codes to the Arduino.
Update: The BLE extension included with the examples is out of date and does not function fully any more. Download the latest version from the app inventer BLE extention download and replace the existing extension. Do not delete the old version, upload the new version and it will over write the older version.
You can check the latest version of the BLE extension on the app inventor BLE page.
Hopefully this guide will give you a good introduction to using the HM-10 with App Inventor 2. I also hope that this takes you beyond the usual starter guides that do not go past very basic information.
Although I am using an Arduino the principles will be the same for any other microprocessor or indeed for using the HM-10 on its own. Warning: This is going to be a very long post.
To use this guide you should be somewhat familiar with App Inventor, have a BLE enabled Android device, and of course have an Arduino and a HM-10.